diff --git a/hooks/neutron_ovs_context.py b/hooks/neutron_ovs_context.py index 6ba80f5c..d9c5ec1e 100644 --- a/hooks/neutron_ovs_context.py +++ b/hooks/neutron_ovs_context.py @@ -45,6 +45,7 @@ from charmhelpers.contrib.openstack.context import ( NeutronAPIContext, parse_data_port_mappings ) +import charmhelpers.contrib.openstack.utils as os_utils from charmhelpers.core.unitdata import kv IPTABLES_HYBRID = 'iptables_hybrid' @@ -609,6 +610,8 @@ class HostIPContext(context.OSContextGenerator): # Use the address used in the neutron-plugin subordinate relation host_ip = get_relation_ip('neutron-plugin') + cmp_release = os_utils.CompareOpenStackReleases( + os_utils.os_release('neutron-common', base='icehouse')) # the contents of the Neutron ``host`` configuration option is # referenced throughout a OpenStack deployment, an example being # Neutron port bindings. It's value should not change after a @@ -617,7 +620,8 @@ class HostIPContext(context.OSContextGenerator): # We do want to migrate to using FQDNs so we enable this for new # installations. db = kv() - if db.get('install_version', 0) >= 1910 and host_ip: + if (db.get('install_version', 0) >= 1910 and cmp_release >= 'stein' and + host_ip): fqdn = socket.getfqdn(host_ip) if '.' in fqdn: # only populate the value if getfqdn() is able to find an diff --git a/unit_tests/test_neutron_ovs_context.py b/unit_tests/test_neutron_ovs_context.py index 02bce021..44deb4a0 100644 --- a/unit_tests/test_neutron_ovs_context.py +++ b/unit_tests/test_neutron_ovs_context.py @@ -987,10 +987,13 @@ class TestHostIPContext(CharmTestCase): super(TestHostIPContext, self).setUp(context, TO_PATCH) self.config.side_effect = self.test_config.get + @patch.object(context.os_utils, 'os_release') @patch.object(context.socket, 'getfqdn') @patch.object(context, 'kv') @patch.object(context, 'get_relation_ip') - def test_host_ip_context(self, _get_relation_ip, _kv, _getfqdn): + def test_host_ip_context(self, _get_relation_ip, _kv, _getfqdn, + _os_release): + _os_release.return_value = 'stein' _kv.return_value = {'install_version': 0} _getfqdn.return_value = 'some' ctxt = context.HostIPContext() @@ -1001,3 +1004,6 @@ class TestHostIPContext(CharmTestCase): _kv.return_value = {'install_version': 1910} ctxt = context.HostIPContext() self.assertDictEqual({'host': 'some.hostname'}, ctxt()) + _os_release.return_value = 'rocky' + ctxt = context.HostIPContext() + self.assertDictEqual({}, ctxt())