blob: c69f68dd4d413264c2d0174d4356f7c5929b2e63 [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# 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
Jay Pipes13b479b2012-06-11 14:52:27 -040018from tempest.common.utils.data_utils import rand_name
Matthew Treinisha83a16e2012-12-07 13:44:02 -050019from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103020from tempest.test import attr
Attila Fazekas19044d52013-02-16 07:35:06 +010021from tempest.tests.compute import base
Daryl Walleck2148b622012-02-22 00:42:06 -060022
23
Attila Fazekas19044d52013-02-16 07:35:06 +010024class ServerAddressesTest(base.BaseComputeTest):
25 _interface = 'json'
Daryl Walleck2148b622012-02-22 00:42:06 -060026
27 @classmethod
28 def setUpClass(cls):
Jay Pipesf38eaac2012-06-21 13:37:35 -040029 super(ServerAddressesTest, cls).setUpClass()
Jay Pipes13b479b2012-06-11 14:52:27 -040030 cls.client = cls.servers_client
Daryl Walleck2148b622012-02-22 00:42:06 -060031
32 cls.name = rand_name('server')
33 resp, cls.server = cls.client.create_server(cls.name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080034 cls.image_ref,
35 cls.flavor_ref)
Daryl Walleck2148b622012-02-22 00:42:06 -060036 cls.client.wait_for_server_status(cls.server['id'], 'ACTIVE')
37
38 @classmethod
39 def tearDownClass(cls):
40 cls.client.delete_server(cls.server['id'])
Jay Pipesf38eaac2012-06-21 13:37:35 -040041 super(ServerAddressesTest, cls).tearDownClass()
Daryl Walleck2148b622012-02-22 00:42:06 -060042
43 @attr(type='negative', category='server-addresses')
44 def test_list_server_addresses_invalid_server_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050045 # List addresses request should fail if server id not in system
Chris Yeohe04628e2013-02-25 17:12:21 +103046 self.assertRaises(exceptions.NotFound, self.client.list_addresses,
47 '999')
Daryl Walleck2148b622012-02-22 00:42:06 -060048
49 @attr(type='negative', category='server-addresses')
50 def test_list_server_addresses_by_network_neg(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050051 # List addresses by network should fail if network name not valid
Chris Yeohe04628e2013-02-25 17:12:21 +103052 self.assertRaises(exceptions.NotFound,
53 self.client.list_addresses_by_network,
54 self.server['id'], 'invalid')
Daryl Walleck2148b622012-02-22 00:42:06 -060055
56 @attr(type='smoke', category='server-addresses')
57 def test_list_server_addresses(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050058 # All public and private addresses for
59 # a server should be returned
Daryl Walleck2148b622012-02-22 00:42:06 -060060
61 resp, addresses = self.client.list_addresses(self.server['id'])
62 self.assertEqual('200', resp['status'])
63
64 # We do not know the exact network configuration, but an instance
65 # should at least have a single public or private address
Tiago Mello7b1f4022013-01-30 17:07:18 -050066 self.assertTrue(len(addresses) >= 1)
Julien Danjou24ea4ad2012-04-11 16:15:00 +020067 for network_name, network_addresses in addresses.iteritems():
Tiago Mello7b1f4022013-01-30 17:07:18 -050068 self.assertTrue(len(network_addresses) >= 1)
Julien Danjou24ea4ad2012-04-11 16:15:00 +020069 for address in network_addresses:
70 self.assertTrue(address['addr'])
71 self.assertTrue(address['version'])
Daryl Walleck2148b622012-02-22 00:42:06 -060072
73 @attr(type='smoke', category='server-addresses')
74 def test_list_server_addresses_by_network(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050075 # Providing a network type should filter
76 # the addresses return by that type
Daryl Walleck2148b622012-02-22 00:42:06 -060077
78 resp, addresses = self.client.list_addresses(self.server['id'])
79
80 # Once again we don't know the environment's exact network config,
81 # but the response for each individual network should be the same
82 # as the partial result of the full address list
83 id = self.server['id']
84 for addr_type in addresses:
85 resp, addr = self.client.list_addresses_by_network(id, addr_type)
86 self.assertEqual('200', resp['status'])
87
88 addr = addr[addr_type]
89 for address in addresses[addr_type]:
90 self.assertTrue(any([a for a in addr if a == address]))