示例#1
0
def test_marathon_job_status(
    mock_is_app_id_running,
    mock_get_running_tasks_from_active_frameworks,
):
    mock_tasks = [mock.Mock(slave={'hostname': 'host1'}),
                  mock.Mock(slave={'hostname': 'host1'}),
                  mock.Mock(slave={'hostname': 'host2'})]
    mock_get_running_tasks_from_active_frameworks.return_value = mock_tasks
    mock_is_app_id_running.return_value = True

    app = mock.create_autospec(marathon.models.app.MarathonApp)
    app.instances = 5
    app.tasks_running = 5
    app.deployments = []

    client = mock.create_autospec(marathon.MarathonClient)
    client.get_app.return_value = app

    job_config = mock.create_autospec(marathon_tools.MarathonServiceConfig)
    job_config.format_marathon_app_dict.return_value = {'id': 'mock_app_id'}
    job_config.get_instances.return_value = 5

    mstatus = {}
    instance.marathon_job_status(mstatus, client, job_config)
    expected = {'deploy_status': 'Running',
                'running_instance_count': 5,
                'expected_instance_count': 5,
                'app_id': 'mock_app_id'}
    expected_slaves = ['host2', 'host1']
    slaves = mstatus.pop('slaves')
    assert len(slaves) == len(expected_slaves) and sorted(slaves) == sorted(expected_slaves)
    assert mstatus == expected
示例#2
0
def test_marathon_job_status_verbose(
    mock_is_app_id_running,
    mock_get_running_tasks_from_frameworks,
):
    mock_tasks = [
        mock.Mock(slave=asynctest.CoroutineMock(
            return_value={'hostname': 'host1'},
            func=asynctest.CoroutineMock(
            ),  # https://github.com/notion/a_sync/pull/40
        )),
        mock.Mock(slave=asynctest.CoroutineMock(
            return_value={'hostname': 'host1'},
            func=asynctest.CoroutineMock(
            ),  # https://github.com/notion/a_sync/pull/40
        )),
        mock.Mock(slave=asynctest.CoroutineMock(
            return_value={'hostname': 'host2'},
            func=asynctest.CoroutineMock(
            ),  # https://github.com/notion/a_sync/pull/40
        )),
    ]
    mock_get_running_tasks_from_frameworks.return_value = mock_tasks
    mock_is_app_id_running.return_value = True

    app = mock.create_autospec(marathon.models.app.MarathonApp)
    app.instances = 5
    app.tasks_running = 5
    app.deployments = []
    app.id = 'mock_app_id'

    client = mock.create_autospec(marathon.MarathonClient)
    client.get_app.return_value = app

    job_config = mock.create_autospec(marathon_tools.MarathonServiceConfig)
    job_config.format_marathon_app_dict.return_value = {'id': 'mock_app_id'}
    job_config.get_instances.return_value = 5

    mstatus = {}
    instance.marathon_job_status(mstatus, client, job_config, verbose=True)
    expected = {
        'deploy_status': 'Running',
        'running_instance_count': 5,
        'expected_instance_count': 5,
        'app_id': 'mock_app_id',
    }
    expected_slaves = ['host2', 'host1']
    slaves = mstatus.pop('slaves')
    assert len(slaves) == len(expected_slaves) and sorted(slaves) == sorted(
        expected_slaves)
    assert mstatus == expected
示例#3
0
def test_marathon_job_status(
    mock_is_app_id_running,
):
    mock_is_app_id_running.return_value = True

    app = mock.create_autospec(marathon.models.app.MarathonApp)
    app.instances = 5
    app.tasks_running = 5
    app.deployments = []

    client = mock.create_autospec(marathon.MarathonClient)
    client.get_app.return_value = app

    job_config = mock.create_autospec(marathon_tools.MarathonServiceConfig)
    job_config.format_marathon_app_dict.return_value = {'id': 'mock_app_id'}
    job_config.get_instances.return_value = 5

    mstatus = {}
    marathon_job_status(mstatus, client, job_config)
    assert mstatus['deploy_status'] == 'Running'
def test_marathon_job_status_no_dashboard_links(
    mock_get_marathon_app_deploy_status,
    mock_get_marathon_dashboard_links,
    mock_marathon_app_status,
    mock_service_config,
):
    mock_service_config.format_marathon_app_dict = lambda: {"id": "foo"}
    settings.system_paasta_config = mock.create_autospec(SystemPaastaConfig)
    mock_get_marathon_app_deploy_status.return_value = 0  # Running status
    mock_app = mock.Mock(id="/foo", tasks_running=2)

    mock_get_marathon_dashboard_links.return_value = None

    # just make sure we don't throw an error
    instance.marathon_job_status(
        "fake_service",
        "fake_instance",
        mock_service_config,
        marathon_apps_with_clients=[(mock_app, mock.Mock())],
        verbose=0,
    )
def test_marathon_job_status_error(mock_service_config):
    mock_service_config.format_marathon_app_dict = mock.Mock(
        side_effect=NoDockerImageError)

    job_status = instance.marathon_job_status(
        "fake_service",
        "fake_instance",
        mock_service_config,
        marathon_apps_with_clients=[],
        verbose=0,
    )

    assert len(job_status["error_message"]) > 0
示例#6
0
def test_marathon_job_status(
    mock_get_marathon_dashboard_links,
    mock_get_autoscaling_info,
    mock_get_marathon_app_deploy_status,
    mock_marathon_app_status,
    mock_service_config,
):
    mock_service_config.format_marathon_app_dict = lambda: {
        "id": "foo.bar.gitabc.config123",
    }
    settings.system_paasta_config = mock.create_autospec(SystemPaastaConfig)

    mock_get_marathon_app_deploy_status.return_value = 0  # Running status
    mock_get_autoscaling_info.return_value = ServiceAutoscalingInfo(
        current_instances=1,
        max_instances=5,
        min_instances=1,
        current_utilization=None,
        target_instances=3,
    )

    mock_app = mock.Mock(id="/foo.bar.gitabc.config123", tasks_running=2)
    mock_app.container.docker.image = "registry.yelp/servicename-abc"
    job_status = instance.marathon_job_status(
        "fake_service",
        "fake_instance",
        mock_service_config,
        marathon_apps_with_clients=[(mock_app, mock.Mock())],
        verbose=3,
    )

    expected_autoscaling_info = mock_get_autoscaling_info.return_value._asdict(
    )
    del expected_autoscaling_info["current_utilization"]

    assert job_status == {
        "app_statuses": [mock_marathon_app_status.return_value],
        "app_count": 1,
        "desired_state": "start",
        "bounce_method": "fake_bounce",
        "expected_instance_count": 1,
        "desired_app_id": "foo.bar.gitabc.config123",
        "deploy_status": "Running",
        "running_instance_count": 2,
        "autoscaling_info": expected_autoscaling_info,
        "active_shas": [("abc", "123")],
    }

    assert mock_marathon_app_status.call_count == 1