Compare versions of OpenStack with LooseVersion

Since release Liberty, OpenStack doesn't have common release version
(like 2015.1.0). If we use release codename to identify the version
instead (like 'liberty'), it cannot be compared to previous numeric
versions with distutils.version.StrictVersion.

Use of LooseVersion instead ensures that alphabetic version will always
be considered 'newer' than numeric version.

Change-Id: Ifefc4fab56993ed369a92804b1a866e766b2ec0b
Related-bug: 1503663
This commit is contained in:
Oleg Gelbukh 2015-11-30 09:25:52 +00:00
parent 9910a4726c
commit 9243eab196
3 changed files with 39 additions and 3 deletions

View File

@ -202,8 +202,8 @@ def _compare_release_versions(cluster_release_version, test_release_version):
test_openstack_ver, test_fuel_ver = test_release_version.split('-')
cond = (
(version.StrictVersion(cl_openstack_ver) >=
version.StrictVersion(test_openstack_ver))
(version.LooseVersion(cl_openstack_ver) >=
version.LooseVersion(test_openstack_ver))
and
(version.StrictVersion(cl_fuel_ver) >=
version.StrictVersion(test_fuel_ver))

View File

@ -47,3 +47,13 @@ class TestVersioning(unittest2.TestCase):
Deployment tags: releases_comparison
"""
self.assertTrue(True)
def test_simple_fake_alphabetic(self):
"""This is simple fake test
for versioning checking.
It should be discovered for
releases == of >= liberty-8.0
Available since release: liberty-8.0
Deployment tags: releases_comparison
"""
self.assertTrue(True)

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import random
from mock import Mock
from nose import case
@ -63,10 +65,30 @@ class TestNoseDiscovery(base.BaseUnitTest):
def _find_needed_test_set(self, test_set_id):
return next(t for t in self.test_sets if t.id == test_set_id)
def test_compare_release_versions(self):
def cmp_version(first, second):
if nose_utils._compare_release_versions(first, second):
return 1
else:
return -1
expected = [
'2014.2-6.0',
'2014.2.2-6.1',
'2015.1.0-7.0',
'liberty-8.0'
]
releases = expected[:]
random.shuffle(releases)
self.assertEqual(expected,
sorted(releases,
cmp=cmp_version))
def test_discovery(self):
expected = {
'test_sets_count': 10,
'tests_count': 29
'tests_count': 30
}
self.assertTrue(
@ -187,6 +209,10 @@ class TestNoseDiscovery(base.BaseUnitTest):
'test_versioning.TestVersioning.'
'test_simple_fake_second'),
'available_since_release': '2015.2-6.1', },
{'name': ('fuel_plugin.testing.fixture.dummy_tests.'
'test_versioning.TestVersioning.'
'test_simple_fake_alphabetic'),
'available_since_release': 'liberty-8.0', }
]
}