-
Notifications
You must be signed in to change notification settings - Fork 97
Reread validation tests from modified lab topology file #2890
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
2 commits
Select commit
Hold shift + click to select a range
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
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
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,60 @@ | ||
| # | ||
| # Common validation utility functions | ||
| # | ||
|
|
||
|
|
||
| import os | ||
|
|
||
| from box import Box | ||
|
|
||
| from ...augment import validate as _validate | ||
| from ...data.types import must_be_id | ||
| from ...data.validate import validate_attributes | ||
| from ...utils import log, read | ||
| from .. import error_and_exit | ||
|
|
||
|
|
||
| def validate_test_attributes(topology: Box) -> None: | ||
| for t_name,t_data in topology.validate.items(): | ||
| must_be_id( | ||
| parent=None, | ||
| key=t_name, | ||
| path=f'NOATTR:test name {t_name}', | ||
| module='validate') | ||
| validate_attributes( | ||
| data=t_data, # Validate test description | ||
| topology=topology, | ||
| data_path=f'validate.{t_name}', # Topology path to test entry | ||
| data_name=f'validation test', | ||
| attr_list=['_v_entry'], # We're checking validation entries | ||
| module='validate') # Function is called from 'validate' command | ||
|
|
||
| log.exit_on_error() | ||
|
|
||
| def update_validation_tests(topology: Box, src: str) -> None: | ||
| if not os.path.exists(src): | ||
| error_and_exit(f'{src} does not exist') | ||
| log.info(f'Reading validation tests from {src}') | ||
| add_topo = read.read_yaml(filename=src) # Read tests or whole topology from input file | ||
ipspace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if add_topo is None: | ||
| error_and_exit(f'The input file ({src}) is not a YAML file') | ||
| if not isinstance(add_topo,Box): # We have to redo most of the sanity checks done by 'netlab create' | ||
| error_and_exit(f'The input file ({src}) is not a dictionary') | ||
|
|
||
| if 'validate' in add_topo: # If we have a 'validate' element in the input dictionary | ||
| v_tests = add_topo.validate # We're assuming we read a whole lab topology | ||
| if not isinstance(v_tests,Box): # ... and validate element must be a dictionary | ||
| error_and_exit('The "validate" element in the input file is not a dictionary') | ||
| else: | ||
| v_tests = add_topo # Maybe we just read the tests source file? | ||
|
|
||
| if 'nodes' in v_tests or 'links' in v_tests: # Anyway, final bit of a sanity check... | ||
| error_and_exit( # ... maybe we got a topology file with no 'validate' element? | ||
| 'The source file contains "nodes" or "links" but no "validate" element', | ||
| more_hints="It looks like your topology file has no validation tests") | ||
|
|
||
| topology.validate = v_tests # Hope we got it right; replace validation tests | ||
| validate_test_attributes(topology) | ||
| _validate.process_validation(topology) # Do checks and data transformation on validation tests | ||
|
|
||
| return | ||
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.