Skip to content

Commit 1655161

Browse files
authored
Merge pull request #678 from mkalcok/tmp-vfio-load
machine_os: Preemptively load vfio kernel module.
2 parents 51c90db + b20ec47 commit 1655161

File tree

11 files changed

+11
-18
lines changed

11 files changed

+11
-18
lines changed

unit_tests/test_zaza_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,6 @@ def test_run_action_on_units(self):
11421142
'app/2': self.unit2}
11431143

11441144
async def _async_get_unit_from_name(x, *args):
1145-
nonlocal units
11461145
return units[x]
11471146

11481147
self.async_get_unit_from_name.side_effect = _async_get_unit_from_name

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/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def get_or_create_libjuju_thread():
6464
:returns: the thread that libjuju is running in.
6565
:rtype: threading.Thread
6666
"""
67-
global _libjuju_thread, _libjuju_loop, _libjuju_run
67+
global _libjuju_thread, _libjuju_run
6868
if _libjuju_thread is None:
6969
_libjuju_run = True
7070
_libjuju_thread = threading.Thread(target=libjuju_thread_run)
@@ -103,7 +103,6 @@ def libjuju_thread_run():
103103
global _libjuju_loop
104104

105105
async def looper():
106-
global _libjuju_run
107106
while _libjuju_run:
108107
# short spinner to ensure that foreground tasks 'happen' so that
109108
# background tasks can complete (e.g. during model disconnection).
@@ -148,7 +147,7 @@ async def looper():
148147

149148
def join_libjuju_thread():
150149
"""Stop and cleanup the asyncio tasks on the loop, and then join it."""
151-
global _libjuju_thread, _libjuju_loop, _libjuju_run
150+
global _libjuju_thread, _libjuju_run
152151
if _libjuju_thread is not None:
153152
logging.debug("stopping the event loop")
154153
# remove the child watcher (that was for subprocess calls) when
@@ -203,7 +202,6 @@ def sync_wrapper(f, timeout=None):
203202
:rtype: function
204203
"""
205204
def _wrapper(*args, **kwargs):
206-
global _libjuju_loop
207205

208206
async def _runner():
209207
return await f(*args, **kwargs)

zaza/charm_lifecycle/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def get_base_test_dir():
9191
:returns: Path to test dir.
9292
:rtype: str
9393
"""
94-
global base_test_dir
9594
return base_test_dir
9695

9796

@@ -399,7 +398,6 @@ def get_charm_config(yaml_file=None, fatal=True, cached=True):
399398
:returns: Config dictionary
400399
:rtype: dict
401400
"""
402-
global _charm_config
403401
if not yaml_file:
404402
if get_base_test_dir():
405403
yaml_file = "{}/{}".format(

zaza/events/collection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def get_collection(name=None):
6969
:returns: the colection named, or creates a new one of that name.
7070
:rtype: Collection
7171
"""
72-
global _collections
7372
if name is None:
7473
name = get_option("zaza-events.collection-name", "DEFAULT")
7574
try:

zaza/events/plugins/conncheck.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def get_plugin_manager(name="DEFAULT"):
109109
:returns: the conncheck plugin manager
110110
:rtype: LoggerPluginManager
111111
"""
112-
global _conncheck_plugin_managers
113112
try:
114113
return _conncheck_plugin_managers[name]
115114
except KeyError:

zaza/events/plugins/logging.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ def get_logger(name="DEFAULT"):
214214
:returns: the logger instance
215215
:rtype: EventLogger
216216
"""
217-
global _loggers
218217
if name not in _loggers:
219218
_loggers[name] = EventLogger(name)
220219
return _loggers[name]
@@ -272,7 +271,6 @@ def get_plugin_manager(name="DEFAULT"):
272271
:returns: the Logger plugin manager
273272
:rtype: LoggerPluginManager
274273
"""
275-
global _logger_plugin_managers
276274
try:
277275
return _logger_plugin_managers[name]
278276
except KeyError:

zaza/model.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def get_juju_model_aliases():
9393
:returns: Model alias map
9494
:rtype: dict
9595
"""
96-
global MODEL_ALIASES
9796
return MODEL_ALIASES
9897

9998

@@ -211,7 +210,6 @@ async def get_model_memo(model_name):
211210
:type model_name: str
212211
:returns: juju.model.Model
213212
"""
214-
global ModelRefs
215213
model = None
216214
if model_name in ModelRefs:
217215
model = ModelRefs[model_name]
@@ -257,7 +255,6 @@ async def remove_model_memo(model_name):
257255
:param model_name: the model name to remove a Model object.
258256
:type model_name: str
259257
"""
260-
global ModelRefs
261258
try:
262259
model = ModelRefs[model_name]
263260
del ModelRefs[model_name]

zaza/notifications/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def subscribe(f, event=None, when=None):
124124
:param when: when the function should be called.
125125
:type when: str
126126
"""
127-
global _notify_map
128127
if event is None:
129128
events = NotifyEvents
130129
elif isinstance(event, Iterable):
@@ -163,7 +162,6 @@ def unsubscribe(f, event=None, when=None):
163162
:param when: when the function should be called.
164163
:type when: str
165164
"""
166-
global _notify_map
167165
if when is None or when == NotifyType.ALL:
168166
whens = (NotifyType.BEFORE, NotifyType.AFTER, NotifyType.EXCEPTION)
169167
elif when == NotifyType.BOTH:

zaza/utilities/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def wrap(f):
3232

3333
@wraps(f)
3434
def wrapped_f(*args, **kwargs):
35-
global deprecations
3635
if f not in deprecations:
3736
msg = "{} is deprecated. ".format(f.__name__)
3837
logging.warning(msg)
@@ -109,7 +108,6 @@ def unit_get(attribute):
109108
"""
110109
@wraps(func)
111110
def wrapper(*args, **kwargs):
112-
global cache
113111
key = json.dumps((func, args, kwargs), sort_keys=True, default=str)
114112
try:
115113
return cache[key]

0 commit comments

Comments
 (0)