Пример #1
0
 def setUp(self):
     logging.basicConfig()
     __builtin__.__pillar__ = {}
     __builtin__.__grains__ = {}
     __builtin__.__salt__ = {'system.wait_for': system.wait_for, 'marathon_client.apps': lambda: {
         'chronos': [models.MarathonTask(app_id='chronos', host='host1', ports=[11]),
                     models.MarathonTask(app_id='chronos', host='host2', ports=[12])],
         'kafka-mesos': [models.MarathonTask(app_id='kafka-mesos', host='host1', ports=[12])]}}
 def test_fetch_tasks_some_tasks(self):
     self.cli.list_tasks.return_value = [
         models.MarathonTask(app_id='/chronos', host='host1', id='task1', staged_at='2014-12-10T11:44:55.001Z'),
         models.MarathonTask(app_id='/chronos', host='host2', id='task2', staged_at='2014-12-10T11:43:55.001Z')]
     self.assertEqual(marathon_client._fetch_tasks(self.cli, 'chronos'),
                      {'chronos': [models.MarathonTask(app_id='/chronos', host='host2', id='task2',
                                                       staged_at='2014-12-10T11:43:55.001Z'),
                                   models.MarathonTask(app_id='/chronos', host='host1', id='task1',
                                                       staged_at='2014-12-10T11:44:55.001Z')]})
 def test_unhealthy_task2(self):
     self.cli.list_tasks.return_value = [
         models.MarathonTask(
             app_id='/chronos',
             host='host1',
             id='task1',
             health_check_results=[
                 models.task.MarathonHealthCheckResult(alive=False)
             ])
     ]
     app = marathon_client._healthy_tasks(self.cli, 'chronos', 1)
     self.assertEquals(app, None)
 def test_fetch_tasks_all_tasks(self):
     self.cli.list_tasks.return_value = [
         models.MarathonTask(app_id='/chronos',
                             host='host1',
                             id='task1',
                             staged_at='2014-12-10T11:44:55.001Z'),
         models.MarathonTask(app_id='/docker',
                             host='host2',
                             id='task2',
                             staged_at='2014-12-10T11:23:55.001Z'),
         models.MarathonTask(app_id='/chronos',
                             host='host2',
                             id='task2',
                             staged_at='2014-12-10T11:43:55.001Z')
     ]
     results = marathon_client._fetch_tasks(self.cli, None)
     self.assertEqual(
         results, {
             'chronos': [
                 models.MarathonTask(app_id='/chronos',
                                     host='host2',
                                     id='task2',
                                     staged_at='2014-12-10T11:43:55.001Z'),
                 models.MarathonTask(app_id='/chronos',
                                     host='host1',
                                     id='task1',
                                     staged_at='2014-12-10T11:44:55.001Z')
             ],
             'docker': [
                 models.MarathonTask(app_id='/docker',
                                     host='host2',
                                     id='task2',
                                     staged_at='2014-12-10T11:23:55.001Z')
             ]
         })
 def test_unhealthy_task(self):
     self.cli.list_tasks.return_value = [
         models.MarathonTask(app_id='/chronos', id='task1')
     ]
     app = marathon_client._healthy_tasks(self.cli, 'chronos', 1)
     self.assertEquals(app, None)
 def test_healthy_task(self):
     self.cli.list_tasks.return_value = [
         models.MarathonTask(app_id='/chronos', host='host1', id='task1')
     ]
     app = marathon_client._healthy_tasks(self.cli, 'chronos', 1)
     self.assertEquals(len(app['chronos']), 1)