-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[build_debian] Include checksum of ASIC config files in SONiC filesystem #3384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fd2e72c
[build_debian] Generate checksum of ASIC config files
daall 5e97d25
Fix typo
daall 34b5de3
Remove unused variable
daall facb4f2
Incorporate feedbacK
daall 669db82
Incorporate feedback
daall 30499a5
Incorporate feedback
daall 8b2296b
Merge branch 'master' into fast-reboot-asic-config-check
daall badf2fe
Advance submodule
daall e72e52d
Revert "Advance submodule"
daall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.