From 71afac4c784e7b01d0d3357cbce73975e5d985d5 Mon Sep 17 00:00:00 2001 From: Adam Collard Date: Tue, 11 Aug 2015 09:28:36 +0100 Subject: [PATCH] Set status to Paused, with informational message on how to undo. --- actions/actions.py | 4 +++- unit_tests/test_actions.py | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) 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):