blob: bc49e7b0331c2f1431dfa925af42c69716a15aab [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_utils
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053018from tempest import test
19
20
21class ServerGroupTestJSON(base.BaseV2ComputeTest):
zhufl9cae8ec2016-10-18 15:00:24 +080022 """These tests check for the server-group APIs.
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000023
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053024 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 """
zhufl9cae8ec2016-10-18 15:00:24 +080028
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053029 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053030 def skip_checks(cls):
31 super(ServerGroupTestJSON, cls).skip_checks()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053032 if not test.is_extension_enabled('os-server-groups', 'compute'):
33 msg = "os-server-groups extension is not enabled."
34 raise cls.skipException(msg)
Rohan Kanade60b73092015-02-04 17:58:19 +053035
36 @classmethod
37 def setup_clients(cls):
38 super(ServerGroupTestJSON, cls).setup_clients()
Ken'ichi Ohmichi7ca54b82015-07-07 01:10:26 +000039 cls.client = cls.server_groups_client
Rohan Kanade60b73092015-02-04 17:58:19 +053040
41 @classmethod
42 def resource_setup(cls):
43 super(ServerGroupTestJSON, cls).resource_setup()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053044 cls.policy = ['affinity']
45
David Kranzae99b9a2015-02-16 13:37:01 -050046 cls.created_server_group = cls.create_test_server_group(
zhufl9cae8ec2016-10-18 15:00:24 +080047 policy=cls.policy)
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053048
49 def _create_server_group(self, name, policy):
50 # create the test server-group with given policy
51 server_group = {'name': name, 'policies': policy}
David Kranzae99b9a2015-02-16 13:37:01 -050052 body = self.create_test_server_group(name, policy)
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053053 for key in ['name', 'policies']:
54 self.assertEqual(server_group[key], body[key])
55 return body
56
57 def _delete_server_group(self, server_group):
58 # delete the test server-group
David Kranzae99b9a2015-02-16 13:37:01 -050059 self.client.delete_server_group(server_group['id'])
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053060 # validation of server-group deletion
ghanshyam2dc13452015-08-24 17:39:25 +090061 server_group_list = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053062 self.assertNotIn(server_group, server_group_list)
63
64 def _create_delete_server_group(self, policy):
65 # Create and Delete the server-group with given policy
66 name = data_utils.rand_name('server-group')
67 server_group = self._create_server_group(name, policy)
68 self._delete_server_group(server_group)
69
Chris Hoge7579c1a2015-02-26 14:12:15 -080070 @test.idempotent_id('5dc57eda-35b7-4af7-9e5f-3c2be3d2d68b')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053071 def test_create_delete_server_group_with_affinity_policy(self):
72 # Create and Delete the server-group with affinity policy
73 self._create_delete_server_group(self.policy)
74
Chris Hoge7579c1a2015-02-26 14:12:15 -080075 @test.idempotent_id('3645a102-372f-4140-afad-13698d850d23')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053076 def test_create_delete_server_group_with_anti_affinity_policy(self):
77 # Create and Delete the server-group with anti-affinity policy
78 policy = ['anti-affinity']
79 self._create_delete_server_group(policy)
80
Chris Hoge7579c1a2015-02-26 14:12:15 -080081 @test.idempotent_id('154dc5a4-a2fe-44b5-b99e-f15806a4a113')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053082 def test_create_delete_multiple_server_groups_with_same_name_policy(self):
83 # Create and Delete the server-groups with same name and same policy
84 server_groups = []
85 server_group_name = data_utils.rand_name('server-group')
86 for i in range(0, 2):
87 server_groups.append(self._create_server_group(server_group_name,
88 self.policy))
89 for key in ['name', 'policies']:
90 self.assertEqual(server_groups[0][key], server_groups[1][key])
91 self.assertNotEqual(server_groups[0]['id'], server_groups[1]['id'])
92
93 for i in range(0, 2):
94 self._delete_server_group(server_groups[i])
95
Chris Hoge7579c1a2015-02-26 14:12:15 -080096 @test.idempotent_id('b3545034-dd78-48f0-bdc2-a4adfa6d0ead')
Ken'ichi Ohmichicd111872015-11-16 06:01:11 +000097 def test_show_server_group(self):
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053098 # Get the server-group
Ken'ichi Ohmichicd111872015-11-16 06:01:11 +000099 body = self.client.show_server_group(
ghanshyam2dc13452015-08-24 17:39:25 +0900100 self.created_server_group['id'])['server_group']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530101 self.assertEqual(self.created_server_group, body)
102
Chris Hoge7579c1a2015-02-26 14:12:15 -0800103 @test.idempotent_id('d4874179-27b4-4d7d-80e4-6c560cdfe321')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530104 def test_list_server_groups(self):
105 # List the server-group
ghanshyam2dc13452015-08-24 17:39:25 +0900106 body = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530107 self.assertIn(self.created_server_group, body)