Esempio n. 1
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