summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-13 16:53:00 +0000
committerGerrit Code Review <review@openstack.org>2017-06-13 16:53:00 +0000
commit34d05289c8e43e660a41d5e455887ee7c352fca7 (patch)
treeedc464cf00c5db871d75ff073a5d705dedbeb7a1
parent14e7c9300daac2f4c40ec4fdd79986b35545edcf (diff)
parentdf585375aef621221020d7f30f6a6127609dd996 (diff)
Merge "Make xenapi driver compatible with assert_can_migrate" into stable/ocata
-rw-r--r--nova/tests/unit/virt/xenapi/test_vmops.py28
-rw-r--r--nova/virt/xenapi/vmops.py18
2 files changed, 40 insertions, 6 deletions
diff --git a/nova/tests/unit/virt/xenapi/test_vmops.py b/nova/tests/unit/virt/xenapi/test_vmops.py
index 241bc68..0261ee8 100644
--- a/nova/tests/unit/virt/xenapi/test_vmops.py
+++ b/nova/tests/unit/virt/xenapi/test_vmops.py
@@ -1344,15 +1344,18 @@ class XenstoreCallsTestCase(VMOpsTestBase):
1344 1344
1345class LiveMigrateTestCase(VMOpsTestBase): 1345class LiveMigrateTestCase(VMOpsTestBase):
1346 1346
1347 @mock.patch.object(vmops.VMOps, '_get_network_ref')
1347 @mock.patch.object(vmops.VMOps, '_ensure_host_in_aggregate') 1348 @mock.patch.object(vmops.VMOps, '_ensure_host_in_aggregate')
1348 def _test_check_can_live_migrate_destination_shared_storage( 1349 def _test_check_can_live_migrate_destination_shared_storage(
1349 self, 1350 self,
1350 shared, 1351 shared,
1351 mock_ensure_host): 1352 mock_ensure_host,
1353 mock_net_ref):
1352 fake_instance = {"name": "fake_instance", "host": "fake_host"} 1354 fake_instance = {"name": "fake_instance", "host": "fake_host"}
1353 block_migration = None 1355 block_migration = None
1354 disk_over_commit = False 1356 disk_over_commit = False
1355 ctxt = 'ctxt' 1357 ctxt = 'ctxt'
1358 mock_net_ref.return_value = 'fake_net_ref'
1356 1359
1357 with mock.patch.object(self._session, 'get_rec') as fake_sr_rec: 1360 with mock.patch.object(self._session, 'get_rec') as fake_sr_rec:
1358 fake_sr_rec.return_value = {'shared': shared} 1361 fake_sr_rec.return_value = {'shared': shared}
@@ -1363,6 +1366,8 @@ class LiveMigrateTestCase(VMOpsTestBase):
1363 self.assertFalse(migrate_data_ret.block_migration) 1366 self.assertFalse(migrate_data_ret.block_migration)
1364 else: 1367 else:
1365 self.assertTrue(migrate_data_ret.block_migration) 1368 self.assertTrue(migrate_data_ret.block_migration)
1369 self.assertEqual({'': 'fake_net_ref'},
1370 migrate_data_ret.vif_uuid_map)
1366 1371
1367 def test_check_can_live_migrate_destination_shared_storage(self): 1372 def test_check_can_live_migrate_destination_shared_storage(self):
1368 self._test_check_can_live_migrate_destination_shared_storage(True) 1373 self._test_check_can_live_migrate_destination_shared_storage(True)
@@ -1370,15 +1375,18 @@ class LiveMigrateTestCase(VMOpsTestBase):
1370 def test_check_can_live_migrate_destination_shared_storage_false(self): 1375 def test_check_can_live_migrate_destination_shared_storage_false(self):
1371 self._test_check_can_live_migrate_destination_shared_storage(False) 1376 self._test_check_can_live_migrate_destination_shared_storage(False)
1372 1377
1378 @mock.patch.object(vmops.VMOps, '_get_network_ref')
1373 @mock.patch.object(vmops.VMOps, '_ensure_host_in_aggregate', 1379 @mock.patch.object(vmops.VMOps, '_ensure_host_in_aggregate',
1374 side_effect=exception.MigrationPreCheckError(reason="")) 1380 side_effect=exception.MigrationPreCheckError(reason=""))
1375 def test_check_can_live_migrate_destination_block_migration( 1381 def test_check_can_live_migrate_destination_block_migration(
1376 self, 1382 self,
1377 mock_ensure_host): 1383 mock_ensure_host,
1384 mock_net_ref):
1378 fake_instance = {"name": "fake_instance", "host": "fake_host"} 1385 fake_instance = {"name": "fake_instance", "host": "fake_host"}
1379 block_migration = None 1386 block_migration = None
1380 disk_over_commit = False 1387 disk_over_commit = False
1381 ctxt = 'ctxt' 1388 ctxt = 'ctxt'
1389 mock_net_ref.return_value = 'fake_net_ref'
1382 1390
1383 migrate_data_ret = self.vmops.check_can_live_migrate_destination( 1391 migrate_data_ret = self.vmops.check_can_live_migrate_destination(
1384 ctxt, fake_instance, block_migration, disk_over_commit) 1392 ctxt, fake_instance, block_migration, disk_over_commit)
@@ -1388,6 +1396,8 @@ class LiveMigrateTestCase(VMOpsTestBase):
1388 migrate_data_ret.destination_sr_ref) 1396 migrate_data_ret.destination_sr_ref)
1389 self.assertEqual({'value': 'fake_migrate_data'}, 1397 self.assertEqual({'value': 'fake_migrate_data'},
1390 migrate_data_ret.migrate_send_data) 1398 migrate_data_ret.migrate_send_data)
1399 self.assertEqual({'': 'fake_net_ref'},
1400 migrate_data_ret.vif_uuid_map)
1391 1401
1392 @mock.patch.object(vmops.objects.AggregateList, 'get_by_host') 1402 @mock.patch.object(vmops.objects.AggregateList, 'get_by_host')
1393 def test_get_host_uuid_from_aggregate_no_aggr(self, mock_get_by_host): 1403 def test_get_host_uuid_from_aggregate_no_aggr(self, mock_get_by_host):
@@ -1641,6 +1651,20 @@ class LiveMigrateHelperTestCase(VMOpsTestBase):
1641 'vif_ref2': 'dest_net_ref2'} 1651 'vif_ref2': 'dest_net_ref2'}
1642 self.assertEqual(vif_map, expected) 1652 self.assertEqual(vif_map, expected)
1643 1653
1654 def test_generate_vif_network_map_default_net(self):
1655 with mock.patch.object(self._session.VIF,
1656 'get_other_config') as mock_other_config, \
1657 mock.patch.object(self._session.VM,
1658 'get_VIFs') as mock_get_vif:
1659 mock_other_config.side_effect = [{'nicira-iface-id': 'vif_id_a'},
1660 {'nicira-iface-id': 'vif_id_b'}]
1661 mock_get_vif.return_value = ['vif_ref1']
1662 vif_uuid_map = {'': 'default_net_ref'}
1663 vif_map = self.vmops._generate_vif_network_map('vm_ref',
1664 vif_uuid_map)
1665 expected = {'vif_ref1': 'default_net_ref'}
1666 self.assertEqual(vif_map, expected)
1667
1644 def test_generate_vif_network_map_exception(self): 1668 def test_generate_vif_network_map_exception(self):
1645 with mock.patch.object(self._session.VIF, 1669 with mock.patch.object(self._session.VIF,
1646 'get_other_config') as mock_other_config, \ 1670 'get_other_config') as mock_other_config, \
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index c10afe7..5418309 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -2129,8 +2129,7 @@ class VMOps(object):
2129 host_uuid = self._get_host_uuid_from_aggregate(context, hostname) 2129 host_uuid = self._get_host_uuid_from_aggregate(context, hostname)
2130 return self._session.call_xenapi("host.get_by_uuid", host_uuid) 2130 return self._session.call_xenapi("host.get_by_uuid", host_uuid)
2131 2131
2132 def _migrate_receive(self, ctxt): 2132 def _get_network_ref(self):
2133 destref = self._session.host_ref
2134 # Get the network to for migrate. 2133 # Get the network to for migrate.
2135 # This is the one associated with the pif marked management. From cli: 2134 # This is the one associated with the pif marked management. From cli:
2136 # uuid=`xe pif-list --minimal management=true` 2135 # uuid=`xe pif-list --minimal management=true`
@@ -2150,6 +2149,12 @@ class VMOps(object):
2150 raise exception.MigrationPreCheckError(reason=msg) 2149 raise exception.MigrationPreCheckError(reason=msg)
2151 2150
2152 nwref = pifs[list(pifs.keys())[0]]['network'] 2151 nwref = pifs[list(pifs.keys())[0]]['network']
2152 return nwref
2153
2154 def _migrate_receive(self, ctxt):
2155 destref = self._session.host_ref
2156 # Get the network to for migrate.
2157 nwref = self._get_network_ref()
2153 try: 2158 try:
2154 options = {} 2159 options = {}
2155 migrate_data = self._session.call_xenapi("host.migrate_receive", 2160 migrate_data = self._session.call_xenapi("host.migrate_receive",
@@ -2219,6 +2224,10 @@ class VMOps(object):
2219 # TODO(johngarbutt) we currently assume 2224 # TODO(johngarbutt) we currently assume
2220 # instance is on a SR shared with other destination 2225 # instance is on a SR shared with other destination
2221 # block migration work will be able to resolve this 2226 # block migration work will be able to resolve this
2227
2228 # Set the default net_ref for use in generate_vif_mapping
2229 net_ref = self._get_network_ref()
2230 dest_check_data.vif_uuid_map = {'': net_ref}
2222 return dest_check_data 2231 return dest_check_data
2223 2232
2224 def check_can_live_migrate_source(self, ctxt, instance_ref, 2233 def check_can_live_migrate_source(self, ctxt, instance_ref,
@@ -2371,14 +2380,15 @@ class VMOps(object):
2371 vif_map = {} 2380 vif_map = {}
2372 # vif_uuid_map is dictionary of neutron_vif_uuid: dest_network_ref 2381 # vif_uuid_map is dictionary of neutron_vif_uuid: dest_network_ref
2373 vifs = self._session.VM.get_VIFs(vm_ref) 2382 vifs = self._session.VM.get_VIFs(vm_ref)
2383 default_net_ref = vif_uuid_map.get('')
2374 for vif in vifs: 2384 for vif in vifs:
2375 other_config = self._session.VIF.get_other_config(vif) 2385 other_config = self._session.VIF.get_other_config(vif)
2376 neutron_id = other_config.get('nicira-iface-id') 2386 neutron_id = other_config.get('nicira-iface-id')
2377 if neutron_id is None or neutron_id not in vif_uuid_map.keys(): 2387 network_ref = vif_uuid_map.get(neutron_id, default_net_ref)
2388 if network_ref is None:
2378 raise exception.MigrationError( 2389 raise exception.MigrationError(
2379 reason=_('No mapping for source network %s') % ( 2390 reason=_('No mapping for source network %s') % (
2380 neutron_id)) 2391 neutron_id))
2381 network_ref = vif_uuid_map[neutron_id]
2382 vif_map[vif] = network_ref 2392 vif_map[vif] = network_ref
2383 return vif_map 2393 return vif_map
2384 2394