Skip to content

Commit 2ba6d03

Browse files
authored
Merge pull request #28 from canonical/install-socat
Install socat on install hook
2 parents 5f27999 + 7eee868 commit 2ba6d03

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/charm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ def _on_install(self, _: ops.InstallEvent) -> None:
405405
self.unit.status = ops.BlockedStatus("Failed to install sqlite3.")
406406
return
407407

408+
self.unit.status = ops.MaintenanceStatus("Installing socat.")
409+
410+
if not pkgs.socat_install():
411+
self.unit.status = ops.BlockedStatus("Failed to install socat.")
412+
return
413+
408414
self.unit.status = ops.MaintenanceStatus("Setting up git-ubuntu user.")
409415
usr.setup_git_ubuntu_user(GIT_UBUNTU_SYSTEM_USER_USERNAME, GIT_UBUNTU_USER_HOME_DIR)
410416

src/package_installation.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ def sqlite3_install() -> bool:
4848
return True
4949

5050

51+
def socat_install() -> bool:
52+
"""Install socat from apt.
53+
54+
Returns:
55+
True if socat install succeeded, False otherwise.
56+
"""
57+
try:
58+
apt.update()
59+
apt.add_package("socat")
60+
logger.info("Installed socat package.")
61+
except apt.PackageError as e:
62+
logger.error("Failed to install socat from apt: %s", e)
63+
return False
64+
65+
return True
66+
67+
5168
def git_ubuntu_snap_refresh(channel: str) -> bool:
5269
"""Install or refresh the git-ubuntu snap with the given channel version.
5370

tests/unit/test_charm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_install_success(
4949
assert out.unit_status == ActiveStatus("Install complete.")
5050

5151
mock_apt_update.assert_called()
52-
mock_add_package.assert_has_calls([call("git"), call("sqlite3")])
52+
mock_add_package.assert_has_calls([call("git"), call("sqlite3"), call("socat")])
5353
mock_setup_git_ubuntu_user.assert_called_once_with("git-ubuntu", "/var/local/git-ubuntu")
5454
mock_setup_git_ubuntu_user_services_dir.assert_called_once_with(
5555
"git-ubuntu", "/var/local/git-ubuntu"

0 commit comments

Comments
 (0)