Merge ~mitchburton/landscape-charm:main into landscape-charm:main

Proposed by Mitch Burton
Status: Merged
Approved by: Mitch Burton
Approved revision: b9714003a8e2d5ab4a58e95e509fa22e24b50f0f
Merged at revision: b9714003a8e2d5ab4a58e95e509fa22e24b50f0f
Proposed branch: ~mitchburton/landscape-charm:main
Merge into: landscape-charm:main
Diff against target: 114 lines (+15/-10)
3 files modified
lib/charms/operator_libs_linux/v0/apt.py (+6/-6)
lib/charms/operator_libs_linux/v0/passwd.py (+6/-2)
tests/test_charm.py (+3/-2)
Reviewer Review Type Date Requested Status
Spencer Runde Approve
Review via email: mp+457566@code.launchpad.net

Commit message

update operator-libs-linux lib to latest; fix test

Description of the change

This change should alleviate "random" hanging apt-get processes. See https://github.com/canonical/operator-libs-linux/pull/114 for full explanation of the change.

To test:

charmcraft pack
juju deploy ./landscape-server_ubuntu-22.04-amd64-arm64_ubuntu-20.04-amd64-arm64.charm

installation time varies, so just be patient and everything should install just fine.

Also fixes a test broken by the last change.

To post a comment you must log in.
Revision history for this message
Mitch Burton (mitchburton) wrote (last edit ):

Doing this downstream to get it done ahead of this PR merging upstream: https://github.com/canonical/operator-libs-linux/pull/114

Disregard above: it's been merged upstream. This MR has been changed to pull the latest lib version.

Revision history for this message
Spencer Runde (spencerrunde) wrote :

LGTM - install went as expected.

review: Approve
Revision history for this message
Spencer Runde (spencerrunde) wrote :

Updated version that pulls in upstream looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/charms/operator_libs_linux/v0/apt.py b/lib/charms/operator_libs_linux/v0/apt.py
index 7afb183..c3a2329 100644
--- a/lib/charms/operator_libs_linux/v0/apt.py
+++ b/lib/charms/operator_libs_linux/v0/apt.py
@@ -108,7 +108,7 @@ import re
108import subprocess108import subprocess
109from collections.abc import Mapping109from collections.abc import Mapping
110from enum import Enum110from enum import Enum
111from subprocess import PIPE, CalledProcessError, check_call, check_output111from subprocess import PIPE, CalledProcessError, check_output
112from typing import Iterable, List, Optional, Tuple, Union112from typing import Iterable, List, Optional, Tuple, Union
113from urllib.parse import urlparse113from urllib.parse import urlparse
114114
@@ -122,7 +122,7 @@ LIBAPI = 0
122122
123# Increment this PATCH version before using `charmcraft publish-lib` or reset123# Increment this PATCH version before using `charmcraft publish-lib` or reset
124# to 0 if you are raising the major API version124# to 0 if you are raising the major API version
125LIBPATCH = 11125LIBPATCH = 12
126126
127127
128VALID_SOURCE_TYPES = ("deb", "deb-src")128VALID_SOURCE_TYPES = ("deb", "deb-src")
@@ -250,7 +250,7 @@ class DebianPackage:
250 try:250 try:
251 env = os.environ.copy()251 env = os.environ.copy()
252 env["DEBIAN_FRONTEND"] = "noninteractive"252 env["DEBIAN_FRONTEND"] = "noninteractive"
253 check_call(_cmd, env=env, stderr=PIPE, stdout=PIPE)253 subprocess.run(_cmd, capture_output=True, check=True, env=env)
254 except CalledProcessError as e:254 except CalledProcessError as e:
255 raise PackageError(255 raise PackageError(
256 "Could not {} package(s) [{}]: {}".format(command, [*package_names], e.output)256 "Could not {} package(s) [{}]: {}".format(command, [*package_names], e.output)
@@ -748,7 +748,7 @@ def add_package(
748748
749 packages = {"success": [], "retry": [], "failed": []}749 packages = {"success": [], "retry": [], "failed": []}
750750
751 package_names = [package_names] if type(package_names) is str else package_names751 package_names = [package_names] if isinstance(package_names, str) else package_names
752 if not package_names:752 if not package_names:
753 raise TypeError("Expected at least one package name to add, received zero!")753 raise TypeError("Expected at least one package name to add, received zero!")
754754
@@ -818,7 +818,7 @@ def remove_package(
818 """818 """
819 packages = []819 packages = []
820820
821 package_names = [package_names] if type(package_names) is str else package_names821 package_names = [package_names] if isinstance(package_names, str) else package_names
822 if not package_names:822 if not package_names:
823 raise TypeError("Expected at least one package name to add, received zero!")823 raise TypeError("Expected at least one package name to add, received zero!")
824824
@@ -837,7 +837,7 @@ def remove_package(
837837
838def update() -> None:838def update() -> None:
839 """Update the apt cache via `apt-get update`."""839 """Update the apt cache via `apt-get update`."""
840 check_call(["apt-get", "update"], stderr=PIPE, stdout=PIPE)840 subprocess.run(["apt-get", "update"], capture_output=True, check=True)
841841
842842
843def import_key(key: str) -> str:843def import_key(key: str) -> str:
diff --git a/lib/charms/operator_libs_linux/v0/passwd.py b/lib/charms/operator_libs_linux/v0/passwd.py
index b692e70..ed5a058 100644
--- a/lib/charms/operator_libs_linux/v0/passwd.py
+++ b/lib/charms/operator_libs_linux/v0/passwd.py
@@ -45,7 +45,7 @@ LIBAPI = 0
4545
46# Increment this PATCH version before using `charmcraft publish-lib` or reset46# Increment this PATCH version before using `charmcraft publish-lib` or reset
47# to 0 if you are raising the major API version47# to 0 if you are raising the major API version
48LIBPATCH = 348LIBPATCH = 4
4949
5050
51def user_exists(user: Union[str, int]) -> Optional[pwd.struct_passwd]:51def user_exists(user: Union[str, int]) -> Optional[pwd.struct_passwd]:
@@ -99,6 +99,7 @@ def add_user(
99 secondary_groups: List[str] = None,99 secondary_groups: List[str] = None,
100 uid: int = None,100 uid: int = None,
101 home_dir: str = None,101 home_dir: str = None,
102 create_home: bool = True,
102) -> str:103) -> str:
103 """Add a user to the system.104 """Add a user to the system.
104105
@@ -113,6 +114,7 @@ def add_user(
113 secondary_groups: Optional list of additional groups114 secondary_groups: Optional list of additional groups
114 uid: UID for user being created115 uid: UID for user being created
115 home_dir: Home directory for user116 home_dir: Home directory for user
117 create_home: Force home directory creation
116118
117 Returns:119 Returns:
118 The password database entry struct, as returned by `pwd.getpwnam`120 The password database entry struct, as returned by `pwd.getpwnam`
@@ -135,7 +137,9 @@ def add_user(
135 if home_dir:137 if home_dir:
136 cmd.extend(["--home", str(home_dir)])138 cmd.extend(["--home", str(home_dir)])
137 if password:139 if password:
138 cmd.extend(["--password", password, "--create-home"])140 cmd.extend(["--password", password])
141 if create_home:
142 cmd.append("--create-home")
139 if system_user or password is None:143 if system_user or password is None:
140 cmd.append("--system")144 cmd.append("--system")
141145
diff --git a/tests/test_charm.py b/tests/test_charm.py
index d904212..785d011 100644
--- a/tests/test_charm.py
+++ b/tests/test_charm.py
@@ -75,8 +75,9 @@ class TestCharm(unittest.TestCase):
75 ["add-apt-repository", "-y", ppa])75 ["add-apt-repository", "-y", ppa])
76 mocks["check_call"].assert_any_call(76 mocks["check_call"].assert_any_call(
77 ["apt-mark", "hold", "landscape-hashids"])77 ["apt-mark", "hold", "landscape-hashids"])
78 mocks["apt"].add_package.assert_called_once_with(["landscape-server", 78 mocks["apt"].add_package.assert_called_once_with(
79 "landscape-hashids"])79 ["landscape-server", "landscape-hashids"], update_cache=True,
80 )
80 status = harness.charm.unit.status81 status = harness.charm.unit.status
81 self.assertIsInstance(status, WaitingStatus)82 self.assertIsInstance(status, WaitingStatus)
82 self.assertEqual(status.message,83 self.assertEqual(status.message,

Subscribers

People subscribed via source and target branches

to all changes: