blob: bff18f899492a01a2bb8ec7ade166ce1207723b6 [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.
Tong Liue0a3b8e2016-03-24 20:32:07 +000027 For example::
Masayuki Igawae63cf0f2016-05-25 10:25:21 +090028
ghanshyambd460ac2016-03-16 16:28:56 +090029 [compute]
30 min_microversion = None
31 max_microversion = latest
32
33
34How To Implement Microversion Tests
35"""""""""""""""""""""""""""""""""""
36
ghanshyame5607282016-03-24 17:22:10 +090037Step1: Add skip logic based on configured Microversion range
ghanshyambd460ac2016-03-16 16:28:56 +090038''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
39
40Add logic to skip the tests based on Tests class and configured Microversion
41range.
42api_version_utils.check_skip_with_microversion function can be used
Tong Liue0a3b8e2016-03-24 20:32:07 +000043to automatically skip the tests which do not fall under configured
ghanshyambd460ac2016-03-16 16:28:56 +090044Microversion range.
45For example::
46
47 class BaseTestCase1(api_version_utils.BaseMicroversionTest):
48
49 [..]
50 @classmethod
51 def skip_checks(cls):
52 super(BaseTestCase1, cls).skip_checks()
53 api_version_utils.check_skip_with_microversion(cls.min_microversion,
54 cls.max_microversion,
55 CONF.compute.min_microversion,
56 CONF.compute.max_microversion)
57
58Skip logic can be added in tests base class or any specific test class depends on
59tests class structure.
60
61Step2: Selected API request microversion
62''''''''''''''''''''''''''''''''''''''''
63
64Select appropriate Microversion which needs to be used
65to send with API request.
66api_version_utils.select_request_microversion function can be used
ghanshyame5607282016-03-24 17:22:10 +090067to select the appropriate Microversion which will be used for API request.
ghanshyambd460ac2016-03-16 16:28:56 +090068For example::
69
70 @classmethod
71 def resource_setup(cls):
72 super(BaseTestCase1, cls).resource_setup()
73 cls.request_microversion = (
74 api_version_utils.select_request_microversion(
75 cls.min_microversion,
76 CONF.compute.min_microversion))
77
78
79Step3: Set Microversion on Service Clients
80''''''''''''''''''''''''''''''''''''''''''
81
82Microversion selected by Test Class in previous step needs to be set on
ghanshyame5607282016-03-24 17:22:10 +090083service clients so that APIs can be requested with selected Microversion.
ghanshyambd460ac2016-03-16 16:28:56 +090084
85Microversion can be defined as global variable on service clients which
86can be set using fixture.
ghanshyame5607282016-03-24 17:22:10 +090087Also Microversion header name needs to be defined on service clients which
ghanshyambd460ac2016-03-16 16:28:56 +090088should be constant because it is not supposed to be changed by project
89as per API contract.
90For example::
91
92 COMPUTE_MICROVERSION = None
93
94 class BaseClient1(rest_client.RestClient):
95 api_microversion_header_name = 'X-OpenStack-Nova-API-Version'
96
ghanshyame5607282016-03-24 17:22:10 +090097Now test class can set the selected Microversion on required service clients
98using fixture which can take care of resetting the same once tests is completed.
ghanshyambd460ac2016-03-16 16:28:56 +090099For example::
100
101 def setUp(self):
ghanshyame5607282016-03-24 17:22:10 +0900102 super(BaseTestCase1, self).setUp()
ghanshyambd460ac2016-03-16 16:28:56 +0900103 self.useFixture(api_microversion_fixture.APIMicroversionFixture(
104 self.request_microversion))
105
ghanshyame5607282016-03-24 17:22:10 +0900106Service clients needs to add set Microversion in API request header which
ghanshyambd460ac2016-03-16 16:28:56 +0900107can be done by overriding the get_headers() method of rest_client.
108For example::
109
110 COMPUTE_MICROVERSION = None
111
112 class BaseClient1(rest_client.RestClient):
113 api_microversion_header_name = 'X-OpenStack-Nova-API-Version'
114
115 def get_headers(self):
116 headers = super(BaseClient1, self).get_headers()
117 if COMPUTE_MICROVERSION:
118 headers[self.api_microversion_header_name] = COMPUTE_MICROVERSION
119 return headers
120
121
122Step4: Separate Test classes for each Microversion
123''''''''''''''''''''''''''''''''''''''''''''''''''
124
ghanshyame5607282016-03-24 17:22:10 +0900125This is last step to implement Microversion test class.
ghanshyambd460ac2016-03-16 16:28:56 +0900126
ghanshyame5607282016-03-24 17:22:10 +0900127For any Microversion tests, basically we need to implement a
ghanshyambd460ac2016-03-16 16:28:56 +0900128separate test class. In addition, each test class defines its
ghanshyame5607282016-03-24 17:22:10 +0900129Microversion range with class variable like min_microversion
ghanshyambd460ac2016-03-16 16:28:56 +0900130and max_microversion. Tests will be valid for that defined range.
ghanshyame5607282016-03-24 17:22:10 +0900131If that range is out of configured Microversion range then, test
ghanshyambd460ac2016-03-16 16:28:56 +0900132will be skipped.
133
Matt Riedemann3ea70c22016-06-08 08:55:58 -0400134.. note:: Microversion testing is supported at test class level not at
135 individual test case level.
136
ghanshyambd460ac2016-03-16 16:28:56 +0900137For example:
138
ghanshyame5607282016-03-24 17:22:10 +0900139Below test is applicable for Microversion from 2.2 till 2.9::
ghanshyambd460ac2016-03-16 16:28:56 +0900140
141 class BaseTestCase1(api_version_utils.BaseMicroversionTest,
142 tempest.test.BaseTestCase):
143
144 [..]
145
146
147 class Test1(BaseTestCase1):
148 min_microversion = '2.2'
149 max_microversion = '2.9'
150
151 [..]
152
ghanshyame5607282016-03-24 17:22:10 +0900153Below test is applicable for Microversion from 2.10 till latest::
ghanshyambd460ac2016-03-16 16:28:56 +0900154
155 class Test2(BaseTestCase1):
156 min_microversion = '2.10'
157 max_microversion = 'latest'
158
159 [..]
160
161
162
163
164Notes about Compute Microversion Tests
Masayuki Igawae63cf0f2016-05-25 10:25:21 +0900165""""""""""""""""""""""""""""""""""""""
166
ghanshyambd460ac2016-03-16 16:28:56 +0900167Some of the compute Microversion tests have been already implemented
ghanshyame5607282016-03-24 17:22:10 +0900168with the Microversion testing framework. So for further tests only
ghanshyambd460ac2016-03-16 16:28:56 +0900169step 4 is needed.
170
171Along with that JSON response schema might need versioning if needed.
172
173Compute service clients strictly validate the response against defined JSON
174schema and does not allow additional elements in response.
Tong Liue0a3b8e2016-03-24 20:32:07 +0000175So if that Microversion changed the API response then schema needs to be versioned.
176New JSON schema file needs to be defined with new response attributes and service
ghanshyambd460ac2016-03-16 16:28:56 +0900177client methods will select the schema based on requested microversion.
178
Tong Liue0a3b8e2016-03-24 20:32:07 +0000179If Microversion tests are implemented randomly meaning not
ghanshyame5607282016-03-24 17:22:10 +0900180in sequence order(v2.20 tests added and previous Microversion tests are not yet added)
Tong Liue0a3b8e2016-03-24 20:32:07 +0000181then, still schema might need to be version for older Microversion if they changed
ghanshyambd460ac2016-03-16 16:28:56 +0900182the response.
ghanshyame5607282016-03-24 17:22:10 +0900183This is because Nova Microversion includes all the previous Microversions behavior.
ghanshyambd460ac2016-03-16 16:28:56 +0900184
185For Example:
ghanshyame5607282016-03-24 17:22:10 +0900186 Implementing the v2.20 Microversion tests before v2.9 and 2.19-
ghanshyambd460ac2016-03-16 16:28:56 +0900187 v2.20 API request will respond as latest behavior of Nova till v2.20,
188 and in v2.9 and 2.19, server response has been changed so response schema needs
Tong Liue0a3b8e2016-03-24 20:32:07 +0000189 to be versioned accordingly.
ghanshyambd460ac2016-03-16 16:28:56 +0900190
191That can be done by using the get_schema method in below module:
192
193The base_compute_client module
194''''''''''''''''''''''''''''''
195
196.. automodule:: tempest.lib.services.compute.base_compute_client
197 :members:
198
199
200Microversion tests implemented in Tempest
201"""""""""""""""""""""""""""""""""""""""""
202
203* Compute
204
205 * `2.1`_
206
207 .. _2.1: http://docs.openstack.org/developer/nova/api_microversion_history.html#id1
208
209 * `2.2`_
210
ghanshyame5607282016-03-24 17:22:10 +0900211 .. _2.2: http://docs.openstack.org/developer/nova/api_microversion_history.html#id2
ghanshyamba48c902016-04-15 13:42:35 +0900212
213 * `2.10`_
214
215 .. _2.10: http://docs.openstack.org/developer/nova/api_microversion_history.html#id9
Matt Riedemann3ea70c22016-06-08 08:55:58 -0400216
217 * `2.20`_
218
219 .. _2.20: http://docs.openstack.org/developer/nova/api_microversion_history.html#id18
Eli Qiaoe07eacc2016-03-03 13:49:37 +0800220
221 * `2.25`_
222
223 .. _2.25: http://docs.openstack.org/developer/nova/api_microversion_history.html#maximum-in-mitaka
Matt Riedemann3e4a46a2016-07-27 14:41:32 -0400224
225 * `2.37`_
226
227 .. _2.37: http://docs.openstack.org/developer/nova/api_microversion_history.html#id34