Browse Source

Add tests for bug #1800511

In Rocky, we started including the MTU for networks when vif_type
is bridge or tap and libvirt >= 3.3.0, however this also meant
that we started specifying the MTU when doing live migrations.

It seems that the guest ABI changes when setting the MTU which
means that live migrations will fail.  This broke the live migration
of any instance that was launched prior to upgrading to Rocky, as
it was not loaded with the ABI having host_mtu specified.

This is a passing (negative) test-case which will include a follow
up patch that contains a fix and correcting tests.

Related-Bug: #1800511
Change-Id: Ia2fe50d727b1f83e808cb9dda3a55f853f048a3e
tags/19.0.0.0rc1
Mohammed Naser 10 months ago
parent
commit
29ee8011b4
1 changed files with 112 additions and 16 deletions
  1. 112
    16
      nova/tests/unit/virt/libvirt/test_migration.py

+ 112
- 16
nova/tests/unit/virt/libvirt/test_migration.py View File

@@ -671,7 +671,7 @@ class UtilityMigrationTestCase(test.NoDBTestCase):
671 671
   </memoryBacking>
672 672
 </domain>"""))
673 673
 
674
-    def test_update_vif_xml(self):
674
+    def _test_update_vif_xml(self, conf, original_xml, expected_xml):
675 675
         """Simulates updating the guest xml for live migrating from a host
676 676
         using OVS to a host using vhostuser as the networking backend.
677 677
         """
@@ -695,6 +695,22 @@ class UtilityMigrationTestCase(test.NoDBTestCase):
695 695
         ]
696 696
         data = objects.LibvirtLiveMigrateData(vifs=migrate_vifs)
697 697
 
698
+        get_vif_config = mock.MagicMock(return_value=conf)
699
+        doc = etree.fromstring(original_xml)
700
+        updated_xml = etree.tostring(
701
+            migration._update_vif_xml(doc, data, get_vif_config),
702
+            encoding='unicode')
703
+        self.assertThat(updated_xml, matchers.XMLMatches(expected_xml))
704
+
705
+    def test_update_vif_xml_to_vhostuser(self):
706
+        conf = vconfig.LibvirtConfigGuestInterface()
707
+        conf.net_type = "vhostuser"
708
+        conf.vhostuser_type = "unix"
709
+        conf.vhostuser_mode = "server"
710
+        conf.mac_addr = "DE:AD:BE:EF:CA:FE"
711
+        conf.vhostuser_path = "/vhost-user/test.sock"
712
+        conf.model = "virtio"
713
+
698 714
         original_xml = """<domain>
699 715
  <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid>
700 716
  <devices>
@@ -711,38 +727,118 @@ class UtilityMigrationTestCase(test.NoDBTestCase):
711 727
     </interface>
712 728
  </devices>
713 729
 </domain>""" % uuids.ovs
730
+        # Note that <target> and <virtualport> are dropped from the ovs source
731
+        # interface xml since they aren't applicable to the vhostuser
732
+        # destination interface xml. The type attribute value changes and the
733
+        # hardware address element is retained.
734
+        expected_xml = """<domain>
735
+ <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid>
736
+ <devices>
737
+    <interface type="vhostuser">
738
+        <mac address="DE:AD:BE:EF:CA:FE"/>
739
+        <model type="virtio"/>
740
+        <source mode="server" path="/vhost-user/test.sock" type="unix"/>
741
+        <address type='pci' domain='0x0000' bus='0x00' slot='0x04'
742
+                 function='0x0'/>
743
+    </interface>
744
+ </devices>
745
+</domain>"""
746
+        self._test_update_vif_xml(conf, original_xml, expected_xml)
714 747
 
748
+    def test_update_vif_xml_to_bridge_without_mtu(self):
749
+        """This test validates _update_vif_xml to make sure it does not add
750
+        MTU to the interface if it does not exist in the source XML.
751
+        """
715 752
         conf = vconfig.LibvirtConfigGuestInterface()
716
-        conf.net_type = "vhostuser"
717
-        conf.vhostuser_type = "unix"
718
-        conf.vhostuser_mode = "server"
753
+        conf.net_type = "bridge"
754
+        conf.source_dev = "qbra188171c-ea"
755
+        conf.target_dev = "tapa188171c-ea"
719 756
         conf.mac_addr = "DE:AD:BE:EF:CA:FE"
720 757
         conf.vhostuser_path = "/vhost-user/test.sock"
721 758
         conf.model = "virtio"
759
+        conf.mtu = 9000
722 760
 
723
-        get_vif_config = mock.MagicMock(return_value=conf)
724
-        doc = etree.fromstring(original_xml)
725
-        updated_xml = etree.tostring(
726
-            migration._update_vif_xml(doc, data, get_vif_config),
727
-            encoding='unicode')
761
+        original_xml = """<domain>
762
+ <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid>
763
+ <devices>
764
+    <interface type="bridge">
765
+        <mac address="DE:AD:BE:EF:CA:FE"/>
766
+        <model type="virtio"/>
767
+        <source bridge="qbra188171c-ea"/>
768
+        <target dev="tapa188171c-ea"/>
769
+        <virtualport type="openvswitch">
770
+            <parameters interfaceid="%s"/>
771
+        </virtualport>
772
+        <address type='pci' domain='0x0000' bus='0x00' slot='0x04'
773
+                 function='0x0'/>
774
+    </interface>
775
+ </devices>
776
+</domain>""" % uuids.ovs
777
+        expected_xml = """<domain>
778
+ <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid>
779
+ <devices>
780
+    <interface type="bridge">
781
+        <mac address="DE:AD:BE:EF:CA:FE"/>
782
+        <model type="virtio"/>
783
+        <source bridge="qbra188171c-ea"/>
784
+        <!--
785
+            NOTE(mnaser): This should not be here, remove when fixed
786
+                          https://bugs.launchpad.net/nova/+bug/1800511
787
+        -->
788
+        <mtu size="9000"/>
789
+        <target dev="tapa188171c-ea"/>
790
+        <address type='pci' domain='0x0000' bus='0x00' slot='0x04'
791
+                 function='0x0'/>
792
+    </interface>
793
+ </devices>
794
+</domain>"""
795
+        self._test_update_vif_xml(conf, original_xml, expected_xml)
728 796
 
729
-        # Note that <target> and <virtualport> are dropped from the ovs source
730
-        # interface xml since they aren't applicable to the vhostuser
731
-        # destination interface xml. The type attribute value changes and the
732
-        # hardware address element is retained.
797
+    def test_update_vif_xml_to_bridge_with_mtu(self):
798
+        """This test validates _update_vif_xml to make sure it maintains the
799
+        interface MTU if it exists in the source XML
800
+        """
801
+        conf = vconfig.LibvirtConfigGuestInterface()
802
+        conf.net_type = "bridge"
803
+        conf.source_dev = "qbra188171c-ea"
804
+        conf.target_dev = "tapa188171c-ea"
805
+        conf.mac_addr = "DE:AD:BE:EF:CA:FE"
806
+        conf.vhostuser_path = "/vhost-user/test.sock"
807
+        conf.model = "virtio"
808
+        conf.mtu = 9000
809
+
810
+        original_xml = """<domain>
811
+ <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid>
812
+ <devices>
813
+    <interface type="bridge">
814
+        <mac address="DE:AD:BE:EF:CA:FE"/>
815
+        <model type="virtio"/>
816
+        <source bridge="qbra188171c-ea"/>
817
+        <target dev="tapa188171c-ea"/>
818
+        <mtu size="9000"/>
819
+        <virtualport type="openvswitch">
820
+            <parameters interfaceid="%s"/>
821
+        </virtualport>
822
+        <address type='pci' domain='0x0000' bus='0x00' slot='0x04'
823
+                 function='0x0'/>
824
+    </interface>
825
+ </devices>
826
+</domain>""" % uuids.ovs
733 827
         expected_xml = """<domain>
734 828
  <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid>
735 829
  <devices>
736
-    <interface type="vhostuser">
830
+    <interface type="bridge">
737 831
         <mac address="DE:AD:BE:EF:CA:FE"/>
738 832
         <model type="virtio"/>
739
-        <source mode="server" path="/vhost-user/test.sock" type="unix"/>
833
+        <source bridge="qbra188171c-ea"/>
834
+        <mtu size="9000"/>
835
+        <target dev="tapa188171c-ea"/>
740 836
         <address type='pci' domain='0x0000' bus='0x00' slot='0x04'
741 837
                  function='0x0'/>
742 838
     </interface>
743 839
  </devices>
744 840
 </domain>"""
745
-        self.assertThat(updated_xml, matchers.XMLMatches(expected_xml))
841
+        self._test_update_vif_xml(conf, original_xml, expected_xml)
746 842
 
747 843
     def test_update_vif_xml_no_mac_address_in_xml(self):
748 844
         """Tests that the <mac address> is not found in the <interface> XML

Loading…
Cancel
Save