blob: 85b03e69c75d76e6a7a985894e36c6339f64c046 [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
JordanPf305c212013-06-25 18:43:19 +020019from tempest import config
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040020from tempest import exceptions
21from tempest.test import attr
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040022
23
Attila Fazekas2265bc42013-09-16 14:22:56 +020024class FixedIPsTestJson(base.BaseComputeAdminTest):
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040025 _interface = 'json'
26
JordanPf305c212013-06-25 18:43:19 +020027 CONF = config.TempestConfig()
28
Attila Fazekas2265bc42013-09-16 14:22:56 +020029 @classmethod
30 def setUpClass(cls):
31 super(FixedIPsTestJson, cls).setUpClass()
32 if cls.config.service_available.neutron:
33 msg = ("%s skipped as neutron is available" % cls.__name__)
34 raise cls.skipException(msg)
35 cls.client = cls.os_adm.fixed_ips_client
36 cls.non_admin_client = cls.fixed_ips_client
37 resp, server = cls.create_server(wait_until='ACTIVE')
38 resp, server = cls.servers_client.get_server(server['id'])
39 for ip_set in server['addresses']:
40 for ip in server['addresses'][ip_set]:
41 if ip['OS-EXT-IPS:type'] == 'fixed':
42 cls.ip = ip['addr']
43 break
44 if cls.ip:
45 break
46
Giulio Fidenteba3985a2013-05-29 01:46:36 +020047 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040048 def test_list_fixed_ip_details(self):
49 resp, fixed_ip = self.client.get_fixed_ip_details(self.ip)
50 self.assertEqual(fixed_ip['address'], self.ip)
51
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040052 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040053 def test_list_fixed_ip_details_with_non_admin_user(self):
54 self.assertRaises(exceptions.Unauthorized,
55 self.non_admin_client.get_fixed_ip_details, self.ip)
56
Giulio Fidenteba3985a2013-05-29 01:46:36 +020057 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040058 def test_set_reserve(self):
59 body = {"reserve": "None"}
60 resp, body = self.client.reserve_fixed_ip(self.ip, body)
61 self.assertEqual(resp.status, 202)
62
Giulio Fidenteba3985a2013-05-29 01:46:36 +020063 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040064 def test_set_unreserve(self):
65 body = {"unreserve": "None"}
66 resp, body = self.client.reserve_fixed_ip(self.ip, body)
67 self.assertEqual(resp.status, 202)
68
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040069 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040070 def test_set_reserve_with_non_admin_user(self):
71 body = {"reserve": "None"}
72 self.assertRaises(exceptions.Unauthorized,
73 self.non_admin_client.reserve_fixed_ip,
74 self.ip, body)
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_unreserve_with_non_admin_user(self):
78 body = {"unreserve": "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_reserve_with_invalid_ip(self):
85 # NOTE(maurosr): since this exercises the same code snippet, we do it
86 # only for reserve action
87 body = {"reserve": "None"}
88 self.assertRaises(exceptions.NotFound,
89 self.client.reserve_fixed_ip,
90 "my.invalid.ip", body)
91
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040092 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040093 def test_fixed_ip_with_invalid_action(self):
94 body = {"invalid_action": "None"}
95 self.assertRaises(exceptions.BadRequest,
96 self.client.reserve_fixed_ip,
97 self.ip, body)
98
99
100class FixedIPsTestXml(FixedIPsTestJson):
101 _interface = 'xml'