def setUp(self): super(MigrationsSamplesJsonTestV2_23, self).setUp() self.api.microversion = self.microversion fake_context = context.RequestContext('fake', 'fake') for mig in self.fake_migrations: mig_obj = objects.Migration(context=fake_context, **mig) mig_obj.create()
def test_live_migration_no_instance_numa_topology(self): instance_type = self._fake_instance_type() instance = self._fake_instance() instance.numa_topology = None claims.MoveClaim(self.context, instance, _NODENAME, instance_type, {}, self.tracker, self.compute_node, self.empty_requests, objects.Migration(migration_type='live-migration'), None)
def test_instance_setter(self): migration = objects.Migration(instance_uuid=uuidsentinel.instance) inst = objects.Instance(uuid=uuidsentinel.instance) with mock.patch('nova.objects.Instance.get_by_uuid') as mock_get: migration.instance = inst migration.instance self.assertFalse(mock_get.called) self.assertEqual(inst, migration._cached_instance) self.assertEqual(inst, migration.instance)
def test_live_migration(self): instance_ref, network_info = self._get_running_instance() fake_context = context.RequestContext('fake', 'fake') migration = objects.Migration(context=fake_context, id=1) migrate_data = objects.LibvirtLiveMigrateData( migration=migration, bdms=[], block_migration=False) self.connection.live_migration(self.ctxt, instance_ref, 'otherhost', lambda *a: None, lambda *a: None, migrate_data=migrate_data)
def test_show_server_migrations_policy(self, mock_show, mock_output): rule_name = policies.POLICY_ROOT % 'show' mock_show.return_value = objects.Migration( migration_type='live-migration', status='running', ) self.common_policy_auth(self.project_admin_authorized_contexts, rule_name, self.controller.show, self.req, self.instance.uuid, 11111)
def test_clean_usage_multiple_migrations_same_instance(self, mock_get): inst_2 = copy.copy(self.inst) inst_2.uuid = uuidsentinel.instance2 migr = objects.Migration() migr.instance_uuid = 'uuid2' migr.vm_state = vm_states.BUILDING migr2 = objects.Migration() migr2.instance_uuid = 'uuid2' migr2.vm_state = vm_states.BUILDING orph = {'uuid': 'uuid3', 'vm_state': vm_states.BUILDING} pci_requests_obj = self._create_pci_requests_object( [{ 'count': 1, 'spec': [{ 'vendor_id': 'v' }] }], self.inst.uuid) self.tracker.claim_instance(mock.sentinel.context, self.inst, pci_requests_obj, None) self.tracker.update_pci_for_instance(None, self.inst, sign=1) pci_requests_obj = self._create_pci_requests_object( [{ 'count': 1, 'spec': [{ 'vendor_id': 'v1' }] }], inst_2.uuid) self.tracker.claim_instance(mock.sentinel.context, inst_2, pci_requests_obj, None) self.tracker.update_pci_for_instance(None, inst_2, sign=1) free_devs = self.tracker.pci_stats.get_free_devs() self.assertEqual(len(free_devs), 1) self.assertEqual(free_devs[0].vendor_id, 'v') with mock.patch.object( nova.objects.Instance, 'get_by_uuid', side_effect=exception.InstanceNotFound(instance_id='')): self.tracker.clean_usage([self.inst], [migr, migr2], [orph]) free_devs = self.tracker.pci_stats.get_free_devs() self.assertEqual(len(free_devs), 2) self.assertEqual(set([dev.vendor_id for dev in free_devs]), set(['v', 'v1']))
def test_instance_not_found(self, mock_get_instance, mock_update_usage): mock_get_instance.side_effect = exception.InstanceNotFound( instance_id='some_id', ) migration = objects.Migration( context=self.context, instance_uuid='some_uuid', ) self.tracker._update_usage_from_migrations(self.context, [migration]) mock_get_instance.assert_called_once_with(self.context, 'some_uuid') self.assertFalse(mock_update_usage.called)
def test_get_migrations(self): filters = {'status': 'confirmed'} cell1_migrations = objects.MigrationList( objects=[objects.Migration(id=123)]) cell2_migrations = objects.MigrationList( objects=[objects.Migration(id=456)]) fake_responses = [ self._get_fake_response(cell1_migrations), self._get_fake_response(cell2_migrations) ] self.mox.StubOutWithMock(self.msg_runner, 'get_migrations') self.msg_runner.get_migrations(self.ctxt, None, False, filters).\ AndReturn(fake_responses) self.mox.ReplayAll() response = self.cells_manager.get_migrations(self.ctxt, filters) self.assertEqual(cell1_migrations.objects + cell2_migrations.objects, response.objects)
def test_replace_allocation_with_migration_no_host(self, mock_cn): mock_cn.side_effect = exception.ComputeHostNotFound(host='host') migration = objects.Migration() instance = objects.Instance(host='host', node='node') self.assertRaises(exception.ComputeHostNotFound, migrate.replace_allocation_with_migration, mock.sentinel.context, instance, migration) mock_cn.assert_called_once_with(mock.sentinel.context, instance.host, instance.node)
def test_replace_allocation_with_migration_no_allocs(self, mock_cn, mock_ga): mock_ga.return_value = None migration = objects.Migration(uuid=uuids.migration) instance = objects.Instance(uuid=uuids.instance, host='host', node='node') result = migrate.replace_allocation_with_migration( mock.sentinel.context, instance, migration) self.assertEqual((None, None), result)
def test_deleted_instances_with_migrations(self, mock_migration_list): migration = objects.Migration(context=self.context, migration_type='resize', instance_uuid='invalid') mock_migration_list.return_value = [migration] self.tracker.update_available_resource(self.context) self.assertEqual(0, self.tracker.compute_node.memory_mb_used) self.assertEqual(0, self.tracker.compute_node.local_gb_used) mock_migration_list.assert_called_once_with(self.context, "fakehost", "fakenode")
def test_from_legacy_dict_migration(self): migration = objects.Migration() obj = migrate_data.LiveMigrateData() obj.from_legacy_dict({ 'is_volume_backed': False, 'ignore': 'foo', 'migration': migration }) self.assertEqual(False, obj.is_volume_backed) self.assertIsInstance(obj.migration, objects.Migration)
def setUp(self): super(CrossCellMigrationTaskTestCase, self).setUp() source_context = nova_context.get_context() host_selection = objects.Selection(cell_uuid=uuids.cell_uuid) migration = objects.Migration(id=1, cross_cell_move=False) self.task = cross_cell_migrate.CrossCellMigrationTask( source_context, mock.sentinel.instance, mock.sentinel.flavor, mock.sentinel.request_spec, migration, mock.sentinel.compute_rpcapi, host_selection, mock.sentinel.alternate_hosts)
def test_update_usage_called(self, mock_get_instance, mock_update_usage): instance = self._fake_instance_obj() mock_get_instance.return_value = instance migration = objects.Migration( context=self.context, instance_uuid=instance.uuid, ) self.tracker._update_usage_from_migrations(self.context, [migration]) mock_get_instance.assert_called_once_with(self.context, instance.uuid) mock_update_usage.assert_called_once_with(self.context, instance, None, migration)
def test_replace_allocation_with_migration_no_allocs( self, mock_cn, mock_ga): mock_ga.return_value = None migration = objects.Migration(uuid=uuids.migration) instance = objects.Instance(uuid=uuids.instance, host='host', node='node') self.assertRaises(exception.InstanceUnacceptable, migrate.replace_allocation_with_migration, mock.sentinel.context, instance, migration)
def test_live_migration(self): instance_ref, network_info = self._get_running_instance() instance_ref.info_cache = objects.InstanceInfoCache( network_info=network_info) fake_context = context.RequestContext('fake', 'fake') migration = objects.Migration(context=fake_context, id=1) migrate_data = objects.LibvirtLiveMigrateData( migration=migration, bdms=[], block_migration=False, serial_listen_addr='127.0.0.1') self.connection.live_migration(self.ctxt, instance_ref, 'otherhost', lambda *a: None, lambda *a: None, migrate_data=migrate_data)
def setUp(self): super(ServerMigrationsSamplesJsonTestV2_23, self).setUp() fake_context = context.RequestContext('fake', 'fake') self.mig1 = objects.Migration(context=fake_context, **self.fake_migrations[0]) self.mig1.create() self.mig2 = objects.Migration(context=fake_context, **self.fake_migrations[1]) self.mig2.create() fake_ins = fake_instance.fake_db_instance(uuid=self.UUID_1) fake_ins.pop("pci_devices") fake_ins.pop("security_groups") fake_ins.pop("services") fake_ins.pop("tags") fake_ins.pop("info_cache") fake_ins.pop("id") self.instance = objects.Instance(context=fake_context, **fake_ins) self.instance.create()
def test_get_events(self): network_info = model.NetworkInfo([ model.VIF(id=uuids.hybrid_vif, details={'ovs_hybrid_plug': True}), model.VIF(id=uuids.normal_vif, details={'ovs_hybrid_plug': False}) ]) same_host = objects.Migration(source_compute='fake-host', dest_compute='fake-host') diff_host = objects.Migration(source_compute='fake-host1', dest_compute='fake-host2') # Same-host migrations will have all events be plug-time. self.assertCountEqual([('network-vif-plugged', uuids.normal_vif), ('network-vif-plugged', uuids.hybrid_vif)], network_info.get_plug_time_events(same_host)) # Same host migration will have no plug-time events. self.assertEqual([], network_info.get_bind_time_events(same_host)) # Diff-host migration + OVS hybrid plug = bind-time events self.assertEqual([('network-vif-plugged', uuids.hybrid_vif)], network_info.get_bind_time_events(diff_host)) # Diff-host migration + normal OVS = plug-time events self.assertEqual([('network-vif-plugged', uuids.normal_vif)], network_info.get_plug_time_events(diff_host))
def test_get_migrations_for_a_given_cell(self): filters = {'status': 'confirmed', 'cell_name': 'ChildCell1'} target_cell = '%s%s%s' % (CONF.cells.name, '!', filters['cell_name']) migrations = objects.MigrationList(objects=[objects.Migration(id=123)]) fake_responses = [self._get_fake_response(migrations)] self.mox.StubOutWithMock(self.msg_runner, 'get_migrations') self.msg_runner.get_migrations(self.ctxt, target_cell, False, filters).AndReturn(fake_responses) self.mox.ReplayAll() response = self.cells_manager.get_migrations(self.ctxt, filters) self.assertEqual(migrations.objects, response.objects)
def test_replace_allocation_with_migration_allocs_fail(self, mock_cn, mock_ga, mock_pa): migration = objects.Migration(uuid=uuids.migration) instance = objects.Instance(uuid=uuids.instance, user_id='fake', project_id='fake', host='host', node='node') mock_pa.return_value = False self.assertRaises(exception.NoValidHost, migrate.replace_allocation_with_migration, mock.sentinel.context, instance, migration)
def test_live_migration_claim_bad_pci_request(self): flavor = self._fake_flavor() instance = self._fake_instance() instance.numa_topology = None self.assertRaisesRegex( exception.ComputeResourcesUnavailable, 'PCI requests are not supported', claims.MoveClaim, self.context, instance, _NODENAME, flavor, {}, self.tracker, self.compute_node, objects.InstancePCIRequests( requests=[objects.InstancePCIRequest( alias_name='fake-alias')]), objects.Migration(migration_type='live-migration'), None)
def get_claim(mock_extra_get, mock_numa_get): return claims.MoveClaim( self.context, self.instance, _NODENAME, instance_type, image_meta, self.tracker, self.resources, requests, objects.Migration(migration_type='migration'), limits=limits)
def test_not_resizing_state(self, mock_get_instance, mock_update_usage): instance = self._fake_instance_obj() instance.vm_state = vm_states.ACTIVE instance.task_state = task_states.SUSPENDING mock_get_instance.return_value = instance migration = objects.Migration( context=self.context, instance_uuid=instance.uuid, ) self.tracker._update_usage_from_migrations(self.context, [migration]) mock_get_instance.assert_called_once_with(self.context, instance.uuid) self.assertFalse(mock_update_usage.called)
def test_flavor_not_found(self, mock_get_instance, mock_update_usage): mock_update_usage.side_effect = exception.FlavorNotFound(flavor_id='') instance = self._fake_instance_obj() mock_get_instance.return_value = instance migration = objects.Migration( context=self.context, instance_uuid=instance.uuid, ) self.tracker._update_usage_from_migrations(self.context, [migration]) mock_get_instance.assert_called_once_with(self.context, instance.uuid) mock_update_usage.assert_called_once_with(self.context, instance, None, migration)
def setUp(self): super(PrepResizeAtSourceTaskTestCase, self).setUp() self.task = cross_cell_migrate.PrepResizeAtSourceTask( nova_context.get_context(), objects.Instance(uuid=uuids.instance, vm_state=vm_states.ACTIVE, display_name='fake-server', system_metadata={}, host='source.host.com'), objects.Migration(), objects.RequestSpec(), compute_rpcapi=mock.Mock(), image_api=mock.Mock())
def test_live_migration_run_tasks_no_tasks(self, mock_pause, mock_postcopy): active_migrations = {} on_migration_failure = deque() mig = objects.Migration(id=1, status="running") migration.run_tasks(self.guest, self.instance, active_migrations, on_migration_failure, mig, False) self.assertFalse(mock_pause.called) self.assertFalse(mock_postcopy.called) self.assertEqual(len(on_migration_failure), 0)
def test_live_migrate_force_complete(self, live_migration_pause_instance, get_by_id_and_instance, service_get_by_compute_host, _live_migrate): migration = objects.Migration() migration.id = 1 migration.status = 'running' migration.source_compute = self.compute.host get_by_id_and_instance.return_value = migration self._do_post('servers/%s/action' % self.uuid, 'live-migrate-server', {'hostname': self.compute.host}) response = self._do_post('servers/%s/migrations/%s/action' % (self.uuid, '3'), 'force_complete', {}) self.assertEqual(202, response.status_code)
def setUp(self): super(CrossCellMigrationTaskTestCase, self).setUp() source_context = nova_context.get_context() host_selection = objects.Selection(service_host='target.host.com', cell_uuid=uuids.cell_uuid) migration = objects.Migration(id=1, cross_cell_move=False, source_compute='source.host.com') instance = objects.Instance() self.task = cross_cell_migrate.CrossCellMigrationTask( source_context, instance, objects.Flavor(), mock.sentinel.request_spec, migration, mock.sentinel.compute_rpcapi, host_selection, mock.sentinel.alternate_hosts)
def test_existing_migration(self, save_mock, save_inst_mock): migration = objects.Migration(self.context, id=42, instance_uuid=self.instance.uuid, source_compute='fake-other-compute', source_node='fake-other-node', status='accepted', migration_type='evacuation') self.claim_method(self.context, self.instance, self.instance_type, migration=migration) self.assertEqual(self.tracker.host, migration.dest_compute) self.assertEqual(self.tracker.nodename, migration.dest_node) self.assertEqual("pre-migrating", migration.status) self.assertEqual(1, len(self.tracker.tracked_migrations)) save_mock.assert_called_once_with() save_inst_mock.assert_called_once_with()
def test_live_migration_run_tasks_force_complete_postcopy( self, mock_pause, mock_postcopy, mock_msave): tasks = deque() tasks.append("force-complete") active_migrations = {self.instance.uuid: tasks} on_migration_failure = deque() mig = objects.Migration(id=1, status="running") migration.run_tasks(self.guest, self.instance, active_migrations, on_migration_failure, mig, True) mock_postcopy.assert_called_once_with() self.assertFalse(mock_pause.called) self.assertEqual(len(on_migration_failure), 0)