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 |
Hoisaleshwara Madan V S | 22356ed | 2013-12-26 14:20:09 +0530 | [diff] [blame] | 17 | from tempest import test |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 18 | |
| 19 | |
Hoisaleshwara Madan V S | 22356ed | 2013-12-26 14:20:09 +0530 | [diff] [blame] | 20 | class ServerAddressesTestJSON(base.BaseV2ComputeTest): |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 21 | |
| 22 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 23 | def resource_setup(cls): |
Salvatore Orlando | 5a33724 | 2014-01-15 22:49:22 +0000 | [diff] [blame] | 24 | # This test module might use a network and a subnet |
| 25 | cls.set_network_resources(network=True, subnet=True) |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 26 | super(ServerAddressesTestJSON, cls).resource_setup() |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 27 | cls.client = cls.servers_client |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 28 | |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame^] | 29 | cls.server = cls.create_test_server(wait_until='ACTIVE') |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 30 | |
Hoisaleshwara Madan V S | 22356ed | 2013-12-26 14:20:09 +0530 | [diff] [blame] | 31 | @test.attr(type='smoke') |
Matthew Treinish | 2df9748 | 2014-06-13 15:02:26 -0400 | [diff] [blame] | 32 | @test.services('network') |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 33 | def test_list_server_addresses(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 34 | # All public and private addresses for |
| 35 | # a server should be returned |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 36 | |
| 37 | resp, addresses = self.client.list_addresses(self.server['id']) |
| 38 | self.assertEqual('200', resp['status']) |
| 39 | |
| 40 | # We do not know the exact network configuration, but an instance |
| 41 | # should at least have a single public or private address |
Tiago Mello | 7b1f402 | 2013-01-30 17:07:18 -0500 | [diff] [blame] | 42 | self.assertTrue(len(addresses) >= 1) |
Julien Danjou | 24ea4ad | 2012-04-11 16:15:00 +0200 | [diff] [blame] | 43 | for network_name, network_addresses in addresses.iteritems(): |
Tiago Mello | 7b1f402 | 2013-01-30 17:07:18 -0500 | [diff] [blame] | 44 | self.assertTrue(len(network_addresses) >= 1) |
Julien Danjou | 24ea4ad | 2012-04-11 16:15:00 +0200 | [diff] [blame] | 45 | for address in network_addresses: |
| 46 | self.assertTrue(address['addr']) |
| 47 | self.assertTrue(address['version']) |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 48 | |
Hoisaleshwara Madan V S | 22356ed | 2013-12-26 14:20:09 +0530 | [diff] [blame] | 49 | @test.attr(type='smoke') |
Matthew Treinish | 2df9748 | 2014-06-13 15:02:26 -0400 | [diff] [blame] | 50 | @test.services('network') |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 51 | def test_list_server_addresses_by_network(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 52 | # Providing a network type should filter |
| 53 | # the addresses return by that type |
Daryl Walleck | 2148b62 | 2012-02-22 00:42:06 -0600 | [diff] [blame] | 54 | |
| 55 | resp, addresses = self.client.list_addresses(self.server['id']) |
| 56 | |
| 57 | # Once again we don't know the environment's exact network config, |
| 58 | # but the response for each individual network should be the same |
| 59 | # as the partial result of the full address list |
| 60 | id = self.server['id'] |
| 61 | for addr_type in addresses: |
| 62 | resp, addr = self.client.list_addresses_by_network(id, addr_type) |
| 63 | self.assertEqual('200', resp['status']) |
| 64 | |
| 65 | addr = addr[addr_type] |
| 66 | for address in addresses[addr_type]: |
| 67 | self.assertTrue(any([a for a in addr if a == address])) |