From f674bcd4fa1724f12ed340db2098e147f89e6d61 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Tue, 13 Sep 2022 09:53:34 +0000 Subject: [PATCH] Add nbd kernel module for snapshot mounts Add nbd kernel module for mounting snapshots. Closes-Bug: 1961149 Change-Id: I59a8a02db3326026f58a775649b63935254b6cf6 --- src/reactive/data_mover_handlers.py | 20 ++++++++++++++++++++ unit_tests/__init__.py | 2 ++ unit_tests/test_data_mover.py | 6 ++++++ 3 files changed, 28 insertions(+) diff --git a/src/reactive/data_mover_handlers.py b/src/reactive/data_mover_handlers.py index ca7281a..659ca2e 100644 --- a/src/reactive/data_mover_handlers.py +++ b/src/reactive/data_mover_handlers.py @@ -12,6 +12,9 @@ import charms_openstack.charm as charm import charms.reactive as reactive +import charmhelpers.core.kernel as ch_kernel +import charmhelpers.core.host as ch_host +import charmhelpers.core.hookenv as ch_hookenv # This charm's library contains all of the handler code associated with # trilio_dm @@ -38,6 +41,23 @@ def render_config(*args): reactive.set_state("config.rendered") +@reactive.when_not('is-update-status-hook') +@reactive.when('charm.installed') +def setup_kernel_modules(): + module = 'nbd' + if ch_host.is_container(): + ch_hookenv.log( + "Cannot load modules inside of a container", + level=ch_hookenv.WARNING) + else: + try: + ch_kernel.modprobe(module) + except Exception: + ch_hookenv.log( + "Failed to load kernel module '%s'" % module, + level=ch_hookenv.WARNING) + + @reactive.when('shared-db.connected') def default_setup_database(database): """Handle the default database connection setup diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py index 64c49f5..9a7aebc 100644 --- a/unit_tests/__init__.py +++ b/unit_tests/__init__.py @@ -7,3 +7,5 @@ sys.path.append("src/lib") import charms_openstack.test_mocks # noqa charms_openstack.test_mocks.mock_charmhelpers() +sys.modules['charmhelpers.core.kernel'] = ( + charms_openstack.test_mocks.charmhelpers.core.kernel) diff --git a/unit_tests/test_data_mover.py b/unit_tests/test_data_mover.py index 86d5c0b..b67384b 100644 --- a/unit_tests/test_data_mover.py +++ b/unit_tests/test_data_mover.py @@ -93,11 +93,17 @@ class Test(test_utils.PatchHelper): "ceph_connected": ( "ceph.connected", ), + "setup_kernel_modules": ( + "charm.installed", + ), } when_not_patterns = { "ceph_connected": ( "ceph.access.req.sent", ), + "setup_kernel_modules": ( + "is-update-status-hook", + ), } # check the when hooks are attached to the expected functions for t, p in [