From 3db26386b5f8de2624e2851a55b12201747e138b Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 2 Nov 2020 21:00:26 +0000 Subject: [PATCH 1/4] [generate_asic_config_checksum.py] Convert to Python 3 --- files/build_scripts/generate_asic_config_checksum.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/build_scripts/generate_asic_config_checksum.py b/files/build_scripts/generate_asic_config_checksum.py index 638259ce938a..9e18c107ca93 100644 --- a/files/build_scripts/generate_asic_config_checksum.py +++ b/files/build_scripts/generate_asic_config_checksum.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -import syslog -import os import hashlib +import os +import syslog SYSLOG_IDENTIFIER = 'asic_config_checksum' From 0cb13b307cf2246d187e7a9802de2085098bdca5 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 2 Nov 2020 21:12:13 +0000 Subject: [PATCH 2/4] Don't invoke python, let program loader use shebang --- build_debian.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_debian.sh b/build_debian.sh index db736d16946e..e5dd24d63b1c 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -463,7 +463,7 @@ EOF sudo cp ./files/scripts/core_cleanup.py $FILESYSTEM_ROOT/usr/bin/core_cleanup.py ## Copy ASIC config checksum -python files/build_scripts/generate_asic_config_checksum.py +./files/build_scripts/generate_asic_config_checksum.py if [[ ! -f './asic_config_checksum' ]]; then echo 'asic_config_checksum not found' exit 1 From 57e40e4a6e0f89689a684de9510665f1faf16f9a Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 3 Nov 2020 03:45:22 +0000 Subject: [PATCH 3/4] make generate_asic_config_checksum.py executable, and do it again before executing as a failsafe --- build_debian.sh | 1 + files/build_scripts/generate_asic_config_checksum.py | 0 2 files changed, 1 insertion(+) mode change 100644 => 100755 files/build_scripts/generate_asic_config_checksum.py diff --git a/build_debian.sh b/build_debian.sh index e5dd24d63b1c..2bb284182db1 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -463,6 +463,7 @@ EOF sudo cp ./files/scripts/core_cleanup.py $FILESYSTEM_ROOT/usr/bin/core_cleanup.py ## Copy ASIC config checksum +sudo chmod 755 files/build_scripts/generate_asic_config_checksum.py ./files/build_scripts/generate_asic_config_checksum.py if [[ ! -f './asic_config_checksum' ]]; then echo 'asic_config_checksum not found' diff --git a/files/build_scripts/generate_asic_config_checksum.py b/files/build_scripts/generate_asic_config_checksum.py old mode 100644 new mode 100755 From 4a06cd5dea120a8ae4583c427b4e646f0f807f0d Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 3 Nov 2020 19:47:02 +0000 Subject: [PATCH 4/4] Open file in binary mode before hashing --- files/build_scripts/generate_asic_config_checksum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_scripts/generate_asic_config_checksum.py b/files/build_scripts/generate_asic_config_checksum.py index 9e18c107ca93..41ef6f045e21 100755 --- a/files/build_scripts/generate_asic_config_checksum.py +++ b/files/build_scripts/generate_asic_config_checksum.py @@ -45,7 +45,7 @@ def generate_checksum(checksum_files): checksum = hashlib.sha1() for checksum_file in checksum_files: try: - with open(checksum_file, 'r') as f: + with open(checksum_file, 'rb') as f: for chunk in iter(lambda: f.read(CHUNK_SIZE), b""): checksum.update(chunk) except IOError as e: