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/3.0.1^0
Drew Thorstensen 2 years ago
parent
commit
75e9992b11
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

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

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

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

Loading…
Cancel
Save