Skip to content

Commit 48841dc

Browse files
committed
machine_os: Preemptively load vfio kernel module.
VFIO kernel module is not always loaded, which causes tests to fail when they try to set No-IOMMU mode. This change calls modprobe to ensure that VFIO is loaded before we try to use it. (cherry picked from commit 0a01a10) Signed-off-by: Martin Kalcok <martin.kalcok@canonical.com>
1 parent c1fa7d8 commit 48841dc

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

unit_tests/utilities/test_zaza_utilities_machine_os.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def test_add_netdevsim(self):
8585

8686
def test__set_vfio_unsafe_noiommu_mode(self):
8787
self.patch_object(machine_os_utils.zaza.utilities.juju, 'remote_run')
88+
self.patch_object(machine_os_utils, 'load_kernel_module')
8889
self.remote_run.return_value = 'Y'
8990
unit = mock.MagicMock()
9091
unit.name = 'aUnit'
@@ -97,6 +98,7 @@ def test__set_vfio_unsafe_noiommu_mode(self):
9798
with self.assertRaises(AssertionError):
9899
machine_os_utils._set_vfio_unsafe_noiommu_mode(unit, True)
99100

101+
self.load_kernel_module.reset_mock()
100102
self.remote_run.reset_mock()
101103
self.remote_run.return_value = 'Y\n'
102104
expect = (
@@ -105,7 +107,10 @@ def test__set_vfio_unsafe_noiommu_mode(self):
105107
machine_os_utils._set_vfio_unsafe_noiommu_mode(unit, True)
106108
self.remote_run.assert_called_once_with(
107109
'aUnit', expect, model_name=None, fatal=True)
110+
self.load_kernel_module.assert_called_once_with(
111+
'aUnit', 'vfio', model_name=None)
108112

113+
self.load_kernel_module.reset_mock()
109114
self.remote_run.reset_mock()
110115
self.remote_run.return_value = 'N\n'
111116
expect = (
@@ -114,6 +119,8 @@ def test__set_vfio_unsafe_noiommu_mode(self):
114119
machine_os_utils._set_vfio_unsafe_noiommu_mode(unit, False)
115120
self.remote_run.assert_called_once_with(
116121
'aUnit', expect, model_name=None, fatal=True)
122+
self.load_kernel_module.assert_called_once_with(
123+
'aUnit', 'vfio', model_name=None)
117124

118125
def test_enable_vfio_unsafe_noiommu_mode(self):
119126
self.patch_object(machine_os_utils, '_set_vfio_unsafe_noiommu_mode')

zaza/utilities/machine_os.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def _set_vfio_unsafe_noiommu_mode(unit, enable, model_name=None):
133133
:type model_name: Optional[str]
134134
:raises: AssertionError, zaza.model.CommandRunFailed
135135
"""
136+
load_kernel_module(unit.name, 'vfio', model_name=model_name)
137+
136138
expected_result = 'Y' if enable else 'N'
137139
value = 1 if enable else 0
138140
cmd = (

0 commit comments

Comments
 (0)