blob: fc05b12fa0d09282311e1cf25be280ddb8fdb7f5 [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:
ghanshyame5607282016-03-24 17:22:10 +090022 * min_microversion
23 * max_microversion
24
ghanshyambd460ac2016-03-16 16:28:56 +090025 Those should be defined under respective section of each service.
Tong Liue0a3b8e2016-03-24 20:32:07 +000026 For example::
ghanshyambd460ac2016-03-16 16:28:56 +090027 [compute]
28 min_microversion = None
29 max_microversion = latest
30
31
32How To Implement Microversion Tests
33"""""""""""""""""""""""""""""""""""
34
ghanshyame5607282016-03-24 17:22:10 +090035Step1: Add skip logic based on configured Microversion range
ghanshyambd460ac2016-03-16 16:28:56 +090036''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
37
38Add logic to skip the tests based on Tests class and configured Microversion
39range.
40api_version_utils.check_skip_with_microversion function can be used
Tong Liue0a3b8e2016-03-24 20:32:07 +000041to automatically skip the tests which do not fall under configured
ghanshyambd460ac2016-03-16 16:28:56 +090042Microversion range.
43For example::
44
45 class BaseTestCase1(api_version_utils.BaseMicroversionTest):
46
47 [..]
48 @classmethod
49 def skip_checks(cls):
50 super(BaseTestCase1, cls).skip_checks()
51 api_version_utils.check_skip_with_microversion(cls.min_microversion,
52 cls.max_microversion,
53 CONF.compute.min_microversion,
54 CONF.compute.max_microversion)
55
56Skip logic can be added in tests base class or any specific test class depends on
57tests class structure.
58
59Step2: Selected API request microversion
60''''''''''''''''''''''''''''''''''''''''
61
62Select appropriate Microversion which needs to be used
63to send with API request.
64api_version_utils.select_request_microversion function can be used
ghanshyame5607282016-03-24 17:22:10 +090065to select the appropriate Microversion which will be used for API request.
ghanshyambd460ac2016-03-16 16:28:56 +090066For example::
67
68 @classmethod
69 def resource_setup(cls):
70 super(BaseTestCase1, cls).resource_setup()
71 cls.request_microversion = (
72 api_version_utils.select_request_microversion(
73 cls.min_microversion,
74 CONF.compute.min_microversion))
75
76
77Step3: Set Microversion on Service Clients
78''''''''''''''''''''''''''''''''''''''''''
79
80Microversion selected by Test Class in previous step needs to be set on
ghanshyame5607282016-03-24 17:22:10 +090081service clients so that APIs can be requested with selected Microversion.
ghanshyambd460ac2016-03-16 16:28:56 +090082
83Microversion can be defined as global variable on service clients which
84can be set using fixture.
ghanshyame5607282016-03-24 17:22:10 +090085Also Microversion header name needs to be defined on service clients which
ghanshyambd460ac2016-03-16 16:28:56 +090086should be constant because it is not supposed to be changed by project
87as per API contract.
88For example::
89
90 COMPUTE_MICROVERSION = None
91
92 class BaseClient1(rest_client.RestClient):
93 api_microversion_header_name = 'X-OpenStack-Nova-API-Version'
94
ghanshyame5607282016-03-24 17:22:10 +090095Now test class can set the selected Microversion on required service clients
96using fixture which can take care of resetting the same once tests is completed.
ghanshyambd460ac2016-03-16 16:28:56 +090097For example::
98
99 def setUp(self):
ghanshyame5607282016-03-24 17:22:10 +0900100 super(BaseTestCase1, self).setUp()
ghanshyambd460ac2016-03-16 16:28:56 +0900101 self.useFixture(api_microversion_fixture.APIMicroversionFixture(
102 self.request_microversion))
103
ghanshyame5607282016-03-24 17:22:10 +0900104Service clients needs to add set Microversion in API request header which
ghanshyambd460ac2016-03-16 16:28:56 +0900105can be done by overriding the get_headers() method of rest_client.
106For example::
107
108 COMPUTE_MICROVERSION = None
109
110 class BaseClient1(rest_client.RestClient):
111 api_microversion_header_name = 'X-OpenStack-Nova-API-Version'
112
113 def get_headers(self):
114 headers = super(BaseClient1, self).get_headers()
115 if COMPUTE_MICROVERSION:
116 headers[self.api_microversion_header_name] = COMPUTE_MICROVERSION
117 return headers
118
119
120Step4: Separate Test classes for each Microversion
121''''''''''''''''''''''''''''''''''''''''''''''''''
122
ghanshyame5607282016-03-24 17:22:10 +0900123This is last step to implement Microversion test class.
ghanshyambd460ac2016-03-16 16:28:56 +0900124
ghanshyame5607282016-03-24 17:22:10 +0900125For any Microversion tests, basically we need to implement a
ghanshyambd460ac2016-03-16 16:28:56 +0900126separate test class. In addition, each test class defines its
ghanshyame5607282016-03-24 17:22:10 +0900127Microversion range with class variable like min_microversion
ghanshyambd460ac2016-03-16 16:28:56 +0900128and max_microversion. Tests will be valid for that defined range.
ghanshyame5607282016-03-24 17:22:10 +0900129If that range is out of configured Microversion range then, test
ghanshyambd460ac2016-03-16 16:28:56 +0900130will be skipped.
131
132*NOTE: Microversion testing is supported at test class level not at individual
133test case level.*
134For example:
135
ghanshyame5607282016-03-24 17:22:10 +0900136Below test is applicable for Microversion from 2.2 till 2.9::
ghanshyambd460ac2016-03-16 16:28:56 +0900137
138 class BaseTestCase1(api_version_utils.BaseMicroversionTest,
139 tempest.test.BaseTestCase):
140
141 [..]
142
143
144 class Test1(BaseTestCase1):
145 min_microversion = '2.2'
146 max_microversion = '2.9'
147
148 [..]
149
ghanshyame5607282016-03-24 17:22:10 +0900150Below test is applicable for Microversion from 2.10 till latest::
ghanshyambd460ac2016-03-16 16:28:56 +0900151
152 class Test2(BaseTestCase1):
153 min_microversion = '2.10'
154 max_microversion = 'latest'
155
156 [..]
157
158
159
160
161Notes about Compute Microversion Tests
162"""""""""""""""""""""""""""""""""""
163Some of the compute Microversion tests have been already implemented
ghanshyame5607282016-03-24 17:22:10 +0900164with the Microversion testing framework. So for further tests only
ghanshyambd460ac2016-03-16 16:28:56 +0900165step 4 is needed.
166
167Along with that JSON response schema might need versioning if needed.
168
169Compute service clients strictly validate the response against defined JSON
170schema and does not allow additional elements in response.
Tong Liue0a3b8e2016-03-24 20:32:07 +0000171So if that Microversion changed the API response then schema needs to be versioned.
172New JSON schema file needs to be defined with new response attributes and service
ghanshyambd460ac2016-03-16 16:28:56 +0900173client methods will select the schema based on requested microversion.
174
Tong Liue0a3b8e2016-03-24 20:32:07 +0000175If Microversion tests are implemented randomly meaning not
ghanshyame5607282016-03-24 17:22:10 +0900176in sequence order(v2.20 tests added and previous Microversion tests are not yet added)
Tong Liue0a3b8e2016-03-24 20:32:07 +0000177then, still schema might need to be version for older Microversion if they changed
ghanshyambd460ac2016-03-16 16:28:56 +0900178the response.
ghanshyame5607282016-03-24 17:22:10 +0900179This is because Nova Microversion includes all the previous Microversions behavior.
ghanshyambd460ac2016-03-16 16:28:56 +0900180
181For Example:
ghanshyame5607282016-03-24 17:22:10 +0900182 Implementing the v2.20 Microversion tests before v2.9 and 2.19-
ghanshyambd460ac2016-03-16 16:28:56 +0900183 v2.20 API request will respond as latest behavior of Nova till v2.20,
184 and in v2.9 and 2.19, server response has been changed so response schema needs
Tong Liue0a3b8e2016-03-24 20:32:07 +0000185 to be versioned accordingly.
ghanshyambd460ac2016-03-16 16:28:56 +0900186
187That can be done by using the get_schema method in below module:
188
189The base_compute_client module
190''''''''''''''''''''''''''''''
191
192.. automodule:: tempest.lib.services.compute.base_compute_client
193 :members:
194
195
196Microversion tests implemented in Tempest
197"""""""""""""""""""""""""""""""""""""""""
198
199* Compute
200
201 * `2.1`_
202
203 .. _2.1: http://docs.openstack.org/developer/nova/api_microversion_history.html#id1
204
205 * `2.2`_
206
ghanshyame5607282016-03-24 17:22:10 +0900207 .. _2.2: http://docs.openstack.org/developer/nova/api_microversion_history.html#id2
ghanshyamba48c902016-04-15 13:42:35 +0900208
209 * `2.10`_
210
211 .. _2.10: http://docs.openstack.org/developer/nova/api_microversion_history.html#id9