# -*- coding: utf-8 -*-
from datetime import date, datetime
from miq_version import ( # noqa
Version, LOWEST, LATEST, UPSTREAM, SPTuple, get_version,
version_stream_product_mapping
)
from cfme.fixtures.pytest_store import store
[docs]def get_stream(ver):
"""Return a stream name for given Version obj or version string
"""
ver = Version(ver)
if ver.stream() is not None:
return ver.stream()
else:
raise LookupError("no matching stream found for version {}".format(ver))
[docs]def current_version():
"""A lazy cached method to return the appliance version.
Do not catch errors, since generally we cannot proceed with
testing, without knowing the server version.
"""
return store.current_appliance.version
[docs]def appliance_build_datetime():
try:
return store.current_appliance.build_datetime
except:
return None
[docs]def appliance_build_date():
try:
return store.current_appliance.build_date
except:
return None
[docs]def appliance_is_downstream():
return store.current_appliance.is_downstream
[docs]def parsedate(o):
if isinstance(o, date):
return o
elif isinstance(o, datetime):
return o.date()
else:
# 1234-12-13
return date(*[int(x) for x in str(o).split("-", 2)])
[docs]def appliance_has_netapp():
try:
return store.current_appliance.has_netapp()
except:
return None
[docs]def pick(v_dict, active_version=None):
"""
Collapses an ambiguous series of objects bound to specific versions
by interrogating the CFME Version and returning the correct item.
"""
# convert keys to Versions
active_version = active_version or current_version()
v_dict = {get_version(k): v for (k, v) in v_dict.items()}
versions = v_dict.keys()
sorted_matching_versions = sorted((v for v in versions if v <= active_version),
reverse=True)
return v_dict.get(sorted_matching_versions[0]) if sorted_matching_versions else None