This changeset provides pause and resume actions to the ceph charm. The pause action issues a 'ceph osd out <local_id>' for each of the ceph osd ids that are on the unit. The action does not stop the ceph osd processes. Note that if the pause-health action is NOT used on the ceph-mon charm then the cluster will start trying to rebalance the PGs accross the remaining OSDs. If the cluster might reach its 'full ratio' then this will be a breaking action. The charm does NOT check for this eventuality. The resume action issues a 'ceph osd in <local_id>' for each of the local ceph osd process on the unit. The charm 'remembers' that a pause action was issued, and if successful, it shows a 'maintenance' workload status as a reminder. Change-Id: I9f53c9c6c4bb737670ffcd542acec0b320cc7f6a
80 lines
2.3 KiB
Python
80 lines
2.3 KiB
Python
import mock
|
|
|
|
import sys
|
|
|
|
from test_utils import CharmTestCase
|
|
|
|
sys.path.append('hooks')
|
|
|
|
import pause_resume as actions
|
|
|
|
|
|
class PauseTestCase(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(PauseTestCase, self).setUp(
|
|
actions, ["check_call",
|
|
"get_local_osd_ids",
|
|
"set_unit_paused",
|
|
"assess_status"])
|
|
|
|
def test_pauses_services(self):
|
|
self.get_local_osd_ids.return_value = [5]
|
|
actions.pause([])
|
|
cmd = ['ceph', 'osd', 'out', '5']
|
|
self.check_call.assert_called_once_with(cmd)
|
|
self.set_unit_paused.assert_called_once_with()
|
|
self.assess_status.assert_called_once_with()
|
|
|
|
|
|
class ResumeTestCase(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(ResumeTestCase, self).setUp(
|
|
actions, ["check_call",
|
|
"get_local_osd_ids",
|
|
"clear_unit_paused",
|
|
"assess_status"])
|
|
|
|
def test_pauses_services(self):
|
|
self.get_local_osd_ids.return_value = [5]
|
|
actions.resume([])
|
|
cmd = ['ceph', 'osd', 'in', '5']
|
|
self.check_call.assert_called_once_with(cmd)
|
|
self.clear_unit_paused.assert_called_once_with()
|
|
self.assess_status.assert_called_once_with()
|
|
|
|
|
|
class MainTestCase(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(MainTestCase, self).setUp(actions, ["action_fail"])
|
|
|
|
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, ["Action foo failed: uh oh"])
|