Bug 1288434 - Add task to mark release as shipped. r=rail a=release DONTBUILD
authorMihai Tabara <mtabara@mozilla.com>
Fri, 26 Aug 2016 12:47:18 +0300
changeset 349960 e02ff365129834713735afeb44d9d4b4490687e1
parent 349959 e58e63e362ff2a402bc7f22f0193097d07c418f1
child 349961 4d38a69eda61f663463af8f020447e9afbb118b1
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrail, release
bugs1288434
milestone50.0a2
Bug 1288434 - Add task to mark release as shipped. r=rail a=release DONTBUILD MozReview-Commit-ID: 9NBQK4BcDUe
testing/mozharness/configs/releases/dev_postrelease_firefox_beta.py
testing/mozharness/configs/releases/dev_postrelease_firefox_release.py
testing/mozharness/configs/releases/postrelease_firefox_beta.py
testing/mozharness/configs/releases/postrelease_firefox_esr45.py
testing/mozharness/configs/releases/postrelease_firefox_release.py
testing/mozharness/scripts/release/postrelease_mark_as_shipped.py
--- a/testing/mozharness/configs/releases/dev_postrelease_firefox_beta.py
+++ b/testing/mozharness/configs/releases/dev_postrelease_firefox_beta.py
@@ -9,9 +9,11 @@ config = {
         "dest": "date",
         "vcs": "hg",
     },
     # date is used for staging mozilla-beta
     "push_dest": "ssh://hg.mozilla.org/projects/date",
     "ignore_no_changes": True,
     "ssh_user": "ffxbld",
     "ssh_key": "~/.ssh/ffxbld_rsa",
+    "ship_it_root": "https://ship-it-dev.allizom.org",
+    "ship_it_username":  "stage-ffxbld",
 }
--- a/testing/mozharness/configs/releases/dev_postrelease_firefox_release.py
+++ b/testing/mozharness/configs/releases/dev_postrelease_firefox_release.py
@@ -11,9 +11,11 @@ config = {
         "branch": "default",
         "dest": "jamun",
         "vcs": "hg",
     },
     "push_dest": "ssh://hg.mozilla.org/projects/jamun",
     "ignore_no_changes": True,
     "ssh_user": "ffxbld",
     "ssh_key": "~/.ssh/ffxbld_rsa",
+    "ship_it_root": "https://ship-it-dev.allizom.org",
+    "ship_it_username":  "stage-ffxbld",
 }
--- a/testing/mozharness/configs/releases/postrelease_firefox_beta.py
+++ b/testing/mozharness/configs/releases/postrelease_firefox_beta.py
@@ -7,9 +7,11 @@ config = {
         "dest": "mozilla-beta",
         "vcs": "hg",
     },
     "vcs_share_base": "/builds/hg-shared",
     "push_dest": "ssh://hg.mozilla.org/releases/mozilla-beta",
     "ignore_no_changes": True,
     "ssh_user": "ffxbld",
     "ssh_key": "~/.ssh/ffxbld_rsa",
+    "ship_it_root": "https://ship-it.mozilla.org",
+    "ship_it_username":  "ffxbld",
 }
--- a/testing/mozharness/configs/releases/postrelease_firefox_esr45.py
+++ b/testing/mozharness/configs/releases/postrelease_firefox_esr45.py
@@ -11,9 +11,11 @@ config = {
         "dest": "mozilla-esr45",
         "vcs": "hg",
     },
     "vcs_share_base": "/builds/hg-shared",
     "push_dest": "ssh://hg.mozilla.org/releases/mozilla-esr45",
     "ignore_no_changes": True,
     "ssh_user": "ffxbld",
     "ssh_key": "~/.ssh/ffxbld_rsa",
+    "ship_it_root": "https://ship-it.mozilla.org",
+    "ship_it_username":  "ffxbld",
 }
--- a/testing/mozharness/configs/releases/postrelease_firefox_release.py
+++ b/testing/mozharness/configs/releases/postrelease_firefox_release.py
@@ -11,9 +11,11 @@ config = {
         "dest": "mozilla-release",
         "vcs": "hg",
     },
     "vcs_share_base": "/builds/hg-shared",
     "push_dest": "ssh://hg.mozilla.org/releases/mozilla-release",
     "ignore_no_changes": True,
     "ssh_user": "ffxbld",
     "ssh_key": "~/.ssh/ffxbld_rsa",
+    "ship_it_root": "https://ship-it.mozilla.org",
+    "ship_it_username":  "ffxbld",
 }
new file mode 100644
--- /dev/null
+++ b/testing/mozharness/scripts/release/postrelease_mark_as_shipped.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+# lint_ignore=E501
+# ***** BEGIN LICENSE BLOCK *****
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+# ***** END LICENSE BLOCK *****
+""" postrelease_mark_as_shipped.py
+
+A script to automate the manual way of updating a release as shipped in Ship-it
+following its successful ship-to-the-door opertion.
+"""
+import os
+import sys
+from datetime import datetime
+
+sys.path.insert(1, os.path.dirname(os.path.dirname(sys.path[0])))
+
+from mozharness.base.python import VirtualenvMixin, virtualenv_config_options
+from mozharness.base.script import BaseScript
+from mozharness.mozilla.buildbot import BuildbotMixin
+
+
+def build_release_name(product, version, buildno):
+    """Function to reconstruct the name of the release based on product,
+    version and buildnumber
+    """
+    return "{}-{}-build{}".format(product.capitalize(),
+                                  str(version), str(buildno))
+
+
+class MarkReleaseAsShipped(BaseScript, VirtualenvMixin, BuildbotMixin):
+    config_options = virtualenv_config_options
+
+    def __init__(self, require_config_file=True):
+        super(MarkReleaseAsShipped, self).__init__(
+            config_options=self.config_options,
+            require_config_file=require_config_file,
+            config={
+                "virtualenv_modules": [
+                    "shipitapi",
+                ],
+                "virtualenv_path": "venv",
+                "credentials_file": "oauth.txt",
+                "buildbot_json_path": "buildprops.json",
+                "timeout": 60,
+            },
+            all_actions=[
+                "create-virtualenv",
+                "activate-virtualenv",
+                "mark-as-shipped",
+            ],
+            default_actions=[
+                "create-virtualenv",
+                "activate-virtualenv",
+                "mark-as-shipped",
+            ],
+        )
+
+    def _pre_config_lock(self, rw_config):
+        super(MarkReleaseAsShipped, self)._pre_config_lock(rw_config)
+        # override properties from buildbot properties here as defined by
+        # taskcluster properties
+        self.read_buildbot_config()
+        if not self.buildbot_config:
+            self.warning("Skipping buildbot properties overrides")
+            return
+        props = self.buildbot_config['properties']
+        mandatory_props = ['product', 'version', 'buildnumber']
+        missing_props = []
+        for prop in mandatory_props:
+            if props.get(prop):
+                self.info("Overriding %s with %s" % (prop, props[prop]))
+                self.config[prop] = props.get(prop)
+            else:
+                self.warning("%s could not be found within buildprops" % prop)
+                missing_props.append(prop)
+
+        if missing_props:
+            raise Exception("%s not found in configs" % missing_props)
+
+        self.config['name'] = build_release_name(self.config['product'],
+                                                 self.config['version'],
+                                                 self.config['buildnumber'])
+
+    def mark_as_shipped(self):
+        """Method to make a simple call to Ship-it API to change a release
+        status to 'shipped'
+        """
+        credentials_file = os.path.join(os.getcwd(),
+                                        self.config["credentials_file"])
+        credentials = {}
+        execfile(credentials_file, credentials)
+        ship_it_credentials = credentials["ship_it_credentials"]
+        auth = (self.config["ship_it_username"],
+                ship_it_credentials.get(self.config["ship_it_username"]))
+        api_root = self.config['ship_it_root']
+
+        from shipitapi import Release
+        release_api = Release(auth, api_root=api_root,
+                              timeout=self.config['timeout'])
+        shipped_at = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
+
+        self.info("Mark the release as shipped with %s timestamp" % shipped_at)
+        release_api.update(self.config['name'],
+                           status='shipped', shippedAt=shipped_at)
+
+
+if __name__ == '__main__':
+    MarkReleaseAsShipped().run_and_exit()