blob: dfda51bd7e46e884c8684e157cdf57d86ebefed4 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# 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
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.compute import base
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080017from tempest.lib import decorators
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053018from tempest import test
Daryl Walleck2148b622012-02-22 00:42:06 -060019
20
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053021class ServerAddressesTestJSON(base.BaseV2ComputeTest):
Daryl Walleck2148b622012-02-22 00:42:06 -060022
23 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000024 def setup_credentials(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000025 # This test module might use a network and a subnet
26 cls.set_network_resources(network=True, subnet=True)
Emily Hugenbruche7991d92014-12-12 16:53:36 +000027 super(ServerAddressesTestJSON, cls).setup_credentials()
28
29 @classmethod
30 def setup_clients(cls):
31 super(ServerAddressesTestJSON, cls).setup_clients()
Jay Pipes13b479b2012-06-11 14:52:27 -040032 cls.client = cls.servers_client
Daryl Walleck2148b622012-02-22 00:42:06 -060033
Emily Hugenbruche7991d92014-12-12 16:53:36 +000034 @classmethod
35 def resource_setup(cls):
36 super(ServerAddressesTestJSON, cls).resource_setup()
37
David Kranz0fb14292015-02-11 15:55:20 -050038 cls.server = cls.create_test_server(wait_until='ACTIVE')
Daryl Walleck2148b622012-02-22 00:42:06 -060039
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053040 @test.attr(type='smoke')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080041 @decorators.idempotent_id('6eb718c0-02d9-4d5e-acd1-4e0c269cef39')
Matthew Treinish2df97482014-06-13 15:02:26 -040042 @test.services('network')
Daryl Walleck2148b622012-02-22 00:42:06 -060043 def test_list_server_addresses(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050044 # All public and private addresses for
45 # a server should be returned
Daryl Walleck2148b622012-02-22 00:42:06 -060046
ghanshyam0f825252015-08-25 16:02:50 +090047 addresses = self.client.list_addresses(self.server['id'])['addresses']
Daryl Walleck2148b622012-02-22 00:42:06 -060048
49 # We do not know the exact network configuration, but an instance
50 # should at least have a single public or private address
zhufl080dcfb2016-10-21 17:45:38 +080051 self.assertGreaterEqual(len(addresses), 1)
guo yunxian7bbbec12016-08-21 20:03:10 +080052 for network_name, network_addresses in addresses.items():
zhufl080dcfb2016-10-21 17:45:38 +080053 self.assertGreaterEqual(len(network_addresses), 1)
Julien Danjou24ea4ad2012-04-11 16:15:00 +020054 for address in network_addresses:
55 self.assertTrue(address['addr'])
56 self.assertTrue(address['version'])
Daryl Walleck2148b622012-02-22 00:42:06 -060057
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053058 @test.attr(type='smoke')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080059 @decorators.idempotent_id('87bbc374-5538-4f64-b673-2b0e4443cc30')
Matthew Treinish2df97482014-06-13 15:02:26 -040060 @test.services('network')
Daryl Walleck2148b622012-02-22 00:42:06 -060061 def test_list_server_addresses_by_network(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050062 # Providing a network type should filter
63 # the addresses return by that type
Daryl Walleck2148b622012-02-22 00:42:06 -060064
ghanshyam0f825252015-08-25 16:02:50 +090065 addresses = self.client.list_addresses(self.server['id'])['addresses']
Daryl Walleck2148b622012-02-22 00:42:06 -060066
67 # Once again we don't know the environment's exact network config,
68 # but the response for each individual network should be the same
69 # as the partial result of the full address list
70 id = self.server['id']
71 for addr_type in addresses:
David Kranzae99b9a2015-02-16 13:37:01 -050072 addr = self.client.list_addresses_by_network(id, addr_type)
Daryl Walleck2148b622012-02-22 00:42:06 -060073
74 addr = addr[addr_type]
75 for address in addresses[addr_type]:
76 self.assertTrue(any([a for a in addr if a == address]))