9be47125b5
Adds pause and resume unit to the charm such that the charm stays paused during maintenance operations. Partial-Bug: 1558642 Change-Id: Id5c44143f30305a3c412648cebb4c30caaa3e789
87 lines
2.4 KiB
Python
87 lines
2.4 KiB
Python
import mock
|
|
|
|
mock.patch('charmhelpers.core.hookenv.status_set').start()
|
|
with mock.patch('charmhelpers.core.hookenv.config') as config:
|
|
config.return_value = 'neutron'
|
|
import neutron_api_utils as utils # noqa
|
|
|
|
# Need to do some early patching to get the module loaded.
|
|
_reg = utils.register_configs
|
|
_map = utils.restart_map
|
|
|
|
utils.register_configs = mock.MagicMock()
|
|
utils.restart_map = mock.MagicMock()
|
|
|
|
import actions
|
|
|
|
# Unpatch it now that its loaded.
|
|
utils.register_configs = _reg
|
|
utils.restart_map = _map
|
|
|
|
from test_utils import (
|
|
CharmTestCase
|
|
)
|
|
|
|
TO_PATCH = [
|
|
]
|
|
|
|
|
|
class PauseTestCase(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(PauseTestCase, self).setUp(
|
|
actions, ["register_configs", "pause_unit_helper"])
|
|
self.register_configs.return_value = 'test-config'
|
|
|
|
def test_pauses_services(self):
|
|
actions.pause([])
|
|
self.pause_unit_helper.assert_called_once_with('test-config')
|
|
|
|
|
|
class ResumeTestCase(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(ResumeTestCase, self).setUp(
|
|
actions, ["register_configs", "resume_unit_helper"])
|
|
self.register_configs.return_value = 'test-config'
|
|
|
|
def test_resumes_services(self):
|
|
actions.resume([])
|
|
self.resume_unit_helper.assert_called_once_with('test-config')
|
|
|
|
|
|
class MainTestCase(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(MainTestCase, self).setUp(actions, ["register_configs",
|
|
"action_fail"])
|
|
self.register_configs.return_value = 'test-config'
|
|
|
|
def test_invokes_action(self):
|
|
dummy_calls = []
|
|
|
|
def dummy_action(args):
|
|
dummy_calls.append(True)
|
|
|
|
with mock.patch.dict(actions.ACTIONS, {"foo": dummy_action}):
|
|
actions.main(["foo"])
|
|
self.assertEqual(dummy_calls, [True])
|
|
|
|
def test_unknown_action(self):
|
|
"""Unknown actions aren't a traceback."""
|
|
exit_string = actions.main(["foo"])
|
|
self.assertEqual("Action foo undefined", exit_string)
|
|
|
|
def test_failing_action(self):
|
|
"""Actions which traceback trigger action_fail() calls."""
|
|
dummy_calls = []
|
|
|
|
self.action_fail.side_effect = dummy_calls.append
|
|
|
|
def dummy_action(args):
|
|
raise ValueError("uh oh")
|
|
|
|
with mock.patch.dict(actions.ACTIONS, {"foo": dummy_action}):
|
|
actions.main(["foo"])
|
|
self.assertEqual(dummy_calls, ["uh oh"])
|