blob: 0af19c0ddeaba0ec62460190e9dc7e2fd58d1f3d [file] [log] [blame]
Abhijeet.Jain87dd4452014-04-23 15:51:23 +05301# Copyright 2014 NEC Technologies India Ltd.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.compute import base
17from tempest.common.utils import data_utils
18from tempest import test
19
20
21class ServerGroupTestJSON(base.BaseV2ComputeTest):
22 """
23 These tests check for the server-group APIs
24 They create/delete server-groups with different policies.
25 policies = affinity/anti-affinity
26 It also adds the tests for list and get details of server-groups
27 """
28 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010029 def resource_setup(cls):
30 super(ServerGroupTestJSON, cls).resource_setup()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053031 if not test.is_extension_enabled('os-server-groups', 'compute'):
32 msg = "os-server-groups extension is not enabled."
33 raise cls.skipException(msg)
34 cls.client = cls.servers_client
35 server_group_name = data_utils.rand_name('server-group')
36 cls.policy = ['affinity']
37
38 _, cls.created_server_group = cls.create_test_server_group(
39 server_group_name,
40 cls.policy)
41
42 def _create_server_group(self, name, policy):
43 # create the test server-group with given policy
44 server_group = {'name': name, 'policies': policy}
45 resp, body = self.create_test_server_group(name, policy)
46 self.assertEqual(200, resp.status)
47 for key in ['name', 'policies']:
48 self.assertEqual(server_group[key], body[key])
49 return body
50
51 def _delete_server_group(self, server_group):
52 # delete the test server-group
53 resp, _ = self.client.delete_server_group(server_group['id'])
54 self.assertEqual(204, resp.status)
55 # validation of server-group deletion
56 resp, server_group_list = self.client.list_server_groups()
57 self.assertEqual(200, resp.status)
58 self.assertNotIn(server_group, server_group_list)
59
60 def _create_delete_server_group(self, policy):
61 # Create and Delete the server-group with given policy
62 name = data_utils.rand_name('server-group')
63 server_group = self._create_server_group(name, policy)
64 self._delete_server_group(server_group)
65
66 @test.attr(type='gate')
67 def test_create_delete_server_group_with_affinity_policy(self):
68 # Create and Delete the server-group with affinity policy
69 self._create_delete_server_group(self.policy)
70
71 @test.attr(type='gate')
72 def test_create_delete_server_group_with_anti_affinity_policy(self):
73 # Create and Delete the server-group with anti-affinity policy
74 policy = ['anti-affinity']
75 self._create_delete_server_group(policy)
76
wingwjaf630da2014-05-30 09:21:30 +080077 @test.skip_because(bug="1324348")
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053078 @test.attr(type='gate')
79 def test_create_delete_server_group_with_multiple_policies(self):
80 # Create and Delete the server-group with multiple policies
81 policies = ['affinity', 'affinity']
82 self._create_delete_server_group(policies)
83
84 @test.attr(type='gate')
85 def test_create_delete_multiple_server_groups_with_same_name_policy(self):
86 # Create and Delete the server-groups with same name and same policy
87 server_groups = []
88 server_group_name = data_utils.rand_name('server-group')
89 for i in range(0, 2):
90 server_groups.append(self._create_server_group(server_group_name,
91 self.policy))
92 for key in ['name', 'policies']:
93 self.assertEqual(server_groups[0][key], server_groups[1][key])
94 self.assertNotEqual(server_groups[0]['id'], server_groups[1]['id'])
95
96 for i in range(0, 2):
97 self._delete_server_group(server_groups[i])
98
99 @test.attr(type='gate')
100 def test_get_server_group(self):
101 # Get the server-group
102 resp, body = self.client.get_server_group(
103 self.created_server_group['id'])
104 self.assertEqual(200, resp.status)
105 self.assertEqual(self.created_server_group, body)
106
107 @test.attr(type='gate')
108 def test_list_server_groups(self):
109 # List the server-group
110 resp, body = self.client.list_server_groups()
111 self.assertEqual(200, resp.status)
112 self.assertIn(self.created_server_group, body)