Example #1
0
    def test_get_erronous_cfg_defaults(self):
        handle, filepath = tempfile.mkstemp()
        self.addCleanup(os.unlink, filepath)

        with os.fdopen(handle, 'w') as conf_file:
            conf_file.write('aaaaaaaaaaa [Defaults]\n')

        with self.assertRaises(errors.MozRegressionError):
            cli.cli(conf_file=filepath)
Example #2
0
 def test_warn_invalid_build_type_in_conf(self):
     filepath = self._create_conf_file("build-type=foo\n")
     conf = cli.cli([], conf_file=filepath)
     warns = []
     conf.logger.warning = warns.append
     conf.validate()
     self.assertIn("Unable to find a suitable build type 'foo'." " (Defaulting to 'opt')", warns)
Example #3
0
def main(argv=None, namespace=None, check_new_version=True):
    """
    main entry point of mozregression command line.
    """
    # terminal color support on windows
    if os.name == 'nt':
        colorama.init()

    if sys.version_info <= (2, 7, 9):
        # requests uses urllib3, and on python <= 2.7.9 there will be a lot
        # of warnings that we do not want. See
        # https://bugzilla.mozilla.org/show_bug.cgi?id=1199020
        import logging
        logging.captureWarnings(True)

    config, app = None, None
    try:
        config = cli(argv=argv, namespace=namespace)
        if check_new_version:
            check_mozregression_version(config.logger)
        config.validate()
        set_http_session(get_defaults={"timeout": config.options.http_timeout})
        app = Application(config.fetch_config, config.options)

        method = getattr(app, config.action)
        sys.exit(method())

    except KeyboardInterrupt:
        sys.exit("\nInterrupted.")
    except UnavailableRelease, exc:
        config.logger.error(str(exc)) if config else sys.exit(str(exc))
        print formatted_valid_release_dates()
        sys.exit(1)
Example #4
0
 def test_missing_tk_credentials(self):
     filepath = self._create_conf_file('app=b2g-aries\n')
     conf = cli.cli([], conf_file=filepath)
     with self.assertRaisesRegexp(
             errors.MozRegressionError,
             "taskcluster-clientid and taskcluster-accesstoken are"
             " required"):
         conf.validate()
Example #5
0
 def test_warn_invalid_build_type_in_conf(self):
     filepath = self._create_conf_file('build-type=foo\n')
     conf = cli.cli([], conf_file=filepath)
     warns = []
     conf.logger.warning = warns.append
     conf.validate()
     self.assertIn(
         "Unable to find a suitable build type 'foo'."
         " (Defaulting to 'opt')", warns)
Example #6
0
 def test_warn_invalid_build_type_in_conf(self):
     filepath = self._create_conf_file('build-type=foo\n')
     conf = cli.cli([], conf_file=filepath)
     warns = []
     conf.logger.warning = warns.append
     conf.validate()
     self.assertIn(
         'foo is not a valid build type (valid: opt, debug)',
         warns
     )
Example #7
0
    def test_get_defaults(self):
        valid_values = {"http-timeout": "10.2", "persist": "/home/foo/.mozregression", "bits": "64"}

        content = ["%s=%s\n" % (key, value) for key, value in valid_values.iteritems()]
        filepath = self._create_conf_file("\n".join(content))

        options = cli.cli(["--bits=32"], conf_file=filepath).options

        self.assertEqual(options.http_timeout, 10.2)
        self.assertEqual(options.persist, "/home/foo/.mozregression")
        self.assertEqual(options.bits, "32")
Example #8
0
    def test_with_tk_credentials(self, get_defaults):
        from mozregression.config import DEFAULTS

        values = dict(DEFAULTS)
        values.update({"app": "b2g-aries", "taskcluster-clientid": "id1", "taskcluster-accesstoken": "mytoken"})
        get_defaults.return_value = values
        filepath = self._create_conf_file("\n".join("%s=%s" % (k, v) for k, v in values.items()))
        conf = cli.cli(["--good=c1", "--bad=c2"], conf_file=filepath)
        conf.validate()
        self.assertEquals(
            conf.fetch_config.tk_options(), {"credentials": {"accessToken": "mytoken", "clientId": "id1"}}
        )
Example #9
0
    def test_get_defaults(self):
        valid_values = {'http-timeout': '10.2',
                        'persist': '/home/foo/.mozregression',
                        'bits': '64'}

        content = ["%s=%s\n" % (key, value)
                   for key, value in valid_values.iteritems()]
        filepath = self._create_conf_file('\n'.join(content))

        options = cli.cli(['--bits=32'], conf_file=filepath).options

        self.assertEqual(options.http_timeout, 10.2)
        self.assertEqual(options.persist, '/home/foo/.mozregression')
        self.assertEqual(options.bits, '32')
Example #10
0
    def test_get_defaults(self):
        valid_values = {'http-timeout': '10.2',
                        'persist': '/home/foo/.mozregression',
                        'bits': '64'}

        content = ["%s=%s\n" % (key, value)
                   for key, value in valid_values.iteritems()]
        filepath = self._create_conf_file('\n'.join(content))

        options = cli.cli(['--bits=32'], conf_file=filepath).options

        self.assertEqual(options.http_timeout, 10.2)
        self.assertEqual(options.persist, '/home/foo/.mozregression')
        self.assertEqual(options.bits, '32')
Example #11
0
def main(
    argv=None,
    namespace=None,
    check_new_version=True,
    mozregression_variant="console",
):
    """
    main entry point of mozregression command line.
    """
    # terminal color support on windows
    if os.name == "nt":
        colorama.init()

    config, app = None, None
    try:
        config = cli(argv=argv, namespace=namespace)
        if check_new_version:
            check_mozregression_version()
        config.validate()
        set_http_session(get_defaults={"timeout": config.options.http_timeout})

        app = Application(config.fetch_config, config.options)
        send_telemetry_ping_oop(
            UsageMetrics(
                variant=mozregression_variant,
                appname=config.fetch_config.app_name,
                build_type=config.fetch_config.build_type,
                good=config.options.good,
                bad=config.options.bad,
                launch=config.options.launch,
            ),
            config.enable_telemetry,
        )

        method = getattr(app, config.action)
        sys.exit(method())

    except KeyboardInterrupt:
        sys.exit("\nInterrupted.")
    except (MozRegressionError, RequestException) as exc:
        if isinstance(exc, HTTPError) and exc.response.status_code == 401:
            # remove the taskcluster credential file - looks like it's wrong
            # anyway. This will force mozregression to ask again next time.
            mozfile.remove(TC_CREDENTIALS_FNAME)
        LOG.error(str(exc)) if config else sys.exit(str(exc))
        sys.exit(1)
    finally:
        if app:
            app.clear()
Example #12
0
    def test_get_defaults(self):
        valid_values = {
            "http-timeout": "10.2",
            "persist": "/home/foo/.mozregression",
            "bits": "64",
        }

        content = ["%s=%s\n" % (key, value) for key, value in six.iteritems(valid_values)]
        filepath = self._create_conf_file("\n".join(content))

        options = cli.cli(["--bits=32"], conf_file=filepath).options

        self.assertEqual(options.http_timeout, 10.2)
        self.assertEqual(options.persist, "/home/foo/.mozregression")
        self.assertEqual(options.bits, "32")
Example #13
0
    def test_get_defaults(self):
        valid_values = {'http-timeout': '10.2',
                        'persist': '/home/foo/.mozregression',
                        'bits': '64'}

        handle, filepath = tempfile.mkstemp()
        self.addCleanup(os.unlink, filepath)

        with os.fdopen(handle, 'w') as conf_file:
            for key, value in valid_values.iteritems():
                conf_file.write("%s=%s\n" % (key, value))

        options = cli.cli(['--bits=32'], conf_file=filepath).options

        self.assertEqual(options.http_timeout, 10.2)
        self.assertEqual(options.persist, '/home/foo/.mozregression')
        self.assertEqual(options.bits, '32')
Example #14
0
 def test_with_tk_credentials(self, get_defaults):
     from mozregression.config import DEFAULTS
     values = dict(DEFAULTS)
     values.update({
         'app': 'b2g-aries',
         'taskcluster-clientid': 'id1',
         'taskcluster-accesstoken': 'mytoken',
     })
     get_defaults.return_value = values
     filepath = self._create_conf_file('\n'.join(
         '%s=%s' % (k, v) for k, v in values.items()))
     conf = cli.cli(['--good=c1', '--bad=c2'], conf_file=filepath)
     conf.validate()
     self.assertEquals(
         conf.fetch_config.tk_options(),
         {'credentials': {
             'accessToken': 'mytoken',
             'clientId': 'id1'
         }})
Example #15
0
 def test_with_tk_credentials(self, get_defaults):
     from mozregression.config import DEFAULTS
     values = dict(DEFAULTS)
     values.update({
         'app': 'b2g-aries',
         'taskcluster-clientid': 'id1',
         'taskcluster-accesstoken': 'mytoken',
     })
     get_defaults.return_value = values
     filepath = self._create_conf_file(
         '\n'.join('%s=%s' % (k, v) for k, v in values.items())
     )
     conf = cli.cli(['--good-rev=1', '--bad-rev=2'], conf_file=filepath)
     conf.validate()
     self.assertEquals(conf.fetch_config.tk_options(), {
         'credentials': {
             'accessToken': 'mytoken',
             'clientId': 'id1'
         }
     })
Example #16
0
def main(argv=None, namespace=None, check_new_version=True):
    """
    main entry point of mozregression command line.
    """
    # terminal color support on windows
    if os.name == 'nt':
        colorama.init()

    if sys.version_info <= (2, 7, 9):
        # requests uses urllib3, and on python <= 2.7.9 there will be a lot
        # of warnings that we do not want. See
        # https://bugzilla.mozilla.org/show_bug.cgi?id=1199020
        import logging
        logging.captureWarnings(True)

    config, app = None, None
    try:
        config = cli(argv=argv, namespace=namespace)
        if check_new_version:
            check_mozregression_version()
        config.validate()
        set_http_session(get_defaults={"timeout": config.options.http_timeout})
        app = Application(config.fetch_config, config.options)

        method = getattr(app, config.action)
        sys.exit(method())

    except KeyboardInterrupt:
        sys.exit("\nInterrupted.")
    except (MozRegressionError, RequestException) as exc:
        if isinstance(exc, HTTPError) and exc.response.status_code == 401:
            # remove the taskcluster credential file - looks like it's wrong
            # anyway. This will force mozregression to ask again next time.
            mozfile.remove(TC_CREDENTIALS_FNAME)
        LOG.error(str(exc)) if config else sys.exit(str(exc))
        sys.exit(1)
    finally:
        if app:
            app.clear()
Example #17
0
def main(argv=None, namespace=None, check_new_version=True):
    """
    main entry point of mozregression command line.
    """
    # terminal color support on windows
    if os.name == 'nt':
        colorama.init()

    if sys.version_info <= (2, 7, 9):
        # requests uses urllib3, and on python <= 2.7.9 there will be a lot
        # of warnings that we do not want. See
        # https://bugzilla.mozilla.org/show_bug.cgi?id=1199020
        import logging
        logging.captureWarnings(True)

    config, app = None, None
    try:
        config = cli(argv=argv, namespace=namespace)
        if check_new_version:
            check_mozregression_version()
        config.validate()
        set_http_session(get_defaults={"timeout": config.options.http_timeout})
        app = Application(config.fetch_config, config.options)

        method = getattr(app, config.action)
        sys.exit(method())

    except KeyboardInterrupt:
        sys.exit("\nInterrupted.")
    except (MozRegressionError, RequestException) as exc:
        if isinstance(exc, HTTPError) and exc.response.status_code == 401:
            # remove the taskcluster credential file - looks like it's wrong
            # anyway. This will force mozregression to ask again next time.
            mozfile.remove(TC_CREDENTIALS_FNAME)
        LOG.error(str(exc)) if config else sys.exit(str(exc))
        sys.exit(1)
    finally:
        if app:
            app.clear()
Example #18
0
    def test_get_erronous_cfg_defaults(self):
        filepath = self._create_conf_file('aaaaaaaaaaa [Defaults]\n')

        with self.assertRaises(errors.MozRegressionError):
            cli.cli(conf_file=filepath)
Example #19
0
def test_warning_no_conf(mocker):
    out = []
    stdout = mocker.patch('sys.stdout')
    stdout.write = out.append
    cli.cli([], conf_file='blah_this is not a valid file_I_hope')
    assert "You should use a config file" in '\n'.join(out)
Example #20
0
def do_cli(*argv):
    conf = cli.cli(argv, conf_file=None)
    conf.validate()
    return conf
Example #21
0
    def test_get_erronous_cfg_defaults(self):
        filepath = self._create_conf_file("aaaaaaaaaaa [Defaults]\n")

        with self.assertRaises(errors.MozRegressionError):
            cli.cli(conf_file=filepath)
Example #22
0
def test_warning_no_conf(mocker):
    out = []
    stdout = mocker.patch("sys.stdout")
    stdout.write = out.append
    cli.cli([], conf_file="blah_this is not a valid file_I_hope")
    assert "You should use a config file" in "\n".join(out)
Example #23
0
def do_cli(*argv):
    conf = cli.cli(argv, conf_file=None)
    conf.validate()
    return conf