Browse Source

Merge "Move get_machine_type() test to test_utils.py"

tags/20.0.0.0rc1
Zuul 1 month ago
parent
commit
b879f1b6df

+ 0
- 10
nova/tests/unit/virt/libvirt/test_driver.py View File

@@ -6592,16 +6592,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
6592 6592
         self.assertTrue(usbhost_exists)
6593 6593
         self.assertTrue(keyboard_exists)
6594 6594
 
6595
-    @mock.patch('nova.virt.libvirt.utils.get_arch')
6596
-    def test_get_guest_config_machine_type_s390(self, mock_get_arch):
6597
-
6598
-        image_meta = objects.ImageMeta.from_dict(self.test_image_meta)
6599
-        host_cpu_archs = (fields.Architecture.S390, fields.Architecture.S390X)
6600
-        for host_cpu_arch in host_cpu_archs:
6601
-            mock_get_arch.return_value = host_cpu_arch
6602
-            os_mach_type = libvirt_utils.get_machine_type(image_meta)
6603
-            self.assertEqual('s390-ccw-virtio', os_mach_type)
6604
-
6605 6595
     def test_get_guest_config_machine_type_through_image_meta(self):
6606 6596
         self.flags(virt_type="kvm",
6607 6597
                    group='libvirt')

+ 21
- 4
nova/tests/unit/virt/libvirt/test_utils.py View File

@@ -957,21 +957,38 @@ sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0
957 957
         self.assertEqual('/test/disk', disk_path)
958 958
         self.assertEqual('ploop', format)
959 959
 
960
-    def test_get_default_machine_type(self):
960
+    @mock.patch('nova.virt.libvirt.utils.get_arch')
961
+    def test_get_machine_type_from_fallbacks(self, mock_get_arch):
962
+        """Test hardcoded arch-specific fallbacks for default machine type"""
963
+        image_meta = objects.ImageMeta.from_dict({"disk_format": "raw"})
964
+        host_cpu_archs = {
965
+            obj_fields.Architecture.ARMV7: "virt",
966
+            obj_fields.Architecture.AARCH64: "virt",
967
+            obj_fields.Architecture.S390: "s390-ccw-virtio",
968
+            obj_fields.Architecture.S390X: "s390-ccw-virtio",
969
+            obj_fields.Architecture.I686: "pc",
970
+            obj_fields.Architecture.X86_64: "pc",
971
+        }
972
+        for arch, expected_mtype in host_cpu_archs.items():
973
+            mock_get_arch.return_value = arch
974
+            mtype = libvirt_utils.get_machine_type(image_meta)
975
+            self.assertEqual(expected_mtype, mtype)
976
+
977
+    def test_get_machine_type_from_conf(self):
961 978
         self.useFixture(nova_fixtures.ConfPatcher(
962 979
             group="libvirt", hw_machine_type=['x86_64=q35', 'i686=legacy']))
963 980
         self.assertEqual('q35',
964 981
                          libvirt_utils.get_default_machine_type('x86_64'))
965 982
 
966
-    def test_get_default_machine_type_empty(self):
983
+    def test_get_machine_type_no_conf_or_fallback(self):
967 984
         self.assertIsNone(libvirt_utils.get_default_machine_type('sparc'))
968 985
 
969
-    def test_get_default_machine_type_missing(self):
986
+    def test_get_machine_type_missing_conf_and_fallback(self):
970 987
         self.useFixture(nova_fixtures.ConfPatcher(
971 988
             group="libvirt", hw_machine_type=['x86_64=q35', 'i686=legacy']))
972 989
         self.assertIsNone(libvirt_utils.get_default_machine_type('sparc'))
973 990
 
974
-    def test_get_default_machine_type_invalid(self):
991
+    def test_get_machine_type_survives_invalid_conf(self):
975 992
         self.useFixture(nova_fixtures.ConfPatcher(
976 993
             group="libvirt", hw_machine_type=['x86_64=q35', 'foo']))
977 994
         self.assertEqual('q35',

Loading…
Cancel
Save