Commit d2c697f
authored
Add sonic-error-report tool for structured error reporting (sonic-net#4037)
* Add sonic-error-report tool for structured error reporting
- Add error_reporter.py library module to utilities_common/
- Add sonic-error-report CLI script to scripts/
- Add comprehensive unit tests to tests/
- Update setup.py to include new script in installation
This provides crash-resilient JSON error reporting for SONiC operations,
preparing for future integration with reboot and upgrade scripts.
* Fix flake8 errors in sonic_error_report_test.py
- Remove unused imports (sys, unittest, pytest, MagicMock, mock_open, call)
- Fix line length violations by breaking long lines
- Fix test logic for mark_failure_missing_report to properly handle SystemExit
- Update test assertions to handle expected sanitization behavior
* Fix whitespace issues in error_reporter.py
- Remove trailing whitespace from blank lines (W293)
- Ensure file ends with newline (W292)
- Fix some long lines for readability
These changes address the pre-commit flake8 failures.
* Fix test_scenario_sanitization to match actual behavior
The scenario sanitization replaces path separators with underscores
but allows dots, so '../../../etc/malicious' becomes
'.._.._.._etc_malicious'. Update test to verify the actual
sanitization behavior rather than incorrect expectations.
* Fix test_scenario_sanitization to test filename only
The test was incorrectly checking the full path which contains
forward slashes from the temporary directory. Now it properly
extracts just the filename to test sanitization behavior.
* Update error reporting to match sonic-metadata improvements
Key updates to align sonic-utilities error reporter with sonic-metadata version:
1. Conservative defaults (safer for production):
- reputation_impact: false (was true)
- isolate_on_failure: false (was true)
- retriable: remains true
2. SONiC logger integration with fallback support:
- Added sonic_py_common.logger import with graceful fallback
- Replaced sys.stderr.write with structured logging
- Compatible with environments that lack sonic_py_common
3. Enhanced error handling:
- Logger initialization in CLI and library
- Proper logging for all operations and errors
4. Python 2/3 compatibility maintained:
- Uses .format() syntax throughout
- No f-string dependencies
This brings the sonic-utilities error reporter up to parity with the
sonic-metadata version while maintaining backward compatibility.
* Fix flake8 whitespace issues
Remove whitespace from blank lines to pass pre-commit checks:
- utilities_common/error_reporter.py:43,46,51,56
* Remove trailing whitespace on blank line
* Fix flake8 line length violations
* Fix tests to use logger mocks instead of stderr and update default expectations
* just to rerun pipeline
* Replace specific scenario names with generic placeholders in help text
* Refactor error reporter to use JSON template file
Address PR review feedback by moving report structure to external JSON template.
- Add error_report_template.json with default report structure
- Add error_report_schema.json for documentation and validation
- Update SonicErrorReportManager to load template from JSON file
- Add fallback behavior if template file is missing
- Maintain crash resilience with no external dependencies at runtime
This provides standardization while keeping the tool reliable and self-contained.
Template can be modified without code changes, and schema serves as documentation.
* Add template generation script for JSON schema workflow
- Add generate_template_from_schema.py to create template from schema
- Include package_data configuration for JSON template files
- Provides development workflow to keep template in sync with schema
- Template generation ensures consistency with schema defaults
* Add comprehensive unit tests for template generation script
- Test all JSON schema type handling (string, boolean, integer, array, object)
- Test explicit default values from schema properties
- Test special handling for errors array with default timeout error
- Test file operations for schema reading and template writing
- Test main function success and error paths
- Achieve full test coverage for generate_template_from_schema.py
* Fix flake8 whitespace issues in template generation files
- Remove trailing whitespace from blank lines (W293)
- Add newline at end of files (W292)
- Remove unused import in test file (F401)
- Move imports to top of test file (E402)
- Ready for CI pipeline static analysis validation
* Fix pre-commit flake8 whitespace violations
- Remove trailing whitespace from error_reporter.py (W291)
- Remove whitespace from blank lines in both files (W293)
- Add newline at end of test file (W292)
- All pre-commit whitespace checks now pass
* Revert "Add template generation script for JSON schema workflow"
This reverts commit e31101b28cc225c476ecb7fcaaccdd08e15a75ee.
* Fix flake8 whitespace violations in error_reporter.py
- Remove trailing whitespace from line 73 (W291)
- Remove whitespace from blank lines 176 and 179 (W293)
- All pre-commit checks now pass1 parent ed5afd8 commit d2c697f
File tree
6 files changed
+1014
-1
lines changed- scripts
- tests
- utilities_common
6 files changed
+1014
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
| 198 | + | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
| |||
0 commit comments