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: |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 22 | * min_microversion |
| 23 | * max_microversion |
| 24 | |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 25 | Those should be defined under respective section of each service. |
Tong Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 26 | For example:: |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 27 | [compute] |
| 28 | min_microversion = None |
| 29 | max_microversion = latest |
| 30 | |
| 31 | |
| 32 | How To Implement Microversion Tests |
| 33 | """"""""""""""""""""""""""""""""""" |
| 34 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 35 | Step1: Add skip logic based on configured Microversion range |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 36 | '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
| 37 | |
| 38 | Add logic to skip the tests based on Tests class and configured Microversion |
| 39 | range. |
| 40 | api_version_utils.check_skip_with_microversion function can be used |
Tong Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 41 | to automatically skip the tests which do not fall under configured |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 42 | Microversion range. |
| 43 | For 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 | |
| 56 | Skip logic can be added in tests base class or any specific test class depends on |
| 57 | tests class structure. |
| 58 | |
| 59 | Step2: Selected API request microversion |
| 60 | '''''''''''''''''''''''''''''''''''''''' |
| 61 | |
| 62 | Select appropriate Microversion which needs to be used |
| 63 | to send with API request. |
| 64 | api_version_utils.select_request_microversion function can be used |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 65 | to select the appropriate Microversion which will be used for API request. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 66 | For 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 | |
| 77 | Step3: Set Microversion on Service Clients |
| 78 | '''''''''''''''''''''''''''''''''''''''''' |
| 79 | |
| 80 | Microversion selected by Test Class in previous step needs to be set on |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 81 | service clients so that APIs can be requested with selected Microversion. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 82 | |
| 83 | Microversion can be defined as global variable on service clients which |
| 84 | can be set using fixture. |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 85 | Also Microversion header name needs to be defined on service clients which |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 86 | should be constant because it is not supposed to be changed by project |
| 87 | as per API contract. |
| 88 | For example:: |
| 89 | |
| 90 | COMPUTE_MICROVERSION = None |
| 91 | |
| 92 | class BaseClient1(rest_client.RestClient): |
| 93 | api_microversion_header_name = 'X-OpenStack-Nova-API-Version' |
| 94 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 95 | Now test class can set the selected Microversion on required service clients |
| 96 | using fixture which can take care of resetting the same once tests is completed. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 97 | For example:: |
| 98 | |
| 99 | def setUp(self): |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 100 | super(BaseTestCase1, self).setUp() |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 101 | self.useFixture(api_microversion_fixture.APIMicroversionFixture( |
| 102 | self.request_microversion)) |
| 103 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 104 | Service clients needs to add set Microversion in API request header which |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 105 | can be done by overriding the get_headers() method of rest_client. |
| 106 | For 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 | |
| 120 | Step4: Separate Test classes for each Microversion |
| 121 | '''''''''''''''''''''''''''''''''''''''''''''''''' |
| 122 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 123 | This is last step to implement Microversion test class. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 124 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 125 | For any Microversion tests, basically we need to implement a |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 126 | separate test class. In addition, each test class defines its |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 127 | Microversion range with class variable like min_microversion |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 128 | and max_microversion. Tests will be valid for that defined range. |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 129 | If that range is out of configured Microversion range then, test |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 130 | will be skipped. |
| 131 | |
| 132 | *NOTE: Microversion testing is supported at test class level not at individual |
| 133 | test case level.* |
| 134 | For example: |
| 135 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 136 | Below test is applicable for Microversion from 2.2 till 2.9:: |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 137 | |
| 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 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 150 | Below test is applicable for Microversion from 2.10 till latest:: |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 151 | |
| 152 | class Test2(BaseTestCase1): |
| 153 | min_microversion = '2.10' |
| 154 | max_microversion = 'latest' |
| 155 | |
| 156 | [..] |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | Notes about Compute Microversion Tests |
| 162 | """"""""""""""""""""""""""""""""""" |
| 163 | Some of the compute Microversion tests have been already implemented |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 164 | with the Microversion testing framework. So for further tests only |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 165 | step 4 is needed. |
| 166 | |
| 167 | Along with that JSON response schema might need versioning if needed. |
| 168 | |
| 169 | Compute service clients strictly validate the response against defined JSON |
| 170 | schema and does not allow additional elements in response. |
Tong Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 171 | So if that Microversion changed the API response then schema needs to be versioned. |
| 172 | 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] | 173 | client methods will select the schema based on requested microversion. |
| 174 | |
Tong Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 175 | If Microversion tests are implemented randomly meaning not |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 176 | 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] | 177 | 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] | 178 | the response. |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 179 | This is because Nova Microversion includes all the previous Microversions behavior. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 180 | |
| 181 | For Example: |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 182 | Implementing the v2.20 Microversion tests before v2.9 and 2.19- |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 183 | 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 Liu | e0a3b8e | 2016-03-24 20:32:07 +0000 | [diff] [blame] | 185 | to be versioned accordingly. |
ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 186 | |
| 187 | That can be done by using the get_schema method in below module: |
| 188 | |
| 189 | The base_compute_client module |
| 190 | '''''''''''''''''''''''''''''' |
| 191 | |
| 192 | .. automodule:: tempest.lib.services.compute.base_compute_client |
| 193 | :members: |
| 194 | |
| 195 | |
| 196 | Microversion 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 | |
ghanshyam | e560728 | 2016-03-24 17:22:10 +0900 | [diff] [blame] | 207 | .. _2.2: http://docs.openstack.org/developer/nova/api_microversion_history.html#id2 |
ghanshyam | ba48c90 | 2016-04-15 13:42:35 +0900 | [diff] [blame^] | 208 | |
| 209 | * `2.10`_ |
| 210 | |
| 211 | .. _2.10: http://docs.openstack.org/developer/nova/api_microversion_history.html#id9 |