From 82daba0f834723af22c56e56151a31d240aea520 Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Thu, 26 May 2022 18:45:37 +0000 Subject: [PATCH] Further validate CI - expected fail now --- examples/chef/chef.py | 19 +++++++++++++++---- examples/chef/chef_util.py | 7 ++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/examples/chef/chef.py b/examples/chef/chef.py index b2751b15b2e2b9..20bda125cb88f2 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -199,13 +199,24 @@ def main(argv: Sequence[str]) -> None: cached_manifest = json.loads(ci_manifest_file.read()) for device in ci_manifest: if device != "zap_commit": - # TODO write the hash into folders and validate folders try: if cached_manifest[device] != ci_manifest[device]: - print("Cached files out of date. Please run chef with the flag --generate_zzz and commit") + print("MISMATCH INPUT - Cached files out of date. Please run chef with the flag --generate_zzz and commit /examples/chef/zzz_generated and /examples/chef/cimanifes.json") exit(1) + else: + zzz_dir = os.path.join(chef_zzz_root, device) + device_md5_file = os.path.join(zzz_dir, "INPUTMD5.txt") + if not os.path.exists(device_md5_file): + print("MISSING RESULT - Cached files out of date. Please run chef with the flag --generate_zzz and commit /examples/chef/zzz_generated and /examples/chef/cimanifes.json") + exit(1) + else: + with open(device_md5_file, "r", encoding="utf-8") as md5_file: + md5 = md5_file.read() + if ci_manifest[device] != md5 + print("MISMATCH OUTPUT - Cached files out of date. Please run chef with the flag --generate_zzz and commit /examples/chef/zzz_generated and /examples/chef/cimanifes.json") + exit(1) except KeyError: - print("Cached files out of date. Please run chef with the flag --generate_zzz and commit /examples/chef/zzz_generated and /examples/chef/cimanifes.json") + print("MISSING DEVICE CACHE - Cached files out of date. Please run chef with the flag --generate_zzz and commit /examples/chef/zzz_generated and /examples/chef/cimanifes.json") exit(1) if device == "zap_commit" and False: # Disabled for now, ci_manifest above created without include_zap_submod, fails in CI env. @@ -263,7 +274,7 @@ def main(argv: Sequence[str]) -> None: {_CHEF_SCRIPT_PATH}/devices/{device_name}.zap -o {device_out_dir}") shell.run_cmd(f"touch {device_out_dir}/af-gen-event.h") chef_util.generate_device_manifest(chef_devices_dir, include_zap_submod=True, write_manifest_file=True, - ci_manifest_file_name=ci_manifest_file_name, repo_base_path=_REPO_BASE_PATH) + ci_manifest_file_name=ci_manifest_file_name, repo_base_path=_REPO_BASE_PATH, chef_zzz_root=chef_zzz_root) exit(0) # diff --git a/examples/chef/chef_util.py b/examples/chef/chef_util.py index fbc8175f5cf363..9b96008d50837d 100644 --- a/examples/chef/chef_util.py +++ b/examples/chef/chef_util.py @@ -40,7 +40,7 @@ def check_zap_master(repo_base_path: str) -> str: return zap_commit -def generate_device_manifest(chef_devices_dir: str, include_zap_submod: bool = False, write_manifest_file: bool = False, ci_manifest_file_name: str = '', repo_base_path: str = '') -> dict: +def generate_device_manifest(chef_devices_dir: str, include_zap_submod: bool = False, write_manifest_file: bool = False, ci_manifest_file_name: str = '', repo_base_path: str = '', chef_zzz_root: str = '') -> dict: """Produces dictionary containing md5 of device dir zap files""" ci_manifest = {} for device_dir_item in os.listdir(chef_devices_dir): @@ -53,6 +53,11 @@ def generate_device_manifest(chef_devices_dir: str, include_zap_submod: bool = F device_file_md5 = hashlib.md5(device_file_data).hexdigest() ci_manifest[device_name] = device_file_md5 print(f"Manifest for {device_name} : {device_file_md5}") + if write_manifest_file: + device_zzz_dir_root = os.path.join(chef_zzz_root, device_name) + device_zzz_md5_file = os.path.join(device_zzz_dir_root, 'INPUTMD5.txt') + with open(device_zzz_md5_file, "w+", encoding="utf-8") as md5file: + md5file.write(device_file_md5) if include_zap_submod: ci_manifest["zap_commit"] = check_zap_master(repo_base_path) if write_manifest_file: