summaryrefslogtreecommitdiff
path: root/nova/tests/unit
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-02-12 15:53:46 +0000
committerStephen Finucane <stephenfin@redhat.com>2021-02-20 15:32:15 +0000
commitf7e3e179911e0a7fbad0d108c202c475560dbcea (patch)
tree9a03d8d20747b5593ea629f320489451903d7d99 /nova/tests/unit
parentb367cf114cdf825c83ada213233133362a6e5acf (diff)
downloadnova-f7e3e179911e0a7fbad0d108c202c475560dbcea.tar.gz
tests: Poison os.uname
We shouldn't be looking up the architecture of the test node during tests to ensure tests work across nodes with varying architectures. Change-Id: I458b1db091e33c0b835e44b5a86de6c0a08f99a3 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Co-authored-by: Lee Yarwood <lyarwood@redhat.com>
Diffstat (limited to 'nova/tests/unit')
-rw-r--r--nova/tests/unit/objects/test_fields.py7
-rw-r--r--nova/tests/unit/virt/disk/vfs/test_guestfs.py15
-rw-r--r--nova/tests/unit/virt/libvirt/test_vif.py46
3 files changed, 51 insertions, 17 deletions
diff --git a/nova/tests/unit/objects/test_fields.py b/nova/tests/unit/objects/test_fields.py
index 47af33f653..39f9de8cfe 100644
--- a/nova/tests/unit/objects/test_fields.py
+++ b/nova/tests/unit/objects/test_fields.py
@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import collections
import datetime
import os
@@ -27,6 +28,10 @@ from nova import test
from nova.tests.unit import fake_instance
from nova import utils
+os_uname = collections.namedtuple(
+ 'uname_result', ['sysname', 'nodename', 'release', 'version', 'machine'],
+)
+
class FakeFieldType(fields.FieldType):
def coerce(self, obj, attr, value):
@@ -187,7 +192,7 @@ class TestEnum(TestField):
class TestArchitecture(TestField):
@mock.patch.object(os, 'uname')
def test_host(self, mock_uname):
- mock_uname.return_value = (
+ mock_uname.return_value = os_uname(
'Linux',
'localhost.localdomain',
'3.14.8-200.fc20.x86_64',
diff --git a/nova/tests/unit/virt/disk/vfs/test_guestfs.py b/nova/tests/unit/virt/disk/vfs/test_guestfs.py
index 87f58ef357..b1c619c955 100644
--- a/nova/tests/unit/virt/disk/vfs/test_guestfs.py
+++ b/nova/tests/unit/virt/disk/vfs/test_guestfs.py
@@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import collections
+
import fixtures
import mock
@@ -21,6 +23,10 @@ from nova.tests.unit.virt.disk.vfs import fakeguestfs
from nova.virt.disk.vfs import guestfs as vfsimpl
from nova.virt.image import model as imgmodel
+os_uname = collections.namedtuple(
+ 'uname_result', ['sysname', 'nodename', 'release', 'version', 'machine'],
+)
+
class VirtDiskVFSGuestFSTest(test.NoDBTestCase):
def setUp(self):
@@ -326,10 +332,11 @@ class VirtDiskVFSGuestFSTest(test.NoDBTestCase):
self.assertFalse(setup_os.called)
@mock.patch('os.access')
- @mock.patch('os.uname', return_value=('Linux', '', 'kernel_name'))
- def test_appliance_setup_inspect_capabilties_fail_with_ubuntu(self,
- mock_uname,
- mock_access):
+ @mock.patch('os.uname', return_value=os_uname(
+ 'Linux', '', 'kernel_name', '', ''))
+ def test_appliance_setup_inspect_capabilties_fail_with_ubuntu(
+ self, mock_uname, mock_access,
+ ):
# In ubuntu os will default host kernel as 600 permission
m = mock.MagicMock()
m.launch.side_effect = Exception
diff --git a/nova/tests/unit/virt/libvirt/test_vif.py b/nova/tests/unit/virt/libvirt/test_vif.py
index f842f51c93..f50c75953e 100644
--- a/nova/tests/unit/virt/libvirt/test_vif.py
+++ b/nova/tests/unit/virt/libvirt/test_vif.py
@@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import collections
+
import fixtures
from lxml import etree
import mock
@@ -36,6 +38,11 @@ from nova.virt.libvirt import vif
CONF = cfg.CONF
+os_uname = collections.namedtuple(
+ 'uname_result', ['sysname', 'nodename', 'release', 'version', 'machine'],
+)
+
+
class LibvirtVifTestCase(test.NoDBTestCase):
gateway_bridge_4 = network_model.IP(address='101.168.1.1', type='gateway')
@@ -497,11 +504,20 @@ class LibvirtVifTestCase(test.NoDBTestCase):
def setUp(self):
super(LibvirtVifTestCase, self).setUp()
+
self.useFixture(fakelibvirt.FakeLibvirtFixture(stub_os_vif=False))
+
# os_vif.initialize is typically done in nova-compute startup
os_vif.initialize()
self.setup_os_vif_objects()
+ # multiqueue configuration is host OS specific
+ _a = mock.patch('os.uname')
+ self.mock_uname = _a.start()
+ self.mock_uname.return_value = os_uname(
+ 'Linux', '', '5.10.13-200-generic', '', 'x86_64')
+ self.addCleanup(_a.stop)
+
def _get_node(self, xml):
doc = etree.fromstring(xml)
ret = doc.findall('./devices/interface')
@@ -636,30 +652,36 @@ class LibvirtVifTestCase(test.NoDBTestCase):
def test_virtio_multiqueue(self):
self._test_virtio_multiqueue(4, '4')
- @mock.patch('os.uname', return_value=('Linux', '', '2.6.32-21-generic'))
- def test_virtio_multiqueue_in_kernel_2(self, mock_uname):
+ def test_virtio_multiqueue_in_kernel_2(self):
+ self.mock_uname.return_value = os_uname(
+ 'Linux', '', '2.6.32-21-generic', '', '')
self._test_virtio_multiqueue(10, '1')
- @mock.patch('os.uname', return_value=('Linux', '', '3.19.0-47-generic'))
- def test_virtio_multiqueue_in_kernel_3(self, mock_uname):
+ def test_virtio_multiqueue_in_kernel_3(self):
+ self.mock_uname.return_value = os_uname(
+ 'Linux', '', '3.19.0-47-generic', '', '')
self._test_virtio_multiqueue(10, '8')
- @mock.patch('os.uname', return_value=('Linux', '', '4.2.0-35-generic'))
- def test_virtio_multiqueue_in_kernel_4(self, mock_uname):
+ def test_virtio_multiqueue_in_kernel_4(self):
+ self.mock_uname.return_value = os_uname(
+ 'Linux', '', '4.2.0-35-generic', '', '')
self._test_virtio_multiqueue(10, '10')
- @mock.patch('os.uname', return_value=('Linux', '', '2.6.32-21-generic'))
- def test_virtio_multiqueue_in_kernel_2_max_queues(self, mock_uname):
+ def test_virtio_multiqueue_in_kernel_2_max_queues(self):
+ self.mock_uname.return_value = os_uname(
+ 'Linux', '', '2.6.32-21-generic', '', '')
self.flags(max_queues=2, group='libvirt')
self._test_virtio_multiqueue(10, '2')
- @mock.patch('os.uname', return_value=('Linux', '', '3.19.0-47-generic'))
- def test_virtio_multiqueue_in_kernel_3_max_queues(self, mock_uname):
+ def test_virtio_multiqueue_in_kernel_3_max_queues(self):
+ self.mock_uname.return_value = os_uname(
+ 'Linux', '', '3.19.0-47-generic', '', '')
self.flags(max_queues=2, group='libvirt')
self._test_virtio_multiqueue(10, '2')
- @mock.patch('os.uname', return_value=('Linux', '', '4.2.0-35-generic'))
- def test_virtio_multiqueue_in_kernel_4_max_queues(self, mock_uname):
+ def test_virtio_multiqueue_in_kernel_4_max_queues(self):
+ self.mock_uname.return_value = os_uname(
+ 'Linux', '', '4.2.0-35-generic', '', '')
self.flags(max_queues=2, group='libvirt')
self._test_virtio_multiqueue(10, '2')