Accept network id or name
This adds a new argument --network to specify either a name or an id of a network that will be set in tempest.conf and used by tempest to run tests. At the same time, argument --network-id is deprecated and will be removed in the future as it is replaced with --network argument. Change-Id: Ifab729d7cf9362b4466c81b9b323b9098ebffd93
This commit is contained in:
parent
e4d8dc124c
commit
eef2a04f22
@ -318,6 +318,9 @@ def get_arg_parser():
|
||||
parser.add_argument('--network-id',
|
||||
help="""Specify which network with external
|
||||
connectivity should be used by the tests.""")
|
||||
parser.add_argument('--network',
|
||||
help="""Specify which network (id/name) with external
|
||||
connectivity should be used by the tests.""")
|
||||
parser.add_argument('--append', action='append', default=[],
|
||||
metavar="SECTION.KEY=VALUE[,VALUE]",
|
||||
help="""Append values to tempest.conf
|
||||
@ -355,6 +358,12 @@ def parse_arguments():
|
||||
if args.test_accounts and args.create_accounts_file:
|
||||
raise Exception("Options '--test-accounts' and "
|
||||
"'--create-accounts-file' can't be used together.")
|
||||
if args.network_id and args.network:
|
||||
raise Exception("--network-id is deprecated and will be replaced with"
|
||||
" --network. Please, use only --network argument.")
|
||||
if args.network_id:
|
||||
LOG.warning("The --network-id is deprecated, please, use --network")
|
||||
args.network = args.network_id
|
||||
args.overrides = parse_overrides(args.overrides)
|
||||
return args
|
||||
|
||||
@ -564,7 +573,7 @@ def config_tempest(**kwargs):
|
||||
|
||||
if services.is_service(**{"type": "network"}):
|
||||
network = services.get_service("network")
|
||||
network.create_tempest_networks(conf, kwargs.get('network_id'))
|
||||
network.create_tempest_networks(conf, kwargs.get('network'))
|
||||
|
||||
services.post_configuration()
|
||||
services.set_supported_api_versions()
|
||||
@ -612,7 +621,7 @@ def main():
|
||||
flavor_min_disk=args.flavor_min_disk,
|
||||
image_disk_format=args.image_disk_format,
|
||||
image_path=args.image,
|
||||
network_id=args.network_id,
|
||||
network=args.network,
|
||||
non_admin=args.non_admin,
|
||||
no_rng=args.no_rng,
|
||||
os_cloud=args.os_cloud,
|
||||
|
@ -28,16 +28,17 @@ class NetworkService(VersionedService):
|
||||
def set_versions(self):
|
||||
super(NetworkService, self).set_versions(top_level=False)
|
||||
|
||||
def create_tempest_networks(self, conf, network_id):
|
||||
def create_tempest_networks(self, conf, network):
|
||||
LOG.info("Setting up network")
|
||||
self.client = self.client.networks
|
||||
self.create_tempest_networks_neutron(conf, network_id)
|
||||
self.create_tempest_networks_neutron(conf, network)
|
||||
|
||||
def create_tempest_networks_neutron(self, conf, public_network_id):
|
||||
def create_tempest_networks_neutron(self, conf, public_network):
|
||||
self._public_network = public_network
|
||||
self._public_network_name = None
|
||||
self._public_network_id = public_network_id
|
||||
self._public_network_id = None
|
||||
# if user supplied the network we should use
|
||||
if public_network_id:
|
||||
if public_network:
|
||||
self._supplied_network()
|
||||
# no network id provided, try to auto discover a public network
|
||||
else:
|
||||
@ -52,17 +53,19 @@ class NetworkService(VersionedService):
|
||||
return 'api_extensions'
|
||||
|
||||
def _supplied_network(self):
|
||||
LOG.info("Looking for existing network id: %s",
|
||||
self._public_network_id)
|
||||
LOG.info("Looking for existing network: %s",
|
||||
self._public_network)
|
||||
given_net = self._public_network
|
||||
# check if network exists
|
||||
network_list = self.client.list_networks()
|
||||
for network in network_list['networks']:
|
||||
if network['id'] == self._public_network_id:
|
||||
if network['id'] == given_net or network['name'] == given_net:
|
||||
self._public_network_name = network['name']
|
||||
self._public_network_id = network['id']
|
||||
break
|
||||
else:
|
||||
raise ValueError('provided network id: {0} was not found.'
|
||||
''.format(self._public_network_id))
|
||||
raise ValueError('provided network: {0} was not found.'
|
||||
''.format(self._public_network))
|
||||
|
||||
def _discover_network(self):
|
||||
LOG.info("No network supplied, trying auto discover for an external "
|
||||
|
@ -67,16 +67,18 @@ class TestNetworkService(BaseServiceTest):
|
||||
def test_tempest_network_id_not_found(self):
|
||||
return_mock = mock.Mock(return_value={"networks": []})
|
||||
self.Service.client.list_networks = return_mock
|
||||
self.Service._public_network_id = "doesn't_exist"
|
||||
self.Service._public_network = "doesn't_exist"
|
||||
self.assertRaises(ValueError,
|
||||
self.Service._supplied_network)
|
||||
|
||||
def test_create_network_id_supplied_by_user(self):
|
||||
return_mock = mock.Mock(return_value=self.FAKE_NETWORK_LIST)
|
||||
self.Service.client.list_networks = return_mock
|
||||
self.Service._public_network_id = '1ea533d7-4c65-4f25'
|
||||
self.Service._public_network = '1ea533d7-4c65-4f25'
|
||||
self.Service._supplied_network()
|
||||
self.assertEqual(self.Service._public_network_name, 'tempest-network')
|
||||
self.assertEqual(
|
||||
self.Service._public_network_id, '1ea533d7-4c65-4f25')
|
||||
|
||||
def test_create_network_auto_discover(self):
|
||||
return_mock = mock.Mock(return_value=self.FAKE_NETWORK_LIST)
|
||||
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add a new argument ``--network`` to specify either a name or an id of
|
||||
a network that will be set in tempest.conf and used by tempest to run
|
||||
tests.
|
||||
deprecations:
|
||||
- |
|
||||
Argument ``--network-id`` is deprecated and will be removed in the future.
|
||||
``--network-id`` is replaced with ``--network`` that can be used to
|
||||
specify both, network id or network name.
|
Loading…
Reference in New Issue
Block a user