Skip to content

Commit

Permalink
Ensure kernel modules are loaded after reboot (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhaliaw authored Sep 15, 2023
1 parent 7ba3abb commit 2a9fb6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,13 @@ def _install_repo_policy_compliance(self) -> bool:
)
return old_version != new_version

def _enable_kernel_modules(self) -> None:
"""Enable kernel modules needed by the charm."""
execute_command(["/usr/sbin/modprobe", "br_netfilter"])

with open("/etc/modules", "a", encoding="utf-8") as modules_file:
modules_file.write("br_netfilter\n")

@retry(tries=10, delay=15, max_delay=60, backoff=1.5, local_logger=logger)
def _install_deps(self) -> None:
"""Install dependencies."""
Expand Down Expand Up @@ -710,7 +717,7 @@ def _install_deps(self) -> None:
execute_command(["/snap/bin/lxc", "network", "set", "lxdbr0", "ipv6.address", "none"])
execute_command(["/snap/bin/lxd", "waitready"])
if not LXD_PROFILE_YAML.exists():
execute_command(["/usr/sbin/modprobe", "br_netfilter"])
self._enable_kernel_modules()
execute_command(
[
"/snap/bin/lxc",
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def test_proxy_setting(self):

@patch("pathlib.Path.write_text")
@patch("subprocess.run")
def test_install(self, run, wt):
@patch("builtins.open")
def test_install(self, open, run, wt):
harness = Harness(GithubRunnerCharm)
harness.begin()
harness.charm.on.install.emit()
Expand Down Expand Up @@ -225,7 +226,8 @@ def test_get_runner_manager(self, run, wt, mkdir):
@patch("pathlib.Path.mkdir")
@patch("pathlib.Path.write_text")
@patch("subprocess.run")
def test_on_install_failure(self, run, wt, mkdir, rm):
@patch("builtins.open")
def test_on_install_failure(self, open, run, wt, mkdir, rm):
"""Test various error thrown during install."""

rm.return_value = mock_rm = MagicMock()
Expand Down

0 comments on commit 2a9fb6e

Please sign in to comment.