Skip to content

Commit 23c260b

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Reproducer for bug 2098892" into unmaintained/2023.1
2 parents 70eaa37 + a5e0048 commit 23c260b

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

nova/test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def _start_compute(self, host, cell_name=None):
482482
self.computes[host] = compute
483483
return compute
484484

485-
def _run_periodics(self):
485+
def _run_periodics(self, raise_on_error=False):
486486
"""Run the update_available_resource task on every compute manager
487487
488488
This runs periodics on the computes in an undefined order; some child
@@ -497,6 +497,15 @@ class redefine this function to force a specific order.
497497
with context.target_cell(
498498
ctx, self.host_mappings[host].cell_mapping) as cctxt:
499499
compute.manager.update_available_resource(cctxt)
500+
501+
if raise_on_error:
502+
if 'Traceback (most recent call last' in self.stdlog.logger.output:
503+
# Get the last line of the traceback, for example:
504+
# TypeError: virNodeDeviceLookupByName() argument 2 must be
505+
# str or None, not Proxy
506+
last_tb_line = self.stdlog.logger.output.splitlines()[-1]
507+
raise TestingException(last_tb_line)
508+
500509
LOG.info('Finished with periodics')
501510

502511
def restart_compute_service(self, compute, keep_hypervisor_state=True):
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from nova import test
14+
from nova.tests.fixtures import libvirt as fakelibvirt
15+
from nova.tests.functional.libvirt import test_vgpu
16+
17+
18+
class VGPUTestsListDevices(test_vgpu.VGPUTestBase):
19+
"""Regression test for bug 2098892.
20+
21+
Test that nodeDeviceLookupByName() is called with valid types to prevent:
22+
23+
File "/usr/lib64/python3.9/site-packages/libvirt.py", line 5201, in
24+
nodeDeviceLookupByName ret =
25+
libvirtmod.virNodeDeviceLookupByName(self._o, name)
26+
TypeError: virNodeDeviceLookupByName() argument 2 must be str or None,
27+
not Proxy
28+
29+
in the future. This test relies on the LibvirtFixture checking for the
30+
correct types in its nodeDeviceLookupByName() method and raising TypeError
31+
if they are invalid.
32+
33+
We don't test this by importing the libvirt module because the libvirt
34+
module is forbidden to be imported into our test environment. It is
35+
excluded from test-requirements.txt and we also use the
36+
ImportModulePoisonFixture in nova/test.py to prevent use of modules such as
37+
libvirt.
38+
"""
39+
40+
def setUp(self):
41+
super().setUp()
42+
43+
# Start compute supporting only nvidia-11
44+
self.flags(
45+
enabled_mdev_types=fakelibvirt.NVIDIA_11_VGPU_TYPE,
46+
group='devices')
47+
48+
self.start_compute_with_vgpu('host1')
49+
50+
def fake_nodeDeviceLookupByName(self, name):
51+
# See bug https://bugs.launchpad.net/nova/+bug/2098892
52+
# We don't test this by importing the libvirt module because the
53+
# libvirt module is forbidden to be imported into our test
54+
# environment. It is excluded from test-requirements.txt and we
55+
# also use the ImportModulePoisonFixture in nova/test.py to prevent
56+
# use of modules such as libvirt.
57+
if not isinstance(name, str) and name is not None:
58+
raise TypeError(
59+
'virNodeDeviceLookupByName() argument 2 must be str or '
60+
f'None, not {type(name)}')
61+
62+
# FIXME(melwitt): We need to patch this only for this test because if
63+
# we add it to the LibvirtFixture right away, it will cause the
64+
# following additional tests to fail:
65+
#
66+
# nova.tests.functional.libvirt.test_reshape.VGPUReshapeTests
67+
# test_create_servers_with_vgpu
68+
#
69+
# nova.tests.functional.libvirt.test_vgpu.DifferentMdevClassesTests
70+
# test_create_servers_with_different_mdev_classes
71+
# test_resize_servers_with_mlx5
72+
#
73+
# nova.tests.functional.libvirt.test_vgpu.VGPULimitMultipleTypesTests
74+
# test_create_servers_with_vgpu
75+
#
76+
# nova.tests.functional.libvirt.test_vgpu.VGPULiveMigrationTests
77+
# test_live_migrate_server
78+
# test_live_migration_fails_on_old_source
79+
# test_live_migration_fails_due_to_non_supported_mdev_types
80+
# test_live_migration_fails_on_old_destination
81+
#
82+
# nova.tests.functional.libvirt.
83+
# test_vgpu.VGPULiveMigrationTestsLMFailed
84+
# test_live_migrate_server
85+
# test_live_migration_fails_on_old_source
86+
# test_live_migration_fails_due_to_non_supported_mdev_types
87+
# test_live_migration_fails_on_old_destination
88+
#
89+
# nova.tests.functional.libvirt.test_vgpu.VGPUMultipleTypesTests
90+
# test_create_servers_with_specific_type
91+
# test_create_servers_with_vgpu
92+
#
93+
# nova.tests.functional.libvirt.test_vgpu.VGPUTests
94+
# test_multiple_instance_create
95+
# test_create_servers_with_vgpu
96+
# test_create_server_with_two_vgpus_isolated
97+
# test_resize_servers_with_vgpu
98+
#
99+
# nova.tests.functional.libvirt.test_vgpu.VGPUTestsLibvirt7_3
100+
# test_create_servers_with_vgpu
101+
# test_create_server_with_two_vgpus_isolated
102+
# test_resize_servers_with_vgpu
103+
# test_multiple_instance_create
104+
#
105+
# nova.tests.functional.regressions.
106+
# test_bug_1951656.VGPUTestsLibvirt7_7
107+
# test_create_servers_with_vgpu
108+
self.stub_out(
109+
'nova.tests.fixtures.libvirt.Connection.nodeDeviceLookupByName',
110+
fake_nodeDeviceLookupByName)
111+
112+
def test_update_available_resource(self):
113+
# We only want to verify no errors were logged by
114+
# update_available_resource (logging under the 'except Exception:').
115+
# FIXME(melwitt): This currently will log an error and traceback
116+
# because of the bug. Update this when the bug is fixed.
117+
e = self.assertRaises(
118+
test.TestingException, self._run_periodics, raise_on_error=True)
119+
self.assertIn('TypeError', str(e))

0 commit comments

Comments
 (0)