blob: 87ce39d3ac72c8758c5c88f59de8417b76f3369e [file] [log] [blame]
Andrea Frittolie258cd72014-07-17 04:47:26 +01001# Copyright 2014 Hewlett-Packard Development Company, L.P.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.compute import base
17from tempest import config
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080018from tempest.lib import decorators
Andrea Frittolie258cd72014-07-17 04:47:26 +010019
20CONF = config.CONF
21
22
Ken'ichi Ohmichi02a8ccd2015-11-05 06:05:29 +000023class NetworksTest(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000024 """Tests Nova Networks API that usually requires admin privileges.
Andrea Frittolie258cd72014-07-17 04:47:26 +010025
Andrea Frittolie258cd72014-07-17 04:47:26 +010026 API docs:
deepak_mouryafb0b7082018-01-23 17:00:27 +053027 https://developer.openstack.org/api-ref/compute/#networks-os-networks-deprecated
Andrea Frittolie258cd72014-07-17 04:47:26 +010028 """
29
30 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053031 def setup_clients(cls):
32 super(NetworksTest, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020033 cls.client = cls.os_admin.compute_networks_client
Andrea Frittolie258cd72014-07-17 04:47:26 +010034
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080035 @decorators.idempotent_id('d206d211-8912-486f-86e2-a9d090d1f416')
Andrea Frittolie258cd72014-07-17 04:47:26 +010036 def test_get_network(self):
ghanshyamf0f7cfc2015-08-24 16:21:18 +090037 networks = self.client.list_networks()['networks']
Matthew Treinish03feae02015-03-27 10:25:45 -040038 if CONF.compute.fixed_network_name:
39 configured_network = [x for x in networks if x['label'] ==
40 CONF.compute.fixed_network_name]
41 self.assertEqual(1, len(configured_network),
42 "{0} networks with label {1}".format(
43 len(configured_network),
44 CONF.compute.fixed_network_name))
Jordan Pittier2a81ede2016-10-28 18:47:00 +020045 elif CONF.network.public_network_id:
46 configured_network = [x for x in networks if x['id'] ==
47 CONF.network.public_network_id]
Matthew Treinish03feae02015-03-27 10:25:45 -040048 else:
Jordan Pittier2a81ede2016-10-28 18:47:00 +020049 raise self.skipException(
50 "Environment has no known-for-sure existing network.")
Andrea Frittolie258cd72014-07-17 04:47:26 +010051 configured_network = configured_network[0]
ghanshyamf0f7cfc2015-08-24 16:21:18 +090052 network = (self.client.show_network(configured_network['id'])
53 ['network'])
Andrea Frittolie258cd72014-07-17 04:47:26 +010054 self.assertEqual(configured_network['label'], network['label'])
55
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080056 @decorators.idempotent_id('df3d1046-6fa5-4b2c-ad0c-cfa46a351cb9')
Andrea Frittolie258cd72014-07-17 04:47:26 +010057 def test_list_all_networks(self):
ghanshyamf0f7cfc2015-08-24 16:21:18 +090058 networks = self.client.list_networks()['networks']
Andrea Frittolie258cd72014-07-17 04:47:26 +010059 # Check the configured network is in the list
Matthew Treinish03feae02015-03-27 10:25:45 -040060 if CONF.compute.fixed_network_name:
61 configured_network = CONF.compute.fixed_network_name
62 self.assertIn(configured_network, [x['label'] for x in networks])
63 else:
Davanum Srinivas816607c2017-01-17 16:01:31 -050064 network_labels = [x['label'] for x in networks]
Ferenc Horváth268ccce2017-06-08 12:39:02 +020065 self.assertNotEmpty(network_labels)