Beispiel #1
0
def main():
    """Scriptworker entry point: get everything set up, then enter the main loop
    """
    context = Context()
    kwargs = {}
    if len(sys.argv) > 1:
        if len(sys.argv) > 2:
            print("Usage: {} [configfile]".format(sys.argv[0]),
                  file=sys.stderr)
            sys.exit(1)
        kwargs['path'] = sys.argv[1]
    context.config, credentials = create_config(**kwargs)
    update_logging_config(context)
    cleanup(context)
    conn = aiohttp.TCPConnector(limit=context.config["max_connections"])
    loop = asyncio.get_event_loop()
    with aiohttp.ClientSession(connector=conn) as session:
        context.session = session
        context.credentials = credentials
        while True:
            try:
                loop.create_task(async_main(context))
                loop.run_forever()
            except RuntimeError:
                pass
Beispiel #2
0
def test_no_creds_in_config():
    fake_creds = {"foo": "bar"}

    def fake_read(*args, **kwargs):
        return deepcopy(fake_creds)

    path = os.path.join(os.path.dirname(__file__), "data", "no_creds.json")
    with mock.patch.object(config, 'read_worker_creds', new=fake_read):
        _, creds = config.create_config(config_path=path)
    assert creds == fake_creds
def test_no_creds_in_config():
    fake_creds = {"foo": "bar"}

    def fake_read(*args, **kwargs):
        return deepcopy(fake_creds)

    path = os.path.join(os.path.dirname(__file__), "data", "no_creds.json")
    with mock.patch.object(config, 'read_worker_creds', new=fake_read):
        _, creds = config.create_config(config_path=path)
    assert creds == fake_creds
Beispiel #4
0
def test_create_config_good(t_config):
    path = os.path.join(os.path.dirname(__file__), "data", "good.json")
    with open(path, "r") as fh:
        contents = json.load(fh)
    t_config.update(contents)
    test_creds = t_config['credentials']
    del (t_config['credentials'])
    generated_config, generated_creds = config.create_config(config_path=path)
    assert generated_config == t_config
    assert generated_creds == test_creds
    assert isinstance(generated_config, frozendict)
    assert isinstance(generated_creds, frozendict)
def test_create_config_good(t_config):
    path = os.path.join(os.path.dirname(__file__), "data", "good.json")
    with open(path, "r") as fh:
        contents = json.load(fh)
    t_config.update(contents)
    test_creds = t_config['credentials']
    del(t_config['credentials'])
    generated_config, generated_creds = config.create_config(config_path=path)
    assert generated_config == t_config
    assert generated_creds == test_creds
    assert isinstance(generated_config, frozendict)
    assert isinstance(generated_creds, frozendict)
Beispiel #6
0
    def test_main(self, mocker, event_loop):
        path = os.path.join(os.path.dirname(__file__), "data", "good.json")
        config, creds = create_config(path)
        loop = mock.MagicMock()
        exceptions = [RuntimeError, ScriptWorkerException]

        def run_forever():
            exc = exceptions.pop(0)
            raise exc("foo")

        def foo(arg):
            assert arg.config == config
            assert arg.credentials == creds

        loop.run_forever = run_forever

        mocker.patch.object(sys, 'argv', new=[__file__, path])
        mocker.patch.object(worker, 'async_main', new=foo)
        with mock.patch.object(asyncio, 'get_event_loop') as p:
            p.return_value = loop
            with pytest.raises(ScriptWorkerException):
                worker.main()
Beispiel #7
0
    def test_main(self, mocker, event_loop):
        path = os.path.join(os.path.dirname(__file__), "data", "good.json")
        config, creds = create_config(path)
        loop = mock.MagicMock()
        exceptions = [RuntimeError, ScriptWorkerException]

        def run_forever():
            exc = exceptions.pop(0)
            raise exc("foo")

        def foo(arg):
            assert arg.config == config
            assert arg.credentials == creds

        loop.run_forever = run_forever

        mocker.patch.object(sys, 'argv', new=[__file__, path])
        mocker.patch.object(worker, 'async_main', new=foo)
        with mock.patch.object(asyncio, 'get_event_loop') as p:
            p.return_value = loop
            with pytest.raises(ScriptWorkerException):
                worker.main()
Beispiel #8
0
def main():
    """Scriptworker entry point: get everything set up, then enter the main loop
    """
    context = Context()
    kwargs = {}
    if len(sys.argv) > 1:
        if len(sys.argv) > 2:
            print("Usage: {} [configfile]".format(sys.argv[0]), file=sys.stderr)
            sys.exit(1)
        kwargs['path'] = sys.argv[1]
    context.config, credentials = create_config(**kwargs)
    update_logging_config(context)
    cleanup(context)
    conn = aiohttp.TCPConnector(limit=context.config["max_connections"])
    loop = asyncio.get_event_loop()
    with aiohttp.ClientSession(connector=conn) as session:
        context.session = session
        context.credentials = credentials
        while True:
            try:
                loop.create_task(async_main(context))
                loop.run_forever()
            except RuntimeError:
                pass
Beispiel #9
0
def test_create_config_bad_config():
    path = os.path.join(os.path.dirname(__file__), "data", "bad.json")
    with pytest.raises(SystemExit):
        config.create_config(config_path=path)
Beispiel #10
0
def test_create_config_missing_file():
    with pytest.raises(SystemExit):
        config.create_config(config_path="this_file_does_not_exist.json")
def test_create_config_bad_config():
    path = os.path.join(os.path.dirname(__file__), "data", "bad.json")
    with pytest.raises(SystemExit):
        config.create_config(config_path=path)
def test_create_config_missing_file():
    with pytest.raises(SystemExit):
        config.create_config(config_path="this_file_does_not_exist.json")