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