Beispiel #1
0
    def get_schema(self, schema_versions_info):
        """Get JSON schema

        This method provides the matching schema for requested
        microversion (self.api_microversion).
        :param schema_versions_info: List of dict which provides schema
        information with range of valid versions.
        Example -
        schema_versions_info = [
            {'min': None, 'max': '2.1', 'schema': schemav21},
            {'min': '2.2', 'max': '2.9', 'schema': schemav22},
            {'min': '2.10', 'max': None, 'schema': schemav210}]
        """
        schema = None
        version = api_version_request.APIVersionRequest(self.api_microversion)
        for items in schema_versions_info:
            min_version = api_version_request.APIVersionRequest(items['min'])
            max_version = api_version_request.APIVersionRequest(items['max'])
            # This is case where self.api_microversion is None, which means
            # request without microversion So select base v2.1 schema.
            if version.is_null() and items['min'] is None:
                schema = items['schema']
                break
            # else select appropriate schema as per self.api_microversion
            elif version.matches(min_version, max_version):
                schema = items['schema']
                break
        if schema is None:
            raise exceptions.JSONSchemaNotFound(
                version=version.get_string(),
                schema_versions_info=schema_versions_info)
        return schema
Beispiel #2
0
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]. configuration 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 "
            "configuration 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)
Beispiel #3
0
    def test_get_string(self):
        vers_string = ["3.23", "latest"]
        for ver in vers_string:
            ver_obj = api_version_request.APIVersionRequest(ver)
            self.assertEqual(ver, ver_obj.get_string())

        self.assertIsNotNone(
            api_version_request.APIVersionRequest().get_string)
Beispiel #4
0
    def test_version_comparisons(self):
        vers2_0 = api_version_request.APIVersionRequest("2.0")
        vers2_5 = api_version_request.APIVersionRequest("2.5")
        vers5_23 = api_version_request.APIVersionRequest("5.23")
        v_null = api_version_request.APIVersionRequest()
        v_latest = api_version_request.APIVersionRequest('latest')

        self.assertTrue(v_null < vers2_5)
        self.assertTrue(vers2_0 < vers2_5)
        self.assertTrue(vers2_0 <= vers2_5)
        self.assertTrue(vers2_0 <= vers2_0)
        self.assertTrue(vers2_5 > v_null)
        self.assertTrue(vers5_23 > vers2_5)
        self.assertTrue(vers2_0 >= vers2_0)
        self.assertTrue(vers5_23 >= vers2_5)
        self.assertTrue(vers2_0 != vers2_5)
        self.assertTrue(vers2_0 == vers2_0)
        self.assertTrue(vers2_0 != v_null)
        self.assertTrue(v_null == v_null)
        self.assertTrue(vers2_0 <= v_latest)
        self.assertTrue(vers2_0 != v_latest)
        self.assertTrue(v_latest == v_latest)
        self.assertRaises(TypeError, vers2_0.__lt__, "2.1")
Beispiel #5
0
    def test_version_matches(self):
        vers2_0 = api_version_request.APIVersionRequest("2.0")
        vers2_5 = api_version_request.APIVersionRequest("2.5")
        vers2_45 = api_version_request.APIVersionRequest("2.45")
        vers3_3 = api_version_request.APIVersionRequest("3.3")
        vers3_23 = api_version_request.APIVersionRequest("3.23")
        vers4_0 = api_version_request.APIVersionRequest("4.0")
        v_null = api_version_request.APIVersionRequest()
        v_latest = api_version_request.APIVersionRequest('latest')

        def _check_version_matches(version, version1, version2, check=True):
            if check:
                msg = "Version %s does not matches with [%s - %s] range"
                self.assertTrue(
                    version.matches(version1, version2),
                    msg % (version.get_string(), version1.get_string(),
                           version2.get_string()))
            else:
                msg = "Version %s matches with [%s - %s] range"
                self.assertFalse(
                    version.matches(version1, version2),
                    msg % (version.get_string(), version1.get_string(),
                           version2.get_string()))

        _check_version_matches(vers2_5, vers2_0, vers2_45)
        _check_version_matches(vers2_5, vers2_0, v_null)
        _check_version_matches(vers2_0, vers2_0, vers2_5)
        _check_version_matches(vers3_3, vers2_5, vers3_3)
        _check_version_matches(vers3_3, v_null, vers3_3)
        _check_version_matches(vers3_3, v_null, vers4_0)
        _check_version_matches(vers2_0, vers2_5, vers2_45, False)
        _check_version_matches(vers3_23, vers2_5, vers3_3, False)
        _check_version_matches(vers2_5, vers2_45, vers2_0, False)
        _check_version_matches(vers2_5, vers2_0, v_latest)
        _check_version_matches(v_latest, v_latest, v_latest)
        _check_version_matches(vers2_5, v_latest, v_latest, False)
        _check_version_matches(v_latest, vers2_0, vers4_0, False)

        self.assertRaises(ValueError, v_null.matches, vers2_0, vers2_45)
Beispiel #6
0
def select_request_microversion(test_min_version, cfg_min_version):
    test_version = api_version_request.APIVersionRequest(test_min_version)
    cfg_version = api_version_request.APIVersionRequest(cfg_min_version)
    max_version = cfg_version if cfg_version >= test_version else test_version
    return max_version.get_string()
Beispiel #7
0
 def test_null_version(self):
     v = api_version_request.APIVersionRequest()
     self.assertTrue(v.is_null())
Beispiel #8
0
 def _test_string(version, exp_major, exp_minor):
     v = api_version_request.APIVersionRequest(version)
     self.assertEqual(v.ver_major, exp_major)
     self.assertEqual(v.ver_minor, exp_minor)