blob: bb48b3f3b1cc2260e9dee95c8ec890e41f9782ef [file] [log] [blame]
ghanshyambd460ac2016-03-16 16:28:56 +09001===================================
2How To Implement Microversion Tests
3===================================
4
5Tempest provides stable interfaces to test API microversion.
6For Details, see: `API Microversion testing Framework`_
7This document explains how to implement microversion tests using those
8interfaces.
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
18 microversions may be different between OpenStack clouds. For operating
19 multiple Microversion tests in a single Tempest operation, configuration
20 options should represent the range of test target Microversions.
21 New configuration options are:
22 - min_microversion
23 - max_microversion
24 Those should be defined under respective section of each service.
25 For Example::
26 [compute]
27 min_microversion = None
28 max_microversion = latest
29
30
31How To Implement Microversion Tests
32"""""""""""""""""""""""""""""""""""
33
34Step1: Add skip logic based on configured microversion range
35''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
36
37Add logic to skip the tests based on Tests class and configured Microversion
38range.
39api_version_utils.check_skip_with_microversion function can be used
40to automatically skip the tests which does not fall under configured
41Microversion range.
42For example::
43
44 class BaseTestCase1(api_version_utils.BaseMicroversionTest):
45
46 [..]
47 @classmethod
48 def skip_checks(cls):
49 super(BaseTestCase1, cls).skip_checks()
50 api_version_utils.check_skip_with_microversion(cls.min_microversion,
51 cls.max_microversion,
52 CONF.compute.min_microversion,
53 CONF.compute.max_microversion)
54
55Skip logic can be added in tests base class or any specific test class depends on
56tests class structure.
57
58Step2: Selected API request microversion
59''''''''''''''''''''''''''''''''''''''''
60
61Select appropriate Microversion which needs to be used
62to send with API request.
63api_version_utils.select_request_microversion function can be used
64to select the appropriate microversion which will be used for API request.
65For example::
66
67 @classmethod
68 def resource_setup(cls):
69 super(BaseTestCase1, cls).resource_setup()
70 cls.request_microversion = (
71 api_version_utils.select_request_microversion(
72 cls.min_microversion,
73 CONF.compute.min_microversion))
74
75
76Step3: Set Microversion on Service Clients
77''''''''''''''''''''''''''''''''''''''''''
78
79Microversion selected by Test Class in previous step needs to be set on
80service clients so that APIs can be requested with selected microversion.
81
82Microversion can be defined as global variable on service clients which
83can be set using fixture.
84Also microversion header name needs to be defined on service clients which
85should be constant because it is not supposed to be changed by project
86as per API contract.
87For example::
88
89 COMPUTE_MICROVERSION = None
90
91 class BaseClient1(rest_client.RestClient):
92 api_microversion_header_name = 'X-OpenStack-Nova-API-Version'
93
94Now test class can set the selected microversion on required service clients
95using fixture which can take care of reseting the same once tests is completed.
96For example::
97
98 def setUp(self):
99 super(BaseTestCase1,, self).setUp()
100 self.useFixture(api_microversion_fixture.APIMicroversionFixture(
101 self.request_microversion))
102
103Service clients needs to add set microversion in API request header which
104can be done by overriding the get_headers() method of rest_client.
105For example::
106
107 COMPUTE_MICROVERSION = None
108
109 class BaseClient1(rest_client.RestClient):
110 api_microversion_header_name = 'X-OpenStack-Nova-API-Version'
111
112 def get_headers(self):
113 headers = super(BaseClient1, self).get_headers()
114 if COMPUTE_MICROVERSION:
115 headers[self.api_microversion_header_name] = COMPUTE_MICROVERSION
116 return headers
117
118
119Step4: Separate Test classes for each Microversion
120''''''''''''''''''''''''''''''''''''''''''''''''''
121
122This is last step to implement microversion test class.
123
124For any microversion tests, basically we need to implement a
125separate test class. In addition, each test class defines its
126microversion range with class variable like min_microversion
127and max_microversion. Tests will be valid for that defined range.
128If that range is out of configured microversion range then, test
129will be skipped.
130
131*NOTE: Microversion testing is supported at test class level not at individual
132test case level.*
133For example:
134
135Below test is applicable for microversion from 2.2 till 2.9::
136
137 class BaseTestCase1(api_version_utils.BaseMicroversionTest,
138 tempest.test.BaseTestCase):
139
140 [..]
141
142
143 class Test1(BaseTestCase1):
144 min_microversion = '2.2'
145 max_microversion = '2.9'
146
147 [..]
148
149Below test is applicable for microversion from 2.10 till latest::
150
151 class Test2(BaseTestCase1):
152 min_microversion = '2.10'
153 max_microversion = 'latest'
154
155 [..]
156
157
158
159
160Notes about Compute Microversion Tests
161"""""""""""""""""""""""""""""""""""
162Some of the compute Microversion tests have been already implemented
163with the microversion testing framework. So for further tests only
164step 4 is needed.
165
166Along with that JSON response schema might need versioning if needed.
167
168Compute service clients strictly validate the response against defined JSON
169schema and does not allow additional elements in response.
170So if that microversion changed the API response then schema needs to be version.
171New JSON schema file needs be defined with new response attributes and service
172client methods will select the schema based on requested microversion.
173
174If microversion tests are implemented randomly means not
175in sequence order(v2.20 tests added and previous microversion tests are not yet added)
176then, still schema might needs to be version for older microversion if they changed
177the response.
178This is because Nova microversion includes all the previous microversions behvaior.
179
180For Example:
181 Implementing the v2.20 microversion tests before v2.9 and 2.19-
182 v2.20 API request will respond as latest behavior of Nova till v2.20,
183 and in v2.9 and 2.19, server response has been changed so response schema needs
184 to be version accordingly.
185
186That can be done by using the get_schema method in below module:
187
188The base_compute_client module
189''''''''''''''''''''''''''''''
190
191.. automodule:: tempest.lib.services.compute.base_compute_client
192 :members:
193
194
195Microversion tests implemented in Tempest
196"""""""""""""""""""""""""""""""""""""""""
197
198* Compute
199
200 * `2.1`_
201
202 .. _2.1: http://docs.openstack.org/developer/nova/api_microversion_history.html#id1
203
204 * `2.2`_
205
206 .. _2.2: http://docs.openstack.org/developer/nova/api_microversion_history.html#id2