Move application version set to charms.openstack
It comes from layer-openstack in the default assess_status handler. The version of the application deployed should be set on all assess_status calls, not just during the 'update-status' hook execution. Change-Id: I1ca762875f307db9bb15dd80b0c6a01a9e17b71e Partial-Bug: 1715429
This commit is contained in:
@@ -772,6 +772,12 @@ class BaseOpenStackCharmAssessStatus(object):
|
|||||||
SIDE EFFECT: this function calls status_set(state, message) to set the
|
SIDE EFFECT: this function calls status_set(state, message) to set the
|
||||||
workload status in juju.
|
workload status in juju.
|
||||||
"""
|
"""
|
||||||
|
# set the application version when we set the status (always)
|
||||||
|
# NOTE(tinwood) this is not, strictly speaking, good code organisation,
|
||||||
|
# as the 'application_version' property is in the classes.py file.
|
||||||
|
# However, as this is ALWAYS a mixin on that class, we can get away
|
||||||
|
# with this.
|
||||||
|
hookenv.application_version_set(self.application_version)
|
||||||
for f in [self.check_if_paused,
|
for f in [self.check_if_paused,
|
||||||
self.custom_assess_status_check,
|
self.custom_assess_status_check,
|
||||||
self.check_interfaces,
|
self.check_interfaces,
|
||||||
|
|||||||
@@ -151,11 +151,19 @@ class TestProvideCharmInstance(utils.BaseTestCase):
|
|||||||
self.assertEqual(charm, 'the-charm')
|
self.assertEqual(charm, 'the-charm')
|
||||||
|
|
||||||
|
|
||||||
|
class AssessStatusCharm(MyOpenStackCharm):
|
||||||
|
release = 'juno'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def application_version(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class TestBaseOpenStackCharmAssessStatus(BaseOpenStackCharmTest):
|
class TestBaseOpenStackCharmAssessStatus(BaseOpenStackCharmTest):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
def make_open_stack_charm():
|
def make_open_stack_charm():
|
||||||
return MyOpenStackCharm(['interface1', 'interface2'])
|
return AssessStatusCharm(['interface1', 'interface2'])
|
||||||
|
|
||||||
super().setUp(make_open_stack_charm, TEST_CONFIG)
|
super().setUp(make_open_stack_charm, TEST_CONFIG)
|
||||||
|
|
||||||
@@ -180,8 +188,13 @@ class TestBaseOpenStackCharmAssessStatus(BaseOpenStackCharmTest):
|
|||||||
self.patch_target('custom_assess_status_check',
|
self.patch_target('custom_assess_status_check',
|
||||||
return_value=(None, None))
|
return_value=(None, None))
|
||||||
self.patch_target('check_services_running', return_value=(None, None))
|
self.patch_target('check_services_running', return_value=(None, None))
|
||||||
self.target._assess_status()
|
self.patch_object(chm_core.hookenv, 'application_version_set')
|
||||||
|
with mock.patch.object(AssessStatusCharm, 'application_version',
|
||||||
|
new_callable=mock.PropertyMock,
|
||||||
|
return_value="abc"):
|
||||||
|
self.target._assess_status()
|
||||||
self.status_set.assert_called_once_with('active', 'Unit is ready')
|
self.status_set.assert_called_once_with('active', 'Unit is ready')
|
||||||
|
self.application_version_set.assert_called_once_with("abc")
|
||||||
# check all the check functions got called
|
# check all the check functions got called
|
||||||
self.check_if_paused.assert_called_once_with()
|
self.check_if_paused.assert_called_once_with()
|
||||||
self.check_interfaces.assert_called_once_with()
|
self.check_interfaces.assert_called_once_with()
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class BaseOpenStackCharmTest(unit_tests.utils.BaseTestCase):
|
|||||||
chm_core._singleton = None
|
chm_core._singleton = None
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def patch_target(self, attr, return_value=None, name=None, new=None):
|
def patch_target(self, attr, return_value=None, name=None, new=None,
|
||||||
|
**kwargs):
|
||||||
# uses BaseTestCase.patch_object() to patch targer.
|
# uses BaseTestCase.patch_object() to patch targer.
|
||||||
self.patch_object(self.target, attr, return_value, name, new)
|
self.patch_object(self.target, attr, return_value, name, new, **kwargs)
|
||||||
|
|||||||
@@ -52,13 +52,14 @@ class BaseTestCase(unittest.TestCase):
|
|||||||
self._patches = None
|
self._patches = None
|
||||||
self._patches_start = None
|
self._patches_start = None
|
||||||
|
|
||||||
def patch_object(self, obj, attr, return_value=None, name=None, new=None):
|
def patch_object(self, obj, attr, return_value=None, name=None, new=None,
|
||||||
|
**kwargs):
|
||||||
if name is None:
|
if name is None:
|
||||||
name = attr
|
name = attr
|
||||||
if new is not None:
|
if new is not None:
|
||||||
mocked = mock.patch.object(obj, attr, new=new)
|
mocked = mock.patch.object(obj, attr, new=new, **kwargs)
|
||||||
else:
|
else:
|
||||||
mocked = mock.patch.object(obj, attr)
|
mocked = mock.patch.object(obj, attr, **kwargs)
|
||||||
self._patches[name] = mocked
|
self._patches[name] = mocked
|
||||||
started = mocked.start()
|
started = mocked.start()
|
||||||
if new is None:
|
if new is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user