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
1diff --git a/lib/charms/operator_libs_linux/v0/apt.py b/lib/charms/operator_libs_linux/v0/apt.py
2index 7afb183..c3a2329 100644
3--- a/lib/charms/operator_libs_linux/v0/apt.py
4+++ b/lib/charms/operator_libs_linux/v0/apt.py
5@@ -108,7 +108,7 @@ import re
6 import subprocess
7 from collections.abc import Mapping
8 from enum import Enum
9-from subprocess import PIPE, CalledProcessError, check_call, check_output
10+from subprocess import PIPE, CalledProcessError, check_output
11 from typing import Iterable, List, Optional, Tuple, Union
12 from urllib.parse import urlparse
13
14@@ -122,7 +122,7 @@ LIBAPI = 0
15
16 # Increment this PATCH version before using `charmcraft publish-lib` or reset
17 # to 0 if you are raising the major API version
18-LIBPATCH = 11
19+LIBPATCH = 12
20
21
22 VALID_SOURCE_TYPES = ("deb", "deb-src")
23@@ -250,7 +250,7 @@ class DebianPackage:
24 try:
25 env = os.environ.copy()
26 env["DEBIAN_FRONTEND"] = "noninteractive"
27- check_call(_cmd, env=env, stderr=PIPE, stdout=PIPE)
28+ subprocess.run(_cmd, capture_output=True, check=True, env=env)
29 except CalledProcessError as e:
30 raise PackageError(
31 "Could not {} package(s) [{}]: {}".format(command, [*package_names], e.output)
32@@ -748,7 +748,7 @@ def add_package(
33
34 packages = {"success": [], "retry": [], "failed": []}
35
36- package_names = [package_names] if type(package_names) is str else package_names
37+ package_names = [package_names] if isinstance(package_names, str) else package_names
38 if not package_names:
39 raise TypeError("Expected at least one package name to add, received zero!")
40
41@@ -818,7 +818,7 @@ def remove_package(
42 """
43 packages = []
44
45- package_names = [package_names] if type(package_names) is str else package_names
46+ package_names = [package_names] if isinstance(package_names, str) else package_names
47 if not package_names:
48 raise TypeError("Expected at least one package name to add, received zero!")
49
50@@ -837,7 +837,7 @@ def remove_package(
51
52 def update() -> None:
53 """Update the apt cache via `apt-get update`."""
54- check_call(["apt-get", "update"], stderr=PIPE, stdout=PIPE)
55+ subprocess.run(["apt-get", "update"], capture_output=True, check=True)
56
57
58 def import_key(key: str) -> str:
59diff --git a/lib/charms/operator_libs_linux/v0/passwd.py b/lib/charms/operator_libs_linux/v0/passwd.py
60index b692e70..ed5a058 100644
61--- a/lib/charms/operator_libs_linux/v0/passwd.py
62+++ b/lib/charms/operator_libs_linux/v0/passwd.py
63@@ -45,7 +45,7 @@ LIBAPI = 0
64
65 # Increment this PATCH version before using `charmcraft publish-lib` or reset
66 # to 0 if you are raising the major API version
67-LIBPATCH = 3
68+LIBPATCH = 4
69
70
71 def user_exists(user: Union[str, int]) -> Optional[pwd.struct_passwd]:
72@@ -99,6 +99,7 @@ def add_user(
73 secondary_groups: List[str] = None,
74 uid: int = None,
75 home_dir: str = None,
76+ create_home: bool = True,
77 ) -> str:
78 """Add a user to the system.
79
80@@ -113,6 +114,7 @@ def add_user(
81 secondary_groups: Optional list of additional groups
82 uid: UID for user being created
83 home_dir: Home directory for user
84+ create_home: Force home directory creation
85
86 Returns:
87 The password database entry struct, as returned by `pwd.getpwnam`
88@@ -135,7 +137,9 @@ def add_user(
89 if home_dir:
90 cmd.extend(["--home", str(home_dir)])
91 if password:
92- cmd.extend(["--password", password, "--create-home"])
93+ cmd.extend(["--password", password])
94+ if create_home:
95+ cmd.append("--create-home")
96 if system_user or password is None:
97 cmd.append("--system")
98
99diff --git a/tests/test_charm.py b/tests/test_charm.py
100index d904212..785d011 100644
101--- a/tests/test_charm.py
102+++ b/tests/test_charm.py
103@@ -75,8 +75,9 @@ class TestCharm(unittest.TestCase):
104 ["add-apt-repository", "-y", ppa])
105 mocks["check_call"].assert_any_call(
106 ["apt-mark", "hold", "landscape-hashids"])
107- mocks["apt"].add_package.assert_called_once_with(["landscape-server",
108- "landscape-hashids"])
109+ mocks["apt"].add_package.assert_called_once_with(
110+ ["landscape-server", "landscape-hashids"], update_cache=True,
111+ )
112 status = harness.charm.unit.status
113 self.assertIsInstance(status, WaitingStatus)
114 self.assertEqual(status.message,

Subscribers

People subscribed via source and target branches

to all changes: