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 |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 18 | from tempest import test |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 19 | |
| 20 | CONF = config.CONF |
| 21 | |
| 22 | |
| 23 | class NetworksTest(base.BaseComputeAdminTest): |
| 24 | _api_version = 2 |
| 25 | |
| 26 | """ |
| 27 | Tests Nova Networks API that usually requires admin privileges. |
| 28 | API docs: |
| 29 | http://developer.openstack.org/api-ref-compute-v2-ext.html#ext-os-networks |
| 30 | """ |
| 31 | |
| 32 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 33 | def setup_clients(cls): |
| 34 | super(NetworksTest, cls).setup_clients() |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 35 | cls.client = cls.os_adm.networks_client |
| 36 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 37 | @test.idempotent_id('d206d211-8912-486f-86e2-a9d090d1f416') |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 38 | def test_get_network(self): |
David Kranz | b2b0c18 | 2015-02-18 13:28:19 -0500 | [diff] [blame] | 39 | networks = self.client.list_networks() |
Matthew Treinish | 03feae0 | 2015-03-27 10:25:45 -0400 | [diff] [blame] | 40 | if CONF.compute.fixed_network_name: |
| 41 | configured_network = [x for x in networks if x['label'] == |
| 42 | CONF.compute.fixed_network_name] |
| 43 | self.assertEqual(1, len(configured_network), |
| 44 | "{0} networks with label {1}".format( |
| 45 | len(configured_network), |
| 46 | CONF.compute.fixed_network_name)) |
| 47 | else: |
| 48 | configured_network = networks |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 49 | configured_network = configured_network[0] |
Ken'ichi Ohmichi | 46f574e | 2015-06-15 04:53:55 +0000 | [diff] [blame] | 50 | network = self.client.show_network(configured_network['id']) |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 51 | self.assertEqual(configured_network['label'], network['label']) |
| 52 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 53 | @test.idempotent_id('df3d1046-6fa5-4b2c-ad0c-cfa46a351cb9') |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 54 | def test_list_all_networks(self): |
David Kranz | b2b0c18 | 2015-02-18 13:28:19 -0500 | [diff] [blame] | 55 | networks = self.client.list_networks() |
Andrea Frittoli | e258cd7 | 2014-07-17 04:47:26 +0100 | [diff] [blame] | 56 | # Check the configured network is in the list |
Matthew Treinish | 03feae0 | 2015-03-27 10:25:45 -0400 | [diff] [blame] | 57 | if CONF.compute.fixed_network_name: |
| 58 | configured_network = CONF.compute.fixed_network_name |
| 59 | self.assertIn(configured_network, [x['label'] for x in networks]) |
| 60 | else: |
| 61 | network_name = map(lambda x: x['label'], networks) |
| 62 | self.assertGreaterEqual(len(network_name), 1) |