[build_debian] Include checksum of ASIC config files in SONiC filesystem (#3384)
[build_debian] Generate checksum of ASIC config files * Adds script to generate checksums for ASIC config files * Adds step to build_debian that copies ASIC config checksum into SONiC filesystem Signed-off-by: Danny Allen daall@microsoft.com
This commit is contained in:
parent
47504d13a6
commit
cfcf30570b
@ -463,6 +463,14 @@ build_number: ${BUILD_NUMBER:-0}
|
||||
built_by: $USER@$BUILD_HOSTNAME
|
||||
EOF
|
||||
|
||||
## Copy ASIC config checksum
|
||||
python files/build_scripts/generate_asic_config_checksum.py
|
||||
if [[ ! -f './asic_config_checksum' ]]; then
|
||||
echo 'asic_config_checksum not found'
|
||||
exit 1
|
||||
fi
|
||||
sudo cp ./asic_config_checksum $FILESYSTEM_ROOT/etc/sonic/asic_config_checksum
|
||||
|
||||
if [ -f sonic_debian_extension.sh ]; then
|
||||
./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR
|
||||
fi
|
||||
|
67
files/build_scripts/generate_asic_config_checksum.py
Normal file
67
files/build_scripts/generate_asic_config_checksum.py
Normal file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import syslog
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
SYSLOG_IDENTIFIER = 'asic_config_checksum'
|
||||
|
||||
CHUNK_SIZE = 8192
|
||||
|
||||
CONFIG_FILES = {
|
||||
os.path.abspath('./src/sonic-swss/swssconfig/sample/'): ['netbouncer.json', '00-copp.config.json']
|
||||
}
|
||||
|
||||
OUTPUT_FILE = os.path.abspath('./asic_config_checksum')
|
||||
|
||||
def log_info(msg):
|
||||
syslog.openlog(SYSLOG_IDENTIFIER)
|
||||
syslog.syslog(syslog.LOG_INFO, msg)
|
||||
syslog.closelog()
|
||||
|
||||
def log_error(msg):
|
||||
syslog.openlog(SYSLOG_IDENTIFIER)
|
||||
syslog.syslog(syslog.LOG_ERR, msg)
|
||||
syslog.closelog()
|
||||
|
||||
def get_config_files(config_file_map):
|
||||
'''
|
||||
Generates a list of absolute paths to ASIC config files.
|
||||
'''
|
||||
config_files = []
|
||||
for path, files in config_file_map.items():
|
||||
for config_file in files:
|
||||
config_files.append(os.path.join(path, config_file))
|
||||
return config_files
|
||||
|
||||
def generate_checksum(checksum_files):
|
||||
'''
|
||||
Generates a checksum for a given list of files. Returns None if an error
|
||||
occurs while reading the files.
|
||||
|
||||
NOTE: The checksum is performed in the order provided. This function does
|
||||
NOT do any re-ordering of the files before creating the checksum.
|
||||
'''
|
||||
checksum = hashlib.sha1()
|
||||
for checksum_file in checksum_files:
|
||||
try:
|
||||
with open(checksum_file, 'r') as f:
|
||||
for chunk in iter(lambda: f.read(CHUNK_SIZE), b""):
|
||||
checksum.update(chunk)
|
||||
except IOError as e:
|
||||
log_error('Error processing ASIC config file ' + checksum_file + ':' + e.strerror)
|
||||
return None
|
||||
|
||||
return checksum.hexdigest()
|
||||
|
||||
def main():
|
||||
config_files = sorted(get_config_files(CONFIG_FILES))
|
||||
checksum = generate_checksum(config_files)
|
||||
if checksum == None:
|
||||
exit(1)
|
||||
|
||||
with open(OUTPUT_FILE, 'w') as output:
|
||||
output.write(checksum + '\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user