-
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |||||
| from ...utils import log, strings | ||||||
| from ...utils import status as _status | ||||||
| from .. import load_snapshot | ||||||
| from . import parse, report, tests | ||||||
| from . import parse, report, source, tests | ||||||
|
|
||||||
| # I'm cheating. Declaring a global variable is easier than passing 'args' argument around | ||||||
| # | ||||||
|
|
@@ -42,8 +42,17 @@ def list_tests(topology: Box) -> None: | |||||
| def run(cli_args: typing.List[str]) -> None: | ||||||
| global TEST_COUNT,ERROR_ONLY | ||||||
| args = parse.validate_parse(cli_args) | ||||||
| if args.error_only: | ||||||
| args.quiet = True | ||||||
| log.set_logging_flags(args) | ||||||
| topology = load_snapshot(args) | ||||||
| topology = load_snapshot(args,warn_modified=False) | ||||||
| if args.test_source: | ||||||
| source.update_validation_tests(topology,args.test_source) | ||||||
| elif topology.get('_input.modified'): | ||||||
| log.warning( | ||||||
| text=f'Topology source file(s) have changed since the lab has started', | ||||||
| module='-') | ||||||
| source.update_validation_tests(topology,topology.input[0]) | ||||||
|
||||||
| source.update_validation_tests(topology,topology.input[0]) | |
| source.update_validation_tests(topology,topology._input.modified) |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||
| # | ||||||||||
| # Common validation utility functions | ||||||||||
| # | ||||||||||
|
|
||||||||||
|
|
||||||||||
| 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: | ||||||||||
| log.info(f'Reading validation tests from {src}') | ||||||||||
| add_topo = read.read_yaml(filename=src) # Read tests or whole topology from input file | ||||||||||
|
||||||||||
| add_topo = read.read_yaml(filename=src) # Read tests or whole topology from input file | |
| add_topo = read.read_yaml(filename=src) # Read tests or whole topology from input file | |
| if add_topo is None: | |
| error_and_exit('Cannot read the input file or the file does not exist') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states that netlab validate will "reread" tests when the topology file changes, but the implementation always uses the first file (
topology.input[0]) rather than the modified file (topology._input.modified). This could lead to reading tests from an unchanged defaults file instead of the modified topology file.