Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 1 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.compute import base |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 19 | from tempest import exceptions |
| 20 | from tempest.test import attr |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class 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 | |
| 51 | class FixedIPsTestJson(FixedIPsBase): |
| 52 | _interface = 'json' |
| 53 | |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame^] | 54 | @attr(type='gate') |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 55 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 59 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 60 | 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 Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame^] | 64 | @attr(type='gate') |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 65 | 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 Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame^] | 70 | @attr(type='gate') |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 71 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 76 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 77 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 83 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 84 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 90 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 91 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 99 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 100 | 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 | |
| 107 | class FixedIPsTestXml(FixedIPsTestJson): |
| 108 | _interface = 'xml' |