Merge lp:~simpoir/landscape-charm/bootstrap_with_key into lp:~landscape/landscape-charm/trunk

Proposed by Simon Poirier
Status: Merged
Approved by: Simon Poirier
Approved revision: 399
Merged at revision: 398
Proposed branch: lp:~simpoir/landscape-charm/bootstrap_with_key
Merge into: lp:~landscape/landscape-charm/trunk
Diff against target: 296 lines (+96/-42)
8 files modified
actions.yaml (+3/-0)
lib/apt.py (+1/-1)
lib/bootstrap.py (+21/-15)
lib/paths.py (+1/-0)
lib/tests/test_apt.py (+10/-4)
lib/tests/test_bootstrap.py (+46/-13)
lib/tests/test_install.py (+2/-1)
lib/tests/test_upgrade.py (+12/-8)
To merge this branch: bzr merge lp:~simpoir/landscape-charm/bootstrap_with_key
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+368020@code.launchpad.net

Commit message

Use API to bootstrap to enable passing registration_key.

Description of the change

Use API to bootstrap to enable passing registration_key.

Testing instructions:

make bundles-local-charm
juju deploy bundles/build/landscape-scalable/bundle.yaml
juju run-action --wait landscape-server/0 bootstrap <email address hidden> admin-password=tedted admin-name=Ted registration-key=landscapeiscool

go to landscape and log with <email address hidden>/tedted and check the registration key is set on the account.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Fail
Revno: 398
Branch: lp:~simpoir/landscape-charm/bootstrap_with_key
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3953/

review: Needs Fixing (test results)
399. By Simon Poirier

fix test

Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Success
Revno: 399
Branch: lp:~simpoir/landscape-charm/bootstrap_with_key
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3954/

review: Approve (test results)
Revision history for this message
Adam Collard (adam-collard) wrote :

LGTM, +1

review: Approve
Revision history for this message
David Coronel (davecore) wrote :

Tested with juju 2.6.2. LGTM, great feature, thanks!

juju bootstrap localhost
bzr branch lp:landscape-charm
cd landscape-charm/
bzr merge lp:~simpoir/landscape-charm/bootstrap_with_key
make bundles-local-charm
juju deploy bundles/build/landscape-scalable/bundle.yaml
juju run-action --wait landscape-server/0 bootstrap <email address hidden> admin-password=tedted admin-name=Ted registration-key=landscapeiscool

Logged in Landscape with ted email and saw the registration key already configured.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'actions.yaml'
--- actions.yaml 2015-06-25 16:01:22 +0000
+++ actions.yaml 2019-05-29 20:31:13 +0000
@@ -25,5 +25,8 @@
25 admin-password:25 admin-password:
26 type: string26 type: string
27 description: Password for the administrator to add.27 description: Password for the administrator to add.
28 registration-key:
29 type: string
30 description: Registration key to set on the account.
28 required: [admin-name, admin-email, admin-password]31 required: [admin-name, admin-email, admin-password]
29 additionalProperties: false32 additionalProperties: false
3033
=== modified file 'lib/apt.py'
--- lib/apt.py 2019-01-17 14:23:49 +0000
+++ lib/apt.py 2019-05-29 20:31:13 +0000
@@ -12,7 +12,7 @@
12from lib.paths import default_paths12from lib.paths import default_paths
13from lib.utils import CommandRunner13from lib.utils import CommandRunner
1414
15LANDSCAPE_PACKAGES = ("landscape-server", "landscape-hashids")15LANDSCAPE_PACKAGES = ("landscape-server", "landscape-hashids", "landscape-api")
16INSTALL_PACKAGES = LANDSCAPE_PACKAGES + ("python-minimal", "python-psutil")16INSTALL_PACKAGES = LANDSCAPE_PACKAGES + ("python-minimal", "python-psutil")
17PACKAGES_DEV = (17PACKAGES_DEV = (
18 "dpkg-dev", "devscripts", "pbuilder", "aptitude", "build-essential")18 "dpkg-dev", "devscripts", "pbuilder", "aptitude", "build-essential")
1919
=== modified file 'lib/bootstrap.py'
--- lib/bootstrap.py 2015-09-17 15:25:30 +0000
+++ lib/bootstrap.py 2019-05-29 20:31:13 +0000
@@ -1,11 +1,10 @@
1import json
1import subprocess2import subprocess
23
3from charmhelpers.core import hookenv4from charmhelpers.core import hookenv
45
5from lib.action import Action6from lib.action import Action
6from lib.paths import SCHEMA_SCRIPT7from lib.paths import API_SCRIPT
7
8CREDENTIALS_MARKER = "API credentials:"
98
109
11class BootstrapAction(Action):10class BootstrapAction(Action):
@@ -19,12 +18,22 @@
19 admin_name = self._hookenv.action_get("admin-name")18 admin_name = self._hookenv.action_get("admin-name")
20 admin_email = self._hookenv.action_get("admin-email")19 admin_email = self._hookenv.action_get("admin-email")
21 admin_password = self._hookenv.action_get("admin-password")20 admin_password = self._hookenv.action_get("admin-password")
2221 registration_key = self._hookenv.action_get("registration-key")
23 cmd = (SCHEMA_SCRIPT, "--create-lds-account-only", "--admin-name",22
24 admin_name, "--admin-email", admin_email,23 environment = {
25 "--admin-password", admin_password)24 "LANDSCAPE_API_KEY": "anonymous",
2625 "LANDSCAPE_API_SECRET": "anonymous",
27 output = self._subprocess.check_output(cmd)26 "LANDSCAPE_API_URI": "http://localhost:9080/api/",
27 }
28 cmd = [
29 API_SCRIPT, "call", "BootstrapLDS", "--json",
30 "admin_name={}".format(admin_name),
31 "admin_email={}".format(admin_email),
32 "admin_password={}".format(admin_password)]
33 if registration_key:
34 cmd.append("registration_key={}".format(registration_key))
35
36 output = self._subprocess.check_output(cmd, env=environment)
28 key, secret = self._parse_schema_output(output)37 key, secret = self._parse_schema_output(output)
29 result = {"api-credentials": {"key": key, "secret": secret}}38 result = {"api-credentials": {"key": key, "secret": secret}}
3039
@@ -32,10 +41,7 @@
3241
33 def _parse_schema_output(self, output):42 def _parse_schema_output(self, output):
34 """Extract API credentials from the schema bootstrap output."""43 """Extract API credentials from the schema bootstrap output."""
35 key = None44 credentials = json.loads(output)
36 secret = None45 key = credentials.get("LANDSCAPE_API_KEY")
37 for line in output.split("\n"):46 secret = credentials.get("LANDSCAPE_API_SECRET")
38 if line.startswith(CREDENTIALS_MARKER):
39 line = line[len(CREDENTIALS_MARKER) + 1:]
40 key, secret = line.split(" ")[2:4]
41 return key, secret47 return key, secret
4248
=== modified file 'lib/paths.py'
--- lib/paths.py 2015-09-29 10:10:33 +0000
+++ lib/paths.py 2019-05-29 20:31:13 +0000
@@ -9,6 +9,7 @@
9CONFIG_DIR = INSTALL_DIR + "/configs/standalone"9CONFIG_DIR = INSTALL_DIR + "/configs/standalone"
10OFFLINE_DIR = INSTALL_DIR + "/canonical/landscape/offline"10OFFLINE_DIR = INSTALL_DIR + "/canonical/landscape/offline"
1111
12API_SCRIPT = "/usr/bin/landscape-api"
12SCHEMA_SCRIPT = "/usr/bin/landscape-schema"13SCHEMA_SCRIPT = "/usr/bin/landscape-schema"
1314
14LICENSE_FILE = "/etc/landscape/license.txt"15LICENSE_FILE = "/etc/landscape/license.txt"
1516
=== modified file 'lib/tests/test_apt.py'
--- lib/tests/test_apt.py 2019-01-17 14:23:49 +0000
+++ lib/tests/test_apt.py 2019-05-29 20:31:13 +0000
@@ -271,8 +271,8 @@
271 installed.271 installed.
272 """272 """
273 self.assertEqual(273 self.assertEqual(
274 ("landscape-server", "landscape-hashids", "python-minimal",274 ("landscape-server", "landscape-hashids", "landscape-api",
275 "python-psutil"),275 "python-minimal", "python-psutil"),
276 INSTALL_PACKAGES)276 INSTALL_PACKAGES)
277277
278 def test_install(self):278 def test_install(self):
@@ -356,7 +356,10 @@
356 """356 """
357 self.apt.hold_packages()357 self.apt.hold_packages()
358 self.assertEqual(358 self.assertEqual(
359 ["apt-mark", "hold", "landscape-server", "landscape-hashids"],359 [
360 "apt-mark", "hold", "landscape-server", "landscape-hashids",
361 "landscape-api",
362 ],
360 self.subprocess.calls[0][0])363 self.subprocess.calls[0][0])
361364
362 def test_unhold_packages(self):365 def test_unhold_packages(self):
@@ -366,5 +369,8 @@
366 """369 """
367 self.apt.unhold_packages()370 self.apt.unhold_packages()
368 self.assertEqual(371 self.assertEqual(
369 ["apt-mark", "unhold", "landscape-server", "landscape-hashids"],372 [
373 "apt-mark", "unhold", "landscape-server", "landscape-hashids",
374 "landscape-api",
375 ],
370 self.subprocess.calls[0][0])376 self.subprocess.calls[0][0])
371377
=== modified file 'lib/tests/test_bootstrap.py'
--- lib/tests/test_bootstrap.py 2015-09-17 15:25:30 +0000
+++ lib/tests/test_bootstrap.py 2019-05-29 20:31:13 +0000
@@ -1,13 +1,10 @@
1from lib.tests.helpers import HookenvTest1from lib.tests.helpers import HookenvTest
2from lib.tests.stubs import SubprocessStub2from lib.tests.stubs import SubprocessStub
3from lib.bootstrap import BootstrapAction3from lib.bootstrap import BootstrapAction
4from lib.paths import SCHEMA_SCRIPT4from lib.paths import API_SCRIPT
55
6SCHEMA_SCRIPT_STDOUT = """6API_SCRIPT_STDOUT = """
7Setting up database schemas (will timeout after 86400 seconds) ...7{"LANDSCAPE_API_KEY": "key-xyz", "LANDSCAPE_API_SECRET": "secret-123"}
8Setting up sample data...
9Generating 72 snapshots from 1442480400 to 1442502186.
10API credentials: free.ekanayaka@canonical.com standalone key-xyz secret-123
11"""8"""
129
1310
@@ -17,14 +14,14 @@
17 super(BootstrapActionTest, self).setUp()14 super(BootstrapActionTest, self).setUp()
18 self.subprocess = SubprocessStub()15 self.subprocess = SubprocessStub()
19 self.subprocess.add_fake_executable(16 self.subprocess.add_fake_executable(
20 SCHEMA_SCRIPT, stdout=SCHEMA_SCRIPT_STDOUT)17 API_SCRIPT, stdout=API_SCRIPT_STDOUT)
21 self.subprocess.add_fake_executable("service")18 self.subprocess.add_fake_executable("service")
22 self.action = BootstrapAction(19 self.action = BootstrapAction(
23 hookenv=self.hookenv, subprocess=self.subprocess)20 hookenv=self.hookenv, subprocess=self.subprocess)
2421
25 def test_run(self):22 def test_run(self):
26 """23 """
27 The BootstrapAction calls the landscape-schema script to create an24 The BootstrapAction calls the landscape-api to create an
28 administrator account.25 administrator account.
29 """26 """
30 self.action()27 self.action()
@@ -32,11 +29,47 @@
32 # the value for each 'key'.29 # the value for each 'key'.
33 [(command, kwargs)] = self.subprocess.calls30 [(command, kwargs)] = self.subprocess.calls
34 self.assertEqual(31 self.assertEqual(
35 (("/usr/bin/landscape-schema", "--create-lds-account-only",32 ["/usr/bin/landscape-api", "call",
36 "--admin-name", "admin-name-value",33 "BootstrapLDS", "--json",
37 "--admin-email", "admin-email-value",34 "admin_name=admin-name-value",
38 "--admin-password", "admin-password-value"), {}),35 "admin_email=admin-email-value",
39 (command, kwargs))36 "admin_password=admin-password-value",
37 "registration_key=registration-key-value"],
38 command)
39 self.assertEqual(
40 {'env': {'LANDSCAPE_API_KEY': 'anonymous',
41 'LANDSCAPE_API_SECRET': 'anonymous',
42 'LANDSCAPE_API_URI': 'http://localhost:9080/api/'}},
43 kwargs)
44 self.assertEqual(
45 [{"api-credentials": {"secret": "secret-123", "key": "key-xyz"}}],
46 self.hookenv.action_sets)
47
48 def test_run_without_registration_key(self):
49 """
50 The BootstrapAction calls the landscape-api to create an
51 administrator account without setting the registration_key.
52 """
53 # patch the stub with fixed values
54 self.hookenv.action_get = {
55 "admin-name": "admin-name-value",
56 "admin-email": "admin-email-value",
57 "admin-password": "admin-password-value"}.get
58
59 self.action()
60 [(command, kwargs)] = self.subprocess.calls
61 self.assertEqual(
62 ["/usr/bin/landscape-api", "call",
63 "BootstrapLDS", "--json",
64 "admin_name=admin-name-value",
65 "admin_email=admin-email-value",
66 "admin_password=admin-password-value"],
67 command)
68 self.assertEqual(
69 {'env': {'LANDSCAPE_API_KEY': 'anonymous',
70 'LANDSCAPE_API_SECRET': 'anonymous',
71 'LANDSCAPE_API_URI': 'http://localhost:9080/api/'}},
72 kwargs)
40 self.assertEqual(73 self.assertEqual(
41 [{"api-credentials": {"secret": "secret-123", "key": "key-xyz"}}],74 [{"api-credentials": {"secret": "secret-123", "key": "key-xyz"}}],
42 self.hookenv.action_sets)75 self.hookenv.action_sets)
4376
=== modified file 'lib/tests/test_install.py'
--- lib/tests/test_install.py 2019-01-17 14:23:49 +0000
+++ lib/tests/test_install.py 2019-05-29 20:31:13 +0000
@@ -83,5 +83,6 @@
83 self.hookenv.config()["source"] = "ppa:landscape/14.10"83 self.hookenv.config()["source"] = "ppa:landscape/14.10"
84 self.hook()84 self.hook()
85 expected_call = [85 expected_call = [
86 "apt-mark", "hold", "landscape-server", "landscape-hashids"]86 "apt-mark", "hold", "landscape-server", "landscape-hashids",
87 "landscape-api"]
87 self.assertEqual(expected_call, self.subprocess.calls[0][0])88 self.assertEqual(expected_call, self.subprocess.calls[0][0])
8889
=== modified file 'lib/tests/test_upgrade.py'
--- lib/tests/test_upgrade.py 2019-01-17 14:23:49 +0000
+++ lib/tests/test_upgrade.py 2019-05-29 20:31:13 +0000
@@ -70,9 +70,11 @@
70 action()70 action()
7171
72 unhold_call = [72 unhold_call = [
73 "apt-mark", "unhold", "landscape-server", "landscape-hashids"]73 "apt-mark", "unhold", "landscape-server", "landscape-hashids",
74 "landscape-api"]
74 hold_call = [75 hold_call = [
75 "apt-mark", "hold", "landscape-server", "landscape-hashids"]76 "apt-mark", "hold", "landscape-server", "landscape-hashids",
77 "landscape-api"]
76 self.assertEqual(unhold_call, self.subprocess.calls[0][0])78 self.assertEqual(unhold_call, self.subprocess.calls[0][0])
77 self.assertEqual(hold_call, self.subprocess.calls[1][0])79 self.assertEqual(hold_call, self.subprocess.calls[1][0])
7880
@@ -95,10 +97,10 @@
95 [('Running action UpgradeAction', None),97 [('Running action UpgradeAction', None),
96 ('Adding repository: ppa:my-ppa', None),98 ('Adding repository: ppa:my-ppa', None),
97 ('running \'apt-mark unhold landscape-server '99 ('running \'apt-mark unhold landscape-server '
98 'landscape-hashids\'',100 'landscape-hashids landscape-api\'',
99 hookenv.DEBUG),101 hookenv.DEBUG),
100 ('running \'apt-mark hold landscape-server '102 ('running \'apt-mark hold landscape-server '
101 'landscape-hashids\'',103 'landscape-hashids landscape-api\'',
102 hookenv.DEBUG),104 hookenv.DEBUG),
103 ])105 ])
104106
@@ -109,7 +111,8 @@
109 """111 """
110 self.subprocess.add_fake_executable('apt-mark',112 self.subprocess.add_fake_executable('apt-mark',
111 ['unhold', 'landscape-server',113 ['unhold', 'landscape-server',
112 'landscape-hashids'],114 'landscape-hashids',
115 'landscape-api'],
113 return_code=1)116 return_code=1)
114 self.hookenv.status_set("maintenance", "")117 self.hookenv.status_set("maintenance", "")
115 self.hookenv.config()["source"] = "ppa:my-ppa"118 self.hookenv.config()["source"] = "ppa:my-ppa"
@@ -122,12 +125,13 @@
122 [('Running action UpgradeAction', None),125 [('Running action UpgradeAction', None),
123 ('Adding repository: ppa:my-ppa', None),126 ('Adding repository: ppa:my-ppa', None),
124 ('running \'apt-mark unhold landscape-server '127 ('running \'apt-mark unhold landscape-server '
125 'landscape-hashids\'',128 'landscape-hashids landscape-api\'',
126 hookenv.DEBUG),129 hookenv.DEBUG),
127 ('got return code 1 running \'apt-mark unhold '130 ('got return code 1 running \'apt-mark unhold '
128 'landscape-server landscape-hashids\'',131 'landscape-server landscape-hashids '
132 'landscape-api\'',
129 hookenv.ERROR),133 hookenv.ERROR),
130 ])134 ])
131 self.assertEqual(self.hookenv.action_fails,135 self.assertEqual(self.hookenv.action_fails,
132 ['command failed (see unit logs): apt-mark unhold '136 ['command failed (see unit logs): apt-mark unhold '
133 'landscape-server landscape-hashids'])137 'landscape-server landscape-hashids landscape-api'])

Subscribers

People subscribed via source and target branches