Skip to content

Commit

Permalink
Make validate better
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed May 31, 2022
1 parent c4a99f0 commit 6dbd4f3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
70 changes: 36 additions & 34 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def generate_device_manifest(
ci_manifest["zap_commit"] = check_zap_master()
if write_manifest_file:
with open(_CI_MANIFEST_FILE_NAME, "w+", encoding="utf-8") as ci_manifest_file:
ci_manifest_file.write(json.dumps(ci_manifest, indent=4)+"\n")
ci_manifest_file.write(json.dumps(ci_manifest, indent=2)+"\n")
return ci_manifest


Expand Down Expand Up @@ -170,8 +170,8 @@ def flush_print(
None
"""
if with_border:
border = ('*' * 64) + '\n'
to_print = f"{border}{to_print}{border}"
border = ('-' * 64) + '\n'
to_print = f"{border}{to_print}\n{border}"
print(to_print, flush=True)


Expand Down Expand Up @@ -270,44 +270,46 @@ def main(argv: Sequence[str]) -> None:
#

if options.validate_zzz:
flush_print(f"Validating\n{_CI_MANIFEST_FILE_NAME}\n{_CHEF_ZZZ_ROOT}\n",
with_border=True)
fix_instructions = """Cached files out of date!
Please:
bootstrap, activate, and install zap
run chef with the flag --generate_zzz
git add examples/chef/zzz_generated
git add examples/chef/cimanifes.json
./scripts/bootstrap.sh
source ./scripts/activate.sh
cd ./third_party/zap/repo
npm install
cd ../../..
./examples/chef/chef.py --generate_zzz
git add examples/chef/zzz_generated
git add examples/chef/cimanifes.json
Ensure you are running with the latest version of ZAP from master!"""
ci_manifest = generate_device_manifest()
with open(_CI_MANIFEST_FILE_NAME, "r", encoding="utf-8") as ci_manifest_file:
cached_manifest = json.loads(ci_manifest_file.read())
for device in ci_manifest:
if device != "zap_commit":
try:
if cached_manifest[device] != ci_manifest[device]:
flush_print("MISMATCH INPUT - "+fix_instructions)
exit(1)
else:
zzz_dir = os.path.join(_CHEF_ZZZ_ROOT, device)
device_md5_file = os.path.join(zzz_dir, _CI_DEVICE_MANIFEST_NAME)
if not os.path.exists(device_md5_file):
flush_print("MISSING RESULT - "+fix_instructions)
exit(1)
else:
with open(device_md5_file, "r", encoding="utf-8") as md5_file:
md5 = md5_file.read()
if ci_manifest[device] != md5:
flush_print("MISMATCH OUTPUT - "+fix_instrucitons)
exit(1)
except KeyError:
flush_print("MISSING DEVICE CACHE - "+fix_instructions)
exit(1)
if device == "zap_commit" and False:
# Disabled; should check:
# Current branch when writing manifest
# Master in CI
if cached_manifest[device] != ci_manifest[device]:
flush_print("BAD ZAP VERSION - "+fix_instructions)
cached_device_manifest = cached_manifest["devices"]
for device, device_md5 in ci_manifest["devices"].items():
zzz_dir = os.path.join(_CHEF_ZZZ_ROOT, device)
device_md5_file = os.path.join(zzz_dir, _CI_DEVICE_MANIFEST_NAME)
if device not in cached_device_manifest:
flush_print(f"NOT IN MANIFEST - {fix_instructions}")
elif cached_device_manifest[device] != device_md5:
flush_print(f"MANIFEST MISMATCH - {fix_instructions}")
exit(1)
elif not os.path.exists(device_md5_file):
flush_print(f"OUTPUT MISSING {fix_instructions}")
exit(1)
else:
with open(device_md5_file, "r", encoding="utf-8") as md5_file:
output_cached_md5 = md5_file.read()
if output_cached_md5 != device_md5:
flush_print(f"MISMATCH OUTPUT - {fix_instrucitons}")
exit(1)
if False:
# Disabled; should check:
# Current branch when writing manifest
# Master in CI
flush_print("BAD ZAP VERSION - "+fix_instructions)
exit(1) # shoul only warn
flush_print("Cached ZAP output is up to date!")
exit(0)

Expand Down
8 changes: 4 additions & 4 deletions examples/chef/cimanifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devices": {
"lighting-app": "81a1262e611fab1a71ac4129b91cec0f"
},
"zap_commit": "TEMP DISABLED"
"devices": {
"lighting-app": "81a1262e611fab1a71ac4129b91cec0f"
},
"zap_commit": "TEMP DISABLED"
}

0 comments on commit 6dbd4f3

Please sign in to comment.