Parse error metadata yaml in reporting script

Parse the X.metadata.yaml files to pull out the
metadata fields for an error, so it can be printed
with the rest of the information.

Change-Id: I2a40fdafff6470ce84ab540469d85b7ac5b5e25d
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/create_error_reports.py b/create_error_reports.py
index 3d4440e..6330912 100755
--- a/create_error_reports.py
+++ b/create_error_reports.py
@@ -74,9 +74,40 @@
     return all_errors
 
 
+def add_error(val):
+    '''Adds the '.Error' before the last segment of an error string.'''
+    dot = val.rfind('.')
+    return val[:dot] + '.Error' + val[dot:]
+
+
 def get_metadata(name, metadata):
-    #TODO
+    '''Finds metadata entries for the error in the metadata
+       dictionary parsed out of the *.metadata.yaml files.
+
+       The metadata YAML looks something like:
+            - name: SlaveDetectionFailure
+              meta:
+                - str: "ERRNO=%d"
+                  type: int32
+              inherits:
+                - xyz.openbmc_project.Callout
+      '''
+
     data = []
+    for m in metadata:
+        if m['name'] == name:
+            if 'meta' in m:
+                for entry in m['meta']:
+                    #Get the name from name=value
+                    n = entry['str'].split('=')[0]
+                    data.append(n)
+
+            #inherits is a list, return it comma separated
+            if 'inherits' in m:
+                vals = list(map(add_error, m['inherits']))
+                i = ','.join(vals)
+                data.append("Inherits %s" % i)
+
     return data