blob: 766589e684cb3ac2ea3c3d52e8c266b4ac6aff0e [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
ivan-zhuf2b00502013-10-18 10:06:52 +080023class FixedIPsTestJson(base.BaseV2ComputeAdminTest):
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040024 _interface = 'json'
25
Attila Fazekas2265bc42013-09-16 14:22:56 +020026 @classmethod
27 def setUpClass(cls):
28 super(FixedIPsTestJson, cls).setUpClass()
29 if cls.config.service_available.neutron:
30 msg = ("%s skipped as neutron is available" % cls.__name__)
31 raise cls.skipException(msg)
32 cls.client = cls.os_adm.fixed_ips_client
33 cls.non_admin_client = cls.fixed_ips_client
34 resp, server = cls.create_server(wait_until='ACTIVE')
35 resp, server = cls.servers_client.get_server(server['id'])
36 for ip_set in server['addresses']:
37 for ip in server['addresses'][ip_set]:
38 if ip['OS-EXT-IPS:type'] == 'fixed':
39 cls.ip = ip['addr']
40 break
41 if cls.ip:
42 break
43
Giulio Fidenteba3985a2013-05-29 01:46:36 +020044 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040045 def test_list_fixed_ip_details(self):
46 resp, fixed_ip = self.client.get_fixed_ip_details(self.ip)
47 self.assertEqual(fixed_ip['address'], self.ip)
48
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040049 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040050 def test_list_fixed_ip_details_with_non_admin_user(self):
51 self.assertRaises(exceptions.Unauthorized,
52 self.non_admin_client.get_fixed_ip_details, self.ip)
53
Giulio Fidenteba3985a2013-05-29 01:46:36 +020054 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040055 def test_set_reserve(self):
56 body = {"reserve": "None"}
57 resp, body = self.client.reserve_fixed_ip(self.ip, body)
58 self.assertEqual(resp.status, 202)
59
Giulio Fidenteba3985a2013-05-29 01:46:36 +020060 @attr(type='gate')
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040061 def test_set_unreserve(self):
62 body = {"unreserve": "None"}
63 resp, body = self.client.reserve_fixed_ip(self.ip, body)
64 self.assertEqual(resp.status, 202)
65
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040066 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040067 def test_set_reserve_with_non_admin_user(self):
68 body = {"reserve": "None"}
69 self.assertRaises(exceptions.Unauthorized,
70 self.non_admin_client.reserve_fixed_ip,
71 self.ip, body)
72
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040073 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040074 def test_set_unreserve_with_non_admin_user(self):
75 body = {"unreserve": "None"}
76 self.assertRaises(exceptions.Unauthorized,
77 self.non_admin_client.reserve_fixed_ip,
78 self.ip, body)
79
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040080 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040081 def test_set_reserve_with_invalid_ip(self):
82 # NOTE(maurosr): since this exercises the same code snippet, we do it
83 # only for reserve action
84 body = {"reserve": "None"}
85 self.assertRaises(exceptions.NotFound,
86 self.client.reserve_fixed_ip,
87 "my.invalid.ip", body)
88
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040089 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesf5166402013-04-01 10:25:26 -040090 def test_fixed_ip_with_invalid_action(self):
91 body = {"invalid_action": "None"}
92 self.assertRaises(exceptions.BadRequest,
93 self.client.reserve_fixed_ip,
94 self.ip, body)
95
96
97class FixedIPsTestXml(FixedIPsTestJson):
98 _interface = 'xml'