Fix rollback op's search call

The pypowervm search call only accepts one input.  We need to key off a
few (PVID and vswitch id).  This change updates the vif rollback code to
search appropriately.

Change-Id: Ib813fe4b668d208b379ec05cacd1704f60c7abc6
Closes-Bug: 1639235
This commit is contained in:
Drew Thorstensen 2016-11-04 09:30:32 -04:00
parent 140ebfda25
commit a8ebbb893b
2 changed files with 29 additions and 16 deletions

View File

@ -786,21 +786,30 @@ class TestVifOvsDriver(test.TestCase):
'br-int', 'tap-dev', 'vif_id', 'aa:bb:cc:dd:ee:ff', self.inst.uuid)
@mock.patch('nova.network.linux_net.delete_ovs_vif_port')
@mock.patch('pypowervm.wrappers.network.CNA.search')
@mock.patch('pypowervm.wrappers.network.CNA.get')
@mock.patch('pypowervm.tasks.partition.get_this_partition')
@mock.patch('pypowervm.wrappers.network.VSwitch.search')
def test_rollback_live_migration_at_destination(
self, mock_vs_search, mock_get_part, mock_cna_search,
self, mock_vs_search, mock_get_part, mock_cna_get,
mock_delete_ovs_port):
# All the fun mocking
mock_vs_search.return_value = mock.MagicMock(switch_id=5)
vea_vlan_mappings = {'aa:bb:cc:dd:ee:ff': 3, 'aa:bb:cc:dd:ee:ee': 4}
# Since this gets passed through conductor, the VLAN's switch to string
# format.
vea_vlan_mappings = {'aa:bb:cc:dd:ee:ff': '3',
'aa:bb:cc:dd:ee:ee': '4'}
vif = {'devname': 'tap-dev', 'address': 'aa:bb:cc:dd:ee:ee',
'network': {'bridge': 'br-int'}, 'id': 'vif_id'}
mock_get_part.return_value = mock.MagicMock(schema_type='VIO',
uuid='uuid')
mock_trunk = mock.MagicMock()
mock_cna_search.return_value = mock_trunk
mock_vio = mock.MagicMock(schema_type='VIO', uuid='uuid')
mock_get_part.return_value = mock_vio
trunk1 = mock.Mock(pvid=2, vswitch_id=3, trunk_pri=1)
trunk2 = mock.Mock(pvid=3, vswitch_id=5, trunk_pri=1)
trunk3 = mock.Mock(pvid=4, vswitch_id=5, trunk_pri=None)
trunk4 = mock.Mock(pvid=4, vswitch_id=5, trunk_pri=1)
mock_cna_get.return_value = [trunk1, trunk2, trunk3, trunk4]
# Invoke
self.drv.rollback_live_migration_at_destination(vif, vea_vlan_mappings)
@ -809,7 +818,7 @@ class TestVifOvsDriver(test.TestCase):
mock_delete_ovs_port.assert_called_once_with('br-int', 'tap-dev')
# Make sure the trunk was deleted
mock_trunk.delete.assert_called_once()
trunk4.delete.assert_called_once()
# Now make sure the calls were done correctly to actually produce a
# trunk adapter
@ -817,9 +826,8 @@ class TestVifOvsDriver(test.TestCase):
self.drv.adapter, parent_type=pvm_ms.System, one_result=True,
name=CONF.powervm.pvm_vswitch_for_novalink_io)
mock_get_part.assert_called_once_with(self.drv.adapter)
mock_cna_search.assert_called_once_with(
self.drv.adapter, parent_type='VIO', parent_uuid='uuid',
vswitch_id=5, pvid=4, one_result=True)
mock_cna_get.assert_called_once_with(
self.drv.adapter, parent=mock_vio)
@mock.patch('nova.network.linux_net.delete_ovs_vif_port')
def test_post_live_migrate_at_source(self, mock_delete_ovs_port):

View File

@ -797,7 +797,7 @@ class PvmOvsVifDriver(PvmLioVifDriver):
# We know that we just attached the VIF to the NovaLink VM. Search
# for a trunk adapter with the PVID and vSwitch that we specified
# above. This is guaranteed to be unique.
vlan = vea_vlan_mappings[vif['address']]
vlan = int(vea_vlan_mappings[vif['address']])
vswitch_id = pvm_net.VSwitch.search(
self.adapter, parent_type=pvm_ms.System, one_result=True,
name=CONF.powervm.pvm_vswitch_for_novalink_io).switch_id
@ -808,10 +808,15 @@ class PvmOvsVifDriver(PvmLioVifDriver):
# Find the trunk
mgmt_wrap = pvm_par.get_this_partition(self.adapter)
trunk = pvm_net.CNA.search(
self.adapter, parent_type=mgmt_wrap.schema_type,
parent_uuid=mgmt_wrap.uuid, pvid=vlan, vswitch_id=vswitch_id,
one_result=True)
child_adpts = pvm_net.CNA.get(self.adapter, parent=mgmt_wrap)
trunk = None
for adpt in child_adpts:
# We need a trunk adapter (so check trunk_pri). Then the trunk
# is unique by PVID and PowerVM vSwitch ID.
if (adpt.pvid == vlan and adpt.vswitch_id == vswitch_id and
adpt.trunk_pri):
trunk = adpt
break
if trunk:
# Delete the peer'd trunk adapter.