rebase
This commit is contained in:
commit
32f25e72d9
@ -4,9 +4,11 @@ import sys
|
||||
import os
|
||||
|
||||
from charmhelpers.core.host import service_pause, service_resume
|
||||
from charmhelpers.core.hookenv import action_fail, status_set
|
||||
from charmhelpers.core.hookenv import action_fail
|
||||
from charmhelpers.core.unitdata import HookData, kv
|
||||
|
||||
from hooks.glance_utils import services
|
||||
from hooks.glance_utils import services, assess_status
|
||||
from hooks.glance_relations import CONFIGS
|
||||
|
||||
|
||||
def pause(args):
|
||||
@ -18,8 +20,9 @@ def pause(args):
|
||||
stopped = service_pause(service)
|
||||
if not stopped:
|
||||
raise Exception("{} didn't stop cleanly.".format(service))
|
||||
status_set(
|
||||
"maintenance", "Paused. Use 'resume' action to resume normal service.")
|
||||
with HookData()():
|
||||
kv().set('unit-paused', True)
|
||||
assess_status(CONFIGS)
|
||||
|
||||
|
||||
def resume(args):
|
||||
@ -31,7 +34,9 @@ def resume(args):
|
||||
started = service_resume(service)
|
||||
if not started:
|
||||
raise Exception("{} didn't start cleanly.".format(service))
|
||||
status_set("active", "")
|
||||
with HookData()():
|
||||
kv().set('unit-paused', False)
|
||||
assess_status(CONFIGS)
|
||||
|
||||
|
||||
# A dictionary of all the defined actions to callables (which take
|
||||
|
@ -24,9 +24,8 @@ from glance_utils import (
|
||||
HAPROXY_CONF,
|
||||
ceph_config_file,
|
||||
setup_ipv6,
|
||||
REQUIRED_INTERFACES,
|
||||
check_optional_relations,
|
||||
swift_temp_url_key
|
||||
swift_temp_url_key,
|
||||
assess_status,
|
||||
)
|
||||
from charmhelpers.core.hookenv import (
|
||||
config,
|
||||
@ -67,7 +66,6 @@ from charmhelpers.contrib.openstack.utils import (
|
||||
openstack_upgrade_available,
|
||||
os_release,
|
||||
sync_db_with_multi_ipv6_addresses,
|
||||
set_os_workload_status,
|
||||
)
|
||||
from charmhelpers.contrib.storage.linux.ceph import (
|
||||
send_request_if_needed,
|
||||
@ -536,5 +534,4 @@ if __name__ == '__main__':
|
||||
hooks.execute(sys.argv)
|
||||
except UnregisteredHookError as e:
|
||||
juju_log('Unknown hook {} - skipping.'.format(e))
|
||||
set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
assess_status(CONFIGS)
|
||||
|
@ -26,6 +26,7 @@ from charmhelpers.core.hookenv import (
|
||||
relation_ids,
|
||||
service_name,
|
||||
status_get,
|
||||
status_set,
|
||||
)
|
||||
|
||||
|
||||
@ -70,6 +71,11 @@ from charmhelpers.core.decorators import (
|
||||
retry_on_exception,
|
||||
)
|
||||
|
||||
from charmhelpers.core.unitdata import (
|
||||
HookData,
|
||||
kv,
|
||||
)
|
||||
|
||||
|
||||
CLUSTER_RES = "grp_glance_vips"
|
||||
|
||||
@ -491,3 +497,31 @@ def swift_temp_url_key():
|
||||
swift_connection.post_account(headers={'x-account-meta-temp-url-key':
|
||||
temp_url_key})
|
||||
return temp_url_key
|
||||
|
||||
|
||||
def is_paused(status_get=status_get):
|
||||
"""Is the unit paused?"""
|
||||
with HookData()():
|
||||
if kv().get('unit-paused'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def assess_status(configs):
|
||||
"""Assess status of current unit
|
||||
|
||||
Decides what the state of the unit should be based on the current
|
||||
configuration.
|
||||
|
||||
@param configs: a templating.OSConfigRenderer() object
|
||||
"""
|
||||
|
||||
if is_paused():
|
||||
status_set("maintenance",
|
||||
"Paused. Use 'resume' action to resume normal service.")
|
||||
return
|
||||
|
||||
# set the status according to the current state of the contexts
|
||||
set_os_workload_status(
|
||||
configs, REQUIRED_INTERFACES, charm_func=check_optional_relations)
|
||||
|
@ -1,11 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""Amulet tests on a basic glance deployment on trusty-liberty."""
|
||||
"""Amulet tests on a basic glance deployment on trusty-mitaka."""
|
||||
|
||||
from basic_deployment import GlanceBasicDeployment
|
||||
|
||||
if __name__ == '__main__':
|
||||
deployment = GlanceBasicDeployment(series='trusty',
|
||||
openstack='cloud:trusty-liberty',
|
||||
source='cloud:trusty-updates/liberty')
|
||||
openstack='cloud:trusty-mitaka',
|
||||
source='cloud:trusty-updates/mitaka')
|
||||
deployment.run_tests()
|
||||
|
@ -1,18 +1,23 @@
|
||||
import os
|
||||
import mock
|
||||
|
||||
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
||||
|
||||
from test_utils import CharmTestCase
|
||||
|
||||
import actions.actions
|
||||
from mock import patch
|
||||
|
||||
os.environ['JUJU_UNIT_NAME'] = 'glance'
|
||||
|
||||
with patch('actions.hooks.glance_utils.is_paused') as is_paused:
|
||||
with patch('actions.hooks.glance_utils.register_configs') as configs:
|
||||
import actions.actions
|
||||
|
||||
|
||||
class PauseTestCase(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(PauseTestCase, self).setUp(
|
||||
actions.actions, ["service_pause", "status_set"])
|
||||
actions.actions, ["service_pause", "HookData", "kv",
|
||||
"assess_status"])
|
||||
|
||||
def test_pauses_services(self):
|
||||
"""Pause action pauses all Glance services."""
|
||||
@ -46,32 +51,20 @@ class PauseTestCase(CharmTestCase):
|
||||
actions.actions.pause, [])
|
||||
self.assertEqual(pause_calls, ['haproxy', '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)
|
||||
def test_pause_sets_value(self):
|
||||
"""Pause action sets the unit-paused value to True."""
|
||||
self.HookData()().return_value = True
|
||||
|
||||
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."])
|
||||
self.kv().set.assert_called_with('unit-paused', True)
|
||||
|
||||
|
||||
class ResumeTestCase(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ResumeTestCase, self).setUp(
|
||||
actions.actions, ["service_resume", "status_set"])
|
||||
actions.actions, ["service_resume", "HookData", "kv",
|
||||
"assess_status"])
|
||||
|
||||
def test_resumes_services(self):
|
||||
"""Resume action resumes all Glance services."""
|
||||
@ -104,23 +97,12 @@ class ResumeTestCase(CharmTestCase):
|
||||
actions.actions.resume, [])
|
||||
self.assertEqual(resume_calls, ['haproxy', 'glance-api'])
|
||||
|
||||
def test_status_mode(self):
|
||||
"""Resume action sets the status to active."""
|
||||
status_calls = []
|
||||
self.status_set.side_effect = lambda state, msg: status_calls.append(
|
||||
state)
|
||||
def test_resume_sets_value(self):
|
||||
"""Resume action sets the unit-paused value to False."""
|
||||
self.HookData()().return_value = True
|
||||
|
||||
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, [""])
|
||||
self.kv().set.assert_called_with('unit-paused', False)
|
||||
|
||||
|
||||
class MainTestCase(CharmTestCase):
|
||||
|
@ -293,3 +293,37 @@ class TestGlanceUtils(CharmTestCase):
|
||||
call('glance-registry'),
|
||||
]
|
||||
self.assertEquals(service_restart.call_args_list, expected)
|
||||
|
||||
@patch.object(utils, 'HookData')
|
||||
@patch.object(utils, 'kv')
|
||||
def test_is_paused(self, kv, HookData):
|
||||
"""test_is_paused: Test is_paused() returns value
|
||||
from kv('unit-paused')"""
|
||||
HookData()().return_value = True
|
||||
kv().get.return_value = True
|
||||
self.assertEqual(utils.is_paused(), True)
|
||||
kv().get.assert_called_with('unit-paused')
|
||||
kv().get.return_value = False
|
||||
self.assertEqual(utils.is_paused(), False)
|
||||
|
||||
@patch.object(utils, 'is_paused')
|
||||
@patch.object(utils, 'status_set')
|
||||
def test_assess_status(self, status_set, is_paused):
|
||||
"""test_assess_status: verify that it does pick the right status"""
|
||||
# check that paused status does the right thing
|
||||
is_paused.return_value = True
|
||||
utils.assess_status(None)
|
||||
status_set.assert_called_with(
|
||||
"maintenance",
|
||||
"Paused. Use 'resume' action to resume normal service.")
|
||||
|
||||
# if it isn't paused, the assess_status() calls
|
||||
# set_os_workload_status()
|
||||
is_paused.return_value = False
|
||||
with patch.object(utils, 'set_os_workload_status') \
|
||||
as set_os_workload_status:
|
||||
utils.assess_status("TEST CONFIG")
|
||||
set_os_workload_status.assert_called_with(
|
||||
"TEST CONFIG",
|
||||
utils.REQUIRED_INTERFACES,
|
||||
charm_func=utils.check_optional_relations)
|
||||
|
Loading…
x
Reference in New Issue
Block a user