From 6dbd4f37a8ca6ad1ee42fa9edb244a594c6da395 Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Tue, 31 May 2022 06:23:25 +0000 Subject: [PATCH] Make validate better --- examples/chef/chef.py | 70 ++++++++++++++++++----------------- examples/chef/cimanifest.json | 8 ++-- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/examples/chef/chef.py b/examples/chef/chef.py index 84895d50b6bcf1..efe1f5c57a1106 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -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 @@ -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) @@ -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) diff --git a/examples/chef/cimanifest.json b/examples/chef/cimanifest.json index 4392775765dc48..bd7a8e787dfa5e 100644 --- a/examples/chef/cimanifest.json +++ b/examples/chef/cimanifest.json @@ -1,6 +1,6 @@ { - "devices": { - "lighting-app": "81a1262e611fab1a71ac4129b91cec0f" - }, - "zap_commit": "TEMP DISABLED" + "devices": { + "lighting-app": "81a1262e611fab1a71ac4129b91cec0f" + }, + "zap_commit": "TEMP DISABLED" }