Ghanshyam Mann | ad8737c | 2019-04-13 01:12:58 +0000 | [diff] [blame] | 1 | # Copyright 2019 NEC Corporation. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import fixtures |
| 16 | |
| 17 | from tempest.lib.services.compute import base_compute_client |
| 18 | from tempest.lib.services.placement import base_placement_client |
| 19 | from tempest.lib.services.volume import base_client as base_volume_client |
| 20 | |
| 21 | |
| 22 | class APIMicroversionFixture(fixtures.Fixture): |
| 23 | """API Microversion Fixture to set service microversion. |
| 24 | |
| 25 | This class provides the fixture to set and reset the microversion |
| 26 | on service client. Service client has global variable to set the |
| 27 | microversion for that service API request. |
| 28 | For example: base_compute_client.COMPUTE_MICROVERSION |
| 29 | Global variable is always risky to set directly which can affect the |
| 30 | other test's API request also. This class provides a way to reset the |
| 31 | service microversion once test finish the API request. |
| 32 | This class can be used with useFixture: Example:: |
| 33 | |
| 34 | def setUp(self): |
| 35 | super(BaseV2ComputeTest, self).setUp() |
| 36 | self.useFixture(api_microversion_fixture.APIMicroversionFixture( |
| 37 | compute_microversion=self.compute_request_microversion)) |
| 38 | |
| 39 | Or you can set microversion on multiple services together:: |
| 40 | |
| 41 | def setUp(self): |
| 42 | super(ScenarioTest, self).setUp() |
| 43 | self.useFixture(api_microversion_fixture.APIMicroversionFixture( |
| 44 | compute_microversion=self.compute_request_microversion, |
| 45 | volume_microversion=self.volume_request_microversion)) |
| 46 | |
| 47 | Current supported services: |
| 48 | - Compute |
| 49 | - Volume |
| 50 | - Placement |
| 51 | |
| 52 | :param str compute_microversion: microvesion to be set on compute |
| 53 | service clients |
| 54 | :param str volume_microversion: microvesion to be set on volume |
| 55 | service clients |
| 56 | :param str placement_microversion: microvesion to be set on placement |
| 57 | service clients |
| 58 | """ |
| 59 | |
| 60 | def __init__(self, compute_microversion=None, volume_microversion=None, |
| 61 | placement_microversion=None): |
| 62 | self.compute_microversion = compute_microversion |
| 63 | self.volume_microversion = volume_microversion |
| 64 | self.placement_microversion = placement_microversion |
| 65 | |
| 66 | def _setUp(self): |
| 67 | super(APIMicroversionFixture, self)._setUp() |
| 68 | if self.compute_microversion: |
| 69 | base_compute_client.COMPUTE_MICROVERSION = ( |
| 70 | self.compute_microversion) |
| 71 | if self.volume_microversion: |
| 72 | base_volume_client.VOLUME_MICROVERSION = self.volume_microversion |
| 73 | if self.placement_microversion: |
| 74 | base_placement_client.PLACEMENT_MICROVERSION = ( |
| 75 | self.placement_microversion) |
| 76 | |
| 77 | self.addCleanup(self._reset_microversion) |
| 78 | |
| 79 | def _reset_microversion(self): |
| 80 | base_compute_client.COMPUTE_MICROVERSION = None |
| 81 | base_volume_client.VOLUME_MICROVERSION = None |
| 82 | base_placement_client.PLACEMENT_MICROVERSION = None |