2016-07-01 17:39:46 +01:00
|
|
|
# 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.
|
|
|
|
|
2016-03-18 12:22:03 +00:00
|
|
|
import mock
|
|
|
|
|
2018-10-15 16:39:39 +01:00
|
|
|
from unit_tests.test_utils import (
|
2016-06-20 18:28:14 -04:00
|
|
|
CharmTestCase,
|
|
|
|
get_default_config,
|
|
|
|
)
|
|
|
|
|
|
|
|
__default_config = get_default_config()
|
|
|
|
# NOTE(freyes): the default 'distro' makes the test suite behave different
|
|
|
|
# depending on where it's being executed
|
|
|
|
__default_config['openstack-origin'] = ''
|
|
|
|
|
2018-10-15 16:39:39 +01:00
|
|
|
import hooks.nova_cc_utils as utils # noqa
|
|
|
|
import actions.actions as actions
|
2016-06-20 18:28:14 -04:00
|
|
|
|
2016-03-18 12:22:03 +00:00
|
|
|
|
|
|
|
TO_PATCH = [
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class PauseTestCase(CharmTestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(PauseTestCase, self).setUp(
|
2018-10-15 16:39:39 +01:00
|
|
|
actions,
|
|
|
|
[
|
|
|
|
"hooks.nova_cc_utils.register_configs",
|
|
|
|
"hooks.nova_cc_utils.pause_unit_helper"
|
|
|
|
])
|
2016-03-18 12:22:03 +00:00
|
|
|
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(
|
2018-10-15 16:39:39 +01:00
|
|
|
actions, [
|
|
|
|
"hooks.nova_cc_utils.register_configs",
|
|
|
|
"hooks.nova_cc_utils.resume_unit_helper"
|
|
|
|
])
|
2016-03-18 12:22:03 +00:00
|
|
|
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):
|
2018-10-15 16:39:39 +01:00
|
|
|
super(MainTestCase, self).setUp(
|
|
|
|
actions,
|
|
|
|
[
|
|
|
|
"charmhelpers.core.hookenv.action_fail",
|
|
|
|
"hooks.nova_cc_utils.register_configs",
|
|
|
|
])
|
2016-03-18 12:22:03 +00:00
|
|
|
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"])
|