def test_get_verbose_status_of_marathon_app(): mock_autoscaling_info = ServiceAutoscalingInfo(current_instances=str(3), max_instances=str(5), min_instances=str(1), current_utilization="81%", target_instances=str(4)) with mock.patch( 'paasta_tools.marathon_serviceinit.get_autoscaling_info', autospec=True, return_value=mock_autoscaling_info ): mock_marathon_client = mock.Mock() fake_app = mock.create_autospec(marathon.models.app.MarathonApp) fake_app.version = '2015-01-15T05:30:49.862Z' fake_app.id = '/fake--service' fake_task = mock.create_autospec(marathon.models.app.MarathonTask) fake_task.id = 'fake_task_id' fake_task.host = 'fake_deployed_host' fake_task.ports = [6666] fake_task.staged_at = datetime.datetime.fromtimestamp(0) fake_task.health_check_results = [] fake_app.tasks = [fake_task] tasks, out = marathon_serviceinit.get_verbose_status_of_marathon_app(mock_marathon_client, fake_app, 'fake_service', 'main', 'fake_cluster', '/nail/blah') assert 'fake_task_id' in out assert '/fake--service' in out assert 'App created: 2015-01-15 05:30:49' in out assert 'fake_deployed_host:6666' in out assert 'Autoscaling Info' in out assert tasks == [fake_task]
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
def test_status_marathon_app(): mock_autoscaling_info = ServiceAutoscalingInfo( current_instances=str(3), max_instances=str(5), min_instances=str(1), current_utilization="81%", target_instances=str(4), ) with mock.patch( 'paasta_tools.marathon_serviceinit.get_autoscaling_info', autospec=True, return_value=mock_autoscaling_info, ): mock_marathon_client = mock.Mock( name='client', list_queue=mock.Mock(return_value=[]), ) fake_app = mock.Mock( name='app', deployments=[], ) fake_app.version = '2015-01-15T05:30:49.862Z' fake_app.id = '/fake--service' fake_task = mock.create_autospec(marathon.models.app.MarathonTask) fake_task.id = 'fake_task_id' fake_task.host = 'fake_deployed_host' fake_task.ports = [6666] fake_task.staged_at = datetime.datetime.fromtimestamp(0) fake_task.health_check_results = [] fake_app.tasks = [fake_task] status, tasks, out = marathon_serviceinit.status_marathon_app( mock_marathon_client, fake_app, 'fake_service', 'main', 'fake_cluster', '/nail/blah', dashboards={mock_marathon_client: "http://marathon/"}, verbose=1, ) assert 'fake_task_id' in out assert 'http://marathon/ui/#/apps/%2Ffake--service' in out assert 'App created: 2015-01-15 05:30:49' in out assert 'fake_deployed_host:6666' in out assert tasks == fake_app.tasks_running
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