예제 #1
0
def tests_status_marathon_job_when_running_not_running():
    client = mock.create_autospec(marathon.MarathonClient)
    service = "my_service"
    instance = "my_instance"
    app_id = "mock_app_id"
    normal_instance_count = 5
    with contextlib.nested(mock.patch("paasta_tools.marathon_tools.is_app_id_running", return_value=True)) as (
        is_app_id_running_patch,
    ):
        marathon_serviceinit.status_marathon_job(service, instance, app_id, normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
예제 #2
0
def tests_status_marathon_job_when_running_not_running():
    client = mock.create_autospec(marathon.MarathonClient)
    service = 'my_service'
    instance = 'my_instance'
    app_id = 'mock_app_id'
    normal_instance_count = 5
    with contextlib.nested(
            mock.patch('paasta_tools.marathon_tools.is_app_id_running',
                       return_value=True), ) as (is_app_id_running_patch, ):
        marathon_serviceinit.status_marathon_job(service, instance, app_id,
                                                 normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
예제 #3
0
def tests_status_marathon_job_when_running_not_running():
    client = mock.create_autospec(marathon.MarathonClient)
    client.get_app.return_value.tasks_running = 0
    service = 'my_service'
    instance = 'my_instance'
    app_id = 'mock_app_id'
    normal_instance_count = 5
    with mock.patch(
        'paasta_tools.marathon_tools.is_app_id_running', return_value=True, autospec=True,
    ) as is_app_id_running_patch:
        marathon_serviceinit.status_marathon_job(service, instance, app_id, normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
예제 #4
0
def tests_status_marathon_job_when_running_running_no_tasks():
    client = mock.create_autospec(marathon.MarathonClient)
    app = mock.create_autospec(marathon.models.app.MarathonApp)
    client.get_app.return_value = app
    service = "my_service"
    instance = "my_instance"
    app_id = "mock_app_id"
    normal_instance_count = 5
    mock_tasks_running = 0
    app.tasks_running = mock_tasks_running
    app.deployments = []
    with contextlib.nested(mock.patch("paasta_tools.marathon_tools.is_app_id_running", return_value=True)) as (
        is_app_id_running_patch,
    ):
        marathon_serviceinit.status_marathon_job(service, instance, app_id, normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
def tests_status_marathon_job_when_running_running_tasks_with_waiting_deployment(
):
    client = mock.create_autospec(marathon.MarathonClient)
    app = mock.create_autospec(marathon.models.app.MarathonApp)
    client.get_app.return_value = app
    service = 'my_service'
    instance = 'my_instance'
    app_id = 'mock_app_id'
    normal_instance_count = 5
    mock_tasks_running = 0
    app.tasks_running = mock_tasks_running
    app.deployments = ['test_deployment']
    app.instances = normal_instance_count
    with mock.patch(
            'paasta_tools.marathon_tools.is_app_id_running',
            return_value=True,
            autospec=True,
    ) as is_app_id_running_patch, mock.patch(
            'paasta_tools.marathon_tools.get_app_queue_status',
            return_value=(True, 0),
            autospec=True,
    ) as get_app_queue_status_patch:
        output = marathon_serviceinit.status_marathon_job(
            service, instance, app_id, normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
        get_app_queue_status_patch.assert_called_once_with(client, app_id)
        assert 'Waiting' in output
def tests_status_marathon_job_when_running_running_tasks_with_suspended_deployment(
):
    client = mock.create_autospec(marathon.MarathonClient)
    app = mock.create_autospec(marathon.models.app.MarathonApp)
    client.get_app.return_value = app
    service = 'my_service'
    instance = 'my_instance'
    app_id = 'mock_app_id'
    normal_instance_count = 5
    mock_tasks_running = 0
    app.tasks_running = mock_tasks_running
    app.deployments = []
    app.instances = 0
    app.tasks_running = 0
    with contextlib.nested(
            mock.patch('paasta_tools.marathon_tools.is_app_id_running',
                       return_value=True,
                       autospec=True),
            mock.patch('paasta_tools.marathon_tools.get_app_queue_status',
                       return_value=(None, None),
                       autospec=True),
    ) as (
            is_app_id_running_patch,
            get_app_queue_status_patch,
    ):
        output = marathon_serviceinit.status_marathon_job(
            service, instance, app_id, normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
        assert get_app_queue_status_patch.call_count == 1
        assert 'Stopped' in output
예제 #7
0
def status_marathon_job(context, status, job_id):
    normal_instance_count = 1
    (service, instance, _, __) = decompose_job_id(job_id)
    job_config = marathon_tools.load_marathon_service_config(
        service=service,
        instance=instance,
        cluster=load_system_paasta_config().get_cluster(),
        soa_dir=context.soa_dir,
    )
    app_id = job_config.format_marathon_app_dict()['id']

    with requests_cache.disabled():
        tasks, output = marathon_serviceinit.status_marathon_job(
            service=service,
            instance=instance,
            cluster=load_system_paasta_config().get_cluster(),
            soa_dir=context.soa_dir,
            dashboards=None,
            normal_instance_count=normal_instance_count,
            clients=context.marathon_clients,
            job_config=job_config,
            desired_app_id=app_id,
            verbose=0,
        )
    assert status in output, f"{status!r} not found in {output!r}"
예제 #8
0
def test_status_marathon_job_when_running():
    client = mock.create_autospec(marathon.MarathonClient)
    app = mock.create_autospec(marathon.models.app.MarathonApp)
    client.get_app.return_value = app
    service = 'my_service'
    instance = 'my_instance'
    app_id = 'mock_app_id'
    normal_instance_count = 5
    mock_tasks_running = 5
    app.tasks_running = mock_tasks_running
    app.deployments = []
    app.instances = normal_instance_count
    with mock.patch(
        'paasta_tools.marathon_tools.is_app_id_running', return_value=True, autospec=True,
    ) as is_app_id_running_patch:
        marathon_serviceinit.status_marathon_job(service, instance, app_id, normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
예제 #9
0
def tests_status_marathon_job_when_running_running_no_tasks():
    client = mock.create_autospec(marathon.MarathonClient)
    app = mock.create_autospec(marathon.models.app.MarathonApp)
    client.get_app.return_value = app
    service = 'my_service'
    instance = 'my_instance'
    app_id = 'mock_app_id'
    normal_instance_count = 5
    mock_tasks_running = 0
    app.tasks_running = mock_tasks_running
    app.deployments = []
    with contextlib.nested(
            mock.patch('paasta_tools.marathon_tools.is_app_id_running',
                       return_value=True), ) as (is_app_id_running_patch, ):
        marathon_serviceinit.status_marathon_job(service, instance, app_id,
                                                 normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
예제 #10
0
def status_marathon_job(context, status, job_id):
    normal_instance_count = 1
    (service, instance, _, __) = decompose_job_id(job_id)
    app_id = marathon_tools.create_complete_config(service, instance, None, soa_dir=context.soa_dir)["id"]

    output = marathon_serviceinit.status_marathon_job(
        service, instance, app_id, normal_instance_count, context.marathon_client
    )
    assert status in output
예제 #11
0
def test_status_marathon_job_when_running():
    client = mock.create_autospec(marathon.MarathonClient)
    app = mock.create_autospec(marathon.models.app.MarathonApp)
    client.get_app.return_value = app
    service = 'my_service'
    instance = 'my_instance'
    app_id = 'mock_app_id'
    normal_instance_count = 5
    mock_tasks_running = 5
    app.tasks_running = mock_tasks_running
    app.deployments = []
    app.instances = normal_instance_count
    with contextlib.nested(
        mock.patch('paasta_tools.marathon_tools.is_app_id_running', return_value=True, autospec=True),
    ) as (
        is_app_id_running_patch,
    ):
        marathon_serviceinit.status_marathon_job(service, instance, app_id, normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
예제 #12
0
def status_marathon_job(context, status, job_id):
    normal_instance_count = 1
    (service, instance, _, __) = decompose_job_id(job_id)
    app_id = marathon_tools.create_complete_config(
        service, instance, soa_dir=context.soa_dir)['id']

    output = marathon_serviceinit.status_marathon_job(service, instance,
                                                      app_id,
                                                      normal_instance_count,
                                                      context.marathon_client)
    assert status in output
예제 #13
0
def status_marathon_job(context, status, job_id):
    normal_instance_count = 1
    (service, instance, _, __) = decompose_job_id(job_id)
    app_id = marathon_tools.create_complete_config(service, instance, soa_dir=context.soa_dir)['id']

    with requests_cache.disabled():
        output = marathon_serviceinit.status_marathon_job(
            service,
            instance,
            app_id,
            normal_instance_count,
            context.marathon_client
        )
    assert status in output
예제 #14
0
def status_marathon_job(context, status, job_id):
    normal_instance_count = 1
    (service, instance, _, __) = decompose_job_id(job_id)
    app_id = marathon_tools.create_complete_config(
        service, instance, soa_dir=context.soa_dir)['id']

    with requests_cache.disabled():
        output = marathon_serviceinit.status_marathon_job(
            service,
            instance,
            app_id,
            normal_instance_count,
            context.marathon_clients.current[0],
        )
    assert status in output
예제 #15
0
def tests_status_marathon_job_when_running_running_tasks_with_waiting_deployment(
):
    client = mock.create_autospec(marathon.MarathonClient,
                                  servers=["server"],
                                  name="client")
    app_id = "servicename.instancename.gitAAAA.configBBBB"
    app = mock.Mock(
        name="app",
        id=f"/{app_id}",
        tasks=[],
        deployments=["test_deployment"],
        version="1970-01-01T00:00:00Z",
    )
    client.get_app.return_value = app
    client.list_apps.return_value = [app]
    clients = marathon_tools.MarathonClients(current=[client],
                                             previous=[client])
    service = "servicename"
    instance = "instancename"
    cluster = "my_cluster"
    soa_dir = "/soa/dir"
    job_config = mock.Mock()
    job_config.get_marathon_shard.return_value = None
    job_config.get_previous_marathon_shards.return_value = None
    normal_instance_count = 5
    mock_tasks_running = 0
    app.tasks_running = mock_tasks_running
    app.instances = normal_instance_count

    with mock.patch(
            "paasta_tools.marathon_tools.get_app_queue_status",
            return_value=(True, 0),
            autospec=True,
    ) as get_app_queue_status_patch:
        _, output = marathon_serviceinit.status_marathon_job(
            service=service,
            instance=instance,
            cluster=cluster,
            soa_dir=soa_dir,
            dashboards=None,
            normal_instance_count=normal_instance_count,
            clients=clients,
            job_config=job_config,
            desired_app_id=app_id,
            verbose=0,
        )
        get_app_queue_status_patch.assert_called_with(client, app.id)
        assert "Waiting" in output
def tests_status_marathon_job_when_running_running_tasks_with_delayed_deployment():
    client = mock.create_autospec(marathon.MarathonClient, servers=['server'], name="client")
    app_id = 'my--service.my--instance.gitAAAA.configBBBB'
    app = mock.Mock(
        name="app",
        id=f"/{app_id}",
        tasks=[],
        deployments=['test_deployment'],
        version='1970-01-01T00:00:00Z',
    )
    client.get_app.return_value = app
    client.list_apps.return_value = [app]
    clients = marathon_tools.MarathonClients(current=[client], previous=[client])
    service = 'my_service'
    instance = 'my_instance'
    cluster = 'my_cluster'
    soa_dir = '/soa/dir'
    job_config = mock.Mock()
    job_config.get_marathon_shard.return_value = None
    job_config.get_previous_marathon_shards.return_value = None
    normal_instance_count = 5
    mock_tasks_running = 0
    app.tasks_running = mock_tasks_running
    app.instances = normal_instance_count

    with mock.patch(
        'paasta_tools.marathon_tools.get_app_queue_status', return_value=(False, 10), autospec=True,
    ) as get_app_queue_status_patch:
        _, output = marathon_serviceinit.status_marathon_job(
            service=service,
            instance=instance,
            cluster=cluster,
            soa_dir=soa_dir,
            dashboards=None,
            normal_instance_count=normal_instance_count,
            clients=clients,
            job_config=job_config,
            desired_app_id=app_id,
            verbose=0,
        )
        get_app_queue_status_patch.assert_called_with(client, app.id)
        assert 'Delayed' in output
예제 #17
0
def status_marathon_job(context, status, job_id):
    normal_instance_count = 1
    (service, instance, _, __) = decompose_job_id(job_id)
    job_config = marathon_tools.load_marathon_service_config(
        service=service,
        instance=instance,
        cluster=load_system_paasta_config().get_cluster(),
        soa_dir=context.soa_dir,
    )
    app_id = job_config.format_marathon_app_dict()['id']

    with requests_cache.disabled():
        output = marathon_serviceinit.status_marathon_job(
            service,
            instance,
            app_id,
            normal_instance_count,
            context.marathon_clients.get_current_client_for_service(
                job_config),
        )
    assert status in output
예제 #18
0
def tests_status_marathon_job_when_running_running_tasks_with_delayed_deployment():
    client = mock.create_autospec(marathon.MarathonClient)
    app = mock.create_autospec(marathon.models.app.MarathonApp)
    client.get_app.return_value = app
    service = 'my_service'
    instance = 'my_instance'
    app_id = 'mock_app_id'
    normal_instance_count = 5
    mock_tasks_running = 0
    app.tasks_running = mock_tasks_running
    app.deployments = ['test_deployment']
    app.instances = normal_instance_count
    with contextlib.nested(
        mock.patch('paasta_tools.marathon_tools.is_app_id_running', return_value=True, autospec=True),
        mock.patch('paasta_tools.marathon_tools.get_app_queue_status', return_value=(False, 10), autospec=True),
    ) as (
        is_app_id_running_patch,
        get_app_queue_status_patch,
    ):
        output = marathon_serviceinit.status_marathon_job(service, instance, app_id, normal_instance_count, client)
        is_app_id_running_patch.assert_called_once_with(app_id, client)
        get_app_queue_status_patch.assert_called_with(client, app_id)
        assert 'Delayed' in output
예제 #19
0
def test_status_marathon_job_verbose():
    client = mock.create_autospec(marathon.MarathonClient)
    clients = mock.Mock(get_all_clients_for_service=mock.Mock(
        return_value=[client]))
    task = mock.Mock()
    app = mock.create_autospec(
        marathon.models.app.MarathonApp,
        id="servicename.instancename.gitAAAAA.configBBBBB",
        tasks=[task],
    )
    client.get_app.return_value = app
    service = "servicename"
    instance = "instancename"
    with mock.patch(
            "paasta_tools.marathon_serviceinit.marathon_tools.get_marathon_apps_with_clients",
            autospec=True,
    ) as mock_get_marathon_apps_with_clients, mock.patch(
            "paasta_tools.marathon_serviceinit.marathon_tools.get_matching_apps_with_clients",
            autospec=True,
    ) as mock_get_matching_apps_with_clients, mock.patch(
            "paasta_tools.marathon_serviceinit.status_marathon_app",
            autospec=True) as mock_status_marathon_app, mock.patch(
                "paasta_tools.marathon_serviceinit.get_autoscaling_info",
                autospec=True,
                return_value=ServiceAutoscalingInfo(
                    current_instances=1,
                    max_instances=2,
                    min_instances=3,
                    current_utilization=0.4,
                    target_instances=5,
                ),
            ):
        mock_get_matching_apps_with_clients.return_value = [(app, client)]
        mock_status_marathon_app.return_value = (0, 0, "fake_return")
        tasks, out = marathon_serviceinit.status_marathon_job(
            service=service,
            instance=instance,
            clients=clients,
            cluster="fake_cluster",
            soa_dir="/nail/blah",
            job_config=mock.Mock(),
            dashboards=None,
            verbose=1,
            normal_instance_count=3,
            desired_app_id="servicename.instancename.gitAAAAA.configBBBBB",
        )
        mock_get_marathon_apps_with_clients.assert_called_once_with(
            clients=[client], embed_tasks=True, service_name=service)
        mock_get_matching_apps_with_clients.assert_called_once_with(
            service, instance,
            mock_get_marathon_apps_with_clients.return_value)
        mock_status_marathon_app.assert_called_once_with(
            marathon_client=client,
            app=app,
            service=service,
            instance=instance,
            cluster="fake_cluster",
            soa_dir="/nail/blah",
            dashboards=None,
            verbose=1,
        )
        assert tasks == [task]
        assert "fake_return" in out
        assert "  Autoscaling Info:" in out
def test_status_marathon_job_verbose():
    client = mock.create_autospec(marathon.MarathonClient)
    clients = mock.Mock(
        get_all_clients_for_service=mock.Mock(return_value=[client]),
    )
    task = mock.Mock()
    app = mock.create_autospec(
        marathon.models.app.MarathonApp,
        id="my_service.my_instance.gitAAAAA.configBBBBB",
        tasks=[task],
    )
    client.get_app.return_value = app
    service = 'my_service'
    instance = 'my_instance'
    with mock.patch(
        'paasta_tools.marathon_serviceinit.marathon_tools.get_marathon_apps_with_clients', autospec=True,
    ) as mock_get_marathon_apps_with_clients, mock.patch(
        'paasta_tools.marathon_serviceinit.marathon_tools.get_matching_apps_with_clients', autospec=True,
    ) as mock_get_matching_apps_with_clients, mock.patch(
        'paasta_tools.marathon_serviceinit.status_marathon_app', autospec=True,
    ) as mock_status_marathon_app, mock.patch(
        'paasta_tools.marathon_serviceinit.get_autoscaling_info', autospec=True, return_value=ServiceAutoscalingInfo(
            current_instances='1',
            max_instances='2',
            min_instances='3',
            current_utilization='4',
            target_instances='5',
        ),
    ):
        mock_get_matching_apps_with_clients.return_value = [(app, client)]
        mock_status_marathon_app.return_value = (0, 0, 'fake_return')
        tasks, out = marathon_serviceinit.status_marathon_job(
            service=service,
            instance=instance,
            clients=clients,
            cluster='fake_cluster',
            soa_dir='/nail/blah',
            job_config=mock.Mock(),
            dashboards=None,
            verbose=1,
            normal_instance_count=3,
            desired_app_id='my_service.my_instance.gitAAAAA.configBBBBB',
        )
        mock_get_marathon_apps_with_clients.assert_called_once_with(
            [client],
            embed_tasks=True,
        )
        mock_get_matching_apps_with_clients.assert_called_once_with(
            service,
            instance,
            mock_get_marathon_apps_with_clients.return_value,
        )
        mock_status_marathon_app.assert_called_once_with(
            marathon_client=client,
            app=app,
            service=service,
            instance=instance,
            cluster='fake_cluster',
            soa_dir='/nail/blah',
            dashboards=None,
            verbose=1,
        )
        assert tasks == [task]
        assert 'fake_return' in out
        assert '  Autoscaling Info:' in out