blob: a17f58184c37d7e6cc385648d5c4a7e97c00c424 [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
Matthew Treinish71426682015-04-23 11:19:38 -040016import six
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053019from tempest import test
Daryl Walleck2148b622012-02-22 00:42:06 -060020
21
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053022class ServerAddressesTestJSON(base.BaseV2ComputeTest):
Daryl Walleck2148b622012-02-22 00:42:06 -060023
24 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000025 def setup_credentials(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000026 # This test module might use a network and a subnet
27 cls.set_network_resources(network=True, subnet=True)
Emily Hugenbruche7991d92014-12-12 16:53:36 +000028 super(ServerAddressesTestJSON, cls).setup_credentials()
29
30 @classmethod
31 def setup_clients(cls):
32 super(ServerAddressesTestJSON, cls).setup_clients()
Jay Pipes13b479b2012-06-11 14:52:27 -040033 cls.client = cls.servers_client
Daryl Walleck2148b622012-02-22 00:42:06 -060034
Emily Hugenbruche7991d92014-12-12 16:53:36 +000035 @classmethod
36 def resource_setup(cls):
37 super(ServerAddressesTestJSON, cls).resource_setup()
38
David Kranz0fb14292015-02-11 15:55:20 -050039 cls.server = cls.create_test_server(wait_until='ACTIVE')
Daryl Walleck2148b622012-02-22 00:42:06 -060040
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053041 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080042 @test.idempotent_id('6eb718c0-02d9-4d5e-acd1-4e0c269cef39')
Matthew Treinish2df97482014-06-13 15:02:26 -040043 @test.services('network')
Daryl Walleck2148b622012-02-22 00:42:06 -060044 def test_list_server_addresses(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050045 # All public and private addresses for
46 # a server should be returned
Daryl Walleck2148b622012-02-22 00:42:06 -060047
David Kranzae99b9a2015-02-16 13:37:01 -050048 addresses = self.client.list_addresses(self.server['id'])
Daryl Walleck2148b622012-02-22 00:42:06 -060049
50 # We do not know the exact network configuration, but an instance
51 # should at least have a single public or private address
Tiago Mello7b1f4022013-01-30 17:07:18 -050052 self.assertTrue(len(addresses) >= 1)
Matthew Treinish71426682015-04-23 11:19:38 -040053 for network_name, network_addresses in six.iteritems(addresses):
Tiago Mello7b1f4022013-01-30 17:07:18 -050054 self.assertTrue(len(network_addresses) >= 1)
Julien Danjou24ea4ad2012-04-11 16:15:00 +020055 for address in network_addresses:
56 self.assertTrue(address['addr'])
57 self.assertTrue(address['version'])
Daryl Walleck2148b622012-02-22 00:42:06 -060058
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053059 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080060 @test.idempotent_id('87bbc374-5538-4f64-b673-2b0e4443cc30')
Matthew Treinish2df97482014-06-13 15:02:26 -040061 @test.services('network')
Daryl Walleck2148b622012-02-22 00:42:06 -060062 def test_list_server_addresses_by_network(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050063 # Providing a network type should filter
64 # the addresses return by that type
Daryl Walleck2148b622012-02-22 00:42:06 -060065
David Kranzae99b9a2015-02-16 13:37:01 -050066 addresses = self.client.list_addresses(self.server['id'])
Daryl Walleck2148b622012-02-22 00:42:06 -060067
68 # Once again we don't know the environment's exact network config,
69 # but the response for each individual network should be the same
70 # as the partial result of the full address list
71 id = self.server['id']
72 for addr_type in addresses:
David Kranzae99b9a2015-02-16 13:37:01 -050073 addr = self.client.list_addresses_by_network(id, addr_type)
Daryl Walleck2148b622012-02-22 00:42:06 -060074
75 addr = addr[addr_type]
76 for address in addresses[addr_type]:
77 self.assertTrue(any([a for a in addr if a == address]))