Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CASMTRIAGE-6650 fix and test for 'IndexError: list index out of range…
…' with 'canu (#472) validate shcd-cabling' When running 'canu validate shcd-cabling' with an SHCD that does not follow currently-supported naming conventions can cause this stacktrace: ``` File "cli.py", line 314, in <module> File "click/core.py", line 1130, in __call__ File "click/core.py", line 1055, in main File "click/core.py", line 1657, in invoke File "click/core.py", line 1657, in invoke File "click/core.py", line 1404, in invoke File "click/core.py", line 760, in invoke File "click/decorators.py", line 26, in new_func File "validate/shcd_cabling/shcd_cabling.py", line 286, in shcd_cabling File "validate/network/cabling/cabling.py", line 412, in node_model_from_canu IndexError: list index out of range [48583] Failed to execute script 'cli' due to unhandled exception! ``` canu is currently not setup to accurately test this situation since it requires an SHCD and a functioning system with switches that can be logged into. To that end, I broke the problematic code into its own function so it could be unit-tested. I then created some unit tests with various inputs to test against. Both the line in question, and the one adjacent suffer from a similiar problem: a lack of checking if an index exists before trying to access it. Thus, I changed the code to check these two lines: ``` dst_middle = re.findall(r"(?:sw-)([a-z-]+)", dst_name)[0] dst_digits = re.findall(r"(\d+)", dst_name)[0] ``` This is quite a small bug, but we often have issues with inconsistencies in the content of cells in the SHCD. Really, we should define the input we expect for every cell, attempt to sanitize any input, and fail if it does not meet specifications. With all of the monolithic functions and complexity of this app, this is just one step in that directions. Many of our functions are cognitively complex and do not unit test easily. We should also start adding testdata fixtures to test the same data against the entire app. even this fix, which breaks some functionality into a simple function contains tech debt and while far from perfect, it is a step in the right direction to begin decomposing these functions into more unit-testable pieces. once we can do complete unit tests and proper integration tests with shellspec, we can easily reproduce customer issues and fix them permanently. unfortunately, csm has entered EOL (while still years away) so it is not worth it at this point to do a complete refactor and enhance things, so take this fix with that in mind Signed-off-by: Jacob Salmela <[email protected]>
- Loading branch information