示例#1
0
 def test_restart_no_such_job_with_instances(self):
   (mock_api, mock_scheduler_proxy) = self.create_mock_api()
   mock_health_check = self.setup_health_checks(mock_api)
   mock_io = IOMock()
   self.setup_mock_scheduler_for_simple_restart(mock_api)
   # Make getTasksWithoutConfigs return an error, which is what happens when a job is not found.
   mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_error_response()
   with contextlib.nested(
       patch('apache.aurora.client.cli.context.AuroraCommandContext.print_err',
             side_effect=mock_io.put),
       patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
       patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
       patch('apache.aurora.client.api.instance_watcher.StatusHealthCheck',
           return_value=mock_health_check),
       patch('time.time', side_effect=functools.partial(self.fake_time, self)),
       patch('threading._Event.wait')):
     with temporary_file() as fp:
       fp.write(self.get_valid_config())
       fp.flush()
       cmd = AuroraCommandLine()
       result = cmd.execute(['job', 'restart', '--batch-size=5', 'west/bozo/test/hello/1-3',
           '--config', fp.name])
       # We need to check tat getTasksWithoutConfigs was called, but that restartShards wasn't.
       # In older versions of the client, if shards were specified, but the job didn't
       # exist, the error wouldn't be detected unti0 restartShards was called, which generated
       # the wrong error message.
       assert mock_scheduler_proxy.getTasksWithoutConfigs.call_count == 1
       assert mock_scheduler_proxy.restartShards.call_count == 0
       assert result == EXIT_API_ERROR
       # Error message should be written to log, and it should be what was returned
       # by the getTasksWithoutConfigs call.
       assert mock_io.get() == ["Error restarting job west/bozo/test/hello:",
                                "\tDamn"]
示例#2
0
 def test_updater_simple_small_doesnt_warn(self):
   mock_out = IOMock()
   mock_err = IOMock()
   (mock_api, mock_scheduler_proxy) = self.create_mock_api()
   mock_health_check = self.setup_health_checks(mock_api)
   mock_quota_check = self.setup_quota_check()
   mock_job_monitor = self.setup_job_monitor()
   fake_mux = self.FakeSchedulerMux()
   self.setup_mock_scheduler_for_simple_update(mock_api)
   # This doesn't work, because:
   # - The mock_context stubs out the API.
   # - the test relies on using live code in the API.
   with contextlib.nested(
       patch('apache.aurora.client.cli.jobs.AuroraCommandContext.print_out',
           side_effect=mock_out.put),
       patch('apache.aurora.client.cli.jobs.AuroraCommandContext.print_err',
           side_effect=mock_err.put),
       patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
       patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
       patch('apache.aurora.client.api.instance_watcher.StatusHealthCheck',
           return_value=mock_health_check),
       patch('apache.aurora.client.api.updater.JobMonitor', return_value=mock_job_monitor),
       patch('apache.aurora.client.api.updater.QuotaCheck', return_value=mock_quota_check),
       patch('apache.aurora.client.api.updater.SchedulerMux', return_value=fake_mux),
       patch('time.time', side_effect=functools.partial(self.fake_time, self)),
       patch('time.sleep', return_value=None),
       patch('threading._Event.wait')):
     with temporary_file() as fp:
       fp.write(self.get_valid_config())
       fp.flush()
       cmd = AuroraCommandLine()
       cmd.execute(['job', 'update', 'west/bozo/test/hello', fp.name])
     assert mock_out.get() == ['Update completed successfully']
     assert mock_err.get() == []
示例#3
0
 def test_updater_simple_large_does_warn(self):
     mock_out = IOMock()
     mock_err = IOMock()
     (mock_api, mock_scheduler_proxy) = self.create_mock_api()
     mock_health_check = self.setup_health_checks(mock_api)
     mock_quota_check = self.setup_quota_check()
     mock_job_monitor = self.setup_job_monitor()
     fake_mux = self.FakeSchedulerMux()
     self.setup_mock_scheduler_for_simple_update(mock_api, count=2)
     # This doesn't work, because:
     # - The mock_context stubs out the API.
     # - the test relies on using live code in the API.
     config = self.get_valid_config()
     config = config.replace("instances = 20", "instances = 2")
     print("CONFIG = %s" % config)
     with contextlib.nested(
             patch(
                 'apache.aurora.client.cli.jobs.AuroraCommandContext.print_out',
                 side_effect=mock_out.put),
             patch(
                 'apache.aurora.client.cli.jobs.AuroraCommandContext.print_err',
                 side_effect=mock_err.put),
             patch('apache.aurora.client.factory.CLUSTERS',
                   new=self.TEST_CLUSTERS),
             patch('apache.aurora.client.api.SchedulerProxy',
                   return_value=mock_scheduler_proxy),
             patch(
                 'apache.aurora.client.api.instance_watcher.StatusHealthCheck',
                 return_value=mock_health_check),
             patch('apache.aurora.client.api.updater.JobMonitor',
                   return_value=mock_job_monitor),
             patch('apache.aurora.client.api.updater.QuotaCheck',
                   return_value=mock_quota_check),
             patch('apache.aurora.client.api.updater.SchedulerMux',
                   return_value=fake_mux),
             patch('time.time',
                   side_effect=functools.partial(self.fake_time, self)),
             patch('time.sleep', return_value=None),
             patch('threading._Event.wait')):
         with temporary_file() as fp:
             fp.write(config)
             fp.flush()
             cmd = AuroraCommandLine()
             result = cmd.execute(
                 ['job', 'update', 'west/bozo/test/hello', fp.name])
             assert result == EXIT_OK
         assert mock_out.get() == [
             "Warning: this update is a large change. Press ^C within 5 seconds to abort",
             'Update completed successfully'
         ]
         assert mock_err.get() == []