Set enforce_type=True in method flags
Current Nova uses method CONF.set_override to change config option's value with designated value in unit test, but never check if the designated vaule is valid. Each config option has a type like strOpt, BoolOpt, etc. StrOpt with parameter choices only allows values in set of choices. In short word, each config option has limitation for type and value. In production code, oslo.conf can ensure user's input is valid, but in unit test, test methods can pass if we use method CONF.set_override without parameter enforce_type=True even we pass wrong type or wrong value to config option. This commit makes enforce_type=True in method flags in nova/test.py and fix related violations. Closes-Bug: #1517839 Change-Id: I105dabfec89b01d131257054fbb3669763af6ca9
This commit is contained in:
parent
8dd230558c
commit
e6a05382bd
@ -282,7 +282,7 @@ class TestCase(testtools.TestCase):
|
||||
"""Override flag variables for a test."""
|
||||
group = kw.pop('group', None)
|
||||
for k, v in six.iteritems(kw):
|
||||
CONF.set_override(k, v, group)
|
||||
CONF.set_override(k, v, group, enforce_type=True)
|
||||
|
||||
def start_service(self, name, host=None, **kwargs):
|
||||
svc = self.useFixture(
|
||||
|
@ -46,9 +46,9 @@ class ServerGroupTestBase(test.TestCase,
|
||||
|
||||
# Note(gibi): RamFilter is needed to ensure that
|
||||
# test_boot_servers_with_affinity_no_valid_host behaves as expected
|
||||
_scheduler_default_filters = ('ServerGroupAntiAffinityFilter',
|
||||
_scheduler_default_filters = ['ServerGroupAntiAffinityFilter',
|
||||
'ServerGroupAffinityFilter',
|
||||
'RamFilter')
|
||||
'RamFilter']
|
||||
|
||||
# Override servicegroup parameters to make the tests run faster
|
||||
_service_down_time = 2
|
||||
|
@ -1485,7 +1485,7 @@ class VlanNetworkTestCase(test.TestCase):
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_floating_ip_init_host_without_public_interface(self):
|
||||
self._test_floating_ip_init_host(public_interface=False,
|
||||
self._test_floating_ip_init_host(public_interface='',
|
||||
expected_arg='fakeiface')
|
||||
|
||||
def test_floating_ip_init_host_with_public_interface(self):
|
||||
|
@ -1532,7 +1532,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
@mock.patch.object(host.Host,
|
||||
'has_min_version', return_value=True)
|
||||
def test_set_admin_password_bad_hyp(self, mock_svc, mock_image):
|
||||
self.flags(virt_type='foo', group='libvirt')
|
||||
self.flags(virt_type='lxc', group='libvirt')
|
||||
instance = objects.Instance(**self.test_instance)
|
||||
mock_image.return_value = {"properties": {
|
||||
"hw_qemu_guest_agent": "yes"}}
|
||||
@ -5288,7 +5288,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_get_guest_config_os_command_line_through_image_meta(self):
|
||||
self.flags(virt_type="kvm",
|
||||
cpu_mode=None,
|
||||
cpu_mode='none',
|
||||
group='libvirt')
|
||||
|
||||
self.test_instance['kernel_id'] = "fake_kernel_id"
|
||||
@ -5311,7 +5311,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_get_guest_config_os_command_line_without_kernel_id(self):
|
||||
self.flags(virt_type="kvm",
|
||||
cpu_mode=None,
|
||||
cpu_mode='none',
|
||||
group='libvirt')
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = objects.Instance(**self.test_instance)
|
||||
@ -5331,7 +5331,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_get_guest_config_os_command_empty(self):
|
||||
self.flags(virt_type="kvm",
|
||||
cpu_mode=None,
|
||||
cpu_mode='none',
|
||||
group='libvirt')
|
||||
|
||||
self.test_instance['kernel_id'] = "fake_kernel_id"
|
||||
@ -5577,7 +5577,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_get_guest_cpu_config_default_kvm(self):
|
||||
self.flags(virt_type="kvm",
|
||||
cpu_mode=None,
|
||||
cpu_mode='none',
|
||||
group='libvirt')
|
||||
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
@ -5592,7 +5592,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
image_meta, disk_info)
|
||||
self.assertIsInstance(conf.cpu,
|
||||
vconfig.LibvirtConfigGuestCPU)
|
||||
self.assertEqual(conf.cpu.mode, "host-model")
|
||||
self.assertIsNone(conf.cpu.mode)
|
||||
self.assertIsNone(conf.cpu.model)
|
||||
self.assertEqual(conf.cpu.sockets, instance_ref.flavor.vcpus)
|
||||
self.assertEqual(conf.cpu.cores, 1)
|
||||
@ -5600,7 +5600,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_get_guest_cpu_config_default_uml(self):
|
||||
self.flags(virt_type="uml",
|
||||
cpu_mode=None,
|
||||
cpu_mode='none',
|
||||
group='libvirt')
|
||||
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
@ -5617,7 +5617,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_get_guest_cpu_config_default_lxc(self):
|
||||
self.flags(virt_type="lxc",
|
||||
cpu_mode=None,
|
||||
cpu_mode='none',
|
||||
group='libvirt')
|
||||
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
@ -6256,7 +6256,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
"/dev/sda")
|
||||
|
||||
def test_attach_blockio_invalid_hypervisor(self):
|
||||
self.flags(virt_type='fake_type', group='libvirt')
|
||||
self.flags(virt_type='lxc', group='libvirt')
|
||||
self.create_fake_libvirt_mock()
|
||||
libvirt_driver.LibvirtDriver._conn.lookupByName = self.fake_lookup
|
||||
instance = objects.Instance(**self.test_instance)
|
||||
@ -7855,7 +7855,6 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
# anything else will return None
|
||||
('lxc', None),
|
||||
('parallels', None),
|
||||
('', None),
|
||||
)
|
||||
dest = 'destination'
|
||||
for hyperv, uri in hypervisor_uri_map:
|
||||
@ -13954,22 +13953,22 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
||||
root_bdm = {'source_type': 'image',
|
||||
'destination_type': 'volume',
|
||||
'image_id': 'fake_id'}
|
||||
self.flags(virt_type='fake_libvirt_type', group='libvirt')
|
||||
self.flags(virt_type='qemu', group='libvirt')
|
||||
|
||||
self.mox.StubOutWithMock(blockinfo, 'get_disk_bus_for_device_type')
|
||||
self.mox.StubOutWithMock(blockinfo, 'get_root_info')
|
||||
|
||||
blockinfo.get_disk_bus_for_device_type(instance,
|
||||
'fake_libvirt_type',
|
||||
'qemu',
|
||||
image_meta,
|
||||
'disk').InAnyOrder().\
|
||||
AndReturn('virtio')
|
||||
blockinfo.get_disk_bus_for_device_type(instance,
|
||||
'fake_libvirt_type',
|
||||
'qemu',
|
||||
image_meta,
|
||||
'cdrom').InAnyOrder().\
|
||||
AndReturn('ide')
|
||||
blockinfo.get_root_info(instance, 'fake_libvirt_type',
|
||||
blockinfo.get_root_info(instance, 'qemu',
|
||||
image_meta, root_bdm,
|
||||
'virtio', 'ide').AndReturn({'dev': 'vda'})
|
||||
self.mox.ReplayAll()
|
||||
@ -17478,7 +17477,7 @@ class LibvirtVolumeSnapshotTestCase(test.NoDBTestCase):
|
||||
@mock.patch.object(host.Host,
|
||||
'has_min_version', return_value=True)
|
||||
def test_can_quiesce_bad_hyp(self, ver):
|
||||
self.flags(virt_type='xxx', group='libvirt')
|
||||
self.flags(virt_type='lxc', group='libvirt')
|
||||
instance = objects.Instance(**self.inst)
|
||||
image_meta = objects.ImageMeta.from_dict(
|
||||
{"properties": {
|
||||
|
Loading…
Reference in New Issue
Block a user