Add the base microversions test part

This is base part of microversions tests.
This patch adds the mechanism for selecting the microversion tests based
on new configration options like the following:

TestClass A: min_microversion = None,  max_microversion = 'latest'
TestClass B: min_microversion = None,  max_microversion = '2.2'
TestClass C: min_microversion = '2.3', max_microversion = 'latest'
TestClass D: min_microversion = '2.5', max_microversion = '2.10'

  +--------------------+-----------------------------------------------------+
  | Configration       | Test classes                                        |
  | (min,    max)      | (Passed microversion)                               |
  +====================+=====================================================+
  | None,     None     | A(Not passed), B(Not passed), C & D - Skipped       |
  +--------------------+-----------------------------------------------------+
  | None,     '2.3'    | A(Not passed), B(Not passed), C('2.3'), D - Skipped |
  +--------------------+-----------------------------------------------------+
  | '2.2',    'latest' | A('2.2'), B('2.2'), C('2.3'), D('2.5')              |
  +--------------------+-----------------------------------------------------+
  | '2.2',    '2.3'    | A('2.2'), B('2.2'), C('2.3'), D - Skipped           |
  +--------------------+-----------------------------------------------------+
  | '2.10',   '2.10'   | A('2.10'), B - Skipped, C('2.10'), D('2.10')        |
  +--------------------+-----------------------------------------------------+
  | None,     'latest' | A(Not passed), B(Not passed), C('2.3'), D('2.5')    |
  +--------------------+-----------------------------------------------------+
  | 'latest', 'latest' | A('latest'), B - Skipped, C('latest'), D - Skipped  |
  +--------------------+-----------------------------------------------------+

After this patch, we need to add tests for each microversion and
these test classes need to contain the range of microversions.

Partially implements blueprint api-microversions-testing-support

Change-Id: I57b78b4c0543b6fb0533b556886a19a03297555e
diff --git a/tempest/common/api_version_utils.py b/tempest/common/api_version_utils.py
new file mode 100644
index 0000000..c499f23
--- /dev/null
+++ b/tempest/common/api_version_utils.py
@@ -0,0 +1,64 @@
+# Copyright 2015 NEC Corporation.  All rights reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import testtools
+
+from tempest.common import api_version_request
+from tempest import exceptions
+
+
+class BaseMicroversionTest(object):
+    """Mixin class for API microversion test class."""
+
+    # NOTE: Basically, each microversion is small API change and we
+    # can use the same tests for most microversions in most cases.
+    # So it is nice to define the test class as possible to run
+    # for all microversions. We need to define microversion range
+    # (min_microversion, max_microversion) on each test class if necessary.
+    min_microversion = None
+    max_microversion = 'latest'
+
+
+def check_skip_with_microversion(test_min_version, test_max_version,
+                                 cfg_min_version, cfg_max_version):
+    min_version = api_version_request.APIVersionRequest(test_min_version)
+    max_version = api_version_request.APIVersionRequest(test_max_version)
+    config_min_version = api_version_request.APIVersionRequest(cfg_min_version)
+    config_max_version = api_version_request.APIVersionRequest(cfg_max_version)
+    if ((min_version > max_version) or
+       (config_min_version > config_max_version)):
+        msg = ("Min version is greater than Max version. Test Class versions "
+               "[%s - %s]. configration versions [%s - %s]."
+               % (min_version.get_string(),
+                  max_version.get_string(),
+                  config_min_version.get_string(),
+                  config_max_version.get_string()))
+        raise exceptions.InvalidConfiguration(msg)
+
+    # NOTE: Select tests which are in range of configuration like
+    #               config min           config max
+    # ----------------+--------------------------+----------------
+    # ...don't-select|
+    #            ...select...  ...select...  ...select...
+    #                                             |don't-select...
+    # ......................select............................
+    if (max_version < config_min_version or
+        config_max_version < min_version):
+        msg = ("The microversion range[%s - %s] of this test is out of the "
+               "configration range[%s - %s]."
+               % (min_version.get_string(),
+                  max_version.get_string(),
+                  config_min_version.get_string(),
+                  config_max_version.get_string()))
+        raise testtools.TestCase.skipException(msg)