blob: c499f23c82dff9ed58135c74b32c89ba52405e8f [file] [log] [blame]
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +00001# Copyright 2015 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
15import testtools
16
17from tempest.common import api_version_request
18from tempest import exceptions
19
20
21class BaseMicroversionTest(object):
22 """Mixin class for API microversion test class."""
23
24 # NOTE: Basically, each microversion is small API change and we
25 # can use the same tests for most microversions in most cases.
26 # So it is nice to define the test class as possible to run
27 # for all microversions. We need to define microversion range
28 # (min_microversion, max_microversion) on each test class if necessary.
29 min_microversion = None
30 max_microversion = 'latest'
31
32
33def check_skip_with_microversion(test_min_version, test_max_version,
34 cfg_min_version, cfg_max_version):
35 min_version = api_version_request.APIVersionRequest(test_min_version)
36 max_version = api_version_request.APIVersionRequest(test_max_version)
37 config_min_version = api_version_request.APIVersionRequest(cfg_min_version)
38 config_max_version = api_version_request.APIVersionRequest(cfg_max_version)
39 if ((min_version > max_version) or
40 (config_min_version > config_max_version)):
41 msg = ("Min version is greater than Max version. Test Class versions "
42 "[%s - %s]. configration versions [%s - %s]."
43 % (min_version.get_string(),
44 max_version.get_string(),
45 config_min_version.get_string(),
46 config_max_version.get_string()))
47 raise exceptions.InvalidConfiguration(msg)
48
49 # NOTE: Select tests which are in range of configuration like
50 # config min config max
51 # ----------------+--------------------------+----------------
52 # ...don't-select|
53 # ...select... ...select... ...select...
54 # |don't-select...
55 # ......................select............................
56 if (max_version < config_min_version or
57 config_max_version < min_version):
58 msg = ("The microversion range[%s - %s] of this test is out of the "
59 "configration range[%s - %s]."
60 % (min_version.get_string(),
61 max_version.get_string(),
62 config_min_version.get_string(),
63 config_max_version.get_string()))
64 raise testtools.TestCase.skipException(msg)