Use unitdata key/value pair to store pause/resume status
This commit is contained in:
parent
cd57171aa4
commit
e246250b48
@ -7,6 +7,7 @@ import yaml
|
||||
|
||||
from charmhelpers.core.host import service_pause, service_resume
|
||||
from charmhelpers.core.hookenv import action_fail
|
||||
from charmhelpers.core.unitdata import HookData, kv
|
||||
from charmhelpers.contrib.openstack.utils import get_os_codename_package
|
||||
|
||||
from lib.swift_storage_utils import SWIFT_SVCS
|
||||
@ -41,6 +42,8 @@ def pause(args):
|
||||
stopped = service_pause(service)
|
||||
if not stopped:
|
||||
raise Exception("{} didn't stop cleanly.".format(service))
|
||||
with HookData()():
|
||||
kv().set('unit-paused', True)
|
||||
|
||||
|
||||
def resume(args):
|
||||
@ -52,6 +55,8 @@ def resume(args):
|
||||
started = service_resume(service)
|
||||
if not started:
|
||||
raise Exception("{} didn't start cleanly.".format(service))
|
||||
with HookData()():
|
||||
kv().set('unit-paused', False)
|
||||
|
||||
|
||||
# A dictionary of all the defined actions to callables (which take
|
||||
|
@ -26,6 +26,11 @@ from charmhelpers.core.hookenv import (
|
||||
status_get,
|
||||
)
|
||||
|
||||
from charmhelpers.core.unitdata import (
|
||||
HookData,
|
||||
kv,
|
||||
)
|
||||
|
||||
DEFAULT_LOOPBACK_SIZE = '5G'
|
||||
|
||||
|
||||
@ -89,8 +94,11 @@ def clean_storage(block_device):
|
||||
|
||||
def is_paused(status_get=status_get):
|
||||
"""Is the unit paused?"""
|
||||
status, message = status_get()
|
||||
return status == "maintenance" and message.startswith("Paused")
|
||||
with HookData()():
|
||||
if kv().get('unit-paused'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def pause_aware_restart_on_change(restart_map):
|
||||
|
@ -14,7 +14,7 @@ class PauseTestCase(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(PauseTestCase, self).setUp(
|
||||
actions.actions, ["service_pause", "status_set"])
|
||||
actions.actions, ["service_pause", "HookData", "kv"])
|
||||
|
||||
class FakeArgs(object):
|
||||
services = ['swift-account',
|
||||
@ -77,32 +77,19 @@ class PauseTestCase(CharmTestCase):
|
||||
'swift-account-reaper',
|
||||
'swift-account-replicator'])
|
||||
|
||||
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)
|
||||
def test_pause_sets_value(self):
|
||||
"""Pause action sets the unit-paused value to True."""
|
||||
self.HookData()().return_value = True
|
||||
|
||||
actions.actions.pause(self.args)
|
||||
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.args)
|
||||
self.assertEqual(
|
||||
status_calls, ["Paused. "
|
||||
"Use 'resume' action to resume normal service."])
|
||||
self.kv().set.assert_called_with('unit-paused', True)
|
||||
|
||||
|
||||
class ResumeTestCase(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ResumeTestCase, self).setUp(
|
||||
actions.actions, ["service_resume", "status_set"])
|
||||
actions.actions, ["service_resume", "HookData", "kv"])
|
||||
|
||||
class FakeArgs(object):
|
||||
services = ['swift-account',
|
||||
@ -164,23 +151,12 @@ class ResumeTestCase(CharmTestCase):
|
||||
'swift-account-reaper',
|
||||
'swift-account-replicator'])
|
||||
|
||||
def test_status_mode(self):
|
||||
"""Resume action sets the status to maintenance."""
|
||||
status_calls = []
|
||||
self.status_set.side_effect = lambda state, msg: status_calls.append(
|
||||
state)
|
||||
def test_resume_sets_value(self):
|
||||
"""Resume action sets the unit-paused value to False."""
|
||||
self.HookData()().return_value = True
|
||||
|
||||
actions.actions.resume(self.args)
|
||||
self.assertEqual(status_calls, ["active"])
|
||||
|
||||
def test_status_message(self):
|
||||
"""Resume action sets an empty status message."""
|
||||
status_calls = []
|
||||
self.status_set.side_effect = lambda state, msg: status_calls.append(
|
||||
msg)
|
||||
|
||||
actions.actions.resume(self.args)
|
||||
self.assertEqual(status_calls, [""])
|
||||
self.kv().set.assert_called_with('unit-paused', False)
|
||||
|
||||
|
||||
class GetActionParserTestCase(unittest.TestCase):
|
||||
|
@ -4,8 +4,9 @@ import os
|
||||
os.environ['JUJU_UNIT_NAME'] = 'swift-storge'
|
||||
|
||||
with patch('charmhelpers.core.hookenv.config') as config:
|
||||
config.return_value = 'swift-storage'
|
||||
import actions.openstack_upgrade as openstack_upgrade
|
||||
with patch('lib.misc_utils.is_paused') as is_paused:
|
||||
config.return_value = 'swift-storage'
|
||||
import actions.openstack_upgrade as openstack_upgrade
|
||||
|
||||
from test_utils import (
|
||||
CharmTestCase
|
||||
|
@ -7,7 +7,8 @@ import lib.swift_storage_utils as utils
|
||||
_reg = utils.register_configs
|
||||
utils.register_configs = MagicMock()
|
||||
|
||||
import hooks.swift_storage_hooks as hooks
|
||||
with patch('hooks.lib.misc_utils.is_paused') as is_paused:
|
||||
import hooks.swift_storage_hooks as hooks
|
||||
|
||||
utils.register_configs = _reg
|
||||
|
||||
|
@ -27,6 +27,7 @@ TO_PATCH = [
|
||||
'service_restart',
|
||||
'_save_script_rc',
|
||||
'lsb_release',
|
||||
'is_paused',
|
||||
]
|
||||
|
||||
|
||||
@ -316,6 +317,7 @@ class SwiftStorageUtilsTests(CharmTestCase):
|
||||
self.assertEquals(ex, configs.register.call_args_list)
|
||||
|
||||
def test_do_upgrade(self):
|
||||
self.is_paused.return_value = False
|
||||
self.test_config.set('openstack-origin', 'cloud:precise-grizzly')
|
||||
self.get_os_codename_install_source.return_value = 'grizzly'
|
||||
swift_utils.do_openstack_upgrade(MagicMock())
|
||||
|
Loading…
Reference in New Issue
Block a user