blob: f201cf73a4d7487aa36650b87097e311186e6675 [file] [log] [blame]
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 IBM Corp
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
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040019from tempest import exceptions
20from tempest.test import attr
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040021
22
23class FixedIPsBase(base.BaseComputeAdminTest):
24 _interface = 'json'
25 ip = None
26
27 @classmethod
28 def setUpClass(cls):
29 super(FixedIPsBase, cls).setUpClass()
30 # NOTE(maurosr): The idea here is: the server creation is just an
31 # auxiliary element to the ip details or reservation, there was no way
32 # (at least none in my mind) to get an valid and existing ip except
33 # by creating a server and using its ip. So the intention is to create
34 # fewer server possible (one) and use it to both: json and xml tests.
35 # This decreased time to run both tests, in my test machine, from 53
36 # secs to 29 (agains 23 secs when running only json tests)
37 if cls.ip is None:
38 cls.client = cls.os_adm.fixed_ips_client
39 cls.non_admin_client = cls.fixed_ips_client
40 resp, server = cls.create_server(wait_until='ACTIVE')
41 resp, server = cls.servers_client.get_server(server['id'])
42 for ip_set in server['addresses']:
43 for ip in server['addresses'][ip_set]:
44 if ip['OS-EXT-IPS:type'] == 'fixed':
45 cls.ip = ip['addr']
46 break
47 if cls.ip:
48 break
49
50
51class FixedIPsTestJson(FixedIPsBase):
52 _interface = 'json'
53
Giulio Fidenteba3985a2013-05-29 01:46:36 +020054 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040055 def test_list_fixed_ip_details(self):
56 resp, fixed_ip = self.client.get_fixed_ip_details(self.ip)
57 self.assertEqual(fixed_ip['address'], self.ip)
58
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040059 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040060 def test_list_fixed_ip_details_with_non_admin_user(self):
61 self.assertRaises(exceptions.Unauthorized,
62 self.non_admin_client.get_fixed_ip_details, self.ip)
63
Giulio Fidenteba3985a2013-05-29 01:46:36 +020064 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040065 def test_set_reserve(self):
66 body = {"reserve": "None"}
67 resp, body = self.client.reserve_fixed_ip(self.ip, body)
68 self.assertEqual(resp.status, 202)
69
Giulio Fidenteba3985a2013-05-29 01:46:36 +020070 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040071 def test_set_unreserve(self):
72 body = {"unreserve": "None"}
73 resp, body = self.client.reserve_fixed_ip(self.ip, body)
74 self.assertEqual(resp.status, 202)
75
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040076 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040077 def test_set_reserve_with_non_admin_user(self):
78 body = {"reserve": "None"}
79 self.assertRaises(exceptions.Unauthorized,
80 self.non_admin_client.reserve_fixed_ip,
81 self.ip, body)
82
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040083 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040084 def test_set_unreserve_with_non_admin_user(self):
85 body = {"unreserve": "None"}
86 self.assertRaises(exceptions.Unauthorized,
87 self.non_admin_client.reserve_fixed_ip,
88 self.ip, body)
89
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040090 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040091 def test_set_reserve_with_invalid_ip(self):
92 # NOTE(maurosr): since this exercises the same code snippet, we do it
93 # only for reserve action
94 body = {"reserve": "None"}
95 self.assertRaises(exceptions.NotFound,
96 self.client.reserve_fixed_ip,
97 "my.invalid.ip", body)
98
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040099 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -0400100 def test_fixed_ip_with_invalid_action(self):
101 body = {"invalid_action": "None"}
102 self.assertRaises(exceptions.BadRequest,
103 self.client.reserve_fixed_ip,
104 self.ip, body)
105
106
107class FixedIPsTestXml(FixedIPsTestJson):
108 _interface = 'xml'