Пример #1
0
def test_get_api_caches_hook_enabled_apis_separately():
  with CLUSTERS.patch([TEST_CLUSTER]):
    context = AuroraCommandContext()
    hooked_api = context.get_api(TEST_CLUSTER.name)
    unhooked_api = context.get_api(TEST_CLUSTER.name, enable_hooks=False)

    assert hooked_api != unhooked_api

    assert hooked_api in context.apis.values()
    assert hooked_api not in context.unhooked_apis.values()

    assert unhooked_api in context.unhooked_apis.values()
    assert unhooked_api not in context.apis.values()
Пример #2
0
def test_get_api_caches_hook_enabled_apis_separately():
    with CLUSTERS.patch([TEST_CLUSTER]):
        context = AuroraCommandContext()
        hooked_api = context.get_api(TEST_CLUSTER.name)
        unhooked_api = context.get_api(TEST_CLUSTER.name, enable_hooks=False)

        assert hooked_api != unhooked_api

        assert hooked_api in context.apis.values()
        assert hooked_api not in context.unhooked_apis.values()

        assert unhooked_api in context.unhooked_apis.values()
        assert unhooked_api not in context.apis.values()
Пример #3
0
def test_get_api_caches_hook_enabled_apis_separately():
    with patch('apache.aurora.client.cli.context.make_client'
               ) as mock_make_client:
        # return a new Mock instance for each call of the two calls we're expecting.
        mock_make_client.side_effect = [Mock(), Mock()]

        cluster = 'some-cluster'

        context = AuroraCommandContext()
        hooked_api = context.get_api(cluster)
        unhooked_api = context.get_api(cluster, False)

        assert mock_make_client.mock_calls == [
            call(cluster, AURORA_V2_USER_AGENT_NAME, True),
            call(cluster, AURORA_V2_USER_AGENT_NAME, False)
        ]

        assert hooked_api != unhooked_api

        assert hooked_api in context.apis.values()
        assert hooked_api not in context.unhooked_apis.values()

        assert unhooked_api in context.unhooked_apis.values()
        assert unhooked_api not in context.apis.values()
Пример #4
0
def test_handles_api_auth_error():
    context = AuroraCommandContext()

    mock_scheduler_proxy = mock.create_autospec(spec=SchedulerProxyApiSpec, instance=True)
    mock_scheduler_proxy.killTasks.side_effect = SchedulerProxy.AuthError()

    mock_api = AuroraClientAPI(TEST_CLUSTER, "user-agent")
    mock_api._scheduler_proxy = mock_scheduler_proxy

    context.apis = {TEST_CLUSTER.name: mock_api}
    api = context.get_api(TEST_CLUSTER.name, clusters={TEST_CLUSTER.name: TEST_CLUSTER})

    with pytest.raises(Context.CommandError) as e:
        api.kill_job(AuroraJobKey(TEST_CLUSTER.name, "role", "env", "job"))

    assert e.value.code == EXIT_AUTH_ERROR
    assert mock_scheduler_proxy.killTasks.call_count == 1
Пример #5
0
def test_handles_api_auth_error():
    context = AuroraCommandContext()

    mock_scheduler_proxy = mock.create_autospec(spec=SchedulerProxyApiSpec,
                                                instance=True)
    mock_scheduler_proxy.killTasks.side_effect = SchedulerProxy.AuthError()

    mock_api = AuroraClientAPI(TEST_CLUSTER, 'user-agent')
    mock_api._scheduler_proxy = mock_scheduler_proxy

    context.apis = {TEST_CLUSTER.name: mock_api}
    api = context.get_api(TEST_CLUSTER.name,
                          clusters={TEST_CLUSTER.name: TEST_CLUSTER})

    with pytest.raises(Context.CommandError) as e:
        api.kill_job(AuroraJobKey(TEST_CLUSTER.name, 'role', 'env', 'job'))

    assert e.value.code == EXIT_AUTH_ERROR
    assert mock_scheduler_proxy.killTasks.call_count == 1