Drop sys.path mangling.
This commit is contained in:
0
actions/__init__.py
Normal file
0
actions/__init__.py
Normal file
@@ -6,7 +6,7 @@ from subprocess import (
|
|||||||
check_call,
|
check_call,
|
||||||
)
|
)
|
||||||
|
|
||||||
from glance_utils import (
|
from hooks.glance_utils import (
|
||||||
do_openstack_upgrade,
|
do_openstack_upgrade,
|
||||||
git_install,
|
git_install,
|
||||||
migrate_database,
|
migrate_database,
|
||||||
|
@@ -1,4 +1 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append('actions/')
|
|
||||||
sys.path.append('hooks/')
|
|
||||||
|
153
unit_tests/test_actions.py
Normal file
153
unit_tests/test_actions.py
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
import os
|
||||||
|
import mock
|
||||||
|
|
||||||
|
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
||||||
|
|
||||||
|
from test_utils import CharmTestCase
|
||||||
|
|
||||||
|
import actions.actions
|
||||||
|
|
||||||
|
|
||||||
|
class PauseTestCase(CharmTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(PauseTestCase, self).setUp(
|
||||||
|
actions.actions, ["service_pause", "status_set"])
|
||||||
|
|
||||||
|
def test_pauses_services(self):
|
||||||
|
"""Pause action pauses all Glance services."""
|
||||||
|
pause_calls = []
|
||||||
|
|
||||||
|
def fake_service_pause(svc):
|
||||||
|
pause_calls.append(svc)
|
||||||
|
return True
|
||||||
|
|
||||||
|
self.service_pause.side_effect = fake_service_pause
|
||||||
|
|
||||||
|
actions.actions.pause([])
|
||||||
|
self.assertEqual(pause_calls, ['glance-api', 'glance-registry'])
|
||||||
|
|
||||||
|
def test_bails_out_early_on_error(self):
|
||||||
|
"""Pause action fails early if there are errors stopping a service."""
|
||||||
|
pause_calls = []
|
||||||
|
|
||||||
|
def maybe_kill(svc):
|
||||||
|
if svc == "glance-registry":
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
pause_calls.append(svc)
|
||||||
|
return True
|
||||||
|
|
||||||
|
self.service_pause.side_effect = maybe_kill
|
||||||
|
self.assertRaisesRegexp(
|
||||||
|
Exception, "glance-registry didn't stop cleanly.",
|
||||||
|
actions.actions.pause, [])
|
||||||
|
self.assertEqual(pause_calls, ['glance-api'])
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
actions.actions.pause([])
|
||||||
|
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.assertEqual(
|
||||||
|
status_calls, ["Paused. "
|
||||||
|
"Use 'resume' action to resume normal service."])
|
||||||
|
|
||||||
|
|
||||||
|
class ResumeTestCase(CharmTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(ResumeTestCase, self).setUp(
|
||||||
|
actions.actions, ["service_resume", "status_set"])
|
||||||
|
|
||||||
|
def test_resumes_services(self):
|
||||||
|
"""Resume action resumes all Glance services."""
|
||||||
|
resume_calls = []
|
||||||
|
|
||||||
|
def fake_service_resume(svc):
|
||||||
|
resume_calls.append(svc)
|
||||||
|
return True
|
||||||
|
|
||||||
|
self.service_resume.side_effect = fake_service_resume
|
||||||
|
actions.actions.resume([])
|
||||||
|
self.assertEqual(resume_calls, ['glance-api', 'glance-registry'])
|
||||||
|
|
||||||
|
def test_bails_out_early_on_error(self):
|
||||||
|
"""Resume action fails early if there are errors starting a service."""
|
||||||
|
resume_calls = []
|
||||||
|
|
||||||
|
def maybe_kill(svc):
|
||||||
|
if svc == "glance-registry":
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
resume_calls.append(svc)
|
||||||
|
return True
|
||||||
|
|
||||||
|
self.service_resume.side_effect = maybe_kill
|
||||||
|
self.assertRaisesRegexp(
|
||||||
|
Exception, "glance-registry didn't start cleanly.",
|
||||||
|
actions.actions.resume, [])
|
||||||
|
self.assertEqual(resume_calls, ['glance-api'])
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
actions.actions.resume([])
|
||||||
|
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.assertEqual(status_calls, [""])
|
||||||
|
|
||||||
|
|
||||||
|
class MainTestCase(CharmTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(MainTestCase, self).setUp(actions.actions, ["action_fail"])
|
||||||
|
|
||||||
|
def test_invokes_action(self):
|
||||||
|
dummy_calls = []
|
||||||
|
|
||||||
|
def dummy_action(args):
|
||||||
|
dummy_calls.append(True)
|
||||||
|
|
||||||
|
with mock.patch.dict(actions.actions.ACTIONS, {"foo": dummy_action}):
|
||||||
|
actions.actions.main(["foo"])
|
||||||
|
self.assertEqual(dummy_calls, [True])
|
||||||
|
|
||||||
|
def test_unknown_action(self):
|
||||||
|
"""Unknown actions aren't a traceback."""
|
||||||
|
exit_string = actions.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.ACTIONS, {"foo": dummy_action}):
|
||||||
|
actions.actions.main(["foo"])
|
||||||
|
self.assertEqual(dummy_calls, ["uh oh"])
|
@@ -4,7 +4,7 @@ import os
|
|||||||
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
||||||
|
|
||||||
with patch('hooks.glance_utils.register_configs') as register_configs:
|
with patch('hooks.glance_utils.register_configs') as register_configs:
|
||||||
import git_reinstall
|
from actions import git_reinstall
|
||||||
|
|
||||||
from test_utils import (
|
from test_utils import (
|
||||||
CharmTestCase
|
CharmTestCase
|
||||||
@@ -53,7 +53,7 @@ class TestGlanceActions(CharmTestCase):
|
|||||||
@patch.object(git_reinstall, 'action_fail')
|
@patch.object(git_reinstall, 'action_fail')
|
||||||
@patch.object(git_reinstall, 'git_install')
|
@patch.object(git_reinstall, 'git_install')
|
||||||
@patch.object(git_reinstall, 'config_changed')
|
@patch.object(git_reinstall, 'config_changed')
|
||||||
@patch('charmhelpers.contrib.openstack.utils.config')
|
@patch('charmhelpers.contrib.openstack.config')
|
||||||
def test_git_reinstall_not_configured(self, _config, config_changed,
|
def test_git_reinstall_not_configured(self, _config, config_changed,
|
||||||
git_install, action_fail,
|
git_install, action_fail,
|
||||||
action_set):
|
action_set):
|
||||||
|
@@ -3,8 +3,7 @@ import os
|
|||||||
|
|
||||||
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
||||||
|
|
||||||
with patch('hooks.glance_utils.register_configs') as register_configs:
|
with patch('glance_utils.register_configs') as register_configs:
|
||||||
register_configs.return_value = None
|
|
||||||
import openstack_upgrade
|
import openstack_upgrade
|
||||||
|
|
||||||
from test_utils import (
|
from test_utils import (
|
||||||
|
@@ -6,7 +6,7 @@ import yaml
|
|||||||
from test_utils import CharmTestCase
|
from test_utils import CharmTestCase
|
||||||
|
|
||||||
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
||||||
import glance_utils as utils
|
import hooks.glance_utils as utils
|
||||||
|
|
||||||
_reg = utils.register_configs
|
_reg = utils.register_configs
|
||||||
_map = utils.restart_map
|
_map = utils.restart_map
|
||||||
@@ -14,7 +14,7 @@ _map = utils.restart_map
|
|||||||
utils.register_configs = MagicMock()
|
utils.register_configs = MagicMock()
|
||||||
utils.restart_map = MagicMock()
|
utils.restart_map = MagicMock()
|
||||||
|
|
||||||
import glance_relations as relations
|
import hooks.glance_relations as relations
|
||||||
|
|
||||||
relations.hooks._config_save = False
|
relations.hooks._config_save = False
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ TO_PATCH = [
|
|||||||
'openstack_upgrade_available',
|
'openstack_upgrade_available',
|
||||||
# charmhelpers.contrib.hahelpers.cluster_utils
|
# charmhelpers.contrib.hahelpers.cluster_utils
|
||||||
'is_elected_leader',
|
'is_elected_leader',
|
||||||
# glance_utils
|
# hooks.glance_utils
|
||||||
'restart_map',
|
'restart_map',
|
||||||
'register_configs',
|
'register_configs',
|
||||||
'do_openstack_upgrade',
|
'do_openstack_upgrade',
|
||||||
@@ -398,8 +398,8 @@ class GlanceRelationTests(CharmTestCase):
|
|||||||
'Could not create ceph keyring: peer not ready?'
|
'Could not create ceph keyring: peer not ready?'
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("glance_relations.relation_set")
|
@patch("hooks.glance_relations.relation_set")
|
||||||
@patch("glance_relations.relation_get")
|
@patch("hooks.glance_relations.relation_get")
|
||||||
@patch.object(relations, 'CONFIGS')
|
@patch.object(relations, 'CONFIGS')
|
||||||
def test_ceph_changed_broker_send_rq(self, configs, mock_relation_get,
|
def test_ceph_changed_broker_send_rq(self, configs, mock_relation_get,
|
||||||
mock_relation_set):
|
mock_relation_set):
|
||||||
@@ -420,7 +420,7 @@ class GlanceRelationTests(CharmTestCase):
|
|||||||
self.assertNotIn(c, configs.write.call_args_list)
|
self.assertNotIn(c, configs.write.call_args_list)
|
||||||
|
|
||||||
@patch("charmhelpers.core.host.service")
|
@patch("charmhelpers.core.host.service")
|
||||||
@patch("glance_relations.relation_get", autospec=True)
|
@patch("hooks.glance_relations.relation_get", autospec=True)
|
||||||
@patch.object(relations, 'CONFIGS')
|
@patch.object(relations, 'CONFIGS')
|
||||||
def test_ceph_changed_with_key_and_relation_data(self, configs,
|
def test_ceph_changed_with_key_and_relation_data(self, configs,
|
||||||
mock_relation_get,
|
mock_relation_get,
|
||||||
|
@@ -4,7 +4,7 @@ from collections import OrderedDict
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
||||||
import glance_utils as utils
|
import hooks.glance_utils as utils
|
||||||
|
|
||||||
from test_utils import (
|
from test_utils import (
|
||||||
CharmTestCase,
|
CharmTestCase,
|
||||||
|
Reference in New Issue
Block a user