blob: a594f6cfe5b0d2df04d32de93b6e3ec8a61ba130 [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Matthew Treinisha83a16e2012-12-07 13:44:02 -050019from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103020from tempest.test import attr
Daryl Walleck2148b622012-02-22 00:42:06 -060021
22
ivan-zhuf2b00502013-10-18 10:06:52 +080023class ServerAddressesTest(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010024 _interface = 'json'
Daryl Walleck2148b622012-02-22 00:42:06 -060025
26 @classmethod
27 def setUpClass(cls):
Jay Pipesf38eaac2012-06-21 13:37:35 -040028 super(ServerAddressesTest, cls).setUpClass()
Jay Pipes13b479b2012-06-11 14:52:27 -040029 cls.client = cls.servers_client
Daryl Walleck2148b622012-02-22 00:42:06 -060030
Mauro S. M. Rodrigues0a1bdff2013-03-11 11:41:18 -040031 resp, cls.server = cls.create_server(wait_until='ACTIVE')
Daryl Walleck2148b622012-02-22 00:42:06 -060032
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040033 @attr(type=['negative', 'gate'])
Daryl Walleck2148b622012-02-22 00:42:06 -060034 def test_list_server_addresses_invalid_server_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050035 # List addresses request should fail if server id not in system
Chris Yeohe04628e2013-02-25 17:12:21 +103036 self.assertRaises(exceptions.NotFound, self.client.list_addresses,
37 '999')
Daryl Walleck2148b622012-02-22 00:42:06 -060038
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040039 @attr(type=['negative', 'gate'])
Daryl Walleck2148b622012-02-22 00:42:06 -060040 def test_list_server_addresses_by_network_neg(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050041 # List addresses by network should fail if network name not valid
Chris Yeohe04628e2013-02-25 17:12:21 +103042 self.assertRaises(exceptions.NotFound,
43 self.client.list_addresses_by_network,
44 self.server['id'], 'invalid')
Daryl Walleck2148b622012-02-22 00:42:06 -060045
Giampaolo Lauriacb9209d2013-05-17 13:39:25 -040046 @attr(type='smoke')
Daryl Walleck2148b622012-02-22 00:42:06 -060047 def test_list_server_addresses(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050048 # All public and private addresses for
49 # a server should be returned
Daryl Walleck2148b622012-02-22 00:42:06 -060050
51 resp, addresses = self.client.list_addresses(self.server['id'])
52 self.assertEqual('200', resp['status'])
53
54 # We do not know the exact network configuration, but an instance
55 # should at least have a single public or private address
Tiago Mello7b1f4022013-01-30 17:07:18 -050056 self.assertTrue(len(addresses) >= 1)
Julien Danjou24ea4ad2012-04-11 16:15:00 +020057 for network_name, network_addresses in addresses.iteritems():
Tiago Mello7b1f4022013-01-30 17:07:18 -050058 self.assertTrue(len(network_addresses) >= 1)
Julien Danjou24ea4ad2012-04-11 16:15:00 +020059 for address in network_addresses:
60 self.assertTrue(address['addr'])
61 self.assertTrue(address['version'])
Daryl Walleck2148b622012-02-22 00:42:06 -060062
Giampaolo Lauriacb9209d2013-05-17 13:39:25 -040063 @attr(type='smoke')
Daryl Walleck2148b622012-02-22 00:42:06 -060064 def test_list_server_addresses_by_network(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050065 # Providing a network type should filter
66 # the addresses return by that type
Daryl Walleck2148b622012-02-22 00:42:06 -060067
68 resp, addresses = self.client.list_addresses(self.server['id'])
69
70 # Once again we don't know the environment's exact network config,
71 # but the response for each individual network should be the same
72 # as the partial result of the full address list
73 id = self.server['id']
74 for addr_type in addresses:
75 resp, addr = self.client.list_addresses_by_network(id, addr_type)
76 self.assertEqual('200', resp['status'])
77
78 addr = addr[addr_type]
79 for address in addresses[addr_type]:
80 self.assertTrue(any([a for a in addr if a == address]))
Matthew Treinisha568b102013-03-04 17:01:49 -050081
82
83class ServerAddressesTestXML(ServerAddressesTest):
84 _interface = 'xml'