Adam Litke has uploaded a new change for review.

Change subject: schema: Strengthen schema verification
......................................................................

schema: Strengthen schema verification

Add additional checking to process-schema.py to detect the following errors:
 - Symbol comment documents a field which is not defined in the symbol
 - Symbol references an undefined type

Change-Id: Ia750e537fad9ad57d1163906b130033e896c36dd
Signed-off-by: Adam Litke <a...@us.ibm.com>
---
M vdsm_api/process-schema.py
M vdsm_api/vdsmapi-schema.json
2 files changed, 46 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/97/11397/1

diff --git a/vdsm_api/process-schema.py b/vdsm_api/process-schema.py
index 970637b..686e624 100755
--- a/vdsm_api/process-schema.py
+++ b/vdsm_api/process-schema.py
@@ -140,6 +140,9 @@
             m = re.search('^\@(.*?):\s*(.*)', line)
             if m:
                 name, desc = (m.group(1), m.group(2))
+                if name not in strip_stars(symbol['data']):
+                    raise ValueError("'%s' comment mentions '%s' which is " \
+                                     "not defined" % (symbol['name'], name))
                 symbol[mode][name] = desc
                 # Track the name in case there is are multiple lines to append
                 last_arg = name
@@ -175,23 +178,24 @@
     return "".join(html_escape_table.get(c, c) for c in text)
 
 
+def strip_stars(items):
+    """
+    A symbol prepended with '*' means the symbol is optional.  Strip this
+    when looking up the symbol documentation.
+    """
+    ret = []
+    for i in items:
+        if i.startswith('*'):
+            ret.append(i[1:])
+        else:
+            ret.append(i)
+    return ret
+
+
 def write_symbol(f, s):
     """
     Write an HTML reprentation of a symbol definition and documentation.
     """
-    def strip_stars(items):
-        """
-        A symbol prepended with '*' means the symbol is optional.  Strip this
-        when looking up the symbol documentation.
-        """
-        ret = []
-        for i in items:
-            if i.startswith('*'):
-                ret.append(i[1:])
-            else:
-                ret.append(i)
-        return ret
-
     def filter_types(items):
         """
         When creating the type crosslink, if an entity is a list container we
@@ -327,6 +331,29 @@
     f.write(footer)
 
 
+def verify_symbols(symbols):
+    def filter_name(name):
+        if isinstance(name, list):
+            name = name[0]
+        if name.startswith('*'):
+            name = name[1:]
+        return name
+
+    names = ['str', 'bool', 'int', 'uint', 'float']
+    names.extend([s['type'] for s in symbols if 'type' in s])
+    names.extend([s['enum'] for s in symbols if 'enum' in s])
+    names.extend([s['alias'] for s in symbols if 'alias' in s])
+    names.extend([s['map'] for s in symbols if 'map' in s])
+
+    # Make sure all type references are defined
+    for s in symbols:
+        if 'type' in s or 'command' in s:
+            for k, v in s.get('data', {}).items():
+                if filter_name(v) not in names:
+                    raise ValueError("'%s': undefined type reference '%s'" % (
+                                        s['type'], v))
+
+
 def main():
     schema = sys.argv[1]
     output = sys.argv[2]
@@ -335,6 +362,8 @@
     # First read in the progmatic schema definition
     with open(schema) as f:
         symbols = vdsmapi.parse_schema(f)
+    verify_symbols(symbols)
+
     # Now merge in the information from the comments
     with open(schema) as f:
         symbols = read_schema_doc(f, symbols)
diff --git a/vdsm_api/vdsmapi-schema.json b/vdsm_api/vdsmapi-schema.json
index 1baffe2..47777b8 100644
--- a/vdsm_api/vdsmapi-schema.json
+++ b/vdsm_api/vdsmapi-schema.json
@@ -368,7 +368,7 @@
 # Since: 4.10.0
 ##
 {'enum': 'TaskState',
- 'data': ['unknown', 'running', 'finished', 'aborting', 'cleaning']}
+ 'data': ['unknown', 'init', 'running', 'finished', 'aborting', 'cleaning']}
 
 ##
 # @TaskResult:
@@ -1550,13 +1550,13 @@
            'storageDomains': 'StorageDomainVitalsMap',
            'elapsedTime': 'uint', 'memUsed': 'uint',
            'anonHugePages': 'uint', 'cpuLoad': 'float',
-           'diskStats': 'PathStatsMap', 'thpState': 'THPStates'},
+           'diskStats': 'PathStatsMap', 'thpState': 'THPStates',
            'memAvailable': 'int', 'memShared': 'int', 'memCommitted': 'int',
            'swapTotal': 'int', 'swapFree': 'int','vmCount': 'int',
            'vmActive': 'int', 'vmMigrating': 'int', 'dateTime': 'str',
            'ksmState': 'bool', 'ksmPages': 'int', 'ksmCpu': 'float',
            'netConfigDirty': 'bool', 'generationID': 'UUID',
-           'momStatus': 'MOMStatus'}
+           'momStatus': 'MOMStatus'}}
 
 ##
 # @Host.getStats:
@@ -2363,7 +2363,7 @@
 #
 # Since: 4.10.0
 ##
-{'enum': 'VmChannelDeviceType', 'data': ['unix', 'spicevmc']}
+{'enum': 'VmChannelDeviceType', 'data': ['unix', 'spicevmc', 'virtio-serial']}
 
 ##
 # @VmChannelDevice:
@@ -6278,8 +6278,6 @@
 # @storagedomainID:  The Storage Domain associated with the Volume
 #
 # @imageID:          The Image associated with the Volume
-#
-# @legality:         The new Volume legality
 #
 # Since: 4.10.0
 ##


--
To view, visit http://gerrit.ovirt.org/11397
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia750e537fad9ad57d1163906b130033e896c36dd
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <a...@us.ibm.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to