Skip to content

Commit cc8b300

Browse files
committed
conductor: Don't use setattr
setattr kills discoverability, making it hard to figure out who's setting various fields. Don't do it. While we're here, we drop legacy compat handlers for pre-Train compute nodes. Change-Id: Ie694a80e89f99c8d3e326eebb4590d93c0ebf671 Signed-off-by: Stephen Finucane <[email protected]>
1 parent 18bae88 commit cc8b300

File tree

4 files changed

+24
-55
lines changed

4 files changed

+24
-55
lines changed

nova/conductor/tasks/live_migrate.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from nova.network import neutron
2727
from nova import objects
2828
from nova.objects import fields as obj_fields
29-
from nova.objects import migrate_data as migrate_data_obj
3029
from nova.scheduler import utils as scheduler_utils
3130

3231
LOG = logging.getLogger(__name__)
@@ -369,14 +368,6 @@ def _call_livem_checks_on_host(self, destination, provider_mapping):
369368

370369
# Check to see that neutron supports the binding-extended API.
371370
if self.network_api.supports_port_binding_extension(self.context):
372-
if 'vifs' not in self.migrate_data:
373-
# migrate data vifs were not constructed in dest compute
374-
# during check_can_live_migrate_destination, construct a
375-
# skeleton to be updated after port binding.
376-
# TODO(adrianc): This can be removed once we move to U release
377-
self.migrate_data.vifs = migrate_data_obj.VIFMigrateData.\
378-
create_skeleton_migrate_vifs(
379-
self.instance.get_network_info())
380371
bindings = self._bind_ports_on_destination(
381372
destination, provider_mapping)
382373
self._update_migrate_vifs_from_bindings(self.migrate_data.vifs,
@@ -432,8 +423,13 @@ def _bind_ports_on_destination(self, destination, provider_mappings):
432423

433424
def _update_migrate_vifs_from_bindings(self, migrate_vifs, bindings):
434425
for migrate_vif in migrate_vifs:
435-
for attr_name, attr_val in bindings[migrate_vif.port_id].items():
436-
setattr(migrate_vif, attr_name, attr_val)
426+
binding = bindings[migrate_vif.port_id]
427+
migrate_vif.profile = binding.get('profile')
428+
migrate_vif.vnic_type = binding['vnic_type']
429+
if 'vif_details' in binding:
430+
migrate_vif.vif_details = binding['vif_details']
431+
if 'vif_type' in binding:
432+
migrate_vif.vif_type = binding['vif_type']
437433

438434
def _get_source_cell_mapping(self):
439435
"""Returns the CellMapping for the cell in which the instance lives

nova/tests/fixtures.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,9 @@ class NeutronFixture(fixtures.Fixture):
13251325
'project_id': tenant_id,
13261326
'device_id': '',
13271327
'binding:profile': {},
1328-
'binding:vnic_type': 'normal',
1328+
'binding:vif_details': {},
13291329
'binding:vif_type': 'ovs',
1330+
'binding:vnic_type': 'normal',
13301331
'port_security_enabled': True,
13311332
'security_groups': [
13321333
security_group['id'],
@@ -1351,8 +1352,9 @@ class NeutronFixture(fixtures.Fixture):
13511352
'project_id': tenant_id,
13521353
'device_id': '',
13531354
'binding:profile': {},
1354-
'binding:vnic_type': 'normal',
1355+
'binding:vif_details': {},
13551356
'binding:vif_type': 'ovs',
1357+
'binding:vnic_type': 'normal',
13561358
'port_security_enabled': True,
13571359
'security_groups': [
13581360
security_group['id'],
@@ -1377,8 +1379,9 @@ class NeutronFixture(fixtures.Fixture):
13771379
'project_id': tenant_id,
13781380
'device_id': '',
13791381
'binding:profile': {},
1380-
'binding:vnic_type': 'normal',
1382+
'binding:vif_details': {},
13811383
'binding:vif_type': 'ovs',
1384+
'binding:vnic_type': 'normal',
13821385
'resource_request': {
13831386
"resources": {
13841387
orc.NET_BW_IGR_KILOBIT_PER_SEC: 1000,
@@ -1462,9 +1465,9 @@ class NeutronFixture(fixtures.Fixture):
14621465
'device_id': '',
14631466
'resource_request': {},
14641467
'binding:profile': {},
1465-
'binding:vnic_type': 'direct',
1466-
'binding:vif_type': 'hw_veb',
14671468
'binding:vif_details': {'vlan': 100},
1469+
'binding:vif_type': 'hw_veb',
1470+
'binding:vnic_type': 'direct',
14681471
'port_security_enabled': False,
14691472
}
14701473

@@ -1616,6 +1619,8 @@ class NeutronFixture(fixtures.Fixture):
16161619
"required": ["CUSTOM_PHYSNET2", "CUSTOM_VNIC_TYPE_DIRECT"]
16171620
},
16181621
'binding:profile': {},
1622+
'binding:vif_details': {},
1623+
'binding:vif_type': 'hw_veb',
16191624
'binding:vnic_type': 'direct',
16201625
'port_security_enabled': False,
16211626
}
@@ -1645,6 +1650,8 @@ class NeutronFixture(fixtures.Fixture):
16451650
"required": ["CUSTOM_PHYSNET2", "CUSTOM_VNIC_TYPE_MACVTAP"]
16461651
},
16471652
'binding:profile': {},
1653+
'binding:vif_details': {},
1654+
'binding:vif_type': 'hw_veb',
16481655
'binding:vnic_type': 'macvtap',
16491656
'port_security_enabled': False,
16501657
}

nova/tests/functional/libvirt/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
261261
'subnet_id': subnet_1['id']
262262
}
263263
],
264+
'binding:vif_details': {},
264265
'binding:vif_type': 'ovs',
265266
'binding:vnic_type': 'normal',
266267
}
@@ -275,6 +276,7 @@ class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
275276
'subnet_id': subnet_1['id']
276277
}
277278
],
279+
'binding:vif_details': {},
278280
'binding:vif_type': 'ovs',
279281
'binding:vnic_type': 'normal',
280282
}
@@ -289,6 +291,7 @@ class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
289291
'subnet_id': subnet_2['id']
290292
}
291293
],
294+
'binding:vif_details': {},
292295
'binding:vif_type': 'ovs',
293296
'binding:vnic_type': 'normal',
294297
}
@@ -303,6 +306,7 @@ class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
303306
'subnet_id': subnet_3['id']
304307
}
305308
],
309+
'binding:vif_details': {},
306310
'binding:vif_type': 'ovs',
307311
'binding:vnic_type': 'normal',
308312
}
@@ -317,9 +321,9 @@ class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
317321
'subnet_id': subnet_4['id']
318322
}
319323
],
324+
'binding:vif_details': {'vlan': 42},
320325
'binding:vif_type': 'hw_veb',
321326
'binding:vnic_type': 'direct',
322-
'binding:vif_details': {'vlan': 42},
323327
'binding:profile': {'pci_vendor_info': '1377:0047',
324328
'pci_slot': '0000:81:00.1',
325329
'physical_network': 'physnet4'},

nova/tests/unit/conductor/tasks/test_live_migrate.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from nova.conductor.tasks import live_migrate
2323
from nova import context as nova_context
2424
from nova import exception
25-
from nova.network import model as network_model
2625
from nova import objects
2726
from nova.scheduler.client import query
2827
from nova.scheduler.client import report
@@ -602,43 +601,6 @@ def test_call_livem_checks_on_host(self):
602601
self.assertRaises(exception.MigrationPreCheckError,
603602
self.task._call_livem_checks_on_host, {}, {})
604603

605-
def test_call_livem_checks_on_host_bind_ports(self):
606-
data = objects.LibvirtLiveMigrateData()
607-
bindings = {
608-
uuids.port1: {'host': 'dest-host'},
609-
uuids.port2: {'host': 'dest-host'}
610-
}
611-
612-
@mock.patch.object(self.task, '_check_can_migrate_pci')
613-
@mock.patch.object(self.task.compute_rpcapi,
614-
'check_can_live_migrate_destination',
615-
return_value=data)
616-
@mock.patch.object(self.task.network_api,
617-
'supports_port_binding_extension',
618-
return_value=True)
619-
@mock.patch.object(self.task.network_api,
620-
'bind_ports_to_host', return_value=bindings)
621-
def _test(mock_bind_ports_to_host,
622-
mock_supports_port_binding,
623-
mock_check_can_live_migrate_dest,
624-
mock_check_can_migrate_pci):
625-
nwinfo = network_model.NetworkInfo([
626-
network_model.VIF(uuids.port1),
627-
network_model.VIF(uuids.port2)])
628-
self.instance.info_cache = objects.InstanceInfoCache(
629-
network_info=nwinfo)
630-
self.task._call_livem_checks_on_host('dest-host', {})
631-
# Assert the migrate_data set on the task based on the port
632-
# bindings created.
633-
self.assertIn('vifs', data)
634-
self.assertEqual(2, len(data.vifs))
635-
for vif in data.vifs:
636-
self.assertIn('source_vif', vif)
637-
self.assertEqual('dest-host', vif.host)
638-
self.assertEqual(vif.port_id, vif.source_vif['id'])
639-
640-
_test()
641-
642604
@mock.patch('nova.network.neutron.API.bind_ports_to_host')
643605
def test_bind_ports_on_destination_merges_profiles(self, mock_bind_ports):
644606
"""Assert that if both the migration_data and the provider mapping

0 commit comments

Comments
 (0)