blob: f79b05f8368d7bafbcf0eb90e7ac4fe62530bfd5 [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
Andrea Frittolicd368412017-08-14 21:37:56 +010017from tempest.common import utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080018from tempest.lib import decorators
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
Jordan Pittier3b46d272017-04-12 16:17:28 +020040 @decorators.attr(type='smoke')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080041 @decorators.idempotent_id('6eb718c0-02d9-4d5e-acd1-4e0c269cef39')
Andrea Frittolicd368412017-08-14 21:37:56 +010042 @utils.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
zhufl9d2ebc42017-06-12 11:09:09 +080051 self.assertNotEmpty(addresses)
Béla Vancsicsb6dfa082017-03-01 10:44:58 +010052 for network_addresses in addresses.values():
Ferenc Horváth268ccce2017-06-08 12:39:02 +020053 self.assertNotEmpty(network_addresses)
Daryl Walleck2148b622012-02-22 00:42:06 -060054
Jordan Pittier3b46d272017-04-12 16:17:28 +020055 @decorators.attr(type='smoke')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080056 @decorators.idempotent_id('87bbc374-5538-4f64-b673-2b0e4443cc30')
Andrea Frittolicd368412017-08-14 21:37:56 +010057 @utils.services('network')
Daryl Walleck2148b622012-02-22 00:42:06 -060058 def test_list_server_addresses_by_network(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050059 # Providing a network type should filter
60 # the addresses return by that type
Daryl Walleck2148b622012-02-22 00:42:06 -060061
ghanshyam0f825252015-08-25 16:02:50 +090062 addresses = self.client.list_addresses(self.server['id'])['addresses']
Daryl Walleck2148b622012-02-22 00:42:06 -060063
64 # Once again we don't know the environment's exact network config,
65 # but the response for each individual network should be the same
66 # as the partial result of the full address list
67 id = self.server['id']
68 for addr_type in addresses:
David Kranzae99b9a2015-02-16 13:37:01 -050069 addr = self.client.list_addresses_by_network(id, addr_type)
Daryl Walleck2148b622012-02-22 00:42:06 -060070
71 addr = addr[addr_type]
72 for address in addresses[addr_type]:
73 self.assertTrue(any([a for a in addr if a == address]))