blob: 47a38b195684a7bdb23c29138c8b512ea563b93b [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
18from tempest.common.utils.data_utils import rand_name
19from tempest import exceptions
20from tempest.test import attr
21from tempest.tests.compute import base
22
23
24class MultipleCreateTestJSON(base.BaseComputeTest):
25 _interface = 'json'
26 _name = 'multiple-create-test'
27
28 def _get_created_servers(self, name):
29 """Get servers created which name match with name param."""
30 resp, body = self.servers_client.list_servers()
31 servers = body['servers']
32 servers_created = []
33 for server in servers:
34 if server['name'].startswith(name):
35 servers_created.append(server)
36 return servers_created
37
38 def _generate_name(self):
39 return rand_name(self._name)
40
41 def _create_multiple_servers(self, name=None, wait_until=None, **kwargs):
42 """
43 This is the right way to create_multiple servers and manage to get the
44 created servers into the servers list to be cleaned up after all.
45 """
46 kwargs['name'] = kwargs.get('name', self._generate_name())
47 resp, body = self.create_server(**kwargs)
48 created_servers = self._get_created_servers(kwargs['name'])
49 # NOTE(maurosr): append it to cls.servers list from base.BaseCompute
50 # class.
Mitsuhiko Yamazaki1d615412013-04-23 12:05:59 +090051 self.servers.extend(created_servers)
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050052 # NOTE(maurosr): get a server list, check status of the ones with names
53 # that match and wait for them become active. At a first look, since
54 # they are building in parallel, wait inside the for doesn't seem be
55 # harmful to the performance
56 if wait_until is not None:
57 for server in created_servers:
58 self.servers_client.wait_for_server_status(server['id'],
59 wait_until)
60
61 return resp, body
62
63 @attr(type='positive')
64 def test_multiple_create(self):
65 resp, body = self._create_multiple_servers(wait_until='ACTIVE',
66 min_count=1,
67 max_count=2)
68 # NOTE(maurosr): do status response check and also make sure that
69 # reservation_id is not in the response body when the request send
70 # contains return_reservation_id=False
71 self.assertEqual('202', resp['status'])
72 self.assertFalse('reservation_id' in body)
73
74 @attr(type='negative')
75 def test_min_count_less_than_one(self):
76 invalid_min_count = 0
77 self.assertRaises(exceptions.BadRequest, self._create_multiple_servers,
78 min_count=invalid_min_count)
79
80 @attr(type='negative')
81 def test_min_count_non_integer(self):
82 invalid_min_count = 2.5
83 self.assertRaises(exceptions.BadRequest, self._create_multiple_servers,
84 min_count=invalid_min_count)
85
86 @attr(type='negative')
87 def test_max_count_less_than_one(self):
88 invalid_max_count = 0
89 self.assertRaises(exceptions.BadRequest, self._create_multiple_servers,
90 max_count=invalid_max_count)
91
92 @attr(type='negative')
93 def test_max_count_non_integer(self):
94 invalid_max_count = 2.5
95 self.assertRaises(exceptions.BadRequest, self._create_multiple_servers,
96 max_count=invalid_max_count)
97
98 @attr(type='negative')
99 def test_max_count_less_than_min_count(self):
100 min_count = 3
101 max_count = 2
102 self.assertRaises(exceptions.BadRequest, self._create_multiple_servers,
103 min_count=min_count,
104 max_count=max_count)
105
106 @attr(type='positive')
107 def test_multiple_create_with_reservation_return(self):
108 resp, body = self._create_multiple_servers(wait_until='ACTIVE',
109 min_count=1,
110 max_count=2,
111 return_reservation_id=True)
112 self.assertTrue(resp['status'], 202)
113 self.assertIn('reservation_id', body)
114
115
116class MultipleCreateTestXML(MultipleCreateTestJSON):
117 _interface = 'xml'