Prioritize external network named public

python-tempestconf will prioritize the external network named public
when auto-discovering an external network for tempest.

The public network is the network we end up using in most of the
cases. This will help avoid potential conflicts with other available
external networks that are not meant to be used by tempest. If no
external network with name public is found, the network discovered
last will be used.

Change-Id: Ib10cae1fa3610c4ea0a54b7f4ebbdb146bf4fce2
This commit is contained in:
Martin Kopec 2024-05-03 13:05:54 +02:00
parent 46fb09a653
commit e4d8dc124c
3 changed files with 41 additions and 8 deletions

View File

@ -65,20 +65,29 @@ class NetworkService(VersionedService):
''.format(self._public_network_id))
def _discover_network(self):
LOG.info("No network supplied, trying auto discover for network")
LOG.info("No network supplied, trying auto discover for an external "
"network while prioritizing the one called public, if not "
"found, the network discovered last will be used.")
network_list = self.client.list_networks()
for network in network_list['networks']:
if network['router:external'] and network['subnets']:
LOG.info("Found network, using: %s", network['id'])
if network['status'] != 'ACTIVE':
continue
self._public_network_id = network['id']
self._public_network_name = network['name']
break
# usually the external network we use is called 'public'
if network['name'] == 'public':
# we found a network called public, end the loop
break
# Couldn't find an existing external network
else:
if not self._public_network_name:
LOG.error("No external networks found. "
"Please note that any test that relies on external "
"connectivity would most likely fail.")
return
LOG.info("Setting %s as the public network for tempest",
self._public_network_id)
@staticmethod
def get_service_type():

View File

@ -35,6 +35,18 @@ class TestNetworkService(BaseServiceTest):
'label': 'my_fake_label',
'name': 'tempest-network',
'admin_state_up': True,
}, {
'provider:physical_network': None,
'id': 'c034f7f8-b860-4ffd',
'router:external': True,
'availability_zone_hints': [],
'availability_zones': [],
'ipv4_address_scope': None,
'status': 'ACTIVE',
'subnets': ['fake_subnet 2'],
'label': 'public_fake_label',
'name': 'public',
'admin_state_up': True,
}]
}
@ -70,15 +82,18 @@ class TestNetworkService(BaseServiceTest):
return_mock = mock.Mock(return_value=self.FAKE_NETWORK_LIST)
self.Service.client.list_networks = return_mock
self.Service._discover_network()
self.assertEqual(self.Service._public_network_id, '1ea533d7-4c65-4f25')
self.assertEqual(self.Service._public_network_name, 'tempest-network')
self.assertEqual(self.Service._public_network_id,
'c034f7f8-b860-4ffd')
self.assertEqual(self.Service._public_network_name, 'public')
@mock.patch('config_tempest.services.network.LOG')
def test_create_network_auto_discover_not_found(self, mock_logging):
# delete subnets => network will not be found
# delete subnets, set DOWN status => networks will not be found
self.FAKE_NETWORK_LIST['networks'][0]['subnets'] = []
self.FAKE_NETWORK_LIST['networks'][1]['status'] = 'DOWN'
return_mock = mock.Mock(return_value=self.FAKE_NETWORK_LIST)
self.Service.client.list_networks = return_mock
self.Service._public_network_name = None
self.Service._discover_network()
# check if LOG.error was called
self.assertTrue(mock_logging.error.called)

View File

@ -0,0 +1,9 @@
---
fixes:
- |
python-tempestconf will prioritize the external network named public when
auto-discovering an external network for tempest. The public network is
the network we end up using in most of the cases. This will help avoid
potential conflicts with other available external networks that are not
meant to be used by tempest. If no external network with name public is
found, the network discovered last will be used.