Fix Tempest microversion comparison approach
Manila microversions have following template:
x.y
where 'x' and 'y' both digits.
And now tempest transforms string 'x.y' to float but it is incorrect
thing to do because float assumes that each left value is bigger than
right one. And it is not suitable for microversion comparisons.
Examples:
Microversions true conditions:
2.9 < 2.10
2.9 < 2.81
Float true conditions:
2.9 > 2.10
2.9 > 2.81
So, create new file 'manila_tempest_tests/utils.py' and place there
old and new functions that serve all microversion actions. In addition,
port another existing utility function called 'rand_ip'.
Change-Id: I88bf2cb51fd8de1bc89bf169bda7a05ca5a0b8ab
Closes-Bug: #1518996
diff --git a/manila_tempest_tests/tests/api/admin/test_share_manage.py b/manila_tempest_tests/tests/api/admin/test_share_manage.py
index 78d28ee..c7efa01 100644
--- a/manila_tempest_tests/tests/api/admin/test_share_manage.py
+++ b/manila_tempest_tests/tests/api/admin/test_share_manage.py
@@ -14,13 +14,14 @@
# under the License.
import six
-from tempest import config # noqa
-from tempest import test # noqa
-from tempest_lib.common.utils import data_utils # noqa
-from tempest_lib import exceptions as lib_exc # noqa
-import testtools # noqa
+from tempest import config
+from tempest import test
+from tempest_lib.common.utils import data_utils
+from tempest_lib import exceptions as lib_exc
+import testtools
from manila_tempest_tests.tests.api import base
+from manila_tempest_tests import utils
CONF = config.CONF
@@ -78,7 +79,7 @@
# Data for creating shares in parallel
data = [creation_data, creation_data]
- if float(CONF.share.max_api_microversion) >= 2.8:
+ if utils.is_microversion_ge(CONF.share.max_api_microversion, "2.8"):
data.append(creation_data)
shares_created = cls.create_shares(data)
@@ -127,7 +128,7 @@
share = self.shares_v2_client.get_share(share['id'], version="2.6")
self.assertEqual(self.st['share_type']['id'], share['share_type'])
- if float(version) >= 2.8:
+ if utils.is_microversion_ge(version, "2.8"):
self.assertEqual(is_public, share['is_public'])
else:
self.assertFalse(share['is_public'])
@@ -139,9 +140,7 @@
self.shares_v2_client.get_share,
share['id'])
- @testtools.skipIf(
- float(CONF.share.max_api_microversion) < 2.8,
- "Only for API Microversion >= 2.8")
+ @base.skip_if_microversion_not_supported("2.8")
@test.attr(type=["gate", "smoke"])
def test_manage_with_is_public_True(self):
self._test_manage(share=self.shares[2], is_public=True)
diff --git a/manila_tempest_tests/tests/api/admin/test_share_types.py b/manila_tempest_tests/tests/api/admin/test_share_types.py
index d58c61c..a521aad 100644
--- a/manila_tempest_tests/tests/api/admin/test_share_types.py
+++ b/manila_tempest_tests/tests/api/admin/test_share_types.py
@@ -20,7 +20,7 @@
from tempest_lib import exceptions as lib_exc # noqa
from manila_tempest_tests.tests.api import base
-
+from manila_tempest_tests import utils
CONF = config.CONF
@@ -51,7 +51,7 @@
def _verify_is_public_key_name(self, share_type, version):
old_key_name = 'os-share-type-access:is_public'
new_key_name = 'share_type_access:is_public'
- if float(version) > 2.6:
+ if utils.is_microversion_gt(version, "2.6"):
self.assertIn(new_key_name, share_type)
self.assertNotIn(old_key_name, share_type)
else:
diff --git a/manila_tempest_tests/tests/api/base.py b/manila_tempest_tests/tests/api/base.py
index be56719..d57b493 100644
--- a/manila_tempest_tests/tests/api/base.py
+++ b/manila_tempest_tests/tests/api/base.py
@@ -15,7 +15,6 @@
import copy
import inspect
-import random
import traceback
from oslo_concurrency import lockutils
@@ -27,27 +26,15 @@
from tempest import test
from tempest_lib.common.utils import data_utils
from tempest_lib import exceptions
-import testtools
from manila_tempest_tests import clients_share as clients
from manila_tempest_tests import share_exceptions
+from manila_tempest_tests import utils
CONF = config.CONF
LOG = log.getLogger(__name__)
-def rand_ip():
- """This uses the TEST-NET-3 range of reserved IP addresses.
-
- Using this range, which are reserved solely for use in
- documentation and example source code, should avoid any potential
- conflicts in real-world testing.
- """
- TEST_NET_3 = '203.0.113.'
- final_octet = six.text_type(random.randint(0, 255))
- return TEST_NET_3 + final_octet
-
-
class handle_cleanup_exceptions(object):
"""Handle exceptions raised with cleanup operations.
@@ -91,19 +78,7 @@
return wrapped_func
-def is_microversion_supported(microversion):
- if (float(microversion) > float(CONF.share.max_api_microversion) or
- float(microversion) < float(CONF.share.min_api_microversion)):
- return False
- return True
-
-
-def skip_if_microversion_not_supported(microversion):
- """Decorator for tests that are microversion-specific."""
- if not is_microversion_supported(microversion):
- reason = ("Skipped. Test requires microversion '%s'." % microversion)
- return testtools.skip(reason)
- return lambda f: f
+skip_if_microversion_not_supported = utils.skip_if_microversion_not_supported
class BaseSharesTest(test.BaseTestCase):
@@ -125,7 +100,7 @@
method_isolated_creds = []
def skip_if_microversion_not_supported(self, microversion):
- if not is_microversion_supported(microversion):
+ if not utils.is_microversion_supported(microversion):
raise self.skipException(
"Microversion '%s' is not supported." % microversion)
@@ -657,8 +632,8 @@
data = {
"name": data_utils.rand_name("ss-name"),
"description": data_utils.rand_name("ss-desc"),
- "dns_ip": rand_ip(),
- "server": rand_ip(),
+ "dns_ip": utils.rand_ip(),
+ "server": utils.rand_ip(),
"domain": data_utils.rand_name("ss-domain"),
"user": data_utils.rand_name("ss-user"),
"password": data_utils.rand_name("ss-password"),