blob: e32f6b02eb7c9e1db52b912045c451da16758812 [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):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000022 """These tests check for the server-group APIs
23
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 """
28 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053029 def skip_checks(cls):
30 super(ServerGroupTestJSON, cls).skip_checks()
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)
Rohan Kanade60b73092015-02-04 17:58:19 +053034
35 @classmethod
36 def setup_clients(cls):
37 super(ServerGroupTestJSON, cls).setup_clients()
Ken'ichi Ohmichi7ca54b82015-07-07 01:10:26 +000038 cls.client = cls.server_groups_client
Rohan Kanade60b73092015-02-04 17:58:19 +053039
40 @classmethod
41 def resource_setup(cls):
42 super(ServerGroupTestJSON, cls).resource_setup()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053043 server_group_name = data_utils.rand_name('server-group')
44 cls.policy = ['affinity']
45
David Kranzae99b9a2015-02-16 13:37:01 -050046 cls.created_server_group = cls.create_test_server_group(
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053047 server_group_name,
48 cls.policy)
49
50 def _create_server_group(self, name, policy):
51 # create the test server-group with given policy
52 server_group = {'name': name, 'policies': policy}
David Kranzae99b9a2015-02-16 13:37:01 -050053 body = self.create_test_server_group(name, policy)
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053054 for key in ['name', 'policies']:
55 self.assertEqual(server_group[key], body[key])
56 return body
57
58 def _delete_server_group(self, server_group):
59 # delete the test server-group
David Kranzae99b9a2015-02-16 13:37:01 -050060 self.client.delete_server_group(server_group['id'])
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053061 # validation of server-group deletion
ghanshyam2dc13452015-08-24 17:39:25 +090062 server_group_list = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053063 self.assertNotIn(server_group, server_group_list)
64
65 def _create_delete_server_group(self, policy):
66 # Create and Delete the server-group with given policy
67 name = data_utils.rand_name('server-group')
68 server_group = self._create_server_group(name, policy)
69 self._delete_server_group(server_group)
70
Chris Hoge7579c1a2015-02-26 14:12:15 -080071 @test.idempotent_id('5dc57eda-35b7-4af7-9e5f-3c2be3d2d68b')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053072 def test_create_delete_server_group_with_affinity_policy(self):
73 # Create and Delete the server-group with affinity policy
74 self._create_delete_server_group(self.policy)
75
Chris Hoge7579c1a2015-02-26 14:12:15 -080076 @test.idempotent_id('3645a102-372f-4140-afad-13698d850d23')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053077 def test_create_delete_server_group_with_anti_affinity_policy(self):
78 # Create and Delete the server-group with anti-affinity policy
79 policy = ['anti-affinity']
80 self._create_delete_server_group(policy)
81
Chris Hoge7579c1a2015-02-26 14:12:15 -080082 @test.idempotent_id('154dc5a4-a2fe-44b5-b99e-f15806a4a113')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053083 def test_create_delete_multiple_server_groups_with_same_name_policy(self):
84 # Create and Delete the server-groups with same name and same policy
85 server_groups = []
86 server_group_name = data_utils.rand_name('server-group')
87 for i in range(0, 2):
88 server_groups.append(self._create_server_group(server_group_name,
89 self.policy))
90 for key in ['name', 'policies']:
91 self.assertEqual(server_groups[0][key], server_groups[1][key])
92 self.assertNotEqual(server_groups[0]['id'], server_groups[1]['id'])
93
94 for i in range(0, 2):
95 self._delete_server_group(server_groups[i])
96
Chris Hoge7579c1a2015-02-26 14:12:15 -080097 @test.idempotent_id('b3545034-dd78-48f0-bdc2-a4adfa6d0ead')
Ken'ichi Ohmichicd111872015-11-16 06:01:11 +000098 def test_show_server_group(self):
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053099 # Get the server-group
Ken'ichi Ohmichicd111872015-11-16 06:01:11 +0000100 body = self.client.show_server_group(
ghanshyam2dc13452015-08-24 17:39:25 +0900101 self.created_server_group['id'])['server_group']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530102 self.assertEqual(self.created_server_group, body)
103
Chris Hoge7579c1a2015-02-26 14:12:15 -0800104 @test.idempotent_id('d4874179-27b4-4d7d-80e4-6c560cdfe321')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530105 def test_list_server_groups(self):
106 # List the server-group
ghanshyam2dc13452015-08-24 17:39:25 +0900107 body = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530108 self.assertIn(self.created_server_group, body)