Add new Trilio version template property

This change adds a new `trilio_compat_version` that can be used
in templates when an option is gated on the trilio Major and
Minor version. The config option cannot be used for examining
atch versions as it relies on a float representation of the
package version.

Change-Id: I9221188b817fbb570700406b97e194aacf6ef786
This commit is contained in:
Liam Young 2022-06-16 10:01:50 +00:00
parent 055fb499b8
commit 1079a19e2e
2 changed files with 35 additions and 11 deletions

View File

@ -55,16 +55,24 @@ def trilio_properties(cls):
:param cls: Configuration Adapter class
:type cls: charms_openstack.adapters.DefaultConfigurationAdapter
"""
properties = {}
cur_ver = cls.charm_instance.release_pkg_version()
comp = fetch.apt_pkg.version_compare(cur_ver, '4.1')
if comp >= 0:
return {
'db_type': 'dedicated',
'transport_type': 'dmapi'}
# The 'trilio_compat_version' property is a float that can be used in
# templates for comparing Trilio MAJOR.MINOR versions.
match = re.match(r'^(\d+)\.(\d+)', cur_ver)
if match:
properties['trilio_compat_version'] = float(match.group(0))
else:
return {
raise ValueError("Unexpected package version {}".format(cur_ver))
if properties['trilio_compat_version'] >= 4.1:
properties.update({
'db_type': 'dedicated',
'transport_type': 'dmapi'})
else:
properties.update({
'db_type': 'legacy',
'transport_type': 'legacy'}
'transport_type': 'legacy'})
return properties
@charms_openstack.adapters.config_property

View File

@ -255,16 +255,32 @@ class TestTrilioCommonBehaviours(BaseOpenStackCharmTest):
_file.write.assert_called_once_with('testsource')
def test_trilio_properties(self):
def _version_compare(a, b):
if a > b:
return 1
if a == b:
return 0
if a < b:
return -1
cls_mock = mock.MagicMock()
cls_mock.charm_instance.release_pkg_version = lambda: '4.0'
self.version_compare.return_value = 0
self.version_compare.side_effect = _version_compare
self.assertEqual(
trilio.trilio_properties(cls_mock),
{'db_type': 'dedicated', 'transport_type': 'dmapi'})
self.version_compare.return_value = -1
{
'db_type': 'legacy',
'transport_type': 'legacy',
'trilio_compat_version': 4.0})
cls_mock.charm_instance.release_pkg_version = lambda: '4.1'
self.assertEqual(
trilio.trilio_properties(cls_mock),
{'db_type': 'legacy', 'transport_type': 'legacy'})
{
'db_type': 'dedicated',
'transport_type': 'dmapi',
'trilio_compat_version': 4.1})
cls_mock.charm_instance.release_pkg_version = lambda: 'a4.1.1'
with self.assertRaises(ValueError):
trilio.trilio_properties(cls_mock)
def test_trilio_s3_cert_config(self):
cls_mock = mock.MagicMock()