blob: 846bf3e55cf8307b696b4e109755667e88a6a4df [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
Matt Riedemann3c7f98f2014-02-18 13:21:43 -080017from tempest import config
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053018from tempest import test
Daryl Walleck2148b622012-02-22 00:42:06 -060019
Matt Riedemann3c7f98f2014-02-18 13:21:43 -080020CONF = config.CONF
21
Daryl Walleck2148b622012-02-22 00:42:06 -060022
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053023class ServerAddressesTestJSON(base.BaseV2ComputeTest):
Daryl Walleck2148b622012-02-22 00:42:06 -060024
25 @classmethod
26 def setUpClass(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000027 # This test module might use a network and a subnet
28 cls.set_network_resources(network=True, subnet=True)
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053029 super(ServerAddressesTestJSON, cls).setUpClass()
Jay Pipes13b479b2012-06-11 14:52:27 -040030 cls.client = cls.servers_client
Daryl Walleck2148b622012-02-22 00:42:06 -060031
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090032 resp, cls.server = cls.create_test_server(wait_until='ACTIVE')
Daryl Walleck2148b622012-02-22 00:42:06 -060033
Matt Riedemann3c7f98f2014-02-18 13:21:43 -080034 @test.skip_because(bug="1210483",
35 condition=CONF.service_available.neutron)
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053036 @test.attr(type='smoke')
Matthew Treinish2df97482014-06-13 15:02:26 -040037 @test.services('network')
Daryl Walleck2148b622012-02-22 00:42:06 -060038 def test_list_server_addresses(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050039 # All public and private addresses for
40 # a server should be returned
Daryl Walleck2148b622012-02-22 00:42:06 -060041
42 resp, addresses = self.client.list_addresses(self.server['id'])
43 self.assertEqual('200', resp['status'])
44
45 # We do not know the exact network configuration, but an instance
46 # should at least have a single public or private address
Tiago Mello7b1f4022013-01-30 17:07:18 -050047 self.assertTrue(len(addresses) >= 1)
Julien Danjou24ea4ad2012-04-11 16:15:00 +020048 for network_name, network_addresses in addresses.iteritems():
Tiago Mello7b1f4022013-01-30 17:07:18 -050049 self.assertTrue(len(network_addresses) >= 1)
Julien Danjou24ea4ad2012-04-11 16:15:00 +020050 for address in network_addresses:
51 self.assertTrue(address['addr'])
52 self.assertTrue(address['version'])
Daryl Walleck2148b622012-02-22 00:42:06 -060053
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053054 @test.attr(type='smoke')
Matthew Treinish2df97482014-06-13 15:02:26 -040055 @test.services('network')
Daryl Walleck2148b622012-02-22 00:42:06 -060056 def test_list_server_addresses_by_network(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050057 # Providing a network type should filter
58 # the addresses return by that type
Daryl Walleck2148b622012-02-22 00:42:06 -060059
60 resp, addresses = self.client.list_addresses(self.server['id'])
61
62 # Once again we don't know the environment's exact network config,
63 # but the response for each individual network should be the same
64 # as the partial result of the full address list
65 id = self.server['id']
66 for addr_type in addresses:
67 resp, addr = self.client.list_addresses_by_network(id, addr_type)
68 self.assertEqual('200', resp['status'])
69
70 addr = addr[addr_type]
71 for address in addresses[addr_type]:
72 self.assertTrue(any([a for a in addr if a == address]))
Matthew Treinisha568b102013-03-04 17:01:49 -050073
74
Hoisaleshwara Madan V S22356ed2013-12-26 14:20:09 +053075class ServerAddressesTestXML(ServerAddressesTestJSON):
Matthew Treinisha568b102013-03-04 17:01:49 -050076 _interface = 'xml'