Merge ~txiao/charm-juju-local:fix/lp#2029516 into charm-juju-local:master

Proposed by Tianqi Xiao
Status: Merged
Approved by: Eric Chen
Approved revision: aa4d37dee3b7bd4756273fc0b5f319fe7448de74
Merged at revision: d8bf76ab8face7901cea301f0f0e3ba863da7c2a
Proposed branch: ~txiao/charm-juju-local:fix/lp#2029516
Merge into: charm-juju-local:master
Diff against target: 175 lines (+50/-5)
9 files modified
Makefile (+4/-0)
lib/lib_charm_juju_local.py (+12/-0)
tests/bundles/focal-juju3.yaml (+1/-0)
tests/bundles/jammy-juju3.yaml (+1/-0)
tests/bundles/overlays/focal-juju3.yaml.j2 (+5/-0)
tests/bundles/overlays/jammy-juju3.yaml.j2 (+5/-0)
tests/tests.yaml (+4/-0)
tests/tests_juju_local.py (+17/-5)
wheelhouse.txt (+1/-0)
Reviewer Review Type Date Requested Status
Eric Chen Approve
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
Ramesh Sattaru (community) Approve
BootStack Reviewers Pending
Review via email: mp+449219@code.launchpad.net

Commit message

Juju 3.x support.

1. Juju 3.x snap is strictly confined and doesn't have the permission to create juju's local user directory (`~/.local/share/juju`). This PR implements a workaround for this issue
2. Refresh lxd snap to "latest/stable" to support bootstrapping Juju 3.x controller.
3. Added functional tests for Juju 3.x
4. Pin tenacity to workaround LP#2031582

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Eric Chen (eric-chen) wrote :

It seems they don't have plan to fix it in the snap.
The suggestion is to let the user to create the folder by themselves.

review: Approve
Revision history for this message
Ramesh Sattaru (rameshcan) :
review: Approve
Revision history for this message
Eric Chen (eric-chen) wrote :

I forget why we don't have jenkins CI in this project. Please attach the unit/func test log into pastebin as workaround solution.

review: Needs Information
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tianqi Xiao (txiao) wrote :

Looking into the dependency issue on bionic series. Setting MP to "Work in progress"

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Eric Chen (eric-chen) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision d8bf76ab8face7901cea301f0f0e3ba863da7c2a

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index df5f479..ed84e3a 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -6,6 +6,7 @@ help:
6 @echo ""
7 @echo " make help - show this text"
8 @echo " make lint - run flake8"
9+ @echo " make unittests - run the tests defined in the unittest subdirectory"
10 @echo " make test - run the functests and lint"
11 @echo " make functional - run the tests defined in the functional subdirectory"
12 @echo " make release - build the charm"
13@@ -16,6 +17,9 @@ lint:
14 @echo "Running flake8"
15 @-tox -e lint
16
17+unittests:
18+ @echo "No unit tests available at the moment"
19+
20 test: lint functional
21
22 functional: build
23diff --git a/lib/lib_charm_juju_local.py b/lib/lib_charm_juju_local.py
24index 39fc880..ba18467 100644
25--- a/lib/lib_charm_juju_local.py
26+++ b/lib/lib_charm_juju_local.py
27@@ -4,6 +4,7 @@ import textwrap
28
29 from charmhelpers.core import hookenv, host, templating
30 from charmhelpers.fetch.ubuntu import apt_cache
31+from charms.layer import snap
32
33
34 LXD_BRIDGE_TMPL = "lxd-bridge.ini.j2"
35@@ -46,6 +47,9 @@ class JujuLocalHelper:
36 subprocess.call("sudo lxd.migrate -yes", shell=True)
37
38 def lxd_init(self):
39+ # Refresh lxd snap to "latest/stable" channel for Juju 3.x support.
40+ snap.refresh("lxd", channel="latest/stable")
41+
42 install_sh = textwrap.dedent(
43 """
44 lxd init --auto --storage-backend dir
45@@ -64,6 +68,14 @@ class JujuLocalHelper:
46 shell=True,
47 )
48 series = host.lsb_release()["DISTRIB_CODENAME"]
49+
50+ # Create juju's local user directory if missing
51+ # This is a workaround for LP #1988355
52+ subprocess.call(
53+ "sudo -u ubuntu mkdir -p /home/ubuntu/.local/share/juju",
54+ shell=True,
55+ )
56+
57 subprocess.call(
58 textwrap.dedent(
59 f"""
60diff --git a/tests/bundles/focal-juju3.yaml b/tests/bundles/focal-juju3.yaml
61new file mode 120000
62index 0000000..f81f6ff
63--- /dev/null
64+++ b/tests/bundles/focal-juju3.yaml
65@@ -0,0 +1 @@
66+base.yaml
67\ No newline at end of file
68diff --git a/tests/bundles/jammy-juju3.yaml b/tests/bundles/jammy-juju3.yaml
69new file mode 120000
70index 0000000..f81f6ff
71--- /dev/null
72+++ b/tests/bundles/jammy-juju3.yaml
73@@ -0,0 +1 @@
74+base.yaml
75\ No newline at end of file
76diff --git a/tests/bundles/overlays/focal-juju3.yaml.j2 b/tests/bundles/overlays/focal-juju3.yaml.j2
77new file mode 100644
78index 0000000..e0bb1d4
79--- /dev/null
80+++ b/tests/bundles/overlays/focal-juju3.yaml.j2
81@@ -0,0 +1,5 @@
82+series: focal
83+applications:
84+ {{ charm_name }}:
85+ options:
86+ juju-channel: "3.1/stable"
87diff --git a/tests/bundles/overlays/jammy-juju3.yaml.j2 b/tests/bundles/overlays/jammy-juju3.yaml.j2
88new file mode 100644
89index 0000000..6dac327
90--- /dev/null
91+++ b/tests/bundles/overlays/jammy-juju3.yaml.j2
92@@ -0,0 +1,5 @@
93+series: jammy
94+applications:
95+ {{ charm_name }}:
96+ options:
97+ juju-channel: "3.1/stable"
98diff --git a/tests/tests.yaml b/tests/tests.yaml
99index 4476d69..c0f919c 100644
100--- a/tests/tests.yaml
101+++ b/tests/tests.yaml
102@@ -2,12 +2,16 @@ charm_name: juju-local
103 tests:
104 - tests.tests_juju_local.CharmJujuLocalTest
105 gate_bundles:
106+ - jammy-juju3
107+ - focal-juju3
108 - jammy
109 - focal
110 - bionic
111 dev_bundles:
112+ - jammy-juju3
113 - jammy
114 smoke_bundles:
115+ - focal-juju3
116 - focal
117 target_deploy_status:
118 juju-local:
119diff --git a/tests/tests_juju_local.py b/tests/tests_juju_local.py
120index b3f8a09..d34cf34 100644
121--- a/tests/tests_juju_local.py
122+++ b/tests/tests_juju_local.py
123@@ -13,8 +13,13 @@ class CharmJujuLocalTest(unittest.TestCase):
124 cls.model_name = model.get_juju_model()
125 cls.test_config = lifecycle_utils.get_charm_config()
126 model.block_until_all_units_idle()
127+ # Add a test model in the remote Juju cloud
128+ # This is needed becuase in Juju 3.x there's no default model created
129+ # after bootstrapping the controller
130+ cls.remote_juju(["add-model", "test"], None)
131
132- def remote_juju(self, args, format="json"):
133+ @classmethod
134+ def remote_juju(cls, args, format="json"):
135 if format:
136 fmt = "--format={}".format(format)
137 else:
138@@ -22,11 +27,18 @@ class CharmJujuLocalTest(unittest.TestCase):
139 cmd = """sudo -u ubuntu bash -c '/snap/bin/juju {} {}'""".format(
140 " ".join(args), fmt
141 )
142- res = model.run_on_unit(self.jlocal_unit, cmd)
143- return res.get("Stdout"), res.get("Stderr")
144+ res = model.run_on_unit(cls.jlocal_unit, cmd)
145+ return_code = int(res["Code"])
146+ if return_code != 0:
147+ raise RuntimeError(
148+ "Failed to execute command in juju-local unit.\nStderr: {}".format(
149+ res.get("Stderr")
150+ )
151+ )
152+ return res.get("Stdout")
153
154 def juju_status(self):
155- stdout, _ = self.remote_juju(["status"])
156+ stdout = self.remote_juju(["status"])
157 return json.loads(stdout)
158
159 def test_juju_status(self):
160@@ -34,7 +46,7 @@ class CharmJujuLocalTest(unittest.TestCase):
161 self.assertEqual(jstatus["model"]["controller"], "lxd")
162
163 def test_juju_users(self):
164- stdout, _ = self.remote_juju(["users"])
165+ stdout = self.remote_juju(["users"])
166 userobjects = json.loads(stdout)
167 usernames = set(u["user-name"] for u in userobjects)
168 self.assertTrue("admin" in usernames)
169diff --git a/wheelhouse.txt b/wheelhouse.txt
170index 02a822a..65c7e41 100644
171--- a/wheelhouse.txt
172+++ b/wheelhouse.txt
173@@ -1 +1,2 @@
174 Markupsafe<2.0.0 # for xenial support
175+tenacity<5.0.4 # workaround for LP#2031582

Subscribers

People subscribed via source and target branches

to all changes: