def test_write_existing_conf(tmp, mocker): mocked_input = mocker.patch("__builtin__.raw_input") mocked_input.return_value = "" conf_path = os.path.join(tmp, "conf.cfg") write_conf(conf_path) results = get_defaults(conf_path) assert results # write conf again write_conf(conf_path) # nothing changed assert results == get_defaults(conf_path) with open(conf_path) as f: # ensure we have comments assert "# ------ mozregression configuration file ------" in f.read()
def test_write_existing_conf(tmp, mocker): mocked_input = mocker.patch('mozregression.config.input') mocked_input.return_value = "" conf_path = os.path.join(tmp, 'conf.cfg') write_conf(conf_path) results = get_defaults(conf_path) assert results # write conf again write_conf(conf_path) # nothing changed assert results == get_defaults(conf_path) with open(conf_path) as f: # ensure we have comments assert "# ------ mozregression configuration file ------" in f.read()
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None): """ parse cli args basically and returns a :class:`Configuration`. if namespace is given, it will be used as a arg parsing result, so no arg parsing will be done. """ if namespace: options = namespace else: defaults = get_defaults(conf_file) options = parse_args(argv=argv, defaults=defaults) if not options.cmdargs: # we don't set the cmdargs default to be that from the # configuration file, because then any new arguments # will be appended: https://bugs.python.org/issue16399 options.cmdargs = defaults['cmdargs'] if conf_file and not os.path.isfile(conf_file): print('*' * 10) print(colorize("You should use a config file. Please use the " + '{sBRIGHT}--write-config{sRESET_ALL}' + " command line flag to help you create one.")) print('*' * 10) print() return Configuration(options)
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None): """ parse cli args basically and returns a :class:`Configuration`. if namespace is given, it will be used as a arg parsing result, so no arg parsing will be done. """ if namespace: options = namespace else: defaults = get_defaults(conf_file) options = parse_args(argv=argv, defaults=defaults) if not options.cmdargs: # we don't set the cmdargs default to be that from the # configuration file, because then any new arguments # will be appended: https://bugs.python.org/issue16399 options.cmdargs = defaults['cmdargs'] if conf_file and not os.path.isfile(conf_file): print '*' * 10 print colorize("You should use a config file. Please use the " + '{sBRIGHT}--write-config{sRESET_ALL}' + " command line flag to help you create one.") print '*' * 10 print return Configuration(options)
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None): """ parse cli args basically and returns a :class:`Configuration`. if namespace is given, it will be used as a arg parsing result, so no arg parsing will be done. """ if namespace: options = namespace else: defaults = None if conf_file: defaults = get_defaults(conf_file) options = parse_args(argv=argv, defaults=defaults) if conf_file and not os.path.isfile(conf_file): term = blessings.Terminal() if blessings else None print "*" * ((term and term.width) or 10) print ( "You should use a config file. Please use the " + (term.bold("--write-config") if term else "--write-config") + " command line flag to help you create one." ) print "*" * ((term and term.width) or 10) print return Configuration(options)
def tc_authenticate(logger): """ Returns valid credentials for use with Taskcluster private builds. """ # first, try to load credentials from mozregression config file defaults = get_defaults(DEFAULT_CONF_FNAME) client_id = defaults.get('taskcluster-clientid') access_token = defaults.get('taskcluster-accesstoken') if client_id and access_token: return dict(clientId=client_id, accessToken=access_token) try: # else, try to load a valid certificate locally with open(TC_CREDENTIALS_FNAME) as f: creds = json.load(f) if not tc_utils.isExpired(creds['certificate']): return creds except Exception: pass # here we need to ask for a certificate, this require web browser # authentication logger.info( "Authentication required from taskcluster. We are going to ask for a" " certificate.\nNote that if you have long term access you can instead" " set your taskcluster-clientid and taskcluster-accesstoken in the" " configuration file (%s)." % DEFAULT_CONF_FNAME) creds = tc_utils.authenticate("mozregression private build access") # save the credentials and the certificate for later use with open(TC_CREDENTIALS_FNAME, 'w') as f: json.dump(creds, f) return creds
def get_prefs(): """ Return the global prefs as a dict. """ settings = get_defaults(DEFAULT_CONF_FNAME) options = dict() options['persist'] = settings['persist'] options['http_timeout'] = float(settings['http-timeout']) options['persist_size_limit'] = float(settings['persist-size-limit']) return options
def get_prefs(): """ Return the global prefs as a dict. """ settings = get_defaults(DEFAULT_CONF_FNAME) options = dict() options['persist'] = settings['persist'] options['http_timeout'] = float(settings['http-timeout']) options['persist_size_limit'] = float(settings['persist-size-limit']) options['background_downloads'] = \ False if settings.get('background_downloads') == 'no' else True return options
def get_prefs(): """ Return the global prefs as a dict. """ settings = get_defaults(DEFAULT_CONF_FNAME) options = dict() options['persist'] = settings['persist'] options['http_timeout'] = float(settings['http-timeout']) options['persist_size_limit'] = float(settings['persist-size-limit']) options['background_downloads'] = \ False if settings.get('background_downloads') == 'no' else True options['approx_policy'] = settings['approx-policy'] == 'auto' options['archive_base_url'] = settings["archive-base-url"] return options
def get_prefs(): """ Return the global prefs as a dict. """ settings = get_defaults(DEFAULT_CONF_FNAME) options = dict() options['persist'] = settings['persist'] options['http_timeout'] = float(settings['http-timeout']) options['persist_size_limit'] = float(settings['persist-size-limit']) options['background_downloads'] = \ False if settings.get('background_downloads') == 'no' else True options['approx_policy'] = settings['approx-policy'] == 'auto' options['archive_base_url'] = settings["archive-base-url"] options['cmdargs'] = settings['cmdargs'] return options
def test_write_conf(tmp, mocker, os_, bits, inputs, conf_dir_exists, results): mozinfo = mocker.patch('mozregression.config.mozinfo') mozinfo.os = os_ mozinfo.bits = bits mocked_input = mocker.patch('__builtin__.raw_input') mocked_input.side_effect = inputs conf_path = os.path.join(tmp, 'conf.cfg') if not conf_dir_exists: mozfile.remove(conf_path) write_conf(conf_path) if 'persist' in results and results['persist'] is None: # default persist is base on the directory of the conf file results['persist'] = os.path.join(tmp, 'persist') conf = get_defaults(conf_path) for key in results: assert conf[key] == results[key] with open(conf_path) as f: # ensure we have comments assert "# ------ mozregression configuration file ------" in f.read()
def test_write_conf(tmp, mocker, os_, bits, inputs, conf_dir_exists, results): mozinfo = mocker.patch("mozregression.config.mozinfo") mozinfo.os = os_ mozinfo.bits = bits mocked_input = mocker.patch("__builtin__.raw_input") mocked_input.side_effect = inputs conf_path = os.path.join(tmp, "conf.cfg") if not conf_dir_exists: mozfile.remove(conf_path) write_conf(conf_path) if "persist" in results and results["persist"] is None: # default persist is base on the directory of the conf file results["persist"] = os.path.join(tmp, "persist") conf = get_defaults(conf_path) for key in results: assert conf[key] == results[key] with open(conf_path) as f: # ensure we have comments assert "# ------ mozregression configuration file ------" in f.read()
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None): """ parse cli args basically and returns a :class:`Configuration`. if namespace is given, it will be used as a arg parsing result, so no arg parsing will be done. """ if namespace: options = namespace else: defaults = get_defaults(conf_file) options = parse_args(argv=argv, defaults=defaults) if conf_file and not os.path.isfile(conf_file): print '*' * 10 print colorize("You should use a config file. Please use the " + '{sBRIGHT}--write-config{sRESET_ALL}' + " command line flag to help you create one.") print '*' * 10 print return Configuration(options)
def validate(self): """ Validate the options, define the `action` and `fetch_config` that should be used to run the application. """ options = self.options user_defined_bits = options.bits is not None options.bits = parse_bits(options.bits or mozinfo.bits) fetch_config = create_config(options.app, mozinfo.os, options.bits) try: fetch_config.set_build_type(options.build_type) except MozRegressionError as msg: self.logger.warning( "%s (Defaulting to %r)" % (msg, fetch_config.build_type) ) self.fetch_config = fetch_config if not user_defined_bits and \ options.bits == 64 and \ mozinfo.os == 'win' and \ 32 in fetch_config.available_bits(): # inform users on windows that we are using 64 bit builds. self.logger.info("bits option not specified, using 64-bit builds.") if options.bits == 32 and mozinfo.os == 'mac': self.logger.info("only 64-bit builds available for mac, using " "64-bit builds") if fetch_config.is_inbound(): # this can be useful for both inbound and nightly, because we # can go to inbound from nightly. fetch_config.set_inbound_branch(options.inbound_branch) if fetch_config.tk_needs_auth(): # re-read configuration to get taskcluster options # TODO: address this to avoid re-reading the conf file defaults = get_defaults(DEFAULT_CONF_FNAME) client_id = defaults.get('taskcluster-clientid') access_token = defaults.get('taskcluster-accesstoken') if not (client_id and access_token): raise MozRegressionError( "taskcluster-clientid and taskcluster-accesstoken are" " required in the configuration file (%s) for %s" % (DEFAULT_CONF_FNAME, fetch_config.app_name) ) fetch_config.set_tk_credentials(client_id, access_token) # set action for just use changset or data to bisect if options.launch: try: options.launch = parse_date(options.launch) self.action = "launch_nightlies" except DateFormatError: try: options.launch = parse_date(date_of_release( options.launch)) self.action = "launch_nightlies" except UnavailableRelease: self.action = "launch_inbound" elif fetch_config.is_b2g_device(): self.action = "bisect_inbounds" check_taskcluster(options, fetch_config, self.logger) elif options.first_bad_revision or options.last_good_revision: # bisect inbound if last good revision or first bad revision are # set self.action = "bisect_inbounds" check_inbounds(options, fetch_config, self.logger) else: self.action = "bisect_nightlies" check_nightlies(options, fetch_config, self.logger) options.preferences = preferences(options.prefs_files, options.prefs) # convert GiB to bytes. options.persist_size_limit = \ int(abs(float(options.persist_size_limit)) * 1073741824)
def parser(): """ Create and returns the mozregression ArgumentParser instance. """ defaults = get_defaults(DEFAULT_CONF_FNAME) return create_parser(defaults=defaults)