def test_status_marathon_app_no_autoscaling(): with mock.patch( 'paasta_tools.marathon_serviceinit.get_autoscaling_info', autospec=True, return_value=None, ): mock_marathon_client = mock.Mock() fake_app = mock.Mock() 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] fake_app.tasks_running = 1 fake_app.deployments = [] mock_marathon_client.list_queue.return_value = [] deploy_status, num_tasks, out = marathon_serviceinit.status_marathon_app( mock_marathon_client, fake_app, 'fake_service', 'main', 'fake_cluster', '/nail/blah', dashboards=None, verbose=1, ) 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' not in out assert num_tasks == 1
def test_status_marathon_app_column_alignment(): with mock.patch( "paasta_tools.marathon_serviceinit.get_autoscaling_info", autospec=True, return_value=None, ): mock_marathon_client = mock.Mock() mock_marathon_client.list_queue.return_value = [] fake_app = mock.Mock() fake_app.version = "2015-01-15T05:30:49.862Z" fake_app.id = "/fake--service" fake_app.deployments = [] fake_task1 = mock.create_autospec(marathon.models.app.MarathonTask) fake_task1.id = "fake_task1_id" fake_task1.host = "fake_deployed_host" fake_task1.ports = [6666] fake_task1.staged_at = datetime.datetime.fromtimestamp(0) fake_task1.health_check_results = [] fake_task2 = mock.create_autospec(marathon.models.app.MarathonTask) fake_task2.id = "fake_task2_id" fake_task2.host = "fake_deployed_host_with_a_really_long_name" fake_task2.ports = [6666] fake_task2.staged_at = datetime.datetime.fromtimestamp(0) fake_task2.health_check_results = [] fake_app.tasks = [fake_task1, fake_task2] 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, ) (headers_line, task1_line, task2_line) = out.split("\n")[-3:] assert headers_line.index("Host deployed to") == task1_line.index( "fake_deployed_host") assert headers_line.index("Host deployed to") == task2_line.index( "fake_deployed_host_with_a_really_long_name") assert headers_line.index("Deployed at what localtime" ) == task1_line.index("1970-01-01T00:00") assert headers_line.index("Deployed at what localtime" ) == task2_line.index("1970-01-01T00:00")
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_app_column_alignment(): with mock.patch( 'paasta_tools.marathon_serviceinit.get_autoscaling_info', autospec=True, return_value=None, ): mock_marathon_client = mock.Mock() mock_marathon_client.list_queue.return_value = [] fake_app = mock.Mock() fake_app.version = '2015-01-15T05:30:49.862Z' fake_app.id = '/fake--service' fake_app.deployments = [] fake_task1 = mock.create_autospec(marathon.models.app.MarathonTask) fake_task1.id = 'fake_task1_id' fake_task1.host = 'fake_deployed_host' fake_task1.ports = [6666] fake_task1.staged_at = datetime.datetime.fromtimestamp(0) fake_task1.health_check_results = [] fake_task2 = mock.create_autospec(marathon.models.app.MarathonTask) fake_task2.id = 'fake_task2_id' fake_task2.host = 'fake_deployed_host_with_a_really_long_name' fake_task2.ports = [6666] fake_task2.staged_at = datetime.datetime.fromtimestamp(0) fake_task2.health_check_results = [] fake_app.tasks = [fake_task1, fake_task2] 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, ) (headers_line, task1_line, task2_line) = out.split('\n')[-3:] assert headers_line.index('Host deployed to') == task1_line.index('fake_deployed_host') assert headers_line.index('Host deployed to') == task2_line.index('fake_deployed_host_with_a_really_long_name') assert headers_line.index('Deployed at what localtime') == task1_line.index('1970-01-01T00:00') assert headers_line.index('Deployed at what localtime') == task2_line.index('1970-01-01T00:00')