def test_restore_machine_iaas_fail(self, log): FakeManager.fail_ids = [2] restorer = scheduler.RestoreMachine(self.config) restorer.start() time.sleep(1) restorer.stop() tasks = [task['_id'] for task in self.storage.find_task({"_id": {"$regex": "restore_.+"}})] self.assertListEqual(['restore_10.2.2.2', 'restore_10.3.3.3', 'restore_10.4.4.4', 'restore_10.5.5.5'], tasks) self.assertEqual(log.info.call_args_list, [call("Machine 0 restored")]) log.reset_mock() redis.StrictRedis().delete("restore_machine:last_run") restorer = scheduler.RestoreMachine(self.config) restorer.start() time.sleep(1) restorer.stop() tasks = [task['_id'] for task in self.storage.find_task({"_id": {"$regex": "restore_.+"}})] self.assertEqual(log.info.call_args_list, [call("Machine 4 restored")]) self.assertListEqual(['restore_10.2.2.2', 'restore_10.3.3.3', 'restore_10.4.4.4'], tasks) log.reset_mock() redis.StrictRedis().delete("restore_machine:last_run") FakeManager.fail_ids = [] with freeze_time("2016-02-03 12:06:00"): restorer = scheduler.RestoreMachine(self.config) restorer.start() time.sleep(1) restorer.stop() tasks = [task['_id'] for task in self.storage.find_task({"_id": {"$regex": "restore_.+"}})] self.assertEqual(log.info.call_args_list, [call("Machine 1 restored"), call("Machine 2 restored"), call("Machine 3 restored")]) self.assertListEqual(tasks, [])
def test_restore_machine_iaas_fail(self, log, nginx): FakeManager.fail_ids = [2] restorer = healing.RestoreMachine(self.config) nginx_manager = nginx.Nginx.return_value restorer.start() time.sleep(1) restorer.stop() tasks = [task['_id'] for task in self.storage.find_task({"_id": {"$regex": "restore_.+"}})] self.assertListEqual(['restore_10.2.2.2', 'restore_10.3.3.3', 'restore_10.4.4.4', 'restore_10.5.5.5'], tasks) self.assertEqual(log.info.call_args_list, [call("Machine 0 restored")]) self.assertEqual(nginx_manager.wait_healthcheck.call_args_list, [call('10.1.1.1', timeout=600)]) log.reset_mock() nginx.reset_mock() redis.StrictRedis().delete("restore_machine:last_run") restorer = healing.RestoreMachine(self.config) restorer.start() time.sleep(1) restorer.stop() tasks = [task['_id'] for task in self.storage.find_task({"_id": {"$regex": "restore_.+"}})] self.assertEqual(log.info.call_args_list, [call("Machine 4 restored")]) self.assertEqual(nginx_manager.wait_healthcheck.call_args_list, [call('10.5.5.5', timeout=600)]) self.assertListEqual(['restore_10.2.2.2', 'restore_10.3.3.3', 'restore_10.4.4.4'], tasks) log.reset_mock() nginx.reset_mock() redis.StrictRedis().delete("restore_machine:last_run") FakeManager.fail_ids = [] with freeze_time("2016-02-03 12:06:00"): restorer = healing.RestoreMachine(self.config) restorer.start() time.sleep(1) restorer.stop() tasks = [task['_id'] for task in self.storage.find_task({"_id": {"$regex": "restore_.+"}})] self.assertEqual(log.info.call_args_list, [call("Machine 1 restored"), call("Machine 2 restored"), call("Machine 3 restored")]) nginx_expected_calls = [call('10.2.2.2', timeout=600), call('10.3.3.3', timeout=600), call('10.4.4.4', timeout=600)] self.assertEqual(nginx_expected_calls, nginx_manager.wait_healthcheck.call_args_list) self.assertListEqual(tasks, [])
def test_restore_machine_iaas_fail(self, log, nginx): FakeManager.fail_ids = [2] restorer = healing.RestoreMachine(self.config) nginx_manager = nginx.Nginx.return_value restorer.start() time.sleep(1) restorer.stop() tasks = [ task['_id'] for task in self.storage.find_task( {"_id": { "$regex": "restore_.+" }}) ] self.assertListEqual([ 'restore_10.2.2.2', 'restore_10.3.3.3', 'restore_10.4.4.4', 'restore_10.5.5.5' ], tasks) self.assertEqual(log.info.call_args_list, [call("Machine 0 restored")]) self.assertEqual(nginx_manager.wait_healthcheck.call_args_list, [call('10.1.1.1', timeout=600)]) log.reset_mock() nginx.reset_mock() redis.StrictRedis().delete("restore_machine:last_run") restorer = healing.RestoreMachine(self.config) restorer.start() time.sleep(1) restorer.stop() tasks = [ task['_id'] for task in self.storage.find_task( {"_id": { "$regex": "restore_.+" }}) ] self.assertEqual(log.info.call_args_list, [call("Machine 4 restored")]) self.assertEqual(nginx_manager.wait_healthcheck.call_args_list, [call('10.5.5.5', timeout=600)]) self.assertListEqual( ['restore_10.2.2.2', 'restore_10.3.3.3', 'restore_10.4.4.4'], tasks) log.reset_mock() nginx.reset_mock() redis.StrictRedis().delete("restore_machine:last_run") FakeManager.fail_ids = [] with freeze_time("2016-02-03 12:06:00"): restorer = healing.RestoreMachine(self.config) restorer.start() time.sleep(1) restorer.stop() tasks = [ task['_id'] for task in self.storage.find_task( {"_id": { "$regex": "restore_.+" }}) ] self.assertEqual(log.info.call_args_list, [ call("Machine 1 restored"), call("Machine 2 restored"), call("Machine 3 restored") ]) nginx_expected_calls = [ call('10.2.2.2', timeout=600), call('10.3.3.3', timeout=600), call('10.4.4.4', timeout=600) ] self.assertEqual(nginx_expected_calls, nginx_manager.wait_healthcheck.call_args_list) self.assertListEqual(tasks, [])