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 |
JordanP | f305c21 | 2013-06-25 18:43:19 +0200 | [diff] [blame] | 19 | from tempest import config |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 20 | from tempest import exceptions |
| 21 | from tempest.test import attr |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 22 | |
| 23 | |
Attila Fazekas | 2265bc4 | 2013-09-16 14:22:56 +0200 | [diff] [blame^] | 24 | class FixedIPsTestJson(base.BaseComputeAdminTest): |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 25 | _interface = 'json' |
| 26 | |
JordanP | f305c21 | 2013-06-25 18:43:19 +0200 | [diff] [blame] | 27 | CONF = config.TempestConfig() |
| 28 | |
Attila Fazekas | 2265bc4 | 2013-09-16 14:22:56 +0200 | [diff] [blame^] | 29 | @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 Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 47 | @attr(type='gate') |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 48 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 52 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 53 | 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 Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 57 | @attr(type='gate') |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 58 | 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 Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 63 | @attr(type='gate') |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 64 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 69 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 70 | 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 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_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 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_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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 92 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | f516640 | 2013-04-01 10:25:26 -0400 | [diff] [blame] | 93 | 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 | |
| 100 | class FixedIPsTestXml(FixedIPsTestJson): |
| 101 | _interface = 'xml' |