Bug 1035551 - Add support for in tree configs in mozharness in marionette.py script.;r=ahal
authorChris Manchester <cmanchester@mozilla.com>
Mon, 14 Jul 2014 16:33:10 -0400
changeset 2978 589cda99ef7634d707a94ec95a4948021a485166
parent 2976 dfcfae9a1bc641c73d9edb98f3bd452ee23682fe
child 2979 09e438ee911ab80779dac8208e9b5b23737bd1f0
push id2246
push usercmanchester@mozilla.com
push dateMon, 21 Jul 2014 19:23:04 +0000
reviewersahal
bugs1035551
Bug 1035551 - Add support for in tree configs in mozharness in marionette.py script.;r=ahal
configs/marionette/automation_emulator_config.py
configs/marionette/gaia_ui_test_prod_config.py
configs/marionette/prod_config.py
configs/marionette/test_config.py
configs/marionette/windows_config.py
mozharness/mozilla/testing/testbase.py
scripts/marionette.py
--- a/configs/marionette/automation_emulator_config.py
+++ b/configs/marionette/automation_emulator_config.py
@@ -34,9 +34,10 @@ config = {
         'run-marionette',
     ],
     "download_symbols": "ondemand",
     "download_minidump_stackwalk": True,
     "default_blob_upload_servers": [
          "https://blobupload.elasticbeanstalk.com",
     ],
     "blob_uploader_auth_file" : os.path.join(os.getcwd(), "oauth.txt"),
+    "in_tree_config": "config/mozharness/marionette.py",
 }
--- a/configs/marionette/gaia_ui_test_prod_config.py
+++ b/configs/marionette/gaia_ui_test_prod_config.py
@@ -42,9 +42,10 @@ config = {
     ],
     "download_symbols": "ondemand",
     "download_minidump_stackwalk": True,
     "default_blob_upload_servers": [
         "https://blobupload.elasticbeanstalk.com",
     ],
     "blob_uploader_auth_file": os.path.join(os.getcwd(), "oauth.txt"),
     "vcs_output_timeout": 1760,
+    "in_tree_config": "config/mozharness/marionette.py",
 }
--- a/configs/marionette/prod_config.py
+++ b/configs/marionette/prod_config.py
@@ -30,10 +30,11 @@ config = {
         'create-virtualenv',
         'install',
         'run-marionette',
     ],
     "default_blob_upload_servers": [
          "https://blobupload.elasticbeanstalk.com",
     ],
     "blob_uploader_auth_file" : os.path.join(os.getcwd(), "oauth.txt"),
+    "in_tree_config": "config/mozharness/marionette.py",
 }
 
--- a/configs/marionette/test_config.py
+++ b/configs/marionette/test_config.py
@@ -12,9 +12,10 @@ config = {
 
     "default_actions": [
         'clobber',
         'download-and-extract',
         'create-virtualenv',
         'install',
         'run-marionette',
     ],
+    "in_tree_config": "config/mozharness/marionette.py",
 }
--- a/configs/marionette/windows_config.py
+++ b/configs/marionette/windows_config.py
@@ -31,9 +31,10 @@ config = {
         'create-virtualenv',
         'install',
         'run-marionette',
     ],
     "default_blob_upload_servers": [
          "https://blobupload.elasticbeanstalk.com",
     ],
     "blob_uploader_auth_file" : os.path.join(os.getcwd(), "oauth.txt"),
+    "in_tree_config": "config/mozharness/marionette.py",
 }
--- a/mozharness/mozilla/testing/testbase.py
+++ b/mozharness/mozilla/testing/testbase.py
@@ -325,17 +325,17 @@ 2. running via buildbot and running the 
                                     os.path.join(dirs['abs_work_dir'], 'tests'))
 
         if 'in_tree_config' in self.config:
             rel_tree_config_path = self.config['in_tree_config']
             tree_config_path = os.path.join(test_install_dir, rel_tree_config_path)
 
             if not os.path.isfile(tree_config_path):
                 self.fatal("The in-tree configuration file '%s' does not exist!"
-                           "It must be added to '%s'. See bug 981030 for more details." %
+                           "It must be added to '%s'. See bug 1035551 for more details." %
                            (tree_config_path, os.path.join('gecko', 'testing', rel_tree_config_path)))
 
             try:
                 self.tree_config.update(parse_config_file(tree_config_path))
             except:
                 msg = "There was a problem parsing the in-tree configuration file '%s'!" % \
                       os.path.join('gecko', 'testing', rel_tree_config_path)
                 self.exception(message=msg, level=FATAL)
--- a/scripts/marionette.py
+++ b/scripts/marionette.py
@@ -264,23 +264,28 @@ class MarionetteTest(TestingMixin, Toolt
                     'repo_path': 'https://hg.mozilla.org/%s' % self.buildbot_config['properties']['repo_path']
                 })
 
             self.clone_gaia(dest, repo,
                             use_gaia_json=self.buildbot_config is not None)
 
         super(MarionetteTest, self).pull(**kwargs)
 
-    def _build_arg(self, option, value):
+    def _get_options_group(self, is_emulator, is_gaiatest):
         """
-        Build a command line argument
+        Determine which in tree options group to use and return the
+        appropriate key.
         """
-        if not value:
-            return []
-        return [str(option), str(value)]
+        platform = 'emulator' if is_emulator else 'desktop'
+        testsuite = 'gaiatest' if is_gaiatest else 'marionette'
+        # Currently running marionette on an emulator means webapi
+        # tests. This method will need to change if this does.
+        if is_emulator and not is_gaiatest:
+            testsuite = 'webapi'
+        return '_'.join([testsuite, platform, 'options'])
 
     def extract_xre(self, filename, parent_dir=None):
         m = re.search('\.tar\.(bz2|gz)$', filename)
         if m:
             # a xulrunner archive, which has a top-level 'xulrunner-sdk' dir
             command = self.query_exe('tar', return_type='list')
             tar_cmd = "jxf"
             if m.group(1) == "gz":
@@ -356,16 +361,17 @@ class MarionetteTest(TestingMixin, Toolt
             self.make_gaia(dirs['abs_gaia_dir'],
                            self.config.get('xre_path'),
                            debug=False,
                            noftu=False,
                            build_config_path=build_config)
 
         # build the marionette command arguments
         python = self.query_python_path('python')
+        testvars = None
         if self.config.get('gaiatest'):
             # write a testvars.json file
             testvars = os.path.join(dirs['abs_gaiatest_dir'],
                                     'gaiatest', 'testvars.json')
             with open(testvars, 'w') as f:
                 f.write("""{"acknowledged_risks": true,
                             "skip_warning": true,
                             "settings": {
@@ -381,67 +387,58 @@ class MarionetteTest(TestingMixin, Toolt
 
             if not self.config.get('emulator'):
                 # support desktop builds with and without a built-in profile
                 binary_path = os.path.dirname(self.binary_path)
                 binary = os.path.join(binary_path, 'b2g-bin')
                 if not os.access(binary, os.F_OK):
                     binary = os.path.join(binary_path, 'b2g')
 
-            cmd.append('--restart')
-
-            # emulator builds require a longer timeout
-            timeout = self.config.get('emulator') and 60000 or 10000
-            cmd.extend(self._build_arg('--timeout', timeout))
-
-            cmd.extend(self._build_arg('--type', self.config['test_type']))
-            cmd.extend(self._build_arg('--testvars', testvars))
-            cmd.extend(self._build_arg('--profile', os.path.join(dirs['abs_gaia_dir'],
-                                                                 'profile')))
-            cmd.extend(self._build_arg('--symbols-path', self.symbols_path))
-            cmd.extend(self._build_arg('--xml-output',
-                                       os.path.join(dirs['abs_work_dir'], 'output.xml')))
-            cmd.extend(self._build_arg('--html-output',
-                                       os.path.join(dirs['abs_blob_upload_dir'], 'output.html')))
             manifest = os.path.join(dirs['abs_gaiatest_dir'], 'gaiatest', 'tests',
                                     'tbpl-manifest.ini')
         else:
             # Marionette or Marionette-webapi tests
             cmd = [python, '-u', os.path.join(dirs['abs_marionette_dir'],
                                               'runtests.py')]
 
-            if self.config.get('emulator'):
-                # emulator Marionette-webapi tests
-                cmd.extend(self._build_arg('--symbols-path', self.symbols_path))
-
-            cmd.extend(self._build_arg('--type', self.config['test_type']))
             manifest = os.path.join(dirs['abs_marionette_tests_dir'],
                                     self.config['test_manifest'])
 
-        if self.config.get('emulator'):
-            cmd.extend(self._build_arg('--logcat-dir', dirs['abs_work_dir']))
-            cmd.extend(self._build_arg('--emulator', self.config['emulator']))
-            cmd.extend(self._build_arg('--homedir',
-                                       os.path.join(dirs['abs_emulator_dir'],
-                                                    'b2g-distro')))
-        else:
-            # tests for Firefox or b2g desktop
-            cmd.extend(self._build_arg('--binary', binary))
-            cmd.extend(self._build_arg('--address',
-                                       self.config['marionette_address']))
             if self.config.get('app_arg'):
                 cmd.extend(['--app-arg', self.config['app_arg']])
 
-        if self.config.get("structured_output"):
+        config_fmt_args = {
+            'type': self.config.get('test_type'),
+            'testvars': testvars,
+            # emulator builds require a longer timeout
+            'timeout': 60000 if self.config.get('emulator') else 10000,
+            'profile': os.path.join(dirs['abs_gaia_dir'], 'profile'),
+            'xml_output': os.path.join(dirs['abs_work_dir'], 'output.xml'),
+            'html_output': os.path.join(dirs['abs_blob_upload_dir'], 'output.html'),
+            'symbols_path': self.symbols_path if self.config.get('emulator') else None,
+            'logcat_dir': dirs['abs_work_dir'],
+            'emulator': self.config.get('emulator'),
+            'homedir': os.path.join(dirs['abs_emulator_dir'], 'b2g-distro'),
+            'binary': binary,
+            'address': self.config.get('marionette_address'),
+            'raw_log_file': os.path.join(dirs["abs_blob_upload_dir"],
+                                         "mn_structured_full.log")
+        }
+
+        options_group = self._get_options_group(self.config.get('emulator'),
+                                                self.config.get('gaiatest'))
+        for s in self.tree_config[options_group]:
+            cmd.append(s % config_fmt_args)
+
+        if self.mkdir_p(dirs["abs_blob_upload_dir"]) == -1:
             # Make sure that the logging directory exists
-            if self.mkdir_p(dirs["abs_blob_upload_dir"]) == -1:
-                self.fatal("Could not create blobber upload directory")
+            self.fatal("Could not create blobber upload directory")
+
+        if self.config.get("structured_output"):
             cmd.append("--log-raw=-")
-            cmd.append("--log-raw=%s" % os.path.join(dirs["abs_blob_upload_dir"],
-                                                     "mn_structured_full.log"))
 
         cmd.append(manifest)
 
         env = {}
         if self.query_minidump_stackwalk():
             env['MINIDUMP_STACKWALK'] = self.minidump_stackwalk_path
         if self.config.get('gaiatest'):
             env['GAIATEST_ACKNOWLEDGED_RISKS'] = '1'