blob: 572d42504024771146117da341795265a12d5e20 [file] [log] [blame]
ghanshyambd460ac2016-03-16 16:28:56 +09001===================================
2How To Implement Microversion Tests
3===================================
4
ghanshyame5607282016-03-24 17:22:10 +09005Tempest provides stable interfaces to test API Microversion.
ghanshyambd460ac2016-03-16 16:28:56 +09006For Details, see: `API Microversion testing Framework`_
ghanshyame5607282016-03-24 17:22:10 +09007This document explains how to implement Microversion tests using those
ghanshyambd460ac2016-03-16 16:28:56 +09008interfaces.
9
10.. _API Microversion testing Framework: http://docs.openstack.org/developer/tempest/library/api_microversion_testing.html
11
12
13Configuration options for Microversion
14""""""""""""""""""""""""""""""""""""""
15
16* Add configuration options for specifying test target Microversions.
17 We need to specify test target Microversions because the supported
ghanshyame5607282016-03-24 17:22:10 +090018 Microversions may be different between OpenStack clouds. For operating
ghanshyambd460ac2016-03-16 16:28:56 +090019 multiple Microversion tests in a single Tempest operation, configuration
20 options should represent the range of test target Microversions.
21 New configuration options are:
Matt Riedemann3ea70c22016-06-08 08:55:58 -040022
ghanshyame5607282016-03-24 17:22:10 +090023 * min_microversion
24 * max_microversion
25
ghanshyambd460ac2016-03-16 16:28:56 +090026 Those should be defined under respective section of each service.
Yushiro FURUKAWA836361d2016-09-30 23:26:58 +090027 For example:
28
29 .. code-block:: ini
Masayuki Igawae63cf0f2016-05-25 10:25:21 +090030
ghanshyambd460ac2016-03-16 16:28:56 +090031 [compute]
32 min_microversion = None
33 max_microversion = latest
34
35
36How To Implement Microversion Tests
37"""""""""""""""""""""""""""""""""""
38
ghanshyame5607282016-03-24 17:22:10 +090039Step1: Add skip logic based on configured Microversion range
ghanshyambd460ac2016-03-16 16:28:56 +090040''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
41
42Add logic to skip the tests based on Tests class and configured Microversion
43range.
44api_version_utils.check_skip_with_microversion function can be used
Tong Liue0a3b8e2016-03-24 20:32:07 +000045to automatically skip the tests which do not fall under configured
ghanshyambd460ac2016-03-16 16:28:56 +090046Microversion range.
Yushiro FURUKAWA836361d2016-09-30 23:26:58 +090047For example:
48
49.. code-block:: python
ghanshyambd460ac2016-03-16 16:28:56 +090050
51 class BaseTestCase1(api_version_utils.BaseMicroversionTest):
52
53 [..]
54 @classmethod
55 def skip_checks(cls):
56 super(BaseTestCase1, cls).skip_checks()
57 api_version_utils.check_skip_with_microversion(cls.min_microversion,
58 cls.max_microversion,
59 CONF.compute.min_microversion,
60 CONF.compute.max_microversion)
61
62Skip logic can be added in tests base class or any specific test class depends on
63tests class structure.
64
65Step2: Selected API request microversion
66''''''''''''''''''''''''''''''''''''''''
67
68Select appropriate Microversion which needs to be used
69to send with API request.
70api_version_utils.select_request_microversion function can be used
ghanshyame5607282016-03-24 17:22:10 +090071to select the appropriate Microversion which will be used for API request.
Yushiro FURUKAWA836361d2016-09-30 23:26:58 +090072For example:
73
74.. code-block:: python
ghanshyambd460ac2016-03-16 16:28:56 +090075
76 @classmethod
77 def resource_setup(cls):
78 super(BaseTestCase1, cls).resource_setup()
79 cls.request_microversion = (
80 api_version_utils.select_request_microversion(
81 cls.min_microversion,
82 CONF.compute.min_microversion))
83
84
85Step3: Set Microversion on Service Clients
86''''''''''''''''''''''''''''''''''''''''''
87
88Microversion selected by Test Class in previous step needs to be set on
ghanshyame5607282016-03-24 17:22:10 +090089service clients so that APIs can be requested with selected Microversion.
ghanshyambd460ac2016-03-16 16:28:56 +090090
91Microversion can be defined as global variable on service clients which
92can be set using fixture.
ghanshyame5607282016-03-24 17:22:10 +090093Also Microversion header name needs to be defined on service clients which
ghanshyambd460ac2016-03-16 16:28:56 +090094should be constant because it is not supposed to be changed by project
95as per API contract.
Yushiro FURUKAWA836361d2016-09-30 23:26:58 +090096For example:
97
98.. code-block:: python
ghanshyambd460ac2016-03-16 16:28:56 +090099
100 COMPUTE_MICROVERSION = None
101
102 class BaseClient1(rest_client.RestClient):
103 api_microversion_header_name = 'X-OpenStack-Nova-API-Version'
104
ghanshyame5607282016-03-24 17:22:10 +0900105Now test class can set the selected Microversion on required service clients
106using fixture which can take care of resetting the same once tests is completed.
Yushiro FURUKAWA836361d2016-09-30 23:26:58 +0900107For example:
108
109.. code-block:: python
ghanshyambd460ac2016-03-16 16:28:56 +0900110
111 def setUp(self):
ghanshyame5607282016-03-24 17:22:10 +0900112 super(BaseTestCase1, self).setUp()
ghanshyambd460ac2016-03-16 16:28:56 +0900113 self.useFixture(api_microversion_fixture.APIMicroversionFixture(
114 self.request_microversion))
115
ghanshyame5607282016-03-24 17:22:10 +0900116Service clients needs to add set Microversion in API request header which
ghanshyambd460ac2016-03-16 16:28:56 +0900117can be done by overriding the get_headers() method of rest_client.
Yushiro FURUKAWA836361d2016-09-30 23:26:58 +0900118For example:
119
120.. code-block:: python
ghanshyambd460ac2016-03-16 16:28:56 +0900121
122 COMPUTE_MICROVERSION = None
123
124 class BaseClient1(rest_client.RestClient):
125 api_microversion_header_name = 'X-OpenStack-Nova-API-Version'
126
127 def get_headers(self):
128 headers = super(BaseClient1, self).get_headers()
129 if COMPUTE_MICROVERSION:
130 headers[self.api_microversion_header_name] = COMPUTE_MICROVERSION
131 return headers
132
133
134Step4: Separate Test classes for each Microversion
135''''''''''''''''''''''''''''''''''''''''''''''''''
136
ghanshyame5607282016-03-24 17:22:10 +0900137This is last step to implement Microversion test class.
ghanshyambd460ac2016-03-16 16:28:56 +0900138
ghanshyame5607282016-03-24 17:22:10 +0900139For any Microversion tests, basically we need to implement a
ghanshyambd460ac2016-03-16 16:28:56 +0900140separate test class. In addition, each test class defines its
ghanshyame5607282016-03-24 17:22:10 +0900141Microversion range with class variable like min_microversion
ghanshyambd460ac2016-03-16 16:28:56 +0900142and max_microversion. Tests will be valid for that defined range.
ghanshyame5607282016-03-24 17:22:10 +0900143If that range is out of configured Microversion range then, test
ghanshyambd460ac2016-03-16 16:28:56 +0900144will be skipped.
145
Matt Riedemann3ea70c22016-06-08 08:55:58 -0400146.. note:: Microversion testing is supported at test class level not at
147 individual test case level.
148
ghanshyambd460ac2016-03-16 16:28:56 +0900149For example:
150
Yushiro FURUKAWA836361d2016-09-30 23:26:58 +0900151Below test is applicable for Microversion from 2.2 till 2.9:
152
153.. code-block:: python
ghanshyambd460ac2016-03-16 16:28:56 +0900154
155 class BaseTestCase1(api_version_utils.BaseMicroversionTest,
156 tempest.test.BaseTestCase):
157
158 [..]
159
160
161 class Test1(BaseTestCase1):
162 min_microversion = '2.2'
163 max_microversion = '2.9'
164
165 [..]
166
Yushiro FURUKAWA836361d2016-09-30 23:26:58 +0900167Below test is applicable for Microversion from 2.10 till latest:
168
169.. code-block:: python
ghanshyambd460ac2016-03-16 16:28:56 +0900170
171 class Test2(BaseTestCase1):
172 min_microversion = '2.10'
173 max_microversion = 'latest'
174
175 [..]
176
177
ghanshyambd460ac2016-03-16 16:28:56 +0900178Notes about Compute Microversion Tests
Masayuki Igawae63cf0f2016-05-25 10:25:21 +0900179""""""""""""""""""""""""""""""""""""""
180
ghanshyambd460ac2016-03-16 16:28:56 +0900181Some of the compute Microversion tests have been already implemented
ghanshyame5607282016-03-24 17:22:10 +0900182with the Microversion testing framework. So for further tests only
ghanshyambd460ac2016-03-16 16:28:56 +0900183step 4 is needed.
184
185Along with that JSON response schema might need versioning if needed.
186
187Compute service clients strictly validate the response against defined JSON
188schema and does not allow additional elements in response.
Tong Liue0a3b8e2016-03-24 20:32:07 +0000189So if that Microversion changed the API response then schema needs to be versioned.
190New JSON schema file needs to be defined with new response attributes and service
ghanshyambd460ac2016-03-16 16:28:56 +0900191client methods will select the schema based on requested microversion.
192
Tong Liue0a3b8e2016-03-24 20:32:07 +0000193If Microversion tests are implemented randomly meaning not
ghanshyame5607282016-03-24 17:22:10 +0900194in sequence order(v2.20 tests added and previous Microversion tests are not yet added)
Tong Liue0a3b8e2016-03-24 20:32:07 +0000195then, still schema might need to be version for older Microversion if they changed
ghanshyambd460ac2016-03-16 16:28:56 +0900196the response.
ghanshyame5607282016-03-24 17:22:10 +0900197This is because Nova Microversion includes all the previous Microversions behavior.
ghanshyambd460ac2016-03-16 16:28:56 +0900198
199For Example:
ghanshyame5607282016-03-24 17:22:10 +0900200 Implementing the v2.20 Microversion tests before v2.9 and 2.19-
ghanshyambd460ac2016-03-16 16:28:56 +0900201 v2.20 API request will respond as latest behavior of Nova till v2.20,
202 and in v2.9 and 2.19, server response has been changed so response schema needs
Tong Liue0a3b8e2016-03-24 20:32:07 +0000203 to be versioned accordingly.
ghanshyambd460ac2016-03-16 16:28:56 +0900204
205That can be done by using the get_schema method in below module:
206
207The base_compute_client module
208''''''''''''''''''''''''''''''
209
210.. automodule:: tempest.lib.services.compute.base_compute_client
211 :members:
212
213
214Microversion tests implemented in Tempest
215"""""""""""""""""""""""""""""""""""""""""
216
217* Compute
218
219 * `2.1`_
220
221 .. _2.1: http://docs.openstack.org/developer/nova/api_microversion_history.html#id1
222
223 * `2.2`_
224
ghanshyame5607282016-03-24 17:22:10 +0900225 .. _2.2: http://docs.openstack.org/developer/nova/api_microversion_history.html#id2
ghanshyamba48c902016-04-15 13:42:35 +0900226
227 * `2.10`_
228
229 .. _2.10: http://docs.openstack.org/developer/nova/api_microversion_history.html#id9
Matt Riedemann3ea70c22016-06-08 08:55:58 -0400230
231 * `2.20`_
232
233 .. _2.20: http://docs.openstack.org/developer/nova/api_microversion_history.html#id18
Eli Qiaoe07eacc2016-03-03 13:49:37 +0800234
235 * `2.25`_
236
237 .. _2.25: http://docs.openstack.org/developer/nova/api_microversion_history.html#maximum-in-mitaka
Matt Riedemann3e4a46a2016-07-27 14:41:32 -0400238
Artom Lifshitzfc8f8e62016-04-13 11:08:32 +0000239 * `2.32`_
240
241 .. _2.32: http://docs.openstack.org/developer/nova/api_microversion_history.html#id29
242
Matt Riedemann3e4a46a2016-07-27 14:41:32 -0400243 * `2.37`_
244
245 .. _2.37: http://docs.openstack.org/developer/nova/api_microversion_history.html#id34
Matt Riedemann07845fa2017-01-30 20:18:08 -0500246
247 * `2.42`_
248
Sergey Nikitin103d5912017-02-08 15:02:34 +0400249 .. _2.42: http://docs.openstack.org/developer/nova/api_microversion_history.html#maximum-in-ocata