Skip version caching for subordinate charms
Caching the charm OpenStack version will cause undesired behaviors if the charm is a subordinate. The charm local cache is firstly populated during the charm install. If the charm is a subordinate, the version will remain the same regardless of future OpenStack upgrades because today, the hook that updates the cache to the new version in only called for principal charms. Related-bug: #1949074 Change-Id: I76abbd29ca910fe4c4d62da09e2d2dd3b5c798a6
This commit is contained in:
parent
7a58988354
commit
fd042afdf1
|
@ -1,4 +1,5 @@
|
|||
import charmhelpers.contrib.openstack.utils as os_utils
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
import charmhelpers.core.unitdata as unitdata
|
||||
import charms.reactive as reactive
|
||||
|
||||
|
@ -97,7 +98,15 @@ def make_default_select_release_handler():
|
|||
that it doesn't need to keep going and getting it from the package
|
||||
information.
|
||||
"""
|
||||
release_version = unitdata.kv().get(OPENSTACK_RELEASE_KEY, None)
|
||||
release_version = None
|
||||
# Using the cached OpenStack version will cause undesired behaviors
|
||||
# if the charm is a subordinate. The charm local cache is firstly
|
||||
# populated during the charm install and after that, only during the
|
||||
# openstack upgrades. If the charm is a subordinate, the version will
|
||||
# always remain the same.
|
||||
if not hookenv.is_subordinate():
|
||||
release_version = unitdata.kv().get(OPENSTACK_RELEASE_KEY, None)
|
||||
|
||||
if release_version is None:
|
||||
try:
|
||||
# First make an attempt of determining release from a charm
|
||||
|
@ -125,7 +134,11 @@ def make_default_select_release_handler():
|
|||
pkg = 'dummy-package'
|
||||
release_version = os_utils.os_release(
|
||||
pkg, source_key=singleton.source_config_key)
|
||||
unitdata.kv().set(OPENSTACK_RELEASE_KEY, release_version)
|
||||
|
||||
# Skip caching the release if the charm is a subordinate.
|
||||
if not hookenv.is_subordinate():
|
||||
unitdata.kv().set(OPENSTACK_RELEASE_KEY, release_version)
|
||||
|
||||
return release_version
|
||||
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ class TestDefaults(BaseOpenStackCharmTest):
|
|||
singleton.source_config_key = 'fake-config-key'
|
||||
singleton.get_os_codename_package.return_value = None
|
||||
self.patch_object(chm, 'get_charm_instance', return_value=singleton)
|
||||
self.patch_object(chm.hookenv, 'is_subordinate', return_value=False)
|
||||
# set a release
|
||||
kv.get.return_value = 'one'
|
||||
release = h.map['function']()
|
||||
|
@ -153,6 +154,19 @@ class TestDefaults(BaseOpenStackCharmTest):
|
|||
self.assertEqual(release, 'four')
|
||||
singleton.get_os_codename_package.assert_called_once_with(
|
||||
mock.ANY, mock.ANY, apt_cache_sufficient=True)
|
||||
# Test subordinate charm
|
||||
kv.reset_mock()
|
||||
kv.get.return_value = None
|
||||
singleton.get_os_codename_package.reset_mock()
|
||||
singleton.get_os_codename_package.return_value = 'five'
|
||||
chm.hookenv.is_subordinate.reset_mock()
|
||||
chm.hookenv.is_subordinate.return_value = True
|
||||
self.os_release.reset_mock()
|
||||
self.os_release.return_value = 'five'
|
||||
release = h.map['function']()
|
||||
self.assertEqual(release, 'five')
|
||||
kv.set.assert_not_called()
|
||||
kv.get.assert_not_called()
|
||||
|
||||
def test_default_select_package_type_handler(self):
|
||||
self.assertIn('charm.default-select-package-type',
|
||||
|
|
Loading…
Reference in New Issue