GNS3 / gns3-registry

GNS3 devices registry
GNU General Public License v3.0
330 stars 395 forks source link

check.py reports duplicate image filenames #687

Closed ghost closed 2 years ago

ghost commented 2 years ago

Currently check.py reports an error in cisco-asav.gns3a and juniper-vrr.gns3a, that they contain duplicate image filenames. After reporting this error check.py stops testing further appliances.

$ python3 check.py
=> Check appliances
Check danos.gns3a
Check arista-ceos.gns3a
.
.
Check f5-bigip.gns3a
Check cisco-asav.gns3a
Duplicate image filename asav9-16-2.qcow2
$

These duplicate images were allowed by @grossmj in https://github.com/GNS3/gns3-registry/issues/678#issuecomment-1196042244. Maybe check.py should be changed so that this condition won't stop the check.

ghost commented 2 years ago

I made two changes to check.py to allow duplicate filenames, see the enclosed patch:

diff --git a/check.py b/check.py
index 25ce584..411e1d7 100644
--- a/check.py
+++ b/check.py
@@ -71,7 +71,7 @@ def signal_abort(sig, frame):
 def check_appliance(appliance):
     global warnings
     images = {}
-    md5sums = set()
+    md5sums = {}

     schemas = {}
     for version in SCHEMA_VERSIONS:
@@ -95,8 +95,9 @@ def check_appliance(appliance):
         for image in appliance_json['images']:
             if image['filename'] in images:
                 print('Duplicate image filename ' + image['filename'])
-                sys.exit(1)
-            if image['md5sum'] in md5sums:
+                warnings += 1
+            if image['md5sum'] in md5sums and \
+               md5sums[image['md5sum']] != image['filename']:
                 print('Duplicate image md5sum ' + image['md5sum'])
                 sys.exit(1)
             versions_found = False
@@ -106,8 +107,8 @@ def check_appliance(appliance):
             if not versions_found:
                 print('Unused image ' + image['filename'] + ' in ' + appliance)
                 warnings += 1
-            images[image['filename']] = image['version']
-            md5sums.add(image['md5sum'])
+            images.setdefault(image['filename'], []).append(image['version'])
+            md5sums[image['md5sum']] = image['filename']

         for version in appliance_json['versions']:
             version_match = False
@@ -115,7 +116,7 @@ def check_appliance(appliance):
                 if image not in images:
                     print('Missing relation ' + image + ' in ' + appliance + ' for version ' + version['name'])
                     sys.exit(1)
-                if images[image] == version['name']:
+                if version['name'] in images[image]:
                     version_match = True
             if not version_match:
                 print('Version mismatch for version ' + version['name'] + ' in ' + appliance)
grossmj commented 2 years ago

Hi, have you closed this issue because it takes us too long to add your changes? ;)

ghost commented 2 years ago

I think that this issue is not important enough to spend time on it.