Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 1 | # 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 | |
| 16 | from tempest.api.compute import base |
| 17 | from tempest import config |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 18 | from tempest.lib import decorators |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 19 | |
| 20 | CONF = config.CONF |
| 21 | |
| 22 | |
Ken'ichi Ohmichi | 02a8ccd | 2015-11-05 06:05:29 +0000 | [diff] [blame] | 23 | class NetworksTest(base.BaseV2ComputeAdminTest): |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 24 | """Tests Nova Networks API that usually requires admin privileges. |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 25 | |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 26 | API docs: |
deepak_mourya | fb0b708 | 2018-01-23 17:00:27 +0530 | [diff] [blame] | 27 | https://developer.openstack.org/api-ref/compute/#networks-os-networks-deprecated |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 28 | """ |
| 29 | |
| 30 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 31 | def setup_clients(cls): |
| 32 | super(NetworksTest, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 33 | cls.client = cls.os_admin.compute_networks_client |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 34 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 35 | @decorators.idempotent_id('d206d211-8912-486f-86e2-a9d090d1f416') |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 36 | def test_get_network(self): |
ghanshyam | f0f7cfc | 2015-08-24 16:21:18 +0900 | [diff] [blame] | 37 | networks = self.client.list_networks()['networks'] |
Matthew Treinish | 03feae0 | 2015-03-27 10:25:45 -0400 | [diff] [blame] | 38 | 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 Pittier | 2a81ede | 2016-10-28 18:47:00 +0200 | [diff] [blame] | 45 | elif CONF.network.public_network_id: |
| 46 | configured_network = [x for x in networks if x['id'] == |
| 47 | CONF.network.public_network_id] |
Matthew Treinish | 03feae0 | 2015-03-27 10:25:45 -0400 | [diff] [blame] | 48 | else: |
Jordan Pittier | 2a81ede | 2016-10-28 18:47:00 +0200 | [diff] [blame] | 49 | raise self.skipException( |
| 50 | "Environment has no known-for-sure existing network.") |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 51 | configured_network = configured_network[0] |
ghanshyam | f0f7cfc | 2015-08-24 16:21:18 +0900 | [diff] [blame] | 52 | network = (self.client.show_network(configured_network['id']) |
| 53 | ['network']) |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 54 | self.assertEqual(configured_network['label'], network['label']) |
| 55 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 56 | @decorators.idempotent_id('df3d1046-6fa5-4b2c-ad0c-cfa46a351cb9') |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 57 | def test_list_all_networks(self): |
ghanshyam | f0f7cfc | 2015-08-24 16:21:18 +0900 | [diff] [blame] | 58 | networks = self.client.list_networks()['networks'] |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 59 | # Check the configured network is in the list |
Matthew Treinish | 03feae0 | 2015-03-27 10:25:45 -0400 | [diff] [blame] | 60 | 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 Srinivas | 816607c | 2017-01-17 16:01:31 -0500 | [diff] [blame] | 64 | network_labels = [x['label'] for x in networks] |
Ferenc Horváth | 268ccce | 2017-06-08 12:39:02 +0200 | [diff] [blame] | 65 | self.assertNotEmpty(network_labels) |