コード例 #1
0
 def migrate(self, scenario=None):
     self.scenario = scenario
     namespace_scheduler = namespace.Namespace({
         '__init_task__': self.init,
         'info_result': {
             utl.INSTANCES_TYPE: {}
         }
     })
     # "process_migration" is dict with 3 keys:
     #    "preparation" - is cursor that points to tasks must be processed
     #                    before migration i.e - taking snapshots,
     #                    figuring out all services are up
     #    "migration" - is cursor that points to the first
     #                  task in migration process
     #    "rollback" - is cursor that points to tasks must be processed
     #                 in case of "migration" failure
     scenario.init_tasks(self.init)
     scenario.load_scenario()
     process_migration = {
         k: cursor.Cursor(v)
         for k, v in scenario.get_net().items() if v
     }
     scheduler_migr = scheduler.Scheduler(namespace=namespace_scheduler,
                                          **process_migration)
     scheduler_migr.start()
     return scheduler_migr.status_error
コード例 #2
0
    def test_task_is_rolled_back_on_error(self):
        migration = mock_out_task(throws_exception=True)
        rollback = mock_out_task()

        s = scheduler.Scheduler(migration=[migration], rollback=[rollback])
        s.start()

        self.assertCalledOnce(rollback.run)
コード例 #3
0
    def test_preparation_step_is_not_rolled_back_and_error_raised(self):
        migration = mock_out_task()
        preparation = mock_out_task(throws_exception=True)
        rollback = mock_out_task()

        s = scheduler.Scheduler(migration=[migration],
                                preparation=[preparation],
                                rollback=[rollback])

        s.start()

        self.assertCalledOnce(preparation.run)
        self.assertFalse(rollback.run.called)
        self.assertFalse(migration.run.called)
コード例 #4
0
 def test_start_scheduler(self):
     fake_cursor = [mock_out_task(), mock_out_task(), mock_out_task()]
     s = scheduler.Scheduler(migration=fake_cursor)
     s.event_start_task = mock.Mock()
     s.event_start_task.return_value = True
     s.event_end_task = mock.Mock()
     s.start()
     self.assertEqual(scheduler.NO_ERROR, s.status_error)
     self.assertIsNotNone(s.event_start_task.call_args)
     self.assertIn(fake_cursor[0], s.event_start_task.call_args[0])
     self.assertIsNotNone(s.event_end_task.call_args)
     self.assertIn(fake_cursor[0], s.event_end_task.call_args[0])
     self.assertTrue(fake_cursor[0].run.called)
     self.assertTrue(fake_cursor[2].run.called)
コード例 #5
0
 def test_start_scheduler(self):
     fake_cursor = [mock_out_task(),
                    mock_out_task(),
                    mock_out_task()]
     s = scheduler.Scheduler(migration=fake_cursor)
     with mock.patch.object(s, 'event_start_task',
                            return_value=True) as start_task:
         with mock.patch.object(s, 'event_end_task') as end_task:
             s.start()
             self.assertEqual(errorcodes.NO_ERROR, s.status_error)
             self.assertEqual(3, start_task.call_count)
             start_task.assert_called_with(fake_cursor[0])
             self.assertEqual(3, end_task.call_count)
             end_task.assert_called_with(fake_cursor[0])
             for t in fake_cursor:
                 self.assertCalledOnce(t.run)
コード例 #6
0
def process_chain(cloud, iteration):
    chain = evacuate_vms.Evacuate(iteration=iteration,
                                  cloud='src_cloud',
                                  init=cloud.init)
    scheduler.Scheduler(migration=cursor.Cursor(chain)).start()