mirror of
https://github.com/GNS3/gns3-registry.git
synced 2025-01-09 22:42:43 +00:00
Refactor check.py to support v5 appliance version
This commit is contained in:
parent
a8da1bc55b
commit
45317c4cca
51
check.py
51
check.py
@ -22,35 +22,46 @@ import sys
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
SCHEMA_VERSIONS = [3, 4, 5]
|
||||||
|
|
||||||
|
def validate_schema(appliance_json, name, schemas):
|
||||||
|
|
||||||
|
version = appliance_json['registry_version']
|
||||||
|
if version not in SCHEMA_VERSIONS:
|
||||||
|
print('Schema version {} is not supported'.format(version))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
jsonschema.validate(appliance_json, schemas[version])
|
||||||
|
|
||||||
|
if version != SCHEMA_VERSIONS[0]:
|
||||||
|
try:
|
||||||
|
version -= 1
|
||||||
|
appliance_json = appliance_json.copy()
|
||||||
|
appliance_json['registry_version'] = version
|
||||||
|
jsonschema.validate(appliance_json, schemas[version])
|
||||||
|
print('Appliance {name} can be downgraded to registry version {version}'.format(name=name,
|
||||||
|
version=version))
|
||||||
|
sys.exit(1)
|
||||||
|
except jsonschema.exceptions.ValidationError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def check_appliance(appliance):
|
def check_appliance(appliance):
|
||||||
global images
|
global images
|
||||||
images = set()
|
images = set()
|
||||||
global md5sums
|
global md5sums
|
||||||
md5sums = set()
|
md5sums = set()
|
||||||
|
|
||||||
with open('schemas/appliance_v4.json') as f:
|
schemas = {}
|
||||||
schema_v4 = json.load(f)
|
for version in SCHEMA_VERSIONS:
|
||||||
with open('schemas/appliance_v3.json') as f:
|
schema_filename = "schemas/appliance_v{}.json".format(version)
|
||||||
schema_v3 = json.load(f)
|
with open(schema_filename) as f:
|
||||||
|
schemas[version] = json.load(f)
|
||||||
|
|
||||||
with open(os.path.join('appliances', appliance)) as f:
|
with open(os.path.join('appliances', appliance)) as f:
|
||||||
appliance_json = json.load(f)
|
appliance_json = json.load(f)
|
||||||
if appliance_json['registry_version'] == 3:
|
validate_schema(appliance_json, appliance, schemas)
|
||||||
jsonschema.validate(appliance_json, schema_v3)
|
|
||||||
elif appliance_json['registry_version'] == 4:
|
|
||||||
jsonschema.validate(appliance_json, schema_v4)
|
|
||||||
try:
|
|
||||||
appliance_json_v3 = appliance_json.copy()
|
|
||||||
appliance_json_v3['registry_version'] = 3
|
|
||||||
jsonschema.validate(appliance_json_v3, schema_v3)
|
|
||||||
print('Appliance ' + appliance + ' can be downgraded to registry version 3')
|
|
||||||
sys.exit(1)
|
|
||||||
except jsonschema.exceptions.ValidationError:
|
|
||||||
# The appliance require the schema V4
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print('Schema version {} is not supported'.format(appliance_json['registry_version']))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if 'images' in appliance_json:
|
if 'images' in appliance_json:
|
||||||
for image in appliance_json['images']:
|
for image in appliance_json['images']:
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
"title": "An optional product url on vendor website"
|
"title": "An optional product url on vendor website"
|
||||||
},
|
},
|
||||||
"registry_version": {
|
"registry_version": {
|
||||||
"enum": [1, 2, 3, 4],
|
"enum": [1, 2, 3, 4, 5],
|
||||||
"title": "Version of the registry compatible with this appliance"
|
"title": "Version of the registry compatible with this appliance"
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
|
Loading…
Reference in New Issue
Block a user