testing: Optionally set BMO API key description (bug 1237491). r?smacleod draft
authorMark Cote <mcote@mozilla.com>
Wed, 09 Mar 2016 19:45:34 -0500
changeset 7521 415fadef62d44b97df92d3445aec65b00b625a2e
parent 7520 33c7af66b068439328d0b66cecfe97f0f9a5ef10
child 7522 6d28f90f0fbda2c1206bb5c4fd235820b5a25078
push id700
push usermcote@mozilla.com
push dateFri, 18 Mar 2016 00:41:48 +0000
reviewerssmacleod
bugs1237491
testing: Optionally set BMO API key description (bug 1237491). r?smacleod MozReview-Commit-ID: DPIonL6YfcO
testing/vcttesting/mozreview.py
testing/vcttesting/mozreview_mach_commands.py
--- a/testing/vcttesting/mozreview.py
+++ b/testing/vcttesting/mozreview.py
@@ -283,17 +283,17 @@ class MozReview(object):
             e.submit(self._docker.execute, self.rbweb_id,
                      ['/set-site-url', self.reviewboard_url,
                       self.autoland_url, self.bugzilla_url])
 
             # Tell Bugzilla about Review Board URL.
             e.submit(self._docker.execute, mr_info['web_id'],
                      ['/set-urls', self.reviewboard_url])
 
-        self.create_user_api_key(bugzilla.username)
+        self.create_user_api_key(bugzilla.username, description='mozreview')
 
         hg_ssh_host_key = self._docker.get_file_content(
                 mr_info['hgrb_id'],
                 '/etc/ssh/ssh_host_rsa_key.pub').rstrip()
         key_type, key_key = hg_ssh_host_key.split()
 
         assert key_type == 'ssh-rsa'
         key = paramiko.rsakey.RSAKey(data=paramiko.py3compat.decodebytes(key_key))
@@ -503,29 +503,30 @@ class MozReview(object):
 
         # TODO make pushes via SSH work (it doesn't work outside of Mercurial
         # tests because dummy expects certain environment variables).
         return LocalMercurialRepository(self._path, self._hg, local_path,
                                         http_url, push_url=ssh_url, ircnick=ircnick,
                                         bugzilla_username=bugzilla_username,
                                         bugzilla_apikey=bugzilla_apikey)
 
-    def create_user_api_key(self, email, sync_to_reviewboard=True):
+    def create_user_api_key(self, email, sync_to_reviewboard=True,
+                            description=''):
         """Creates an API key for the given user.
 
         This creates an API key in Bugzilla and then triggers the
         auth-delegation callback to register the key with Review Board. Note
         that this also logs the user in, although we don't record the session
         cookie anywhere so this shouldn't have an effect on subsequent
         interactions with Review Board.
         """
         api_key = self._docker.execute(
             self.bmoweb_id,
             ['/var/lib/bugzilla/bugzilla/scripts/issue-api-key.pl',
-             email], stdout=True).strip()
+             email, description], stdout=True).strip()
 
         assert len(api_key) == 40
 
         if not sync_to_reviewboard:
             return api_key
 
         # When running tests in parallel, the auth callback can time out.
         # Try up to 3 times before giving up.
@@ -587,17 +588,18 @@ class MozReview(object):
         res = {
             'bugzilla': b.create_user(email, password, fullname),
         }
 
         for g in bugzilla_groups:
             b.add_user_to_group(email, g)
 
         if api_key:
-            res['bugzilla']['api_key'] = self.create_user_api_key(email)
+            res['bugzilla']['api_key'] = self.create_user_api_key(
+                email, description='mozreview')
 
         # Create an LDAP account as well.
         if uid:
             if key_filename is None:
                 key_filename = os.path.join(self._path, 'keys', email)
 
             lr = self.get_ldap().create_user(email, username, uid,
                                              fullname,
--- a/testing/vcttesting/mozreview_mach_commands.py
+++ b/testing/vcttesting/mozreview_mach_commands.py
@@ -251,19 +251,22 @@ class MozReviewCommands(object):
                                   key_filename=key_file, scm_level=scm_level)
 
     @Command('create-api-key', category='mozreview',
              description='Create a Bugzilla API key for a user')
     @CommandArgument('where', nargs='?',
                      help='Directory of MozReview instance')
     @CommandArgument('email',
                      help='Bugzilla account to create API key for')
-    def create_api_key(self, where, email):
+    @CommandArgument('--description',
+                     help='Optional API key description, e.g. "mozreview"')
+    def create_api_key(self, where, email, description=''):
         mr = self._get_mozreview(where)
-        print(mr.create_user_api_key(email, sync_to_reviewboard=False))
+        print(mr.create_user_api_key(email, sync_to_reviewboard=False,
+                                     description=description))
 
     @Command('exec', category='mozreview',
              description='Execute a command in a Docker container')
     @CommandArgument('name', help='Name of container to shell into',
                      choices={'bmoweb', 'bmodb', 'pulse', 'rbweb', 'hgrb',
                               'autoland', 'hgweb', 'treestatus'})
     @CommandArgument('command', help='Command to execute',
                      nargs=argparse.REMAINDER)