ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 1 | =================================== |
| 2 | How To Implement Microversion Tests |
| 3 | =================================== |
| 4 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 5 | Tempest provides stable interfaces to test API Microversion. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 6 | For Details, see: `API Microversion testing Framework`_ |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 7 | This document explains how to implement Microversion tests using those |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 8 | interfaces. |
| 9 | |
| 10 | .. _API Microversion testing Framework: http://docs.openstack.org/developer/tempest/library/api_microversion_testing.html |
| 11 | |
| 12 | |
| 13 | Configuration 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 |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 18 | Microversions may be different between OpenStack clouds. For operating |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 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: |
Matt Riedemann | 3ea70c2 | 2016-06-08 08:55:58 -0400 | [diff] [blame] | 22 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 23 | * min_microversion |
| 24 | * max_microversion |
| 25 | |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 26 | Those should be defined under respective section of each service. |
Yushiro FURUKAWA | 836361d | 2016-09-30 23:26:58 +0900 | [diff] [blame] | 27 | For example: |
| 28 | |
| 29 | .. code-block:: ini |
Masayuki Igawa | e63cf0f | 2016-05-25 10:25:21 +0900 | [diff] [blame] | 30 | |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 31 | [compute] |
| 32 | min_microversion = None |
| 33 | max_microversion = latest |
| 34 | |
| 35 | |
| 36 | How To Implement Microversion Tests |
| 37 | """"""""""""""""""""""""""""""""""" |
| 38 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 39 | Step1: Add skip logic based on configured Microversion range |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 40 | '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
| 41 | |
| 42 | Add logic to skip the tests based on Tests class and configured Microversion |
| 43 | range. |
| 44 | api_version_utils.check_skip_with_microversion function can be used |
Tong Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 45 | to automatically skip the tests which do not fall under configured |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 46 | Microversion range. |
Yushiro FURUKAWA | 836361d | 2016-09-30 23:26:58 +0900 | [diff] [blame] | 47 | For example: |
| 48 | |
| 49 | .. code-block:: python |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 50 | |
| 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 | |
| 62 | Skip logic can be added in tests base class or any specific test class depends on |
| 63 | tests class structure. |
| 64 | |
| 65 | Step2: Selected API request microversion |
| 66 | '''''''''''''''''''''''''''''''''''''''' |
| 67 | |
| 68 | Select appropriate Microversion which needs to be used |
| 69 | to send with API request. |
| 70 | api_version_utils.select_request_microversion function can be used |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 71 | to select the appropriate Microversion which will be used for API request. |
Yushiro FURUKAWA | 836361d | 2016-09-30 23:26:58 +0900 | [diff] [blame] | 72 | For example: |
| 73 | |
| 74 | .. code-block:: python |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 75 | |
| 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 | |
| 85 | Step3: Set Microversion on Service Clients |
| 86 | '''''''''''''''''''''''''''''''''''''''''' |
| 87 | |
| 88 | Microversion selected by Test Class in previous step needs to be set on |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 89 | service clients so that APIs can be requested with selected Microversion. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 90 | |
| 91 | Microversion can be defined as global variable on service clients which |
| 92 | can be set using fixture. |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 93 | Also Microversion header name needs to be defined on service clients which |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 94 | should be constant because it is not supposed to be changed by project |
| 95 | as per API contract. |
Yushiro FURUKAWA | 836361d | 2016-09-30 23:26:58 +0900 | [diff] [blame] | 96 | For example: |
| 97 | |
| 98 | .. code-block:: python |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 99 | |
| 100 | COMPUTE_MICROVERSION = None |
| 101 | |
| 102 | class BaseClient1(rest_client.RestClient): |
| 103 | api_microversion_header_name = 'X-OpenStack-Nova-API-Version' |
| 104 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 105 | Now test class can set the selected Microversion on required service clients |
| 106 | using fixture which can take care of resetting the same once tests is completed. |
Yushiro FURUKAWA | 836361d | 2016-09-30 23:26:58 +0900 | [diff] [blame] | 107 | For example: |
| 108 | |
| 109 | .. code-block:: python |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 110 | |
| 111 | def setUp(self): |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 112 | super(BaseTestCase1, self).setUp() |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 113 | self.useFixture(api_microversion_fixture.APIMicroversionFixture( |
| 114 | self.request_microversion)) |
| 115 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 116 | Service clients needs to add set Microversion in API request header which |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 117 | can be done by overriding the get_headers() method of rest_client. |
Yushiro FURUKAWA | 836361d | 2016-09-30 23:26:58 +0900 | [diff] [blame] | 118 | For example: |
| 119 | |
| 120 | .. code-block:: python |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 121 | |
| 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 | |
| 134 | Step4: Separate Test classes for each Microversion |
| 135 | '''''''''''''''''''''''''''''''''''''''''''''''''' |
| 136 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 137 | This is last step to implement Microversion test class. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 138 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 139 | For any Microversion tests, basically we need to implement a |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 140 | separate test class. In addition, each test class defines its |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 141 | Microversion range with class variable like min_microversion |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 142 | and max_microversion. Tests will be valid for that defined range. |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 143 | If that range is out of configured Microversion range then, test |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 144 | will be skipped. |
| 145 | |
Matt Riedemann | 3ea70c2 | 2016-06-08 08:55:58 -0400 | [diff] [blame] | 146 | .. note:: Microversion testing is supported at test class level not at |
| 147 | individual test case level. |
| 148 | |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 149 | For example: |
| 150 | |
Yushiro FURUKAWA | 836361d | 2016-09-30 23:26:58 +0900 | [diff] [blame] | 151 | Below test is applicable for Microversion from 2.2 till 2.9: |
| 152 | |
| 153 | .. code-block:: python |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 154 | |
| 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 FURUKAWA | 836361d | 2016-09-30 23:26:58 +0900 | [diff] [blame] | 167 | Below test is applicable for Microversion from 2.10 till latest: |
| 168 | |
| 169 | .. code-block:: python |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 170 | |
| 171 | class Test2(BaseTestCase1): |
| 172 | min_microversion = '2.10' |
| 173 | max_microversion = 'latest' |
| 174 | |
| 175 | [..] |
| 176 | |
| 177 | |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 178 | Notes about Compute Microversion Tests |
Masayuki Igawa | e63cf0f | 2016-05-25 10:25:21 +0900 | [diff] [blame] | 179 | """""""""""""""""""""""""""""""""""""" |
| 180 | |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 181 | Some of the compute Microversion tests have been already implemented |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 182 | with the Microversion testing framework. So for further tests only |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 183 | step 4 is needed. |
| 184 | |
| 185 | Along with that JSON response schema might need versioning if needed. |
| 186 | |
| 187 | Compute service clients strictly validate the response against defined JSON |
| 188 | schema and does not allow additional elements in response. |
Tong Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 189 | So if that Microversion changed the API response then schema needs to be versioned. |
| 190 | New JSON schema file needs to be defined with new response attributes and service |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 191 | client methods will select the schema based on requested microversion. |
| 192 | |
Tong Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 193 | If Microversion tests are implemented randomly meaning not |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 194 | in sequence order(v2.20 tests added and previous Microversion tests are not yet added) |
Tong Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 195 | then, still schema might need to be version for older Microversion if they changed |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 196 | the response. |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 197 | This is because Nova Microversion includes all the previous Microversions behavior. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 198 | |
| 199 | For Example: |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 200 | Implementing the v2.20 Microversion tests before v2.9 and 2.19- |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 201 | 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 Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 203 | to be versioned accordingly. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 204 | |
| 205 | That can be done by using the get_schema method in below module: |
| 206 | |
| 207 | The base_compute_client module |
| 208 | '''''''''''''''''''''''''''''' |
| 209 | |
| 210 | .. automodule:: tempest.lib.services.compute.base_compute_client |
| 211 | :members: |
| 212 | |
| 213 | |
| 214 | Microversion 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 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 225 | .. _2.2: http://docs.openstack.org/developer/nova/api_microversion_history.html#id2 |
ghanshyam | ba48c90 | 2016-04-15 13:42:35 +0900 | [diff] [blame] | 226 | |
| 227 | * `2.10`_ |
| 228 | |
| 229 | .. _2.10: http://docs.openstack.org/developer/nova/api_microversion_history.html#id9 |
Matt Riedemann | 3ea70c2 | 2016-06-08 08:55:58 -0400 | [diff] [blame] | 230 | |
| 231 | * `2.20`_ |
| 232 | |
| 233 | .. _2.20: http://docs.openstack.org/developer/nova/api_microversion_history.html#id18 |
Eli Qiao | e07eacc | 2016-03-03 13:49:37 +0800 | [diff] [blame] | 234 | |
| 235 | * `2.25`_ |
| 236 | |
| 237 | .. _2.25: http://docs.openstack.org/developer/nova/api_microversion_history.html#maximum-in-mitaka |
Matt Riedemann | 3e4a46a | 2016-07-27 14:41:32 -0400 | [diff] [blame] | 238 | |
Artom Lifshitz | fc8f8e6 | 2016-04-13 11:08:32 +0000 | [diff] [blame] | 239 | * `2.32`_ |
| 240 | |
| 241 | .. _2.32: http://docs.openstack.org/developer/nova/api_microversion_history.html#id29 |
| 242 | |
Matt Riedemann | 3e4a46a | 2016-07-27 14:41:32 -0400 | [diff] [blame] | 243 | * `2.37`_ |
| 244 | |
| 245 | .. _2.37: http://docs.openstack.org/developer/nova/api_microversion_history.html#id34 |
Matt Riedemann | 07845fa | 2017-01-30 20:18:08 -0500 | [diff] [blame] | 246 | |
| 247 | * `2.42`_ |
| 248 | |
Sergey Nikitin | 103d591 | 2017-02-08 15:02:34 +0400 | [diff] [blame] | 249 | .. _2.42: http://docs.openstack.org/developer/nova/api_microversion_history.html#maximum-in-ocata |