Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [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 | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 19 | from tempest.common.utils.data_utils import rand_name |
| 20 | from tempest import exceptions |
| 21 | from tempest.test import attr |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class MultipleCreateTestJSON(base.BaseComputeTest): |
| 25 | _interface = 'json' |
| 26 | _name = 'multiple-create-test' |
| 27 | |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 28 | def _generate_name(self): |
| 29 | return rand_name(self._name) |
| 30 | |
| 31 | def _create_multiple_servers(self, name=None, wait_until=None, **kwargs): |
| 32 | """ |
| 33 | This is the right way to create_multiple servers and manage to get the |
| 34 | created servers into the servers list to be cleaned up after all. |
| 35 | """ |
| 36 | kwargs['name'] = kwargs.get('name', self._generate_name()) |
| 37 | resp, body = self.create_server(**kwargs) |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 38 | |
| 39 | return resp, body |
| 40 | |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 41 | @attr(type='gate') |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 42 | def test_multiple_create(self): |
| 43 | resp, body = self._create_multiple_servers(wait_until='ACTIVE', |
| 44 | min_count=1, |
| 45 | max_count=2) |
| 46 | # NOTE(maurosr): do status response check and also make sure that |
| 47 | # reservation_id is not in the response body when the request send |
| 48 | # contains return_reservation_id=False |
| 49 | self.assertEqual('202', resp['status']) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame^] | 50 | self.assertNotIn('reservation_id', body) |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 51 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 52 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 53 | def test_min_count_less_than_one(self): |
| 54 | invalid_min_count = 0 |
| 55 | self.assertRaises(exceptions.BadRequest, self._create_multiple_servers, |
| 56 | min_count=invalid_min_count) |
| 57 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 58 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 59 | def test_min_count_non_integer(self): |
| 60 | invalid_min_count = 2.5 |
| 61 | self.assertRaises(exceptions.BadRequest, self._create_multiple_servers, |
| 62 | min_count=invalid_min_count) |
| 63 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 64 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 65 | def test_max_count_less_than_one(self): |
| 66 | invalid_max_count = 0 |
| 67 | self.assertRaises(exceptions.BadRequest, self._create_multiple_servers, |
| 68 | max_count=invalid_max_count) |
| 69 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 70 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 71 | def test_max_count_non_integer(self): |
| 72 | invalid_max_count = 2.5 |
| 73 | self.assertRaises(exceptions.BadRequest, self._create_multiple_servers, |
| 74 | max_count=invalid_max_count) |
| 75 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 76 | @attr(type=['negative', 'gate']) |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 77 | def test_max_count_less_than_min_count(self): |
| 78 | min_count = 3 |
| 79 | max_count = 2 |
| 80 | self.assertRaises(exceptions.BadRequest, self._create_multiple_servers, |
| 81 | min_count=min_count, |
| 82 | max_count=max_count) |
| 83 | |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 84 | @attr(type='gate') |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 85 | def test_multiple_create_with_reservation_return(self): |
| 86 | resp, body = self._create_multiple_servers(wait_until='ACTIVE', |
| 87 | min_count=1, |
| 88 | max_count=2, |
| 89 | return_reservation_id=True) |
| 90 | self.assertTrue(resp['status'], 202) |
| 91 | self.assertIn('reservation_id', body) |
| 92 | |
| 93 | |
| 94 | class MultipleCreateTestXML(MultipleCreateTestJSON): |
| 95 | _interface = 'xml' |