Fix finally verify_osp_version using packaging lib
Change-Id: Ib97d8b001c100d08c5d144621cd87f010c8b07d2
This commit is contained in:
parent
af20a2f12b
commit
079c894bf1
@ -11,6 +11,7 @@ netaddr==0.8.0
|
|||||||
neutron-lib==2.7.0
|
neutron-lib==2.7.0
|
||||||
oslo.config==8.4.0
|
oslo.config==8.4.0
|
||||||
oslo.log==4.4.0
|
oslo.log==4.4.0
|
||||||
|
packaging==20.4
|
||||||
paramiko==2.9.2
|
paramiko==2.9.2
|
||||||
pbr==5.5.1
|
pbr==5.5.1
|
||||||
psutil==5.8.0
|
psutil==5.8.0
|
||||||
|
@ -11,6 +11,7 @@ netaddr>=0.8.0 # BSD
|
|||||||
neutron-lib>=2.7.0 # Apache-2.0
|
neutron-lib>=2.7.0 # Apache-2.0
|
||||||
oslo.config>=8.4.0 # Apache-2.0
|
oslo.config>=8.4.0 # Apache-2.0
|
||||||
oslo.log>=4.4.0 # Apache-2.0
|
oslo.log>=4.4.0 # Apache-2.0
|
||||||
|
packaging>=20.4 # Apache-2.0
|
||||||
paramiko>=2.9.2 # LGPLv2.1
|
paramiko>=2.9.2 # LGPLv2.1
|
||||||
pbr>=5.5.1 # Apache-2.0
|
pbr>=5.5.1 # Apache-2.0
|
||||||
psutil>=5.8.0 # BSD
|
psutil>=5.8.0 # BSD
|
||||||
|
@ -22,6 +22,7 @@ import weakref
|
|||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
from packaging import version
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.shell import files
|
from tobiko.shell import files
|
||||||
@ -662,7 +663,7 @@ def get_openstack_version():
|
|||||||
os_to_nova_versions = {'13.0.0': '17', # Queens
|
os_to_nova_versions = {'13.0.0': '17', # Queens
|
||||||
'16.0.0': '19', # Stein
|
'16.0.0': '19', # Stein
|
||||||
'16.1.0': '20', # Train
|
'16.1.0': '20', # Train
|
||||||
'17.0.0': '22'} # Ussuri
|
'17.0.0': '23'} # Wallaby
|
||||||
for os_version, nova_major_version in os_to_nova_versions.items():
|
for os_version, nova_major_version in os_to_nova_versions.items():
|
||||||
if nova_version.split('.')[0] == nova_major_version:
|
if nova_version.split('.')[0] == nova_major_version:
|
||||||
return os_version
|
return os_version
|
||||||
@ -681,58 +682,31 @@ def remove_duplications(items: typing.List) -> typing.List:
|
|||||||
return list(mapping.keys())
|
return list(mapping.keys())
|
||||||
|
|
||||||
|
|
||||||
def _is_version_matched(current, required, higher=False, lower=False):
|
def verify_osp_version(required_version, higher=False, lower=False):
|
||||||
# return True means the condition has been fulfilled and next items do not
|
|
||||||
# need to be compared
|
|
||||||
# return False means the condition has not been fulfilled and next items do
|
|
||||||
# not need to be compared
|
|
||||||
# return None means the condition has been fulfilled so far, but next items
|
|
||||||
# need to be compared too
|
|
||||||
if not higher and not lower: # this means equal
|
|
||||||
if int(current) != int(required):
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
elif higher:
|
|
||||||
if int(current) < int(required):
|
|
||||||
return False
|
|
||||||
elif lower:
|
|
||||||
if int(current) > int(required):
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
raise RuntimeError
|
|
||||||
if int(current) != int(required):
|
|
||||||
return True
|
|
||||||
# else: return None
|
|
||||||
|
|
||||||
|
|
||||||
def verify_osp_version(version, higher=False, lower=False):
|
|
||||||
try:
|
try:
|
||||||
current_version = get_openstack_version()
|
current_version = get_openstack_version()
|
||||||
except Exception:
|
except Exception:
|
||||||
current_version = None
|
current_version = None
|
||||||
if not current_version:
|
if current_version is None:
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
correct_version = True
|
required_version_parsed = version.parse(required_version)
|
||||||
os_version = current_version.split('.')
|
current_version_parsed = version.parse(current_version)
|
||||||
required_version = version.split('.')
|
|
||||||
for version_type in range(len(required_version)):
|
if higher and lower:
|
||||||
is_version_match = _is_version_matched(
|
raise RuntimeError
|
||||||
os_version[version_type],
|
elif not higher and not lower: # this means equal
|
||||||
required_version[version_type],
|
return current_version_parsed == required_version_parsed
|
||||||
higher=higher,
|
elif higher:
|
||||||
lower=lower)
|
return current_version_parsed > required_version_parsed
|
||||||
if is_version_match is not None:
|
elif lower:
|
||||||
correct_version = is_version_match
|
return current_version_parsed < required_version_parsed
|
||||||
break
|
|
||||||
return correct_version
|
|
||||||
|
|
||||||
|
|
||||||
def skip_unless_osp_version(version, higher=False, lower=False):
|
def skip_unless_osp_version(required_version, higher=False, lower=False):
|
||||||
skip_msg = "OSP version doesn't match the requirement"
|
skip_msg = "OSP version doesn't match the requirement"
|
||||||
return tobiko.skip_unless(skip_msg, verify_osp_version,
|
return tobiko.skip_unless(skip_msg, verify_osp_version,
|
||||||
version, higher, lower)
|
required_version, higher, lower)
|
||||||
|
|
||||||
|
|
||||||
MatchStringType = typing.Union[str, typing.Pattern]
|
MatchStringType = typing.Union[str, typing.Pattern]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user