Ejemplo n.º 1
0
def test_chronos_instance_status(
    mock_status_chronos_jobs,
    mock_get_actual_deployments,
    mock_validate_service_instance,
    mock_get_chronos_client,
    mock_load_chronos_config,
):
    settings.cluster = "fake_cluster"
    mock_get_actual_deployments.return_value = {
        "fake_cluster.fake_instance": "GIT_SHA",
        "fake_cluster.fake_instance2": "GIT_SHA",
        "fake_cluster2.fake_instance": "GIT_SHA",
        "fake_cluster2.fake_instance2": "GIT_SHA",
    }
    mock_validate_service_instance.return_value = "chronos"

    request = testing.DummyRequest()
    request.swagger_data = {
        "service": "fake_service",
        "instance": "fake_instance"
    }

    instance.instance_status(request)
    assert mock_status_chronos_jobs.call_args == mock.call(
        mock_get_chronos_client.return_value,
        "fake_service",
        "fake_instance",
        "fake_cluster",
        "/nail/etc/services",
        0,
    )
Ejemplo n.º 2
0
def service_instance_status_error(context, error_code, job_id):
    marathon_config = marathon_tools.load_marathon_config()
    settings.marathon_client = marathon_tools.get_marathon_client(
        marathon_config.get_url(),
        marathon_config.get_username(),
        marathon_config.get_password()
    )
    settings.cluster = load_system_paasta_config().get_cluster()
    settings.soa_dir = context.soa_dir

    (service, instance, _, __) = decompose_job_id(job_id)

    request = testing.DummyRequest()
    request.matchdict = {'service': service, 'instance': instance}

    response = None
    try:
        response = instance_status(request)
    except InstanceFailure as exc:
        print exc.msg
        assert exc.err == int(error_code)
    except:
        raise

    assert not response
Ejemplo n.º 3
0
def test_instances_status_adhoc(
    mock_get_actual_deployments,
    mock_validate_service_instance,
    mock_adhoc_instance_status,
):
    settings.cluster = 'fake_cluster'
    mock_get_actual_deployments.return_value = {
        'fake_cluster.fake_instance': 'GIT_SHA',
        'fake_cluster.fake_instance2': 'GIT_SHA',
        'fake_cluster2.fake_instance': 'GIT_SHA',
        'fake_cluster2.fake_instance2': 'GIT_SHA',
    }
    mock_validate_service_instance.return_value = 'adhoc'
    mock_adhoc_instance_status.return_value = {}

    request = testing.DummyRequest()
    request.swagger_data = {
        'service': 'fake_service',
        'instance': 'fake_instance'
    }

    response = instance.instance_status(request)
    assert mock_adhoc_instance_status.called
    assert response == {
        'service': 'fake_service',
        'instance': 'fake_instance',
        'git_sha': 'GIT_SHA',
        'adhoc': {},
    }
def test_instances_status_adhoc(
    mock_get_actual_deployments,
    mock_validate_service_instance,
    mock_adhoc_instance_status,
):
    settings.cluster = "fake_cluster"
    mock_get_actual_deployments.return_value = {
        "fake_cluster.fake_instance": "GIT_SHA",
        "fake_cluster.fake_instance2": "GIT_SHA",
        "fake_cluster2.fake_instance": "GIT_SHA",
        "fake_cluster2.fake_instance2": "GIT_SHA",
    }
    mock_validate_service_instance.return_value = "adhoc"
    mock_adhoc_instance_status.return_value = {}

    request = testing.DummyRequest()
    request.swagger_data = {
        "service": "fake_service",
        "instance": "fake_instance"
    }

    response = instance.instance_status(request)
    assert mock_adhoc_instance_status.called
    assert response == {
        "service": "fake_service",
        "instance": "fake_instance",
        "git_sha": "GIT_SHA",
        "adhoc": {},
    }
Ejemplo n.º 5
0
def test_chronos_instance_status(
    mock_get_cached_list_of_running_tasks_from_frameworks,
    mock_select_tasks_by_id,
    mock_get_actual_deployments,
    mock_validate_service_instance,
    mock_load_chronos_job_config,
    mock_get_chronos_client,
    mock_load_chronos_config,
):
    settings.cluster = 'fake_cluster'
    mock_get_actual_deployments.return_value = {
        'fake_cluster.fake_instance': 'GIT_SHA',
        'fake_cluster.fake_instance2': 'GIT_SHA',
        'fake_cluster2.fake_instance': 'GIT_SHA',
        'fake_cluster2.fake_instance2': 'GIT_SHA',
    }
    mock_validate_service_instance.return_value = 'chronos'
    mock_select_tasks_by_id.return_value = [1, 2, 3]

    mock_load_chronos_job_config.return_value = ChronosJobConfig(
        'fake_service',
        'fake_instance',
        'fake_cluster',
        {
            'schedule': 'always',
        },
        None,
    )

    request = testing.DummyRequest()
    request.swagger_data = {'service': 'fake_service', 'instance': 'fake_instance'}

    response = instance.instance_status(request)
    assert response['chronos']['schedule']['schedule'] == 'always'
    assert response['chronos']['schedule_type'] == 'schedule'
Ejemplo n.º 6
0
def test_instances_status_marathon(
    mock_get_actual_deployments,
    mock_validate_service_instance,
    mock_load_marathon_service_config,
    mock_get_matching_appids,
    mock_marathon_job_status,
):
    settings.cluster = 'fake_cluster'
    mock_get_actual_deployments.return_value = {
        'fake_cluster.fake_instance': 'GIT_SHA',
        'fake_cluster.fake_instance2': 'GIT_SHA',
        'fake_cluster2.fake_instance': 'GIT_SHA',
        'fake_cluster2.fake_instance2': 'GIT_SHA',
    }
    mock_validate_service_instance.return_value = 'marathon'

    settings.marathon_clients = mock.Mock()

    mock_get_matching_appids.return_value = ['a', 'b']
    mock_service_config = marathon_tools.MarathonServiceConfig(
        service='fake_service',
        cluster='fake_cluster',
        instance='fake_instance',
        config_dict={'bounce_method': 'fake_bounce'},
        branch_dict=None,
    )
    mock_load_marathon_service_config.return_value = mock_service_config
    mock_marathon_job_status.return_value = 'fake_marathon_status'

    request = testing.DummyRequest()
    request.swagger_data = {'service': 'fake_service', 'instance': 'fake_instance'}

    response = instance.instance_status(request)
    assert response['marathon']['bounce_method'] == 'fake_bounce'
    assert response['marathon']['desired_state'] == 'start'
Ejemplo n.º 7
0
def service_instance_status(context, app_count, job_id):
    settings.cluster = context.cluster
    settings.marathon_client = context.marathon_client
    settings.soa_dir = context.soa_dir

    (service, instance, _, __) = decompose_job_id(job_id)
    request = testing.DummyRequest()
    request.swagger_data = {'service': service, 'instance': instance}
    response = instance_status(request)

    assert response['marathon']['app_count'] == int(app_count), response
    assert response['marathon']['running_instance_count'] == response['marathon']['expected_instance_count'], response
Ejemplo n.º 8
0
def service_instance_status_error(context, error_code, job_id):
    (service, instance, _, __) = decompose_job_id(job_id)
    request = testing.DummyRequest()
    request.swagger_data = {'service': service, 'instance': instance}

    response = None
    try:
        response = instance_status(request)
    except ApiFailure as exc:
        assert 'not found' in exc.msg
        assert exc.err == int(error_code)

    assert not response
Ejemplo n.º 9
0
def service_instance_status_error(context, error_code, job_id):
    (service, instance, _, __) = decompose_job_id(job_id)
    request = testing.DummyRequest()
    request.swagger_data = {'service': service, 'instance': instance}

    response = None
    try:
        response = instance_status(request)
    except ApiFailure as exc:
        assert 'not found' in exc.msg
        assert exc.err == int(error_code)

    assert not response
Ejemplo n.º 10
0
def service_instance_status_error(context, error_code, job_id):
    (service, instance, _, __) = decompose_job_id(job_id)
    request = testing.DummyRequest()
    request.swagger_data = {"service": service, "instance": instance}

    response = None
    try:
        response = instance_status(request)
    except InstanceFailure as exc:
        assert "not found" in exc.msg
        assert exc.err == int(error_code)
    except:
        raise

    assert not response
def test_tron_instance_status(
    mock_validate_service_instance,
    mock_get_tron_client,
    mock_tron_client,
    mock_get_tron_dashboard_for_cluster,
):
    settings.cluster = "fake_cluster"
    mock_validate_service_instance.return_value = "tron"
    mock_client = mock_tron_client("fake_url")
    mock_get_tron_client.return_value = mock_client
    mock_client.get_job_content.return_value = {
        "status": "fake_status",
        "scheduler": {
            "type": "daily",
            "value": "1 2 3"
        },
    }
    mock_client.get_action_run.return_value = {
        "state": "fake_state",
        "start_time": "fake_start_time",
        "raw_command": "fake_raw_command",
        "command": "fake_command",
        "stdout": ["fake_stdout"],
        "stderr": ["fake_stderr"],
    }
    mock_get_tron_dashboard_for_cluster.return_value = "http://fake_url/"

    request = testing.DummyRequest()
    request.swagger_data = {
        "service": "fake_service",
        "instance": "fake_job.fake_action",
    }
    response = instance.instance_status(request)
    assert response["tron"]["job_name"] == "fake_job"
    assert response["tron"]["job_status"] == "fake_status"
    assert response["tron"]["job_schedule"] == "daily 1 2 3"
    assert response["tron"][
        "job_url"] == "http://fake_url/#job/fake_service.fake_job"
    assert response["tron"]["action_name"] == "fake_action"
    assert response["tron"]["action_state"] == "fake_state"
    assert response["tron"]["action_raw_command"] == "fake_raw_command"
    assert response["tron"]["action_command"] == "fake_command"
    assert response["tron"]["action_start_time"] == "fake_start_time"
    assert response["tron"]["action_stdout"] == "fake_stdout"
    assert response["tron"]["action_stderr"] == "fake_stderr"
Ejemplo n.º 12
0
def service_instance_status(context, app_count, job_id):
    marathon_config = marathon_tools.load_marathon_config()
    settings.marathon_client = marathon_tools.get_marathon_client(
        marathon_config.get_url(),
        marathon_config.get_username(),
        marathon_config.get_password()
    )
    settings.cluster = load_system_paasta_config().get_cluster()
    settings.soa_dir = context.soa_dir

    (service, instance, _, __) = decompose_job_id(job_id)

    request = testing.DummyRequest()
    request.matchdict = {'service': service, 'instance': instance}
    response = instance_status(request)

    assert response['app_count'] == int(app_count), response
    assert response['marathon']['running_instance_count'] == response['marathon']['expected_instance_count'], response
Ejemplo n.º 13
0
def test_tron_instance_status(
    mock_validate_service_instance,
    mock_get_tron_client,
    mock_tron_client,
    mock_get_tron_dashboard_for_cluster,
):
    settings.cluster = 'fake_cluster'
    mock_validate_service_instance.return_value = 'tron'
    mock_client = mock_tron_client('fake_url')
    mock_get_tron_client.return_value = mock_client
    mock_client.get_job_content.return_value = {
        'status': 'fake_status',
        'scheduler': {
            'type': 'daily',
            'value': '1 2 3',
        },
    }
    mock_client.get_action_run.return_value = {
        'state': 'fake_state',
        'start_time': 'fake_start_time',
        'raw_command': 'fake_raw_command',
        'command': 'fake_command',
        'stdout': ['fake_stdout'],
        'stderr': ['fake_stderr'],
    }
    mock_get_tron_dashboard_for_cluster.return_value = 'http://fake_url/'

    request = testing.DummyRequest()
    request.swagger_data = {'service': 'fake_service', 'instance': 'fake_job.fake_action'}
    response = instance.instance_status(request)
    assert response['tron']['job_name'] == 'fake_job'
    assert response['tron']['job_status'] == 'fake_status'
    assert response['tron']['job_schedule'] == 'daily 1 2 3'
    assert response['tron']['job_url'] == 'http://fake_url/#job/fake_service.fake_job'
    assert response['tron']['action_name'] == 'fake_action'
    assert response['tron']['action_state'] == 'fake_state'
    assert response['tron']['action_raw_command'] == 'fake_raw_command'
    assert response['tron']['action_command'] == 'fake_command'
    assert response['tron']['action_start_time'] == 'fake_start_time'
    assert response['tron']['action_stdout'] == 'fake_stdout'
    assert response['tron']['action_stderr'] == 'fake_stderr'
Ejemplo n.º 14
0
def test_instances_status(
    mock_get_actual_deployments,
    mock_validate_service_instance,
    mock_load_marathon_service_config,
    mock_get_matching_appids,
    mock_marathon_job_status,
):
    settings.cluster = 'fake_cluster'
    mock_get_actual_deployments.return_value = {'fake_cluster.fake_instance': 'GIT_SHA',
                                                'fake_cluster.fake_instance2': 'GIT_SHA',
                                                'fake_cluster2.fake_instance': 'GIT_SHA',
                                                'fake_cluster2.fake_instance2': 'GIT_SHA'}
    mock_validate_service_instance.return_value = 'marathon'

    mock_marathon_config = marathon_tools.MarathonConfig(
        {'url': 'fake_url', 'user': '******', 'password': '******'}
    )
    settings.marathon_client = marathon_tools.get_marathon_client(
        mock_marathon_config.get_url(),
        mock_marathon_config.get_username(),
        mock_marathon_config.get_password()
    )

    mock_get_matching_appids.return_value = ['a', 'b']
    mock_service_config = marathon_tools.MarathonServiceConfig(
        service='fake_service',
        cluster='fake_cluster',
        instance='fake_instance',
        config_dict={'bounce_method': 'fake_bounce'},
        branch_dict={},
    )
    mock_load_marathon_service_config.return_value = mock_service_config
    mock_marathon_job_status.return_value = 'fake_marathon_status'

    request = testing.DummyRequest()
    request.swagger_data = {'service': 'fake_service', 'instance': 'fake_instance'}

    response = instance.instance_status(request)
    assert response['marathon']['bounce_method'] == 'fake_bounce'
    assert response['marathon']['desired_state'] == 'start'
def test_instance_status_marathon(
    mock_get_actual_deployments,
    mock_validate_service_instance,
    mock_load_marathon_service_config,
    mock_get_marathon_apps_with_clients,
    mock_get_matching_apps_with_clients,
    mock_marathon_job_status,
    mock_load_service_namespace_config,
    mock_marathon_smartstack_status,
    mock_marathon_mesos_status,
    include_smartstack,
    include_mesos,
):
    settings.cluster = "fake_cluster"

    mock_get_actual_deployments.return_value = {
        "fake_cluster.fake_instance": "GIT_SHA",
        "fake_cluster.fake_instance2": "GIT_SHA",
        "fake_cluster2.fake_instance": "GIT_SHA",
        "fake_cluster2.fake_instance2": "GIT_SHA",
    }
    mock_validate_service_instance.return_value = "marathon"

    settings.marathon_clients = mock.Mock()

    mock_service_config = marathon_tools.MarathonServiceConfig(
        service="fake_service",
        cluster="fake_cluster",
        instance="fake_instance",
        config_dict={"bounce_method": "fake_bounce"},
        branch_dict=None,
    )
    mock_load_marathon_service_config.return_value = mock_service_config
    mock_app = mock.Mock(tasks=[mock.Mock()])
    mock_get_matching_apps_with_clients.return_value = [(mock_app, mock.Mock())
                                                        ]

    mock_marathon_job_status.return_value = {
        "marathon_job_status_field1": "field1_value",
        "marathon_job_status_field2": "field2_value",
    }
    mock_load_service_namespace_config.return_value = {"proxy_port": 1234}

    request = testing.DummyRequest()
    request.swagger_data = {
        "service": "fake_service",
        "instance": "fake_instance",
        "verbose": 2,
        "include_smartstack": include_smartstack,
        "include_mesos": include_mesos,
    }
    response = instance.instance_status(request)

    expected_response = {
        "marathon_job_status_field1": "field1_value",
        "marathon_job_status_field2": "field2_value",
    }
    if include_smartstack:
        expected_response[
            "smartstack"] = mock_marathon_smartstack_status.return_value
    if include_mesos:
        expected_response["mesos"] = mock_marathon_mesos_status.return_value
    assert response["marathon"] == expected_response

    mock_marathon_job_status.assert_called_once_with(
        "fake_service",
        "fake_instance",
        mock_service_config,
        mock_get_matching_apps_with_clients.return_value,
        2,
    )
    if include_mesos:
        mock_marathon_mesos_status.assert_called_once_with(
            "fake_service", "fake_instance", 2)
    if include_smartstack:
        mock_marathon_smartstack_status.assert_called_once_with(
            "fake_service",
            "fake_instance",
            mock_service_config,
            mock_load_service_namespace_config.return_value,
            mock_app.tasks,
            should_return_individual_backends=True,
        )