Pull the network settings from the actual dict

Turns out self._openstack_config is not the config dict. self.config is.
Also, return names.

Change-Id: Ib2013e737b506b3a2acd7aa7b7884240c25384c5
This commit is contained in:
Monty Taylor 2016-04-05 10:38:46 -04:00
parent fdb80ad04f
commit 5605034fc3
No known key found for this signature in database
GPG Key ID: 3390DB68041A12F0
3 changed files with 55 additions and 6 deletions

View File

@ -442,23 +442,25 @@ class CloudConfig(object):
def get_external_networks(self):
"""Get list of network names for external networks."""
return [
net['name'] for net in self._openstack_config['networks']
net['name'] for net in self.config['networks']
if net['routes_externally']]
def get_internal_networks(self):
"""Get list of network names for internal networks."""
return [
net['name'] for net in self._openstack_config['networks']
net['name'] for net in self.config['networks']
if not net['routes_externally']]
def get_default_network(self):
"""Get network used for default interactions."""
for net in self._openstack_config['networks']:
for net in self.config['networks']:
if net['default_interface']:
return net
return net['name']
return None
def get_nat_destination(self):
"""Get network used for NAT destination."""
for net in self._openstack_config['networks']:
for net in self.config['networks']:
if net['nat_destination']:
return net
return net['name']
return None

View File

@ -90,6 +90,32 @@ USER_CONF = {
},
'region_name': 'test-region',
},
'_test-cloud-networks_': {
'auth': {
'username': 'testuser',
'password': 'testpass',
'project_id': 12345,
'auth_url': 'http://example.com/v2',
'domain_id': '6789',
'project_domain_id': '123456789',
},
'networks': [{
'name': 'a-public',
'routes_externally': True,
}, {
'name': 'another-public',
'routes_externally': True,
'default_interface': True,
}, {
'name': 'a-private',
'routes_externally': False,
}, {
'name': 'another-private',
'routes_externally': False,
'nat_destination': True,
}],
'region_name': 'test-region',
},
'_test_cloud_regions': {
'auth': {
'username': 'testuser',

View File

@ -187,6 +187,26 @@ class TestConfig(base.TestCase):
self.assertEqual('user', cc.auth['username'])
self.assertEqual('testpass', cc.auth['password'])
def test_get_one_cloud_networks(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud('_test-cloud-networks_')
self.assertEqual(
['a-public', 'another-public'], cc.get_external_networks())
self.assertEqual(
['a-private', 'another-private'], cc.get_internal_networks())
self.assertEqual('another-private', cc.get_nat_destination())
self.assertEqual('another-public', cc.get_default_network())
def test_get_one_cloud_no_networks(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud('_test-cloud-domain-scoped_')
self.assertEqual([], cc.get_external_networks())
self.assertEqual([], cc.get_internal_networks())
self.assertIsNone(cc.get_nat_destination())
self.assertIsNone(cc.get_default_network())
def test_only_secure_yaml(self):
c = config.OpenStackConfig(config_files=['nonexistent'],
vendor_files=['nonexistent'],
@ -201,6 +221,7 @@ class TestConfig(base.TestCase):
['_test-cloud-domain-id_',
'_test-cloud-domain-scoped_',
'_test-cloud-int-project_',
'_test-cloud-networks_',
'_test-cloud_',
'_test-cloud_no_region',
'_test_cloud_hyphenated',