diff --git a/actions/actions.py b/actions/actions.py index 778adfe..4dadaf6 100755 --- a/actions/actions.py +++ b/actions/actions.py @@ -6,7 +6,7 @@ import sys import yaml from charmhelpers.core.host import service_pause -from charmhelpers.core.hookenv import action_fail +from charmhelpers.core.hookenv import action_fail, status_set from lib.swift_storage_utils import SWIFT_SVCS @@ -29,6 +29,8 @@ def pause(args): stopped = service_pause(service) if not stopped: raise Exception("{} didn't stop cleanly.".format(service)) + status_set( + "maintenance", "Paused. Use 'resume' action to resume normal service.") # A dictionary of all the defined actions to callables (which take diff --git a/unit_tests/test_actions.py b/unit_tests/test_actions.py index a73d48c..df51022 100644 --- a/unit_tests/test_actions.py +++ b/unit_tests/test_actions.py @@ -13,7 +13,8 @@ import actions.actions class PauseTestCase(CharmTestCase): def setUp(self): - super(PauseTestCase, self).setUp(actions.actions, ["service_pause"]) + super(PauseTestCase, self).setUp( + actions.actions, ["service_pause", "status_set"]) def test_pauses_services(self): """Pause action pauses all of the Swift services.""" @@ -59,6 +60,26 @@ class PauseTestCase(CharmTestCase): 'swift-account-replicator', 'swift-account-server']) + def test_status_mode(self): + """Pause action sets the status to maintenance.""" + status_calls = [] + self.status_set.side_effect = lambda state, msg: status_calls.append( + state) + + actions.actions.pause([]) + self.assertEqual(status_calls, ["maintenance"]) + + def test_status_message(self): + """Pause action sets a status message reflecting that it's paused.""" + status_calls = [] + self.status_set.side_effect = lambda state, msg: status_calls.append( + msg) + + actions.actions.pause([]) + self.assertEqual( + status_calls, ["Paused. " + "Use 'resume' action to resume normal service."]) + class GetActionParserTestCase(unittest.TestCase):