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 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 23 | class FixedIPsTestJson(base.BaseV2ComputeAdminTest): |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 24 | _interface = 'json' |
| 25 | |
Attila Fazekas | 2265bc4 | 2013-09-16 14:22:56 +0200 | [diff] [blame] | 26 | @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 Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 44 | @attr(type='gate') |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 45 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 49 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 50 | 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 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_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 Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 60 | @attr(type='gate') |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 61 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 66 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 67 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 73 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 74 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 80 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 81 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 89 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 90 | 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 | |
| 97 | class FixedIPsTestXml(FixedIPsTestJson): |
| 98 | _interface = 'xml' |