Gate HostIPContext on OpenStack release

The original implementation in [0] relied on the template content
appearing at the ``Stein`` release.

With the addition of sharing of this value on the subordinate
relation in [1] we need this gating in the context too.

0: Iee73164358745628a4b8658614608bc872771fd1
1: I75cbc5eb97cf3603ffa5a9a49670411288d90520

Change-Id: I2b252fd3512c07bb7bccd388809b0514ebcd5bde
Closes-Bug: #1845303
This commit is contained in:
Frode Nordahl 2019-10-03 06:48:48 +02:00
parent 32d7c17b7f
commit d0028a7dcd
No known key found for this signature in database
GPG Key ID: 6A5D59A3BA48373F
2 changed files with 12 additions and 2 deletions

View File

@ -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

View File

@ -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())