Call assess_status() in pause/resume actions and update is_paused
This commit is contained in:
parent
744d05a142
commit
93ea05a733
@ -5,10 +5,13 @@ import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
from charmhelpers.core.host import service_pause, service_resume
|
||||
from charmhelpers.core.hookenv import action_fail, status_set
|
||||
sys.path.append('hooks/')
|
||||
|
||||
from lib.swift_utils import services
|
||||
from charmhelpers.core.host import service_pause, service_resume
|
||||
from charmhelpers.core.hookenv import action_fail
|
||||
from charmhelpers.core.unitdata import HookData, kv
|
||||
from lib.swift_utils import assess_status, services
|
||||
from swift_hooks import CONFIGS
|
||||
|
||||
|
||||
def get_action_parser(actions_yaml_path, action_name,
|
||||
@ -31,6 +34,9 @@ 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)
|
||||
assess_status(CONFIGS)
|
||||
|
||||
|
||||
def resume(args):
|
||||
@ -42,6 +48,9 @@ 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)
|
||||
assess_status(CONFIGS)
|
||||
|
||||
|
||||
# A dictionary of all the defined actions to callables (which take
|
||||
|
1
actions/hooks
Symbolic link
1
actions/hooks
Symbolic link
@ -0,0 +1 @@
|
||||
../hooks/
|
@ -64,6 +64,11 @@ from charmhelpers.contrib.network.ip import (
|
||||
from charmhelpers.core.decorators import (
|
||||
retry_on_exception,
|
||||
)
|
||||
from charmhelpers.core.unitdata import (
|
||||
HookData,
|
||||
kv,
|
||||
)
|
||||
|
||||
|
||||
# Various config files that are managed via templating.
|
||||
SWIFT_CONF_DIR = '/etc/swift'
|
||||
@ -993,8 +998,11 @@ def get_hostaddr():
|
||||
|
||||
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):
|
||||
|
@ -5,6 +5,8 @@ import unittest
|
||||
import mock
|
||||
import yaml
|
||||
|
||||
from mock import patch
|
||||
with patch('lib.swift_utils.is_paused') as is_paused:
|
||||
import actions.actions
|
||||
|
||||
|
||||
@ -31,7 +33,8 @@ class PauseTestCase(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(PauseTestCase, self).setUp(
|
||||
actions.actions, ["service_pause", "status_set"])
|
||||
actions.actions, ["service_pause", "HookData", "kv",
|
||||
"assess_status"])
|
||||
|
||||
class FakeArgs(object):
|
||||
services = ['swift-proxy', 'haproxy', 'memcached', 'apache2']
|
||||
@ -68,32 +71,20 @@ class PauseTestCase(CharmTestCase):
|
||||
actions.actions.pause, self.args)
|
||||
self.assertEqual(pause_calls, ["swift-proxy"])
|
||||
|
||||
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",
|
||||
"assess_status"])
|
||||
|
||||
class FakeArgs(object):
|
||||
services = ['swift-proxy', 'haproxy', 'memcached', 'apache2']
|
||||
@ -129,23 +120,12 @@ class ResumeTestCase(CharmTestCase):
|
||||
actions.actions.resume, self.args)
|
||||
self.assertEqual(resume_calls, ['swift-proxy'])
|
||||
|
||||
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):
|
||||
|
@ -5,6 +5,7 @@ import unittest
|
||||
os.environ['JUJU_UNIT_NAME'] = 'swift-proxy'
|
||||
|
||||
with patch('actions.charmhelpers.core.hookenv.config') as config:
|
||||
with patch('lib.swift_utils.is_paused') as is_paused:
|
||||
config.return_value = 'swift'
|
||||
import actions.openstack_upgrade as openstack_upgrade
|
||||
|
||||
|
@ -5,6 +5,7 @@ import uuid
|
||||
|
||||
sys.path.append("hooks")
|
||||
with patch('charmhelpers.core.hookenv.log'):
|
||||
with patch('lib.swift_utils.is_paused') as is_paused:
|
||||
import swift_hooks
|
||||
|
||||
|
||||
|
@ -5,7 +5,9 @@ import tempfile
|
||||
import uuid
|
||||
import unittest
|
||||
|
||||
from mock import patch
|
||||
with mock.patch('charmhelpers.core.hookenv.config'):
|
||||
with patch('lib.swift_utils.is_paused') as is_paused:
|
||||
import lib.swift_utils as swift_utils
|
||||
|
||||
|
||||
@ -223,18 +225,6 @@ class SwiftUtilsTestCase(unittest.TestCase):
|
||||
rsps = []
|
||||
self.assertIsNone(swift_utils.get_first_available_value(rsps, 'key3'))
|
||||
|
||||
def test_is_paused_unknown(self):
|
||||
fake_status_get = lambda: ("unknown", "")
|
||||
self.assertFalse(swift_utils.is_paused(status_get=fake_status_get))
|
||||
|
||||
def test_is_paused_paused(self):
|
||||
fake_status_get = lambda: ("maintenance", "Paused")
|
||||
self.assertTrue(swift_utils.is_paused(status_get=fake_status_get))
|
||||
|
||||
def test_is_paused_other_maintenance(self):
|
||||
fake_status_get = lambda: ("maintenance", "Hook")
|
||||
self.assertFalse(swift_utils.is_paused(status_get=fake_status_get))
|
||||
|
||||
@mock.patch('lib.swift_utils.config')
|
||||
@mock.patch('lib.swift_utils.set_os_workload_status')
|
||||
@mock.patch('lib.swift_utils.SwiftRingContext.__call__')
|
||||
|
Loading…
Reference in New Issue
Block a user