def test_create(self): ctxt = context.get_admin_context() self.mox.StubOutWithMock(db, 'migration_create') db.migration_create(ctxt, { 'source_compute': 'foo' }).AndReturn(fake_migration) self.mox.ReplayAll() mig = migration.Migration() mig.source_compute = 'foo' mig.create(ctxt) self.assertEqual(fake_migration['dest_compute'], mig.dest_compute)
def test_revert_snapshot_based_resize_at_dest(self): """Tests happy path for revert_snapshot_based_resize_at_dest.""" self.flags(long_rpc_timeout=1234) self._test_compute_api( 'revert_snapshot_based_resize_at_dest', 'call', # compute method kwargs instance=self.fake_instance_obj, migration=migration_obj.Migration(dest_compute='dest'), # client.prepare kwargs version='5.9', prepare_server='dest', call_monitor_timeout=60, timeout=1234)
def test_confirm_snapshot_based_resize_at_source(self): """Tests happy path for confirm_snapshot_based_resize_at_source.""" self.flags(long_rpc_timeout=1234) self._test_compute_api( 'confirm_snapshot_based_resize_at_source', 'call', # compute method kwargs instance=self.fake_instance_obj, migration=migration_obj.Migration(source_compute='source'), # client.prepare kwargs version='5.8', prepare_server='source', call_monitor_timeout=60, timeout=1234)
def test_save(self, mock_update): ctxt = context.get_admin_context() fake_migration = fake_db_migration() mock_update.return_value = fake_migration mig = migration.Migration(context=ctxt) mig.id = 123 mig.source_compute = 'foo' mig.save() self.assertEqual(fake_migration['dest_compute'], mig.dest_compute) mock_update.assert_called_once_with(ctxt, 123, {'source_compute': 'foo'})
def test_recreate_fails(self): ctxt = context.get_admin_context() fake_migration = fake_db_migration() self.mox.StubOutWithMock(db, 'migration_create') db.migration_create(ctxt, {'source_compute': 'foo'}).AndReturn( fake_migration) self.mox.ReplayAll() mig = migration.Migration(context=ctxt) mig.source_compute = 'foo' mig.create() self.assertRaises(exception.ObjectActionError, mig.create, self.context)
def test_instance(self): ctxt = context.get_admin_context() fake_inst = fake_instance.fake_db_instance() self.mox.StubOutWithMock(db, 'instance_get_by_uuid') db.instance_get_by_uuid(ctxt, fake_migration['instance_uuid'], columns_to_join=[]).AndReturn(fake_inst) mig = migration.Migration._from_db_object(ctxt, migration.Migration(), fake_migration) mig._context = ctxt self.mox.ReplayAll() self.assertEqual(mig.instance.host, fake_inst['host'])
def test_prep_snapshot_based_resize_at_source(self): """Tests happy path for prep_snapshot_based_resize_at_source rpc call """ self.flags(long_rpc_timeout=1234) self._test_compute_api( 'prep_snapshot_based_resize_at_source', 'call', # compute method kwargs instance=self.fake_instance_obj, migration=migration_obj.Migration(), snapshot_id=uuids.snapshot_id, # client.prepare kwargs version='5.6', call_monitor_timeout=60, timeout=1234)
def test_create(self, mock_create): ctxt = context.get_admin_context() fake_migration = fake_db_migration() mock_create.return_value = fake_migration mig = migration.Migration(context=ctxt) mig.source_compute = 'foo' mig.migration_type = 'resize' mig.create() self.assertEqual(fake_migration['dest_compute'], mig.dest_compute) mock_create.assert_called_once_with(ctxt, { 'source_compute': 'foo', 'migration_type': 'resize' })
def test_recreate_fails(self, mock_create): ctxt = context.get_admin_context() fake_migration = fake_db_migration() mock_create.return_value = fake_migration mig = migration.Migration(context=ctxt) mig.source_compute = 'foo' mig.migration_type = 'resize' mig.create() self.assertRaises(exception.ObjectActionError, mig.create) mock_create.assert_called_once_with(ctxt, { 'source_compute': 'foo', 'migration_type': 'resize' })
def test_confirm_snapshot_based_resize_at_source_old_compute(self, client): """Tests when the source compute service is too old to call confirm_snapshot_based_resize_at_source so MigrationError is raised. """ client.return_value.can_send_version.return_value = False rpcapi = compute_rpcapi.ComputeAPI() ex = self.assertRaises( exception.MigrationError, rpcapi.confirm_snapshot_based_resize_at_source, self.context, instance=self.fake_instance_obj, migration=migration_obj.Migration(source_compute='source')) self.assertIn('Compute too old', str(ex))
def test_finish_snapshot_based_resize_at_dest(self): """Tests happy path for finish_snapshot_based_resize_at_dest.""" self.flags(long_rpc_timeout=1234) self._test_compute_api( 'finish_snapshot_based_resize_at_dest', 'call', # compute method kwargs instance=self.fake_instance_obj, migration=migration_obj.Migration(dest_compute='dest'), snapshot_id=uuids.snapshot_id, request_spec=objects.RequestSpec(), # client.prepare kwargs version='5.7', prepare_server='dest', call_monitor_timeout=60, timeout=1234)
def test_instance(self, mock_get): ctxt = context.get_admin_context() fake_migration = fake_db_migration() fake_inst = fake_instance.fake_db_instance() mock_get.return_value = fake_inst mig = migration.Migration._from_db_object(ctxt, migration.Migration(), fake_migration) mig._context = ctxt self.assertEqual(mig.instance.host, fake_inst['host']) mock_get.assert_called_once_with( ctxt, fake_migration['instance_uuid'], columns_to_join=['info_cache', 'security_groups'])
def test_revert_snapshot_based_resize_at_dest_old_compute(self, client): """Tests when the dest compute service is too old to call revert_snapshot_based_resize_at_dest so MigrationError is raised. """ client.return_value.can_send_version.return_value = False rpcapi = compute_rpcapi.ComputeAPI() ex = self.assertRaises( exception.MigrationError, rpcapi.revert_snapshot_based_resize_at_dest, self.context, instance=self.fake_instance_obj, migration=migration_obj.Migration(dest_compute='dest')) self.assertIn('Compute too old', six.text_type(ex))
def test_prep_snapshot_based_resize_at_source_old_compute( self, mock_client): """Tests when the source compute service is too old to call prep_snapshot_based_resize_at_source so MigrationError is raised. """ mock_client.return_value.can_send_version.return_value = False rpcapi = compute_rpcapi.ComputeAPI() ex = self.assertRaises(exception.MigrationError, rpcapi.prep_snapshot_based_resize_at_source, self.context, instance=self.fake_instance_obj, migration=migration_obj.Migration(), snapshot_id=uuids.snapshot_id) self.assertIn('Compute too old', six.text_type(ex))
def test_finish_snapshot_based_resize_at_dest_old_compute(self, client): """Tests when the dest compute service is too old to call finish_snapshot_based_resize_at_dest so MigrationError is raised. """ client.return_value.can_send_version.return_value = False rpcapi = compute_rpcapi.ComputeAPI() ex = self.assertRaises( exception.MigrationError, rpcapi.finish_snapshot_based_resize_at_dest, self.context, instance=self.fake_instance_obj, migration=migration_obj.Migration(dest_compute='dest'), snapshot_id=uuids.snapshot_id, request_spec=objects.RequestSpec()) self.assertIn('Compute too old', str(ex))
def test_prep_snapshot_based_resize_at_dest(self): """Tests happy path for prep_snapshot_based_resize_at_dest rpc call""" self.flags(long_rpc_timeout=1234) self._test_compute_api( 'prep_snapshot_based_resize_at_dest', 'call', # compute method kwargs instance=self.fake_instance_obj, flavor=self.fake_flavor_obj, nodename='node', migration=migration_obj.Migration(), limits={}, request_spec=objects.RequestSpec(), destination='dest', # client.prepare kwargs version='5.5', call_monitor_timeout=60, timeout=1234, # assert the expected return value _return_value=mock.sentinel.migration_context)
def _create_migration(self, context, instance, instance_type): """Create a migration record for the upcoming resize. This should be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource claim will not be lost if the audit process starts. """ old_instance_type = flavors.extract_flavor(instance) migration = migration_obj.Migration() migration.dest_compute = self.host migration.dest_node = self.nodename migration.dest_host = self.driver.get_host_ip_addr() migration.old_instance_type_id = old_instance_type['id'] migration.new_instance_type_id = instance_type['id'] migration.status = 'pre-migrating' migration.instance_uuid = instance['uuid'] migration.source_compute = instance['host'] migration.source_node = instance['node'] migration.create(context.elevated()) return migration
def test_create(self, mock_create): ctxt = context.get_admin_context() fake_migration = fake_db_migration() mock_create.return_value = fake_migration mig = migration.Migration(context=ctxt) mig.source_compute = 'foo' mig.migration_type = 'resize' mig.uuid = uuidsentinel.migration mig.create() self.assertEqual(fake_migration['dest_compute'], mig.dest_compute) self.assertIn('uuid', mig) self.assertFalse(mig.cross_cell_move) mock_create.assert_called_once_with( ctxt, { 'source_compute': 'foo', 'migration_type': 'resize', 'uuid': uuidsentinel.migration })
def test_prep_snapshot_based_resize_at_dest_old_compute(self, mock_client): """Tests when the destination compute service is too old to call prep_snapshot_based_resize_at_dest so MigrationPreCheckError is raised. """ mock_client.return_value.can_send_version.return_value = False rpcapi = compute_rpcapi.ComputeAPI() ex = self.assertRaises(exception.MigrationPreCheckError, rpcapi.prep_snapshot_based_resize_at_dest, self.context, instance=self.fake_instance_obj, flavor=self.fake_flavor_obj, nodename='node', migration=migration_obj.Migration(), limits={}, request_spec=objects.RequestSpec(), destination='dest') self.assertIn('Compute too old', six.text_type(ex))
def test_live_migration_force_complete(self): migration = migration_obj.Migration() migration.id = 1 migration.source_compute = 'fake' ctxt = context.RequestContext('fake_user', 'fake_project') version = '4.12' rpcapi = compute_rpcapi.ComputeAPI() mock_client = mock.MagicMock() rpcapi.client = mock_client mock_client.can_send_version.return_value = True mock_cctx = mock.MagicMock() mock_client.prepare.return_value = mock_cctx rpcapi.live_migration_force_complete(ctxt, self.fake_instance_obj, migration) mock_client.prepare.assert_called_with(server=migration.source_compute, version=version) mock_cctx.cast.assert_called_with(ctxt, 'live_migration_force_complete', instance=self.fake_instance_obj)
def _fake_migration_create(self, context, values=None): instance_uuid = str(uuid.uuid1()) mig_dict = test_migration.fake_db_migration() mig_dict.update({ 'id': 1, 'source_compute': 'host1', 'source_node': 'fakenode', 'dest_compute': 'host2', 'dest_node': 'fakenode', 'dest_host': '127.0.0.1', 'old_instance_type_id': 1, 'new_instance_type_id': 2, 'instance_uuid': instance_uuid, 'status': 'pre-migrating', 'updated_at': timeutils.utcnow() }) if values: mig_dict.update(values) migration = migration_obj.Migration() migration.update(mig_dict) # This hits the stub in setUp() migration.create('fake')