blob: edfafeccbc2cc9966cd51869a852dc9096d281bf [file] [log] [blame]
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -05001# 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. Rodriguesc5da4f42013-03-04 23:57:10 -050019from tempest.common.utils.data_utils import rand_name
20from tempest import exceptions
21from tempest.test import attr
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050022
23
24class MultipleCreateTestJSON(base.BaseComputeTest):
25 _interface = 'json'
26 _name = 'multiple-create-test'
27
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050028 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. Rodriguesc5da4f42013-03-04 23:57:10 -050038
39 return resp, body
40
Giulio Fidenteba3985a2013-05-29 01:46:36 +020041 @attr(type='gate')
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050042 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 Fazekase191cb12013-07-29 06:41:52 +020050 self.assertNotIn('reservation_id', body)
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050051
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040052 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050053 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 Lauriae9c77022013-05-22 01:23:58 -040058 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050059 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 Lauriae9c77022013-05-22 01:23:58 -040064 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050065 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 Lauriae9c77022013-05-22 01:23:58 -040070 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050071 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 Lauriae9c77022013-05-22 01:23:58 -040076 @attr(type=['negative', 'gate'])
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050077 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 Fidenteba3985a2013-05-29 01:46:36 +020084 @attr(type='gate')
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050085 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
94class MultipleCreateTestXML(MultipleCreateTestJSON):
95 _interface = 'xml'