summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bogott <abogott@wikimedia.org>2021-05-12 15:52:53 -0500
committerAndrew Bogott <abogott@wikimedia.org>2021-05-12 19:39:32 -0500
commit0f666fb95f1909932fe635d8717e7ff66d7f7b44 (patch)
tree2555dc71ab62b615d34eaf24b2616bacf5dfb501
parente232cb800c8924ece60beb1590f50b25bd9f9b3a (diff)
downloadtrove-0f666fb95f1909932fe635d8717e7ff66d7f7b44.tar.gz
instance model: fix extraction of ip addresses from instance record
The instance.addresses value will be a dictionary of network: [addr_info] key/value pairs. addr_info is not itself the address but a dict that contains the address under ['addr']. The nova api changed quite a while ago so we need to catch up. In addition: this function previously returned a list of dictionaries; users of the function are clearly expecting a list of simple IPs, so return that instead. Change-Id: I9f7fed17b93e909f572949037b4e229d527e8fe4
-rw-r--r--trove/instance/models.py18
-rw-r--r--trove/tests/unittests/instance/test_instance_models.py13
2 files changed, 15 insertions, 16 deletions
diff --git a/trove/instance/models.py b/trove/instance/models.py
index e00bff0c..172ca406 100644
--- a/trove/instance/models.py
+++ b/trove/instance/models.py
@@ -255,18 +255,18 @@ class SimpleInstance(object):
def get_visible_ip_addresses(self):
"""Returns IPs that will be visible to the user."""
- if self.addresses is None:
+ if not self.addresses:
return None
IPs = []
-
- for addr_info in self.addresses:
- if CONF.ip_regex and CONF.black_list_regex:
- if not ip_visible(addr_info['address'], CONF.ip_regex,
- CONF.black_list_regex):
- continue
-
- IPs.append(addr_info)
+ for address_list in self.addresses.values():
+ for addr_info in address_list:
+ if CONF.ip_regex and CONF.black_list_regex:
+ if not ip_visible(addr_info['addr'], CONF.ip_regex,
+ CONF.black_list_regex):
+ continue
+
+ IPs.append(addr_info['addr'])
return IPs
diff --git a/trove/tests/unittests/instance/test_instance_models.py b/trove/tests/unittests/instance/test_instance_models.py
index 10befc8c..96ab8726 100644
--- a/trove/tests/unittests/instance/test_instance_models.py
+++ b/trove/tests/unittests/instance/test_instance_models.py
@@ -50,11 +50,12 @@ class SimpleInstanceTest(trove_testtools.TestCase):
ServiceStatuses.BUILDING), ds_version=Mock(), ds=Mock(),
locality='affinity')
self.instance.context = self.context
- db_info.addresses = [
- {'type': 'private', 'address': '123.123.123.123'},
- {'type': 'private', 'address': '10.123.123.123'},
- {'type': 'public', 'address': '15.123.123.123'},
- ]
+ db_info.addresses = {
+ 'private': [
+ {'version': 4, 'addr': '123.123.123.123'},
+ {'version': 4, 'addr': '10.123.123.123'}],
+ 'public': [
+ {'version': 4, 'addr': '15.123.123.123'}]}
self.orig_ip_regex = CONF.ip_regex
self.orig_black_list_regex = CONF.black_list_regex
@@ -76,7 +77,6 @@ class SimpleInstanceTest(trove_testtools.TestCase):
CONF.ip_regex = '^(15.|123.)'
CONF.black_list_regex = '^10.123.123.*'
ip = self.instance.get_visible_ip_addresses()
- ip = [addr['address'] for addr in ip]
self.assertEqual(2, len(ip))
self.assertIn('123.123.123.123', ip)
self.assertIn('15.123.123.123', ip)
@@ -85,7 +85,6 @@ class SimpleInstanceTest(trove_testtools.TestCase):
CONF.ip_regex = '.*'
CONF.black_list_regex = '^10.123.123.*'
ip = self.instance.get_visible_ip_addresses()
- ip = [addr['address'] for addr in ip]
self.assertEqual(2, len(ip))
self.assertNotIn('10.123.123.123', ip)