blob: 4b5efaa694fc83f1b22c66029f4318623abd9e80 [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
Andrea Frittolicd368412017-08-14 21:37:56 +010020from tempest.common import utils
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080021from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080022from tempest.lib import decorators
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053023
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 """
Eric Friedbfaa50f2020-01-09 12:04:54 -060032 create_default_network = True
zhufl9cae8ec2016-10-18 15:00:24 +080033
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053034 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053035 def skip_checks(cls):
36 super(ServerGroupTestJSON, cls).skip_checks()
Andrea Frittolicd368412017-08-14 21:37:56 +010037 if not utils.is_extension_enabled('os-server-groups', 'compute'):
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053038 msg = "os-server-groups extension is not enabled."
39 raise cls.skipException(msg)
Rohan Kanade60b73092015-02-04 17:58:19 +053040
41 @classmethod
42 def setup_clients(cls):
43 super(ServerGroupTestJSON, cls).setup_clients()
Ken'ichi Ohmichi7ca54b82015-07-07 01:10:26 +000044 cls.client = cls.server_groups_client
Rohan Kanade60b73092015-02-04 17:58:19 +053045
46 @classmethod
47 def resource_setup(cls):
48 super(ServerGroupTestJSON, cls).resource_setup()
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053049 cls.policy = ['affinity']
50
zhuflbe7be1b2018-07-24 14:09:17 +080051 def setUp(self):
52 super(ServerGroupTestJSON, self).setUp()
53 # TODO(zhufl): After microversion 2.13 project_id and user_id are
54 # added to the body of server_group, and microversion is not used
55 # in resource_setup for now, so we should create server group in setUp
56 # in order to use the same microversion as in testcases till
57 # microversion support in resource_setup is fulfilled.
58 if not hasattr(self, 'created_server_group'):
59 self.__class__.created_server_group = \
60 self.create_test_server_group(policy=self.policy)
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053061
62 def _create_server_group(self, name, policy):
63 # create the test server-group with given policy
64 server_group = {'name': name, 'policies': policy}
David Kranzae99b9a2015-02-16 13:37:01 -050065 body = self.create_test_server_group(name, policy)
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053066 for key in ['name', 'policies']:
67 self.assertEqual(server_group[key], body[key])
68 return body
69
70 def _delete_server_group(self, server_group):
71 # delete the test server-group
David Kranzae99b9a2015-02-16 13:37:01 -050072 self.client.delete_server_group(server_group['id'])
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053073 # validation of server-group deletion
ghanshyam2dc13452015-08-24 17:39:25 +090074 server_group_list = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053075 self.assertNotIn(server_group, server_group_list)
76
77 def _create_delete_server_group(self, policy):
78 # Create and Delete the server-group with given policy
79 name = data_utils.rand_name('server-group')
80 server_group = self._create_server_group(name, policy)
81 self._delete_server_group(server_group)
82
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080083 @decorators.idempotent_id('5dc57eda-35b7-4af7-9e5f-3c2be3d2d68b')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053084 def test_create_delete_server_group_with_affinity_policy(self):
85 # Create and Delete the server-group with affinity policy
86 self._create_delete_server_group(self.policy)
87
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080088 @decorators.idempotent_id('3645a102-372f-4140-afad-13698d850d23')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053089 def test_create_delete_server_group_with_anti_affinity_policy(self):
90 # Create and Delete the server-group with anti-affinity policy
91 policy = ['anti-affinity']
92 self._create_delete_server_group(policy)
93
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080094 @decorators.idempotent_id('154dc5a4-a2fe-44b5-b99e-f15806a4a113')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +053095 def test_create_delete_multiple_server_groups_with_same_name_policy(self):
96 # Create and Delete the server-groups with same name and same policy
97 server_groups = []
98 server_group_name = data_utils.rand_name('server-group')
zhufl4311dc42017-01-26 16:26:18 +080099 for _ in range(0, 2):
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530100 server_groups.append(self._create_server_group(server_group_name,
101 self.policy))
102 for key in ['name', 'policies']:
103 self.assertEqual(server_groups[0][key], server_groups[1][key])
104 self.assertNotEqual(server_groups[0]['id'], server_groups[1]['id'])
105
106 for i in range(0, 2):
107 self._delete_server_group(server_groups[i])
108
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800109 @decorators.idempotent_id('b3545034-dd78-48f0-bdc2-a4adfa6d0ead')
Ken'ichi Ohmichicd111872015-11-16 06:01:11 +0000110 def test_show_server_group(self):
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530111 # Get the server-group
Ken'ichi Ohmichicd111872015-11-16 06:01:11 +0000112 body = self.client.show_server_group(
ghanshyam2dc13452015-08-24 17:39:25 +0900113 self.created_server_group['id'])['server_group']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530114 self.assertEqual(self.created_server_group, body)
115
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800116 @decorators.idempotent_id('d4874179-27b4-4d7d-80e4-6c560cdfe321')
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530117 def test_list_server_groups(self):
118 # List the server-group
ghanshyam2dc13452015-08-24 17:39:25 +0900119 body = self.client.list_server_groups()['server_groups']
Abhijeet.Jain87dd4452014-04-23 15:51:23 +0530120 self.assertIn(self.created_server_group, body)
zhufld0958472017-08-11 13:08:36 +0800121
122 @decorators.idempotent_id('ed20d3fb-9d1f-4329-b160-543fbd5d9811')
123 @testtools.skipUnless(
124 compute.is_scheduler_filter_enabled("ServerGroupAffinityFilter"),
125 'ServerGroupAffinityFilter is not available.')
126 def test_create_server_with_scheduler_hint_group(self):
127 # Create a server with the scheduler hint "group".
128 hints = {'group': self.created_server_group['id']}
129 server = self.create_test_server(scheduler_hints=hints,
130 wait_until='ACTIVE')
131 self.addCleanup(self.delete_server, server['id'])
132
133 # Check a server is in the group
134 server_group = (self.server_groups_client.show_server_group(
135 self.created_server_group['id'])['server_group'])
136 self.assertIn(server['id'], server_group['members'])