blob: f4025408273b6dda4ed55df3526ccd9210d22481 [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
zhufld0958472017-08-11 13:08:36 +080016import testtools
17
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053018from tempest.api.compute import base
zhufld0958472017-08-11 13:08:36 +080019from tempest.common import compute
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080020from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080021from tempest.lib import decorators
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053022from tempest import test
23
24
25class ServerGroupTestJSON(base.BaseV2ComputeTest):
zhufl9cae8ec2016-10-18 15:00:24 +080026 """These tests check for the server-group APIs.
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000027
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053028 They create/delete server-groups with different policies.
29 policies = affinity/anti-affinity
30 It also adds the tests for list and get details of server-groups
31 """
zhufl9cae8ec2016-10-18 15:00:24 +080032
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053033 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053034 def skip_checks(cls):
35 super(ServerGroupTestJSON, cls).skip_checks()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053036 if not test.is_extension_enabled('os-server-groups', 'compute'):
37 msg = "os-server-groups extension is not enabled."
38 raise cls.skipException(msg)
Rohan Kanade60b73092015-02-04 17:58:19 +053039
40 @classmethod
41 def setup_clients(cls):
42 super(ServerGroupTestJSON, cls).setup_clients()
Ken'ichi Ohmichi7ca54b82015-07-07 01:10:26 +000043 cls.client = cls.server_groups_client
Rohan Kanade60b73092015-02-04 17:58:19 +053044
45 @classmethod
46 def resource_setup(cls):
47 super(ServerGroupTestJSON, cls).resource_setup()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053048 cls.policy = ['affinity']
49
David Kranzae99b9a2015-02-16 13:37:01 -050050 cls.created_server_group = cls.create_test_server_group(
zhufl9cae8ec2016-10-18 15:00:24 +080051 policy=cls.policy)
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053052
53 def _create_server_group(self, name, policy):
54 # create the test server-group with given policy
55 server_group = {'name': name, 'policies': policy}
David Kranzae99b9a2015-02-16 13:37:01 -050056 body = self.create_test_server_group(name, policy)
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053057 for key in ['name', 'policies']:
58 self.assertEqual(server_group[key], body[key])
59 return body
60
61 def _delete_server_group(self, server_group):
62 # delete the test server-group
David Kranzae99b9a2015-02-16 13:37:01 -050063 self.client.delete_server_group(server_group['id'])
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053064 # validation of server-group deletion
ghanshyam2dc13452015-08-24 17:39:25 +090065 server_group_list = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053066 self.assertNotIn(server_group, server_group_list)
67
68 def _create_delete_server_group(self, policy):
69 # Create and Delete the server-group with given policy
70 name = data_utils.rand_name('server-group')
71 server_group = self._create_server_group(name, policy)
72 self._delete_server_group(server_group)
73
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080074 @decorators.idempotent_id('5dc57eda-35b7-4af7-9e5f-3c2be3d2d68b')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053075 def test_create_delete_server_group_with_affinity_policy(self):
76 # Create and Delete the server-group with affinity policy
77 self._create_delete_server_group(self.policy)
78
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080079 @decorators.idempotent_id('3645a102-372f-4140-afad-13698d850d23')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053080 def test_create_delete_server_group_with_anti_affinity_policy(self):
81 # Create and Delete the server-group with anti-affinity policy
82 policy = ['anti-affinity']
83 self._create_delete_server_group(policy)
84
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080085 @decorators.idempotent_id('154dc5a4-a2fe-44b5-b99e-f15806a4a113')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053086 def test_create_delete_multiple_server_groups_with_same_name_policy(self):
87 # Create and Delete the server-groups with same name and same policy
88 server_groups = []
89 server_group_name = data_utils.rand_name('server-group')
zhufl4311dc42017-01-26 16:26:18 +080090 for _ in range(0, 2):
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053091 server_groups.append(self._create_server_group(server_group_name,
92 self.policy))
93 for key in ['name', 'policies']:
94 self.assertEqual(server_groups[0][key], server_groups[1][key])
95 self.assertNotEqual(server_groups[0]['id'], server_groups[1]['id'])
96
97 for i in range(0, 2):
98 self._delete_server_group(server_groups[i])
99
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800100 @decorators.idempotent_id('b3545034-dd78-48f0-bdc2-a4adfa6d0ead')
Ken'ichi Ohmichicd111872015-11-16 06:01:11 +0000101 def test_show_server_group(self):
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530102 # Get the server-group
Ken'ichi Ohmichicd111872015-11-16 06:01:11 +0000103 body = self.client.show_server_group(
ghanshyam2dc13452015-08-24 17:39:25 +0900104 self.created_server_group['id'])['server_group']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530105 self.assertEqual(self.created_server_group, body)
106
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800107 @decorators.idempotent_id('d4874179-27b4-4d7d-80e4-6c560cdfe321')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530108 def test_list_server_groups(self):
109 # List the server-group
ghanshyam2dc13452015-08-24 17:39:25 +0900110 body = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530111 self.assertIn(self.created_server_group, body)
zhufld0958472017-08-11 13:08:36 +0800112
113 @decorators.idempotent_id('ed20d3fb-9d1f-4329-b160-543fbd5d9811')
114 @testtools.skipUnless(
115 compute.is_scheduler_filter_enabled("ServerGroupAffinityFilter"),
116 'ServerGroupAffinityFilter is not available.')
117 def test_create_server_with_scheduler_hint_group(self):
118 # Create a server with the scheduler hint "group".
119 hints = {'group': self.created_server_group['id']}
120 server = self.create_test_server(scheduler_hints=hints,
121 wait_until='ACTIVE')
122 self.addCleanup(self.delete_server, server['id'])
123
124 # Check a server is in the group
125 server_group = (self.server_groups_client.show_server_group(
126 self.created_server_group['id'])['server_group'])
127 self.assertIn(server['id'], server_group['members'])