blob: 981a5c90ae97154c04224f4c68d7a79408c83526 [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
Chris Hoge7579c1a2015-02-26 14:12:15 -080018from tempest import test
Andrea Frittolie258cd72014-07-17 04:47:26 +010019
20CONF = config.CONF
21
22
23class 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 Kanade60b73092015-02-04 17:58:19 +053033 def setup_clients(cls):
34 super(NetworksTest, cls).setup_clients()
Andrea Frittolie258cd72014-07-17 04:47:26 +010035 cls.client = cls.os_adm.networks_client
36
Chris Hoge7579c1a2015-02-26 14:12:15 -080037 @test.idempotent_id('d206d211-8912-486f-86e2-a9d090d1f416')
Andrea Frittolie258cd72014-07-17 04:47:26 +010038 def test_get_network(self):
David Kranzb2b0c182015-02-18 13:28:19 -050039 networks = self.client.list_networks()
Matthew Treinish03feae02015-03-27 10:25:45 -040040 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 Frittolie258cd72014-07-17 04:47:26 +010049 configured_network = configured_network[0]
Ken'ichi Ohmichi46f574e2015-06-15 04:53:55 +000050 network = self.client.show_network(configured_network['id'])
Andrea Frittolie258cd72014-07-17 04:47:26 +010051 self.assertEqual(configured_network['label'], network['label'])
52
Chris Hoge7579c1a2015-02-26 14:12:15 -080053 @test.idempotent_id('df3d1046-6fa5-4b2c-ad0c-cfa46a351cb9')
Andrea Frittolie258cd72014-07-17 04:47:26 +010054 def test_list_all_networks(self):
David Kranzb2b0c182015-02-18 13:28:19 -050055 networks = self.client.list_networks()
Andrea Frittolie258cd72014-07-17 04:47:26 +010056 # Check the configured network is in the list
Matthew Treinish03feae02015-03-27 10:25:45 -040057 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)