ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 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 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 16 | from tempest.api.compute import base |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 17 | from tempest.common import utils |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 18 | from tempest.lib import decorators |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 19 | |
| 20 | |
Hoisaleshwara Madan V S | 22356ed | 2013-12-26 14:20:09 +0530 | [diff] [blame] | 21 | class ServerAddressesTestJSON(base.BaseV2ComputeTest): |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 22 | |
| 23 | @classmethod |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 24 | def setup_credentials(cls): |
Salvatore Orlando | 5a33724 | 2014-01-15 22:49:22 +0000 | [diff] [blame] | 25 | # This test module might use a network and a subnet |
| 26 | cls.set_network_resources(network=True, subnet=True) |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 27 | super(ServerAddressesTestJSON, cls).setup_credentials() |
| 28 | |
| 29 | @classmethod |
| 30 | def setup_clients(cls): |
| 31 | super(ServerAddressesTestJSON, cls).setup_clients() |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 32 | cls.client = cls.servers_client |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 33 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 34 | @classmethod |
| 35 | def resource_setup(cls): |
| 36 | super(ServerAddressesTestJSON, cls).resource_setup() |
| 37 | |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 38 | cls.server = cls.create_test_server(wait_until='ACTIVE') |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 39 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 40 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 41 | @decorators.idempotent_id('6eb718c0-02d9-4d5e-acd1-4e0c269cef39') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 42 | @utils.services('network') |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 43 | def test_list_server_addresses(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 44 | # All public and private addresses for |
| 45 | # a server should be returned |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 46 | |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame] | 47 | addresses = self.client.list_addresses(self.server['id'])['addresses'] |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 48 | |
| 49 | # We do not know the exact network configuration, but an instance |
| 50 | # should at least have a single public or private address |
zhufl | 9d2ebc4 | 2017-06-12 11:09:09 +0800 | [diff] [blame] | 51 | self.assertNotEmpty(addresses) |
Béla Vancsics | b6dfa08 | 2017-03-01 10:44:58 +0100 | [diff] [blame] | 52 | for network_addresses in addresses.values(): |
Ferenc Horváth | 268ccce | 2017-06-08 12:39:02 +0200 | [diff] [blame] | 53 | self.assertNotEmpty(network_addresses) |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 54 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 55 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 56 | @decorators.idempotent_id('87bbc374-5538-4f64-b673-2b0e4443cc30') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 57 | @utils.services('network') |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 58 | def test_list_server_addresses_by_network(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 59 | # Providing a network type should filter |
| 60 | # the addresses return by that type |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 61 | |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame] | 62 | addresses = self.client.list_addresses(self.server['id'])['addresses'] |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 63 | |
| 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 Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 69 | addr = self.client.list_addresses_by_network(id, addr_type) |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 70 | |
| 71 | addr = addr[addr_type] |
| 72 | for address in addresses[addr_type]: |
| 73 | self.assertTrue(any([a for a in addr if a == address])) |