3ab6133c2a
The pause and resume actions shell out to the ceph command to run OSD operations (in/out). Because the default cephx key given out by the monitor cluster does not contain the correct permissions, these commands fail. Use the osd-upgrade user which has the correct permissions. Closes-Bug: 1602826 Depends-On: I6af43b61149c6eeeeb5c77950701194beda2da71 Change-Id: Ie31bc9048972dbb0986ac8deb5b821a4db5d585f
93 lines
2.9 KiB
Python
93 lines
2.9 KiB
Python
# Copyright 2016 Canonical Ltd
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
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', '--id',
|
|
'osd-upgrade', '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', '--id',
|
|
'osd-upgrade', '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"])
|