ghanshyam | bd460ac | 2016-03-16 16:28:56 +0900 | [diff] [blame] | 1 | =================================== |
| 2 | How To Implement Microversion Tests |
| 3 | =================================== |
| 4 | |
| 5 | Tempest provides stable interfaces to test API microversion. |
| 6 | For Details, see: `API Microversion testing Framework`_ |
| 7 | This document explains how to implement microversion tests using those |
| 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 |
| 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 | |
| 31 | How To Implement Microversion Tests |
| 32 | """"""""""""""""""""""""""""""""""" |
| 33 | |
| 34 | Step1: Add skip logic based on configured microversion range |
| 35 | '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
| 36 | |
| 37 | Add logic to skip the tests based on Tests class and configured Microversion |
| 38 | range. |
| 39 | api_version_utils.check_skip_with_microversion function can be used |
| 40 | to automatically skip the tests which does not fall under configured |
| 41 | Microversion range. |
| 42 | For 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 | |
| 55 | Skip logic can be added in tests base class or any specific test class depends on |
| 56 | tests class structure. |
| 57 | |
| 58 | Step2: Selected API request microversion |
| 59 | '''''''''''''''''''''''''''''''''''''''' |
| 60 | |
| 61 | Select appropriate Microversion which needs to be used |
| 62 | to send with API request. |
| 63 | api_version_utils.select_request_microversion function can be used |
| 64 | to select the appropriate microversion which will be used for API request. |
| 65 | For 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 | |
| 76 | Step3: Set Microversion on Service Clients |
| 77 | '''''''''''''''''''''''''''''''''''''''''' |
| 78 | |
| 79 | Microversion selected by Test Class in previous step needs to be set on |
| 80 | service clients so that APIs can be requested with selected microversion. |
| 81 | |
| 82 | Microversion can be defined as global variable on service clients which |
| 83 | can be set using fixture. |
| 84 | Also microversion header name needs to be defined on service clients which |
| 85 | should be constant because it is not supposed to be changed by project |
| 86 | as per API contract. |
| 87 | For example:: |
| 88 | |
| 89 | COMPUTE_MICROVERSION = None |
| 90 | |
| 91 | class BaseClient1(rest_client.RestClient): |
| 92 | api_microversion_header_name = 'X-OpenStack-Nova-API-Version' |
| 93 | |
| 94 | Now test class can set the selected microversion on required service clients |
| 95 | using fixture which can take care of reseting the same once tests is completed. |
| 96 | For example:: |
| 97 | |
| 98 | def setUp(self): |
| 99 | super(BaseTestCase1,, self).setUp() |
| 100 | self.useFixture(api_microversion_fixture.APIMicroversionFixture( |
| 101 | self.request_microversion)) |
| 102 | |
| 103 | Service clients needs to add set microversion in API request header which |
| 104 | can be done by overriding the get_headers() method of rest_client. |
| 105 | For 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 | |
| 119 | Step4: Separate Test classes for each Microversion |
| 120 | '''''''''''''''''''''''''''''''''''''''''''''''''' |
| 121 | |
| 122 | This is last step to implement microversion test class. |
| 123 | |
| 124 | For any microversion tests, basically we need to implement a |
| 125 | separate test class. In addition, each test class defines its |
| 126 | microversion range with class variable like min_microversion |
| 127 | and max_microversion. Tests will be valid for that defined range. |
| 128 | If that range is out of configured microversion range then, test |
| 129 | will be skipped. |
| 130 | |
| 131 | *NOTE: Microversion testing is supported at test class level not at individual |
| 132 | test case level.* |
| 133 | For example: |
| 134 | |
| 135 | Below 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 | |
| 149 | Below 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 | |
| 160 | Notes about Compute Microversion Tests |
| 161 | """"""""""""""""""""""""""""""""""" |
| 162 | Some of the compute Microversion tests have been already implemented |
| 163 | with the microversion testing framework. So for further tests only |
| 164 | step 4 is needed. |
| 165 | |
| 166 | Along with that JSON response schema might need versioning if needed. |
| 167 | |
| 168 | Compute service clients strictly validate the response against defined JSON |
| 169 | schema and does not allow additional elements in response. |
| 170 | So if that microversion changed the API response then schema needs to be version. |
| 171 | New JSON schema file needs be defined with new response attributes and service |
| 172 | client methods will select the schema based on requested microversion. |
| 173 | |
| 174 | If microversion tests are implemented randomly means not |
| 175 | in sequence order(v2.20 tests added and previous microversion tests are not yet added) |
| 176 | then, still schema might needs to be version for older microversion if they changed |
| 177 | the response. |
| 178 | This is because Nova microversion includes all the previous microversions behvaior. |
| 179 | |
| 180 | For 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 | |
| 186 | That can be done by using the get_schema method in below module: |
| 187 | |
| 188 | The base_compute_client module |
| 189 | '''''''''''''''''''''''''''''' |
| 190 | |
| 191 | .. automodule:: tempest.lib.services.compute.base_compute_client |
| 192 | :members: |
| 193 | |
| 194 | |
| 195 | Microversion 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 |