Merge lp:~free.ekanayaka/landscape-charm/pause-action into lp:~landscape/landscape-charm/trunk

Proposed by Free Ekanayaka
Status: Merged
Approved by: Free Ekanayaka
Approved revision: 260
Merged at revision: 262
Proposed branch: lp:~free.ekanayaka/landscape-charm/pause-action
Merge into: lp:~landscape/landscape-charm/trunk
Diff against target: 147 lines (+59/-5)
9 files modified
Makefile (+1/-1)
actions.yaml (+4/-0)
actions/pause (+9/-0)
charm-helpers.yaml (+1/-1)
lib/callbacks/scripts.py (+2/-1)
lib/paths.py (+1/-0)
lib/pause.py (+18/-0)
lib/tests/helpers.py (+1/-2)
lib/tests/test_pause.py (+22/-0)
To merge this branch: bzr merge lp:~free.ekanayaka/landscape-charm/pause-action
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
Данило Шеган (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+258475@code.launchpad.net

Commit message

Add a first simplistic implementation of the pause action.

This branch is little more than wiring code, the full semantics of the pause action will be implemented in follow-up branches (for example changing leadership).

In particular:

- add an actions/ dir containing the action pause script

- move hooks/lib and hooks/charmhelpers to the root charm dir, since this
  code is shared between hooks/ and actions/

- add a lib/pause.py file implementing the behavior of the pause action

Description of the change

Add a first simplistic implementation of the pause action.

This branch is little more than wiring code, the full semantics of the pause action will be implemented in follow-up branches (for example changing leadership).

In particular:

- add an actions/ dir containing the action pause script

- move hooks/lib and hooks/charmhelpers to the root charm dir, since this
  code is shared between hooks/ and actions/

- add a lib/pause.py file implementing the behavior of the pause action

To test, bootstrap a Juju environment (e.g. with local provider) and then:

make repo-file-trunk
make deploy # Wait
juju action defined landscape-server # See that the pause action is listed
juju action do landscape-server/0 pause # Services will be stopped on the unit

I'm planning to add integration tests too, but in a separate branch since I'd like to move integration tests to use zope test layers first.

To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) wrote :

Code looks good, I'll be doing a round of testing now.

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

Command: make ci-test
Result: Success
Revno: 260
Branch: lp:~free.ekanayaka/landscape-charm/pause-action
Jenkins: https://ci.lscape.net/job/latch-test/865/

review: Approve (test results)
Revision history for this message
Данило Шеган (danilo) wrote :

Works fine (and at least the appserver continues working after one unit is paused with multiple units, and haproxy detects the services as down).

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

Looks good, +1

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2015-05-06 15:48:29 +0000
3+++ Makefile 2015-05-07 10:31:54 +0000
4@@ -2,7 +2,7 @@
5 PYTHON := /usr/bin/env python
6
7 test:
8- @cd hooks && trial lib
9+ trial lib
10
11 ci-test:
12 ./dev/ubuntu-deps
13
14=== added directory 'actions'
15=== added file 'actions.yaml'
16--- actions.yaml 1970-01-01 00:00:00 +0000
17+++ actions.yaml 2015-05-07 10:31:54 +0000
18@@ -0,0 +1,4 @@
19+pause:
20+ description: Pause the Landscape unit. This action will interrupt any
21+ Landscape-related processing on the unit and prevent any further processing
22+ from happening. It will also transition the unit to the blocked state.
23
24=== added symlink 'actions/charmhelpers'
25=== target is u'../charmhelpers/'
26=== added symlink 'actions/lib'
27=== target is u'../lib/'
28=== added file 'actions/pause'
29--- actions/pause 1970-01-01 00:00:00 +0000
30+++ actions/pause 2015-05-07 10:31:54 +0000
31@@ -0,0 +1,9 @@
32+#!/usr/bin/python
33+import sys
34+
35+from lib.pause import PauseAction
36+
37+
38+if __name__ == "__main__":
39+ action = PauseAction()
40+ sys.exit(action())
41
42=== modified file 'charm-helpers.yaml'
43--- charm-helpers.yaml 2015-01-30 11:16:09 +0000
44+++ charm-helpers.yaml 2015-05-07 10:31:54 +0000
45@@ -1,5 +1,5 @@
46 branch: lp:charm-helpers
47-destination: hooks/charmhelpers
48+destination: charmhelpers
49 include:
50 - __init__
51 - core
52
53=== renamed directory 'hooks/charmhelpers' => 'charmhelpers'
54=== added symlink 'hooks/charmhelpers'
55=== target is u'../charmhelpers/'
56=== added symlink 'hooks/lib'
57=== target is u'../lib/'
58=== renamed directory 'hooks/lib' => 'lib'
59=== modified file 'lib/callbacks/scripts.py'
60--- hooks/lib/callbacks/scripts.py 2015-04-07 13:56:21 +0000
61+++ lib/callbacks/scripts.py 2015-05-07 10:31:54 +0000
62@@ -2,7 +2,8 @@
63
64 from charmhelpers.core.services.base import ManagerCallback
65
66-LSCTL = "/usr/bin/lsctl"
67+from lib.paths import LSCTL
68+
69 SCHEMA = "/usr/bin/landscape-schema"
70
71
72
73=== modified file 'lib/paths.py'
74--- hooks/lib/paths.py 2015-05-05 12:40:55 +0000
75+++ lib/paths.py 2015-05-07 10:31:54 +0000
76@@ -7,6 +7,7 @@
77 CONFIG_DIR = "/opt/canonical/landscape/configs/standalone"
78 OFFLINE_DIR = "/opt/canonical/landscape/canonical/landscape/offline"
79 LICENSE_FILE = "/etc/landscape/license.txt"
80+LSCTL = "/usr/bin/lsctl"
81
82
83 class Paths(object):
84
85=== added file 'lib/pause.py'
86--- lib/pause.py 1970-01-01 00:00:00 +0000
87+++ lib/pause.py 2015-05-07 10:31:54 +0000
88@@ -0,0 +1,18 @@
89+import subprocess
90+
91+from charmhelpers.core import hookenv
92+
93+from lib.hook import Hook
94+from lib.paths import LSCTL
95+
96+
97+class PauseAction(Hook):
98+ """Execute pause action logic."""
99+
100+ def __init__(self, hookenv=hookenv, subprocess=subprocess):
101+ super(PauseAction, self).__init__(hookenv=hookenv)
102+ self._subprocess = subprocess
103+
104+ def _run(self):
105+ self._subprocess.check_call((LSCTL, "stop"))
106+ self._subprocess.check_call(("service", "cron", "stop"))
107
108=== modified file 'lib/tests/helpers.py'
109--- hooks/lib/tests/helpers.py 2015-04-07 11:05:57 +0000
110+++ lib/tests/helpers.py 2015-05-07 10:31:54 +0000
111@@ -53,8 +53,7 @@
112
113 def setUp(self):
114 super(TestWithFixtures, self).setUp()
115- charm_dir = os.path.dirname(
116- os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
117+ charm_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
118 templates_dir = os.path.join(charm_dir, "templates")
119 loader = Environment(loader=FileSystemLoader(templates_dir))
120 self.template = loader.get_template(self.template_filename)
121
122=== added file 'lib/tests/test_pause.py'
123--- lib/tests/test_pause.py 1970-01-01 00:00:00 +0000
124+++ lib/tests/test_pause.py 2015-05-07 10:31:54 +0000
125@@ -0,0 +1,22 @@
126+from lib.tests.helpers import HookenvTest
127+from lib.tests.stubs import SubprocessStub
128+from lib.pause import PauseAction
129+
130+
131+class PauseActionTest(HookenvTest):
132+
133+ def setUp(self):
134+ super(PauseActionTest, self).setUp()
135+ self.subprocess = SubprocessStub()
136+ self.action = PauseAction(
137+ hookenv=self.hookenv, subprocess=self.subprocess)
138+
139+ def test_run(self):
140+ """
141+ The PauseAction stops the Landscape services.
142+ """
143+ self.action()
144+ self.assertEqual(
145+ [(("/usr/bin/lsctl", "stop"), {}),
146+ (("service", "cron", "stop"), {})],
147+ self.subprocess.calls)

Subscribers

People subscribed via source and target branches