Browse Source

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
tags/4.0.0.0b2
Drew Thorstensen 2 years ago
parent
commit
a8ebbb893b
2 changed files with 29 additions and 16 deletions
  1. 19
    11
      nova_powervm/tests/virt/powervm/test_vif.py
  2. 10
    5
      nova_powervm/virt/powervm/vif.py

+ 19
- 11
nova_powervm/tests/virt/powervm/test_vif.py View File

@@ -786,21 +786,30 @@ class TestVifOvsDriver(test.TestCase):
786 786
             'br-int', 'tap-dev', 'vif_id', 'aa:bb:cc:dd:ee:ff', self.inst.uuid)
787 787
 
788 788
     @mock.patch('nova.network.linux_net.delete_ovs_vif_port')
789
-    @mock.patch('pypowervm.wrappers.network.CNA.search')
789
+    @mock.patch('pypowervm.wrappers.network.CNA.get')
790 790
     @mock.patch('pypowervm.tasks.partition.get_this_partition')
791 791
     @mock.patch('pypowervm.wrappers.network.VSwitch.search')
792 792
     def test_rollback_live_migration_at_destination(
793
-            self, mock_vs_search, mock_get_part, mock_cna_search,
793
+            self, mock_vs_search, mock_get_part, mock_cna_get,
794 794
             mock_delete_ovs_port):
795 795
         # All the fun mocking
796 796
         mock_vs_search.return_value = mock.MagicMock(switch_id=5)
797
-        vea_vlan_mappings = {'aa:bb:cc:dd:ee:ff': 3, 'aa:bb:cc:dd:ee:ee': 4}
797
+
798
+        # Since this gets passed through conductor, the VLAN's switch to string
799
+        # format.
800
+        vea_vlan_mappings = {'aa:bb:cc:dd:ee:ff': '3',
801
+                             'aa:bb:cc:dd:ee:ee': '4'}
798 802
         vif = {'devname': 'tap-dev', 'address': 'aa:bb:cc:dd:ee:ee',
799 803
                'network': {'bridge': 'br-int'}, 'id': 'vif_id'}
800
-        mock_get_part.return_value = mock.MagicMock(schema_type='VIO',
801
-                                                    uuid='uuid')
802
-        mock_trunk = mock.MagicMock()
803
-        mock_cna_search.return_value = mock_trunk
804
+
805
+        mock_vio = mock.MagicMock(schema_type='VIO', uuid='uuid')
806
+        mock_get_part.return_value = mock_vio
807
+
808
+        trunk1 = mock.Mock(pvid=2, vswitch_id=3, trunk_pri=1)
809
+        trunk2 = mock.Mock(pvid=3, vswitch_id=5, trunk_pri=1)
810
+        trunk3 = mock.Mock(pvid=4, vswitch_id=5, trunk_pri=None)
811
+        trunk4 = mock.Mock(pvid=4, vswitch_id=5, trunk_pri=1)
812
+        mock_cna_get.return_value = [trunk1, trunk2, trunk3, trunk4]
804 813
 
805 814
         # Invoke
806 815
         self.drv.rollback_live_migration_at_destination(vif, vea_vlan_mappings)
@@ -809,7 +818,7 @@ class TestVifOvsDriver(test.TestCase):
809 818
         mock_delete_ovs_port.assert_called_once_with('br-int', 'tap-dev')
810 819
 
811 820
         # Make sure the trunk was deleted
812
-        mock_trunk.delete.assert_called_once()
821
+        trunk4.delete.assert_called_once()
813 822
 
814 823
         # Now make sure the calls were done correctly to actually produce a
815 824
         # trunk adapter
@@ -817,9 +826,8 @@ class TestVifOvsDriver(test.TestCase):
817 826
             self.drv.adapter, parent_type=pvm_ms.System, one_result=True,
818 827
             name=CONF.powervm.pvm_vswitch_for_novalink_io)
819 828
         mock_get_part.assert_called_once_with(self.drv.adapter)
820
-        mock_cna_search.assert_called_once_with(
821
-            self.drv.adapter, parent_type='VIO', parent_uuid='uuid',
822
-            vswitch_id=5, pvid=4, one_result=True)
829
+        mock_cna_get.assert_called_once_with(
830
+            self.drv.adapter, parent=mock_vio)
823 831
 
824 832
     @mock.patch('nova.network.linux_net.delete_ovs_vif_port')
825 833
     def test_post_live_migrate_at_source(self, mock_delete_ovs_port):

+ 10
- 5
nova_powervm/virt/powervm/vif.py View File

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

Loading…
Cancel
Save