Ejemplo n.º 1
0
def _assert_pod_update_propagates_exception(resource_reader, marathon_client,
                                            error_message):
    subcmd = main.MarathonSubcommand(resource_reader, lambda: marathon_client)

    with pytest.raises(DCOSException) as exception_info:
        subcmd.pod_update(pod_id='foo', force=False)

    assert str(exception_info.value) == error_message
Ejemplo n.º 2
0
def _assert_pod_add_propagates_exceptions_from_add_pod(exception):
    resource_reader = create_autospec(main.ResourceReader)
    resource_reader.get_resource.return_value = {'some': 'json'}

    marathon_client = _marathon_client_fixture()
    marathon_client.add_pod.side_effect = exception

    subcmd = main.MarathonSubcommand(resource_reader, lambda: marathon_client)
    with pytest.raises(exception.__class__) as exception_info:
        subcmd.pod_add('does/not/matter')

    assert exception_info.value == exception
Ejemplo n.º 3
0
def _assert_pod_add_invoked_successfully(pod_file_json):
    pod_file_path = "some/path/to/pod.json"
    resource_reader = create_autospec(main.ResourceReader)
    resource_reader.get_resource.return_value = pod_file_json
    marathon_client = _marathon_client_fixture()

    subcmd = main.MarathonSubcommand(resource_reader, lambda: marathon_client)
    returncode = subcmd.pod_add(pod_file_path)

    assert returncode == 0
    resource_reader.get_resource.assert_called_with(pod_file_path)
    marathon_client.add_pod.assert_called_with(pod_file_json)
Ejemplo n.º 4
0
def test_pod_kill_reports_error_when_no_instance_ids_are_provided():
    def no_marathon_client():
        assert False, "should not be called"

    subcmd = main.MarathonSubcommand(_failing_resource_reader(),
                                     no_marathon_client)

    with pytest.raises(DCOSException) as exception_info:
        subcmd.pod_kill('arbitrary', [])

    message = 'Please provide at least one pod instance ID'
    assert str(exception_info.value) == message
Ejemplo n.º 5
0
def _assert_pod_update_invoked_successfully(emitter, pod_id, force, resource,
                                            deployment_id, emitted):
    resource_reader = create_autospec(main.ResourceReader)
    resource_reader.get_resource.return_value = resource

    marathon_client = _marathon_client_fixture()
    marathon_client.update_pod.return_value = deployment_id

    subcmd = main.MarathonSubcommand(resource_reader, lambda: marathon_client)
    returncode = subcmd.pod_update(pod_id, force)

    assert returncode == 0
    marathon_client.show_pod.assert_called_with(pod_id)
    resource_reader.get_resource.assert_called_with(name=None)
    marathon_client.update_pod.assert_called_with(pod_id,
                                                  pod_json=resource,
                                                  force=force)
    emitter.publish.assert_called_with(emitted)
Ejemplo n.º 6
0
def _failing_reader_fixture():
    marathon_client = _marathon_client_fixture()
    subcmd = main.MarathonSubcommand(_failing_resource_reader(),
                                     lambda: marathon_client)

    return subcmd, marathon_client