Merge lp:~tribaal/landscape-charm/migrate-schema-action into lp:~landscape/landscape-charm/trunk

Proposed by Chris Glass
Status: Merged
Approved by: Chris Glass
Approved revision: 288
Merged at revision: 286
Proposed branch: lp:~tribaal/landscape-charm/migrate-schema-action
Merge into: lp:~landscape/landscape-charm/trunk
Diff against target: 114 lines (+57/-6)
6 files modified
actions.yaml (+3/-0)
actions/migrate-schema (+9/-0)
lib/callbacks/scripts.py (+2/-4)
lib/migrate_schema.py (+17/-0)
lib/paths.py (+6/-2)
lib/tests/test_migrate_schema.py (+20/-0)
To merge this branch: bzr merge lp:~tribaal/landscape-charm/migrate-schema-action
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
🤖 Landscape Builder test results Approve
Alberto Donato (community) Approve
Review via email: mp+259603@code.launchpad.net

Commit message

This branch introduces a minimal "migrate schema" juju action that simply runs the
schema migration script.

In a future branch (tracked by bug #1456953) we will implement a slightly more
secure way of doing so.

Description of the change

This branch introduces a minimal "migrate schema" juju action that simply runs the
schema migration script.

In a future branch (tracked by bug #1456953) we will implement a slightly more
secure way of doing so.

To post a comment you must log in.
Revision history for this message
Alberto Donato (ack) wrote :

+1. Looks good, with a comment inline.

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

Command: make ci-test
Result: Success
Revno: 285
Branch: lp:~tribaal/landscape-charm/migrate-schema-action
Jenkins: https://ci.lscape.net/job/latch-test/974/

review: Approve (test results)
286. By Chris Glass

Adressed review comment.

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Success
Revno: 286
Branch: lp:~tribaal/landscape-charm/migrate-schema-action
Jenkins: https://ci.lscape.net/job/latch-test/975/

review: Approve (test results)
Revision history for this message
Chris Glass (tribaal) wrote :

all comments should be addressed.

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Looks good, just a few minor comments, +1

review: Approve
287. By Chris Glass

Address review comments.

Revision history for this message
Chris Glass (tribaal) wrote :

all comments addressed!

288. By Chris Glass

Lint.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'actions.yaml'
2--- actions.yaml 2015-05-12 12:22:20 +0000
3+++ actions.yaml 2015-05-21 07:33:22 +0000
4@@ -6,3 +6,6 @@
5 description: Upgrade software on the Landscape unit. This action will update
6 APT package indexes and upgrade the landscape-server package.
7 Unit must already be paused with the 'pause' action.
8+migrate-schema:
9+ description: Upgrade the landscape schemas on the related databases.
10+ Unit must already be paused with the 'pause' action.
11
12=== added file 'actions/migrate-schema'
13--- actions/migrate-schema 1970-01-01 00:00:00 +0000
14+++ actions/migrate-schema 2015-05-21 07:33:22 +0000
15@@ -0,0 +1,9 @@
16+#!/usr/bin/python
17+import sys
18+
19+from lib.migrate_schema import MigrateSchemaAction
20+
21+
22+if __name__ == "__main__":
23+ action = MigrateSchemaAction()
24+ sys.exit(action())
25
26=== modified file 'lib/callbacks/scripts.py'
27--- lib/callbacks/scripts.py 2015-05-13 17:57:51 +0000
28+++ lib/callbacks/scripts.py 2015-05-21 07:33:22 +0000
29@@ -3,9 +3,7 @@
30 from charmhelpers.core import hookenv
31 from charmhelpers.core.services.base import ManagerCallback
32
33-from lib.paths import LSCTL
34-
35-SCHEMA = "/usr/bin/landscape-schema"
36+from lib.paths import LSCTL, SCHEMA_SCRIPT
37
38
39 class ScriptCallback(ManagerCallback):
40@@ -27,7 +25,7 @@
41 This will invoke the schema script with the --bootstrap flag.
42 """
43 def __call__(self, manager, service_name, event_name):
44- self._run(SCHEMA, ("--bootstrap",))
45+ self._run(SCHEMA_SCRIPT, ("--bootstrap",))
46
47
48 class LSCtl(ScriptCallback):
49
50=== added file 'lib/migrate_schema.py'
51--- lib/migrate_schema.py 1970-01-01 00:00:00 +0000
52+++ lib/migrate_schema.py 2015-05-21 07:33:22 +0000
53@@ -0,0 +1,17 @@
54+import subprocess
55+
56+from charmhelpers.core import hookenv
57+
58+from lib.hook import Hook
59+from lib.paths import SCHEMA_SCRIPT
60+
61+
62+class MigrateSchemaAction(Hook):
63+ """Execute schema upgrade action logic."""
64+
65+ def __init__(self, hookenv=hookenv, subprocess=subprocess):
66+ super(MigrateSchemaAction, self).__init__(hookenv=hookenv)
67+ self._subprocess = subprocess
68+
69+ def _run(self):
70+ self._subprocess.check_call([SCHEMA_SCRIPT])
71
72=== modified file 'lib/paths.py'
73--- lib/paths.py 2015-05-11 06:56:57 +0000
74+++ lib/paths.py 2015-05-21 07:33:22 +0000
75@@ -4,8 +4,12 @@
76 SERVICE_CONF = "/etc/landscape/service.conf"
77 DEFAULT_FILE = "/etc/default/landscape-server"
78 SSL_CERT_PATH = "/etc/ssl/certs/landscape_server_ca.crt"
79-CONFIG_DIR = "/opt/canonical/landscape/configs/standalone"
80-OFFLINE_DIR = "/opt/canonical/landscape/canonical/landscape/offline"
81+
82+INSTALL_DIR = "/opt/canonical/landscape"
83+CONFIG_DIR = INSTALL_DIR + "/configs/standalone"
84+OFFLINE_DIR = INSTALL_DIR + "/canonical/landscape/offline"
85+SCHEMA_SCRIPT = "/usr/bin/landscape-schema"
86+
87 LICENSE_FILE = "/etc/landscape/license.txt"
88 LSCTL = "/usr/bin/lsctl"
89
90
91=== added file 'lib/tests/test_migrate_schema.py'
92--- lib/tests/test_migrate_schema.py 1970-01-01 00:00:00 +0000
93+++ lib/tests/test_migrate_schema.py 2015-05-21 07:33:22 +0000
94@@ -0,0 +1,20 @@
95+from lib.tests.helpers import HookenvTest
96+from lib.migrate_schema import MigrateSchemaAction
97+from lib.tests.stubs import SubprocessStub
98+from lib.paths import SCHEMA_SCRIPT
99+
100+
101+class MigrateSchemaActionTest(HookenvTest):
102+
103+ def setUp(self):
104+ super(MigrateSchemaActionTest, self).setUp()
105+ self.subprocess = SubprocessStub()
106+ self.action = MigrateSchemaAction(
107+ hookenv=self.hookenv, subprocess=self.subprocess)
108+
109+ def test_run(self):
110+ """
111+ The MigrateSchemaAction calls the schema script.
112+ """
113+ self.action()
114+ self.assertEqual([([SCHEMA_SCRIPT], {})], self.subprocess.calls)

Subscribers

People subscribed via source and target branches