Exemplo n.º 1
0
    def test_version_comparisons(self):
        v1 = api_versioning.APIVersion("2.0")
        v2 = api_versioning.APIVersion("2.5")
        v3 = api_versioning.APIVersion("5.23")
        v4 = api_versioning.APIVersion("2.0")
        v_null = api_versioning.APIVersion()

        self.assertTrue(v1 < v2)
        self.assertTrue(v3 > v2)
        self.assertTrue(v1 != v2)
        self.assertTrue(v1 == v4)
        self.assertTrue(v1 != v_null)
        self.assertTrue(v_null == v_null)
        self.assertRaises(TypeError, v1.__le__, "2.1")
Exemplo n.º 2
0
    def test_version_comparisons(self):
        v1 = api_versioning.APIVersion("2.0")
        v2 = api_versioning.APIVersion("2.5")
        v3 = api_versioning.APIVersion("5.23")
        v4 = api_versioning.APIVersion("2.0")
        v_null = api_versioning.APIVersion()

        self.assertLess(v1, v2)
        self.assertGreater(v3, v2)
        self.assertNotEqual(v1, v2)
        self.assertEqual(v1, v4)
        self.assertNotEqual(v1, v_null)
        self.assertEqual(v_null, v_null)
        self.assertRaises(TypeError, v1.__le__, "2.1")
Exemplo n.º 3
0
def check_api_version(check_version):
    """Validate version supplied by user

    Returns:
    * True if version is OK
    * False if the version has not been checked and the previous plugin
    check should be performed
    * throws an exception if the version is no good
    """

    infra_api_version = api_versioning.get_api_version(check_version)

    # Bypass X.latest format microversion
    if not infra_api_version.is_latest():
        if infra_api_version > api_versioning.APIVersion("2.0"):
            if not infra_api_version.matches(
                    watcherclient.API_MIN_VERSION,
                    watcherclient.API_MAX_VERSION,
            ):
                msg = "versions supported by client: %(min)s - %(max)s" % {
                    "min": watcherclient.API_MIN_VERSION.get_string(),
                    "max": watcherclient.API_MAX_VERSION.get_string(),
                }
                raise exceptions.CommandError(msg)
    return True
Exemplo n.º 4
0
    def test_version_matches(self):
        v1 = api_versioning.APIVersion("2.0")
        v2 = api_versioning.APIVersion("2.5")
        v3 = api_versioning.APIVersion("2.45")
        v4 = api_versioning.APIVersion("3.3")
        v5 = api_versioning.APIVersion("3.23")
        v6 = api_versioning.APIVersion("2.0")
        v7 = api_versioning.APIVersion("3.3")
        v8 = api_versioning.APIVersion("4.0")
        v_null = api_versioning.APIVersion()

        self.assertTrue(v2.matches(v1, v3))
        self.assertTrue(v2.matches(v1, v_null))
        self.assertTrue(v1.matches(v6, v2))
        self.assertTrue(v4.matches(v2, v7))
        self.assertTrue(v4.matches(v_null, v7))
        self.assertTrue(v4.matches(v_null, v8))
        self.assertFalse(v1.matches(v2, v3))
        self.assertFalse(v5.matches(v2, v4))
        self.assertFalse(v2.matches(v3, v1))

        self.assertRaises(ValueError, v_null.matches, v1, v3)
Exemplo n.º 5
0
def make_client(instance):
    """Returns an infra-optim service client."""

    version = api_versioning.APIVersion(instance._api_version[API_NAME])

    infraoptim_client_class = utils.get_client_class(API_NAME,
                                                     version.ver_major,
                                                     API_VERSIONS)
    LOG.debug('Instantiating infraoptim client: %s', infraoptim_client_class)

    client = infraoptim_client_class(
        os_infra_optim_api_version=instance._api_version[API_NAME],
        session=instance.session,
        region_name=instance._region_name,
    )

    return client
Exemplo n.º 6
0
 def test_null_version(self):
     v = api_versioning.APIVersion()
     self.assertTrue(v.is_null())
Exemplo n.º 7
0
 def _test_string(version, exp_major, exp_minor):
     v = api_versioning.APIVersion(version)
     self.assertEqual(v.ver_major, exp_major)
     self.assertEqual(v.ver_minor, exp_minor)
Exemplo n.º 8
0
    def test_get_string(self):
        v1_string = "3.23"
        v1 = api_versioning.APIVersion(v1_string)
        self.assertEqual(v1_string, v1.get_string())

        self.assertRaises(ValueError, api_versioning.APIVersion().get_string)
Exemplo n.º 9
0
# 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 pbr.version

from watcherclient import client
from watcherclient.common import api_versioning
from watcherclient import exceptions


__version__ = pbr.version.VersionInfo(
    'python-watcherclient').version_string()

__all__ = ['client', 'exceptions', ]

API_MIN_VERSION = api_versioning.APIVersion("1.0")
# The max version should be the latest version that is supported in the client,
# not necessarily the latest that the server can provide. This is only bumped
# when client supported the max version, and bumped sequentially, otherwise
# the client may break due to server side new version may include some
# backward incompatible change.
API_MAX_VERSION = api_versioning.APIVersion("1.1")