import sys
import yaml
-from functest.utils import env
-
LOGGER = logging.getLogger(__name__)
ofd.write(line)
else:
line = line.replace('\n', '')
- print (line)
+ print(line)
sys.stdout.flush()
if output_file:
ofd.close()
return value
-def get_external_network(cloud):
+def get_nova_version(cloud):
+ """ Get Nova API microversion
+
+ Returns:
+
+ - Nova API microversion
+ - None on operation error
"""
- Returns the configured external network name or
- the first retrieved external network name
+ # pylint: disable=protected-access
+ try:
+ request = cloud._compute_client.request("/", "GET")
+ LOGGER.debug('cloud._compute_client.request: %s', request)
+ version = request["version"]["version"]
+ major, minor = version.split('.')
+ LOGGER.debug('nova version: %s', (int(major), int(minor)))
+ return (int(major), int(minor))
+ except Exception: # pylint: disable=broad-except
+ LOGGER.exception("Cannot detect Nova version")
+ return None
+
+
+def get_openstack_version(cloud):
+ """ Detect OpenStack version via Nova API microversion
+
+ It follows `MicroversionHistory
+ <https://docs.openstack.org/nova/latest/reference/api-microversion-history.html>`_.
+
+ Returns:
+
+ - OpenStack release
+ - Unknown on operation error
"""
- assert cloud
- if env.get("EXTERNAL_NETWORK"):
- network = cloud.get_network(
- env.get("EXTERNAL_NETWORK"), {"router:external": True})
- if network:
- return network
- networks = cloud.list_networks({"router:external": True})
- if networks:
- return networks[0]
- return None
+ version = get_nova_version(cloud)
+ try:
+ assert version
+ if version > (2, 60):
+ osversion = "Rocky or newer"
+ elif version > (2, 53):
+ osversion = "Queens"
+ elif version > (2, 42):
+ osversion = "Pike"
+ elif version > (2, 38):
+ osversion = "Ocata"
+ elif version > (2, 25):
+ osversion = "Newton"
+ elif version > (2, 12):
+ osversion = "Mitaka"
+ elif version > (2, 3):
+ osversion = "Liberty"
+ elif version >= (2, 1):
+ osversion = "Kilo"
+ else:
+ osversion = "Unknown"
+ LOGGER.info('Detect OpenStack version: %s', osversion)
+ return osversion
+ except AssertionError:
+ LOGGER.exception("Cannot detect OpenStack version")
+ return "Unknown"