In nova_cc_utils.py:resolve_hosts_for: .append -> .add

The method was refactored (in part) to use sets to enforce uniqueness of
the hosts.  Unfortunately, a list method (.append()) slipped through
that should have been converted to .add(). This fixes that error.

Change-Id: I248430cd1a9156efab745fe110a39441b503b3a5
Closes-Bug: #1992789
This commit is contained in:
Alex Kavanagh 2022-10-16 20:27:42 +01:00
parent abb8ee551c
commit 007f9e33b0
2 changed files with 23 additions and 1 deletions

View File

@ -1381,7 +1381,7 @@ def resolve_hosts_for(private_address, hostname):
hosts.add(hostname)
if not ch_utils.is_ip(private_address):
hosts.append(private_address.lower())
hosts.add(private_address.lower())
hosts.add(ch_utils.get_host_ip(private_address))
short = private_address.split('.')[0]
if ch_ip.ns_query(short):

View File

@ -861,6 +861,28 @@ class NovaCCUtilsTests(CharmTestCase):
utils.ssh_compute_remove(removed_key)
self.assertEqual(_written, keys_removed)
@patch.object(utils.ch_utils, 'get_host_ip')
@patch.object(utils.ch_ip, 'ns_query')
def test_resolve_hosts_for_bug_1992789(self, _ns_query, _get_host_ip):
# regression test for bug: 1992789; when the function was refactored to
# use a set instead of a list to ensure uniqueness of hosts, a method
# was missed from being converted from .append() to .add()
private_address = "myhostname" # trigger behaviour of bug
hostname = "myhostname2"
db_key = "hostset-{}".format(private_address)
# note that this is patched in class setup to :memory: sqlite db
db = charmhelpers.core.unitdata.kv()
db.unset(db_key)
# ensure caching is disabled
self.test_config.set('cache-known-hosts', False)
_get_host_ip.return_value = "10.0.0.10"
_ns_query.return_value = False
hosts = utils.resolve_hosts_for(private_address, hostname)
self.assertEqual(sorted(hosts),
["10.0.0.10", "myhostname", "myhostname2"])
def test_determine_endpoints_base(self):
self.relation_ids.return_value = []
self.os_release.return_value = 'diablo'