blob: 0da7912ad21386203f3e1e34fc54fede1345fe22 [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
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050016from tempest_lib import decorators
17
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053018from tempest.api.compute import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053020from tempest import test
21
22
23class ServerGroupTestJSON(base.BaseV2ComputeTest):
24 """
25 These tests check for the server-group APIs
26 They create/delete server-groups with different policies.
27 policies = affinity/anti-affinity
28 It also adds the tests for list and get details of server-groups
29 """
30 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053031 def skip_checks(cls):
32 super(ServerGroupTestJSON, cls).skip_checks()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053033 if not test.is_extension_enabled('os-server-groups', 'compute'):
34 msg = "os-server-groups extension is not enabled."
35 raise cls.skipException(msg)
Rohan Kanade60b73092015-02-04 17:58:19 +053036
37 @classmethod
38 def setup_clients(cls):
39 super(ServerGroupTestJSON, cls).setup_clients()
Ken'ichi Ohmichi7ca54b82015-07-07 01:10:26 +000040 cls.client = cls.server_groups_client
Rohan Kanade60b73092015-02-04 17:58:19 +053041
42 @classmethod
43 def resource_setup(cls):
44 super(ServerGroupTestJSON, cls).resource_setup()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053045 server_group_name = data_utils.rand_name('server-group')
46 cls.policy = ['affinity']
47
David Kranzae99b9a2015-02-16 13:37:01 -050048 cls.created_server_group = cls.create_test_server_group(
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053049 server_group_name,
50 cls.policy)
51
52 def _create_server_group(self, name, policy):
53 # create the test server-group with given policy
54 server_group = {'name': name, 'policies': policy}
David Kranzae99b9a2015-02-16 13:37:01 -050055 body = self.create_test_server_group(name, policy)
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053056 for key in ['name', 'policies']:
57 self.assertEqual(server_group[key], body[key])
58 return body
59
60 def _delete_server_group(self, server_group):
61 # delete the test server-group
David Kranzae99b9a2015-02-16 13:37:01 -050062 self.client.delete_server_group(server_group['id'])
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053063 # validation of server-group deletion
ghanshyam2dc13452015-08-24 17:39:25 +090064 server_group_list = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053065 self.assertNotIn(server_group, server_group_list)
66
67 def _create_delete_server_group(self, policy):
68 # Create and Delete the server-group with given policy
69 name = data_utils.rand_name('server-group')
70 server_group = self._create_server_group(name, policy)
71 self._delete_server_group(server_group)
72
Chris Hoge7579c1a2015-02-26 14:12:15 -080073 @test.idempotent_id('5dc57eda-35b7-4af7-9e5f-3c2be3d2d68b')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053074 def test_create_delete_server_group_with_affinity_policy(self):
75 # Create and Delete the server-group with affinity policy
76 self._create_delete_server_group(self.policy)
77
Chris Hoge7579c1a2015-02-26 14:12:15 -080078 @test.idempotent_id('3645a102-372f-4140-afad-13698d850d23')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053079 def test_create_delete_server_group_with_anti_affinity_policy(self):
80 # Create and Delete the server-group with anti-affinity policy
81 policy = ['anti-affinity']
82 self._create_delete_server_group(policy)
83
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050084 @decorators.skip_because(bug="1324348")
Chris Hoge7579c1a2015-02-26 14:12:15 -080085 @test.idempotent_id('6d9bae05-eb32-425d-a673-e14e1b1c6306')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053086 def test_create_delete_server_group_with_multiple_policies(self):
87 # Create and Delete the server-group with multiple policies
88 policies = ['affinity', 'affinity']
89 self._create_delete_server_group(policies)
90
Chris Hoge7579c1a2015-02-26 14:12:15 -080091 @test.idempotent_id('154dc5a4-a2fe-44b5-b99e-f15806a4a113')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053092 def test_create_delete_multiple_server_groups_with_same_name_policy(self):
93 # Create and Delete the server-groups with same name and same policy
94 server_groups = []
95 server_group_name = data_utils.rand_name('server-group')
96 for i in range(0, 2):
97 server_groups.append(self._create_server_group(server_group_name,
98 self.policy))
99 for key in ['name', 'policies']:
100 self.assertEqual(server_groups[0][key], server_groups[1][key])
101 self.assertNotEqual(server_groups[0]['id'], server_groups[1]['id'])
102
103 for i in range(0, 2):
104 self._delete_server_group(server_groups[i])
105
Chris Hoge7579c1a2015-02-26 14:12:15 -0800106 @test.idempotent_id('b3545034-dd78-48f0-bdc2-a4adfa6d0ead')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530107 def test_get_server_group(self):
108 # Get the server-group
David Kranzae99b9a2015-02-16 13:37:01 -0500109 body = self.client.get_server_group(
ghanshyam2dc13452015-08-24 17:39:25 +0900110 self.created_server_group['id'])['server_group']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530111 self.assertEqual(self.created_server_group, body)
112
Chris Hoge7579c1a2015-02-26 14:12:15 -0800113 @test.idempotent_id('d4874179-27b4-4d7d-80e4-6c560cdfe321')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530114 def test_list_server_groups(self):
115 # List the server-group
ghanshyam2dc13452015-08-24 17:39:25 +0900116 body = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530117 self.assertIn(self.created_server_group, body)