]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa.utils.metadata: re-organise host distro information
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 13 Jan 2017 13:12:37 +0000 (15:12 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 19 Jan 2017 22:45:45 +0000 (22:45 +0000)
Put all host distro data under one <host_distro> element. In addition
take the data directly from /etc/os-release instead of the "lsb API".
The /etc/os-release file is virtually ubiquitous, now, and using its
field names and values provides a more standardized and extensible
format.

[YOCTO #10590]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/lib/oeqa/utils/metadata.py

index 5d8bf84755f97c76b6c2922c862e7a24306df085..2316841e0fb04705e7cb91895cc23cc72ccb8a97 100644 (file)
@@ -10,11 +10,22 @@ from collections.abc import MutableMapping
 from xml.dom.minidom import parseString
 from xml.etree.ElementTree import Element, tostring
 
-from oe.lsb import distro_identifier
 from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars
 
 metadata_vars = ['MACHINE', 'DISTRO', 'DISTRO_VERSION']
 
+def get_os_release():
+    """Get info from /etc/os-release as a dict"""
+    data = OrderedDict()
+    os_release_file = '/etc/os-release'
+    if not os.path.exists(os_release_file):
+        return None
+    with open(os_release_file) as fobj:
+        for line in fobj:
+            key, value = line.split('=', 1)
+            data[key.strip().lower()] = value.strip().strip('"')
+    return data
+
 def metadata_from_bb():
     """ Returns test's metadata as OrderedDict.
 
@@ -27,10 +38,15 @@ def metadata_from_bb():
     data_dict = get_bb_vars(metadata_vars)
     for var in metadata_vars:
         info_dict[var.lower()] = data_dict[var]
-    host_distro= distro_identifier()
-    host_distro, _, host_distro_release = host_distro.partition('-')
-    info_dict['host_distro'] = host_distro
-    info_dict['host_distro_release'] = host_distro_release
+
+    # Host distro information
+    os_release = get_os_release()
+    if os_release:
+        info_dict['host_distro'] = OrderedDict()
+        for key in ('id', 'version_id', 'pretty_name'):
+            if key in os_release:
+                info_dict['host_distro'][key] = os_release[key]
+
     info_dict['layers'] = get_layers(get_bb_var('BBLAYERS'))
     return info_dict