blob: deb81a9cfe09d72e96d89353a8e516bf1396afb3 [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):
ghanshyamf0f7cfc2015-08-24 16:21:18 +090039 networks = self.client.list_networks()['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]
ghanshyamf0f7cfc2015-08-24 16:21:18 +090050 network = (self.client.show_network(configured_network['id'])
51 ['network'])
Andrea Frittolie258cd72014-07-17 04:47:26 +010052 self.assertEqual(configured_network['label'], network['label'])
53
Chris Hoge7579c1a2015-02-26 14:12:15 -080054 @test.idempotent_id('df3d1046-6fa5-4b2c-ad0c-cfa46a351cb9')
Andrea Frittolie258cd72014-07-17 04:47:26 +010055 def test_list_all_networks(self):
ghanshyamf0f7cfc2015-08-24 16:21:18 +090056 networks = self.client.list_networks()['networks']
Andrea Frittolie258cd72014-07-17 04:47:26 +010057 # Check the configured network is in the list
Matthew Treinish03feae02015-03-27 10:25:45 -040058 if CONF.compute.fixed_network_name:
59 configured_network = CONF.compute.fixed_network_name
60 self.assertIn(configured_network, [x['label'] for x in networks])
61 else:
62 network_name = map(lambda x: x['label'], networks)
63 self.assertGreaterEqual(len(network_name), 1)