Merge lp:~ajkavanagh/charms/trusty/glance/use-assess-status-lp1531767 into lp:~openstack-charmers-archive/charms/trusty/glance/next

Proposed by Alex Kavanagh
Status: Merged
Merged at revision: 162
Proposed branch: lp:~ajkavanagh/charms/trusty/glance/use-assess-status-lp1531767
Merge into: lp:~openstack-charmers-archive/charms/trusty/glance/next
Diff against target: 272 lines (+104/-52)
5 files modified
actions/actions.py (+10/-5)
hooks/glance_relations.py (+3/-6)
hooks/glance_utils.py (+34/-0)
unit_tests/test_actions.py (+23/-41)
unit_tests/test_glance_utils.py (+34/-0)
To merge this branch: bzr merge lp:~ajkavanagh/charms/trusty/glance/use-assess-status-lp1531767
Reviewer Review Type Date Requested Status
David Ames (community) Approve
Liam Young (community) Needs Fixing
Review via email: mp+282343@code.launchpad.net

Description of the change

Change to the implementation of pause and resume actions such that they use a new function called assess_status() which (currently) only checks if the unit is_paused() -- which is also new.

Note that it doesn't (as yet?) change any of the other status_set() functions which means this is only a partial solution.

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

This look good, just a couple of comments inline

review: Needs Fixing
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #17246 glance-next for ajkavanagh mp282343
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/17246/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #16113 glance-next for ajkavanagh mp282343
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/16113/

Revision history for this message
David Ames (thedac) wrote :

As the purpose of the MP is to implement assess_status() we need to make sure it runs after every hook.

Currently in glance_relations.py set_os_workload_status is called which will clobber any paused status. This should be replaced with a call to asssess_status() and as Liam points out assess_status should ultimately call set_os_workload_status.

if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        juju_log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
                           charm_func=check_optional_relations)

review: Needs Fixing
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #8752 glance-next for ajkavanagh mp282343
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/8752/

Revision history for this message
Alex Kavanagh (ajkavanagh) wrote :

> As the purpose of the MP is to implement assess_status() we need to make sure
> it runs after every hook.
>
> Currently in glance_relations.py set_os_workload_status is called which will
> clobber any paused status. This should be replaced with a call to
> asssess_status() and as Liam points out assess_status should ultimately call
> set_os_workload_status.
>
> if __name__ == '__main__':
> try:
> hooks.execute(sys.argv)
> except UnregisteredHookError as e:
> juju_log('Unknown hook {} - skipping.'.format(e))
> set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
> charm_func=check_optional_relations)

Yep, ok. I'll do an search of all the set_os_workload_status() calls and see if they would be better as assess_status() -- i.e. just to check that it won't clobber a pause status as you say.

161. By Alex Kavanagh

Change set_os_workload_status() call in hooks/glance_relations.py to assess_status(...) call

This is so that invoking glance_relations.py doesn't clobber a user set 'paused' state.

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #17318 glance-next for ajkavanagh mp282343
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/17318/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #16179 glance-next for ajkavanagh mp282343
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/16179/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #8778 glance-next for ajkavanagh mp282343
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/8778/

Revision history for this message
David Ames (thedac) wrote :

Looks good. Merging.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'actions/actions.py'
--- actions/actions.py 2015-08-26 13:16:31 +0000
+++ actions/actions.py 2016-01-14 11:24:53 +0000
@@ -4,9 +4,11 @@
4import os4import os
55
6from charmhelpers.core.host import service_pause, service_resume6from charmhelpers.core.host import service_pause, service_resume
7from charmhelpers.core.hookenv import action_fail, status_set7from charmhelpers.core.hookenv import action_fail
8from charmhelpers.core.unitdata import HookData, kv
89
9from hooks.glance_utils import services10from hooks.glance_utils import services, assess_status
11from hooks.glance_relations import CONFIGS
1012
1113
12def pause(args):14def pause(args):
@@ -18,8 +20,9 @@
18 stopped = service_pause(service)20 stopped = service_pause(service)
19 if not stopped:21 if not stopped:
20 raise Exception("{} didn't stop cleanly.".format(service))22 raise Exception("{} didn't stop cleanly.".format(service))
21 status_set(23 with HookData()():
22 "maintenance", "Paused. Use 'resume' action to resume normal service.")24 kv().set('unit-paused', True)
25 assess_status(CONFIGS)
2326
2427
25def resume(args):28def resume(args):
@@ -31,7 +34,9 @@
31 started = service_resume(service)34 started = service_resume(service)
32 if not started:35 if not started:
33 raise Exception("{} didn't start cleanly.".format(service))36 raise Exception("{} didn't start cleanly.".format(service))
34 status_set("active", "")37 with HookData()():
38 kv().set('unit-paused', False)
39 assess_status(CONFIGS)
3540
3641
37# A dictionary of all the defined actions to callables (which take42# A dictionary of all the defined actions to callables (which take
3843
=== modified file 'hooks/glance_relations.py'
--- hooks/glance_relations.py 2015-10-30 22:11:38 +0000
+++ hooks/glance_relations.py 2016-01-14 11:24:53 +0000
@@ -24,9 +24,8 @@
24 HAPROXY_CONF,24 HAPROXY_CONF,
25 ceph_config_file,25 ceph_config_file,
26 setup_ipv6,26 setup_ipv6,
27 REQUIRED_INTERFACES,27 swift_temp_url_key,
28 check_optional_relations,28 assess_status,
29 swift_temp_url_key
30)29)
31from charmhelpers.core.hookenv import (30from charmhelpers.core.hookenv import (
32 config,31 config,
@@ -67,7 +66,6 @@
67 openstack_upgrade_available,66 openstack_upgrade_available,
68 os_release,67 os_release,
69 sync_db_with_multi_ipv6_addresses,68 sync_db_with_multi_ipv6_addresses,
70 set_os_workload_status,
71)69)
72from charmhelpers.contrib.storage.linux.ceph import (70from charmhelpers.contrib.storage.linux.ceph import (
73 send_request_if_needed,71 send_request_if_needed,
@@ -536,5 +534,4 @@
536 hooks.execute(sys.argv)534 hooks.execute(sys.argv)
537 except UnregisteredHookError as e:535 except UnregisteredHookError as e:
538 juju_log('Unknown hook {} - skipping.'.format(e))536 juju_log('Unknown hook {} - skipping.'.format(e))
539 set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,537 assess_status(CONFIGS)
540 charm_func=check_optional_relations)
541538
=== modified file 'hooks/glance_utils.py'
--- hooks/glance_utils.py 2015-10-30 22:11:38 +0000
+++ hooks/glance_utils.py 2016-01-14 11:24:53 +0000
@@ -26,6 +26,7 @@
26 relation_ids,26 relation_ids,
27 service_name,27 service_name,
28 status_get,28 status_get,
29 status_set,
29)30)
3031
3132
@@ -70,6 +71,11 @@
70 retry_on_exception,71 retry_on_exception,
71)72)
7273
74from charmhelpers.core.unitdata import (
75 HookData,
76 kv,
77)
78
7379
74CLUSTER_RES = "grp_glance_vips"80CLUSTER_RES = "grp_glance_vips"
7581
@@ -491,3 +497,31 @@
491 swift_connection.post_account(headers={'x-account-meta-temp-url-key':497 swift_connection.post_account(headers={'x-account-meta-temp-url-key':
492 temp_url_key})498 temp_url_key})
493 return temp_url_key499 return temp_url_key
500
501
502def is_paused(status_get=status_get):
503 """Is the unit paused?"""
504 with HookData()():
505 if kv().get('unit-paused'):
506 return True
507 else:
508 return False
509
510
511def assess_status(configs):
512 """Assess status of current unit
513
514 Decides what the state of the unit should be based on the current
515 configuration.
516
517 @param configs: a templating.OSConfigRenderer() object
518 """
519
520 if is_paused():
521 status_set("maintenance",
522 "Paused. Use 'resume' action to resume normal service.")
523 return
524
525 # set the status according to the current state of the contexts
526 set_os_workload_status(
527 configs, REQUIRED_INTERFACES, charm_func=check_optional_relations)
494528
=== modified file 'unit_tests/test_actions.py'
--- unit_tests/test_actions.py 2015-09-02 11:40:06 +0000
+++ unit_tests/test_actions.py 2016-01-14 11:24:53 +0000
@@ -1,18 +1,23 @@
1import os1import os
2import mock2import mock
33
4from test_utils import CharmTestCase
5
6from mock import patch
7
4os.environ['JUJU_UNIT_NAME'] = 'glance'8os.environ['JUJU_UNIT_NAME'] = 'glance'
59
6from test_utils import CharmTestCase10with patch('actions.hooks.glance_utils.is_paused') as is_paused:
711 with patch('actions.hooks.glance_utils.register_configs') as configs:
8import actions.actions12 import actions.actions
913
1014
11class PauseTestCase(CharmTestCase):15class PauseTestCase(CharmTestCase):
1216
13 def setUp(self):17 def setUp(self):
14 super(PauseTestCase, self).setUp(18 super(PauseTestCase, self).setUp(
15 actions.actions, ["service_pause", "status_set"])19 actions.actions, ["service_pause", "HookData", "kv",
20 "assess_status"])
1621
17 def test_pauses_services(self):22 def test_pauses_services(self):
18 """Pause action pauses all Glance services."""23 """Pause action pauses all Glance services."""
@@ -46,32 +51,20 @@
46 actions.actions.pause, [])51 actions.actions.pause, [])
47 self.assertEqual(pause_calls, ['haproxy', 'glance-api'])52 self.assertEqual(pause_calls, ['haproxy', 'glance-api'])
4853
49 def test_status_mode(self):54 def test_pause_sets_value(self):
50 """Pause action sets the status to maintenance."""55 """Pause action sets the unit-paused value to True."""
51 status_calls = []56 self.HookData()().return_value = True
52 self.status_set.side_effect = lambda state, msg: status_calls.append(57
53 state)58 actions.actions.pause([])
5459 self.kv().set.assert_called_with('unit-paused', True)
55 actions.actions.pause([])
56 self.assertEqual(status_calls, ["maintenance"])
57
58 def test_status_message(self):
59 """Pause action sets a status message reflecting that it's paused."""
60 status_calls = []
61 self.status_set.side_effect = lambda state, msg: status_calls.append(
62 msg)
63
64 actions.actions.pause([])
65 self.assertEqual(
66 status_calls, ["Paused. "
67 "Use 'resume' action to resume normal service."])
6860
6961
70class ResumeTestCase(CharmTestCase):62class ResumeTestCase(CharmTestCase):
7163
72 def setUp(self):64 def setUp(self):
73 super(ResumeTestCase, self).setUp(65 super(ResumeTestCase, self).setUp(
74 actions.actions, ["service_resume", "status_set"])66 actions.actions, ["service_resume", "HookData", "kv",
67 "assess_status"])
7568
76 def test_resumes_services(self):69 def test_resumes_services(self):
77 """Resume action resumes all Glance services."""70 """Resume action resumes all Glance services."""
@@ -104,23 +97,12 @@
104 actions.actions.resume, [])97 actions.actions.resume, [])
105 self.assertEqual(resume_calls, ['haproxy', 'glance-api'])98 self.assertEqual(resume_calls, ['haproxy', 'glance-api'])
10699
107 def test_status_mode(self):100 def test_resume_sets_value(self):
108 """Resume action sets the status to active."""101 """Resume action sets the unit-paused value to False."""
109 status_calls = []102 self.HookData()().return_value = True
110 self.status_set.side_effect = lambda state, msg: status_calls.append(103
111 state)104 actions.actions.resume([])
112105 self.kv().set.assert_called_with('unit-paused', False)
113 actions.actions.resume([])
114 self.assertEqual(status_calls, ["active"])
115
116 def test_status_message(self):
117 """Resume action sets an empty status message."""
118 status_calls = []
119 self.status_set.side_effect = lambda state, msg: status_calls.append(
120 msg)
121
122 actions.actions.resume([])
123 self.assertEqual(status_calls, [""])
124106
125107
126class MainTestCase(CharmTestCase):108class MainTestCase(CharmTestCase):
127109
=== modified file 'unit_tests/test_glance_utils.py'
--- unit_tests/test_glance_utils.py 2015-09-28 11:42:38 +0000
+++ unit_tests/test_glance_utils.py 2016-01-14 11:24:53 +0000
@@ -293,3 +293,37 @@
293 call('glance-registry'),293 call('glance-registry'),
294 ]294 ]
295 self.assertEquals(service_restart.call_args_list, expected)295 self.assertEquals(service_restart.call_args_list, expected)
296
297 @patch.object(utils, 'HookData')
298 @patch.object(utils, 'kv')
299 def test_is_paused(self, kv, HookData):
300 """test_is_paused: Test is_paused() returns value
301 from kv('unit-paused')"""
302 HookData()().return_value = True
303 kv().get.return_value = True
304 self.assertEqual(utils.is_paused(), True)
305 kv().get.assert_called_with('unit-paused')
306 kv().get.return_value = False
307 self.assertEqual(utils.is_paused(), False)
308
309 @patch.object(utils, 'is_paused')
310 @patch.object(utils, 'status_set')
311 def test_assess_status(self, status_set, is_paused):
312 """test_assess_status: verify that it does pick the right status"""
313 # check that paused status does the right thing
314 is_paused.return_value = True
315 utils.assess_status(None)
316 status_set.assert_called_with(
317 "maintenance",
318 "Paused. Use 'resume' action to resume normal service.")
319
320 # if it isn't paused, the assess_status() calls
321 # set_os_workload_status()
322 is_paused.return_value = False
323 with patch.object(utils, 'set_os_workload_status') \
324 as set_os_workload_status:
325 utils.assess_status("TEST CONFIG")
326 set_os_workload_status.assert_called_with(
327 "TEST CONFIG",
328 utils.REQUIRED_INTERFACES,
329 charm_func=utils.check_optional_relations)

Subscribers

People subscribed via source and target branches