Skip to contentSkip to conversation

oeqa.utils.metadata: update xml schema

PATCH New Markus Lehtonen 1 participant 11 messages Jan 13, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover oeqa.utils.metadata: update xml schema

Changes since v1:
- import of git module moved back to function level
- two new patches regarding config variables

The following changes since commit acce512a0b85853b5acf2ef07e4163a3b4f33a98:

selftest/devtool: update test to work with new mtd-utils (2017-01-09 13:34:32 +0000)

are available in the git repository at:

git://git.openembedded.org/openembedded-core-contrib marquiz/oeqa-metaxml
http://git.openembedded.org/openembedded-core-contrib/log/?h=marquiz/oeqa-metaxml

Markus Lehtonen (10):
oeqa.utils.metadata: re-organise host distro information oeqa.utils.metadata: re-organise distro information oeqa.utils.metadata: drop 'unknown' git data elements oeqa.utils.metadata: fix retrieval of git branch and revision oeqa.utils.metadata: rename 'revision' to 'commit' oeqa.utils.metadata: add commit count information oeqa.utils.metadata: have layer name as an attribute in xml oeqa.utils.metadata: add bitbake revision information oeqa.utils.metadata: allow storing any bitbake config variables oeqa.utils.metadata: include BB_NUMBER_THREADS and PARALLEL_MAKE

 meta/lib/oeqa/utils/metadata.py | 87 +++++++++++++++++++++++++++++------------
 scripts/oe-selftest             | 12 +++---
 2 files changed, 67 insertions(+), 32 deletions(-)
Signature · 1 line
2.6.6
#1 lore raw

PATCH v2 1/10 oeqa.utils.metadata: re-organise host distro information

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]

---
 meta/lib/oeqa/utils/metadata.py | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)
meta/lib/oeqa/utils/metadata.py +21 -5
index 5d8bf84..2316841 100644
@@ -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
 
Signature · 1 line
2.6.6
#2 lore raw

PATCH v2 2/10 oeqa.utils.metadata: re-organise distro information

In reply to Markus Lehtonen

Use the same format, based on /etc/os-release, as for host distro information.

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 17 ++++++++++-------
 scripts/oe-selftest             |  4 ++--
 2 files changed, 12 insertions(+), 9 deletions(-)
meta/lib/oeqa/utils/metadata.py +10 -7
index 2316841..df6ed91 100644
@@ -10,9 +10,7 @@ from collections.abc import MutableMapping
 from xml.dom.minidom import parseString
 from xml.etree.ElementTree import Element, tostring
 
-from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars
-
-metadata_vars = ['MACHINE', 'DISTRO', 'DISTRO_VERSION']
+from oeqa.utils.commands import runCmd, get_bb_vars
 
 def get_os_release():
     """Get info from /etc/os-release as a dict"""
@@ -35,9 +33,14 @@ def metadata_from_bb():
     info_dict = OrderedDict()
     hostname = runCmd('hostname')
     info_dict['hostname'] = hostname.output
-    data_dict = get_bb_vars(metadata_vars)
-    for var in metadata_vars:
-        info_dict[var.lower()] = data_dict[var]
+    data_dict = get_bb_vars()
+
+    info_dict['machine'] = data_dict['MACHINE']
+
+    # Distro information
+    info_dict['distro'] = {'id': data_dict['DISTRO'],
+                           'version_id': data_dict['DISTRO_VERSION'],
+                           'pretty_name': '%s %s' % (data_dict['DISTRO'], data_dict['DISTRO_VERSION'])}
 
     # Host distro information
     os_release = get_os_release()
@@ -47,7 +50,7 @@ def metadata_from_bb():
             if key in os_release:
                 info_dict['host_distro'][key] = os_release[key]
 
-    info_dict['layers'] = get_layers(get_bb_var('BBLAYERS'))
+    info_dict['layers'] = get_layers(data_dict['BBLAYERS'])
     return info_dict
 
 def metadata_from_data_store(d):
scripts/oe-selftest +2 -2
index adfa92f..5510410 100755
@@ -632,8 +632,8 @@ def main():
             for layer, values in metadata['layers'].items():
                 layer_info = '%s%-17s = %s:%s\n' % (layer_info, layer,
                               values['branch'], values['revision'])
-            msg = 'Selftest for build %s of %s %s for machine %s on %s\n\n%s' % (
-                   log_prefix[12:], metadata['distro'], metadata['distro_version'],
+            msg = 'Selftest for build %s of %s for machine %s on %s\n\n%s' % (
+                   log_prefix[12:], metadata['distro']['pretty_name'],
                    metadata['machine'], metadata['hostname'], layer_info)
 
             log.debug('Commiting results to local repository')
Signature · 1 line
2.6.6
#3 lore raw

PATCH v2 3/10 oeqa.utils.metadata: drop 'unknown' git data elements

In reply to Markus Lehtonen

It's better just to not have the xml elements than to have elements with faux data. One could have git branch named 'unknown', for example.

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 7 +++----
 scripts/oe-selftest             | 4 ++--
 2 files changed, 5 insertions(+), 6 deletions(-)
meta/lib/oeqa/utils/metadata.py +3 -4
index df6ed91..a389c6a 100644
@@ -73,11 +73,10 @@ def get_layers(layers):
         try:
             repo = Repo(layer, search_parent_directories=True)
             revision, branch = repo.head.object.name_rev.split()
-            layer_dict[layer_name]['branch'] = branch
-            layer_dict[layer_name]['revision'] = revision
         except (InvalidGitRepositoryError, NoSuchPathError):
-            layer_dict[layer_name]['branch'] = 'unknown'
-            layer_dict[layer_name]['revision'] = 'unknown'
+            continue
+        layer_dict[layer_name]['branch'] = branch
+        layer_dict[layer_name]['revision'] = revision
     return layer_dict
 
 def write_metadata_file(file_path, metadata):
scripts/oe-selftest +2 -2
index 5510410..a2298a3 100755
@@ -603,7 +603,7 @@ def main():
             r_branches = set(r_branches.replace('origin/', '').split())
             l_branches = {str(branch) for branch in repo.branches}
             branch = '%s/%s/%s' % (metadata['hostname'],
-                                   metadata['layers']['meta']['branch'],
+                                   metadata['layers']['meta'].get('branch', '(nogit)'),
                                    metadata['machine'])
 
             if branch in l_branches:
@@ -631,7 +631,7 @@ def main():
             layer_info = ''
             for layer, values in metadata['layers'].items():
                 layer_info = '%s%-17s = %s:%s\n' % (layer_info, layer,
-                              values['branch'], values['revision'])
+                              values.get('branch', '(nogit)'), values.get('revision', '0'*40))
             msg = 'Selftest for build %s of %s for machine %s on %s\n\n%s' % (
                    log_prefix[12:], metadata['distro']['pretty_name'],
                    metadata['machine'], metadata['hostname'], layer_info)
Signature · 1 line
2.6.6
#4 lore raw

PATCH v2 4/10 oeqa.utils.metadata: fix retrieval of git branch and revision

In reply to Markus Lehtonen

Always return a valid branch name, or, '(nobranch)' if the current HEAD is detached. Also, always return the hash of the commit object that HEAD is pointing to. Previous code returned an incorrect branch name (or crashed) e.g. in the case of detached HEAD.

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
meta/lib/oeqa/utils/metadata.py +5 -3
index a389c6a..b732d37 100644
@@ -72,11 +72,13 @@ def get_layers(layers):
         layer_dict[layer_name] = OrderedDict()
         try:
             repo = Repo(layer, search_parent_directories=True)
-            revision, branch = repo.head.object.name_rev.split()
         except (InvalidGitRepositoryError, NoSuchPathError):
             continue
-        layer_dict[layer_name]['branch'] = branch
-        layer_dict[layer_name]['revision'] = revision
+        layer_dict[layer_name]['revision'] = repo.head.commit.hexsha
+        try:
+            layer_dict[layer_name]['branch'] = repo.active_branch.name
+        except TypeError:
+            layer_dict[layer_name]['branch'] = '(nobranch)'
     return layer_dict
 
 def write_metadata_file(file_path, metadata):
Signature · 1 line
2.6.6
#5 lore raw

PATCH v2 5/10 oeqa.utils.metadata: rename 'revision' to 'commit'

In reply to Markus Lehtonen

Revision is a bit vague and could point to a tag, for example. Git commit objects are unambiguous and persistent so be explicit that the element should contain git commit hash.

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 2 +-
 scripts/oe-selftest             | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
meta/lib/oeqa/utils/metadata.py +1 -1
index b732d37..2f7e8f2 100644
@@ -74,7 +74,7 @@ def get_layers(layers):
             repo = Repo(layer, search_parent_directories=True)
         except (InvalidGitRepositoryError, NoSuchPathError):
             continue
-        layer_dict[layer_name]['revision'] = repo.head.commit.hexsha
+        layer_dict[layer_name]['commit'] = repo.head.commit.hexsha
         try:
             layer_dict[layer_name]['branch'] = repo.active_branch.name
         except TypeError:
scripts/oe-selftest +1 -1
index a2298a3..be63d5e 100755
@@ -631,7 +631,7 @@ def main():
             layer_info = ''
             for layer, values in metadata['layers'].items():
                 layer_info = '%s%-17s = %s:%s\n' % (layer_info, layer,
-                              values.get('branch', '(nogit)'), values.get('revision', '0'*40))
+                              values.get('branch', '(nogit)'), values.get('commit', '0'*40))
             msg = 'Selftest for build %s of %s for machine %s on %s\n\n%s' % (
                    log_prefix[12:], metadata['distro']['pretty_name'],
                    metadata['machine'], metadata['hostname'], layer_info)
Signature · 1 line
2.6.6
#6 lore raw

PATCH v2 6/10 oeqa.utils.metadata: add commit count information

In reply to Markus Lehtonen

Makes it easier to put the commits into a timeline.

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/lib/oeqa/utils/metadata.py +2 -1
index 2f7e8f2..d5cc290 100644
@@ -63,7 +63,7 @@ def metadata_from_data_store(d):
     pass
 
 def get_layers(layers):
-    """ Returns layer name, branch, and revision as OrderedDict. """
+    """Returns layer information in dict format"""
     from git import Repo, InvalidGitRepositoryError, NoSuchPathError
 
     layer_dict = OrderedDict()
@@ -75,6 +75,7 @@ def get_layers(layers):
         except (InvalidGitRepositoryError, NoSuchPathError):
             continue
         layer_dict[layer_name]['commit'] = repo.head.commit.hexsha
+        layer_dict[layer_name]['commit_count'] = repo.head.commit.count()
         try:
             layer_dict[layer_name]['branch'] = repo.active_branch.name
         except TypeError:
Signature · 1 line
2.6.6
#7 lore raw

PATCH v2 7/10 oeqa.utils.metadata: have layer name as an attribute in xml

In reply to Markus Lehtonen

Have the layer name as an attribute instead of of the name of the element itself. That is, have <layer name="layer_name"/> instead of <layer_name/>. A bit better XML design.

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
meta/lib/oeqa/utils/metadata.py +5 -3
index d5cc290..6331c21 100644
@@ -90,12 +90,14 @@ def write_metadata_file(file_path, metadata):
     with open(file_path, 'w') as f:
         f.write(xml_doc.toprettyxml())
 
-def dict_to_XML(tag, dictionary):
+def dict_to_XML(tag, dictionary, **kwargs):
     """ Return XML element converting dicts recursively. """
 
-    elem = Element(tag)
+    elem = Element(tag, **kwargs)
     for key, val in dictionary.items():
-        if isinstance(val, MutableMapping):
+        if tag == 'layers':
+            child = (dict_to_XML('layer', val, name=key))
+        elif isinstance(val, MutableMapping):
             child = (dict_to_XML(key, val))
         else:
             child = Element(key)
Signature · 1 line
2.6.6
#8 lore raw

PATCH v2 8/10 oeqa.utils.metadata: add bitbake revision information

In reply to Markus Lehtonen

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
meta/lib/oeqa/utils/metadata.py +19 -13
index 6331c21..a3c1b2b 100644
@@ -51,6 +51,7 @@ def metadata_from_bb():
                 info_dict['host_distro'][key] = os_release[key]
 
     info_dict['layers'] = get_layers(data_dict['BBLAYERS'])
+    info_dict['bitbake'] = git_rev_info(os.path.dirname(bb.__file__))
     return info_dict
 
 def metadata_from_data_store(d):
@@ -62,24 +63,29 @@ def metadata_from_data_store(d):
     # be useful when running within bitbake.
     pass
 
-def get_layers(layers):
-    """Returns layer information in dict format"""
+def git_rev_info(path):
+    """Get git revision information as a dict"""
     from git import Repo, InvalidGitRepositoryError, NoSuchPathError
 
+    info = OrderedDict()
+    try:
+        repo = Repo(path, search_parent_directories=True)
+    except (InvalidGitRepositoryError, NoSuchPathError):
+        return info
+    info['commit'] = repo.head.commit.hexsha
+    info['commit_count'] = repo.head.commit.count()
+    try:
+        info['branch'] = repo.active_branch.name
+    except TypeError:
+        info['branch'] = '(nobranch)'
+    return info
+
+def get_layers(layers):
+    """Returns layer information in dict format"""
     layer_dict = OrderedDict()
     for layer in layers.split():
         layer_name = os.path.basename(layer)
-        layer_dict[layer_name] = OrderedDict()
-        try:
-            repo = Repo(layer, search_parent_directories=True)
-        except (InvalidGitRepositoryError, NoSuchPathError):
-            continue
-        layer_dict[layer_name]['commit'] = repo.head.commit.hexsha
-        layer_dict[layer_name]['commit_count'] = repo.head.commit.count()
-        try:
-            layer_dict[layer_name]['branch'] = repo.active_branch.name
-        except TypeError:
-            layer_dict[layer_name]['branch'] = '(nobranch)'
+        layer_dict[layer_name] = git_rev_info(layer)
     return layer_dict
 
 def write_metadata_file(file_path, metadata):
Signature · 1 line
2.6.6
#9 lore raw

PATCH v2 9/10 oeqa.utils.metadata: allow storing any bitbake config variables

In reply to Markus Lehtonen

Make it possible to store any bitbake config variables in the metadata. Config values will be stored under a new config element in the xml report:

    <config>
        <variable name="MACHINE">qemux86</variable>
    </config>

The value of MACHINE is moved there instead of having a dedicated <machine> element.

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 12 +++++++++---
 scripts/oe-selftest             |  4 ++--
 2 files changed, 11 insertions(+), 5 deletions(-)
meta/lib/oeqa/utils/metadata.py +9 -3
index a3c1b2b..08d8198 100644
@@ -29,14 +29,13 @@ def metadata_from_bb():
 
         Data will be gathered using bitbake -e thanks to get_bb_vars.
     """
+    metadata_config_vars = ('MACHINE')
 
     info_dict = OrderedDict()
     hostname = runCmd('hostname')
     info_dict['hostname'] = hostname.output
     data_dict = get_bb_vars()
 
-    info_dict['machine'] = data_dict['MACHINE']
-
     # Distro information
     info_dict['distro'] = {'id': data_dict['DISTRO'],
                            'version_id': data_dict['DISTRO_VERSION'],
@@ -52,6 +51,10 @@ def metadata_from_bb():
 
     info_dict['layers'] = get_layers(data_dict['BBLAYERS'])
     info_dict['bitbake'] = git_rev_info(os.path.dirname(bb.__file__))
+
+    info_dict['config'] = OrderedDict()
+    for var in sorted(metadata_config_vars):
+        info_dict['config'][var] = data_dict[var]
     return info_dict
 
 def metadata_from_data_store(d):
@@ -106,7 +109,10 @@ def dict_to_XML(tag, dictionary, **kwargs):
         elif isinstance(val, MutableMapping):
             child = (dict_to_XML(key, val))
         else:
-            child = Element(key)
+            if tag == 'config':
+                child = Element('variable', name=key)
+            else:
+                child = Element(key)
             child.text = str(val)
         elem.append(child)
     return elem
scripts/oe-selftest +2 -2
index be63d5e..e33ca85 100755
@@ -604,7 +604,7 @@ def main():
             l_branches = {str(branch) for branch in repo.branches}
             branch = '%s/%s/%s' % (metadata['hostname'],
                                    metadata['layers']['meta'].get('branch', '(nogit)'),
-                                   metadata['machine'])
+                                   metadata['config']['MACHINE'])
 
             if branch in l_branches:
                 log.debug('Found branch in local repository, checking out')
@@ -634,7 +634,7 @@ def main():
                               values.get('branch', '(nogit)'), values.get('commit', '0'*40))
             msg = 'Selftest for build %s of %s for machine %s on %s\n\n%s' % (
                    log_prefix[12:], metadata['distro']['pretty_name'],
-                   metadata['machine'], metadata['hostname'], layer_info)
+                   metadata['config']['MACHINE'], metadata['hostname'], layer_info)
 
             log.debug('Commiting results to local repository')
             repo.index.commit(msg)
Signature · 1 line
2.6.6
#10 lore raw

PATCH v2 10/10 oeqa.utils.metadata: include BB_NUMBER_THREADS and PARALLEL_MAKE

In reply to Markus Lehtonen

Inlude values of BB_NUMBER_THREADS and PARALLEL_MAKE in the metadata.

[YOCTO #10590]

---
 meta/lib/oeqa/utils/metadata.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/utils/metadata.py +1 -1
index 08d8198..cb81155 100644
@@ -29,7 +29,7 @@ def metadata_from_bb():
 
         Data will be gathered using bitbake -e thanks to get_bb_vars.
     """
-    metadata_config_vars = ('MACHINE')
+    metadata_config_vars = ('MACHINE', 'BB_NUMBER_THREADS', 'PARALLEL_MAKE')
 
     info_dict = OrderedDict()
     hostname = runCmd('hostname')
Signature · 1 line
2.6.6