forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI to configure YANG config validation (sonic-net#2147)
**- What I did** Add CLI to configure YANG config validation mode `config yang_config_validation <enable|disable>` **- How I did it** Add a CLI script that writes the configuration of YANG config validation enable/disable into CONFIG_DB
- Loading branch information
1 parent
30f1e13
commit 87cee04
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,33 @@ | ||
from click.testing import CliRunner | ||
import config.main as config | ||
|
||
class TestYangConfigValidation(object): | ||
@classmethod | ||
def setup_class(cls): | ||
print("SETUP") | ||
|
||
def __check_result(self, result_msg, mode): | ||
if mode == "enable" or mode == "disable": | ||
expected_msg = """Wrote %s yang config validation into CONFIG_DB""" % mode | ||
else: | ||
expected_msg = "Error: Invalid argument %s, expect either enable or disable" % mode | ||
|
||
return expected_msg in result_msg | ||
|
||
def test_yang_config_validation(self): | ||
runner = CliRunner() | ||
|
||
result = runner.invoke(config.config.commands["yang_config_validation"], ["enable"]) | ||
print(result.output) | ||
assert result.exit_code == 0 | ||
assert self.__check_result(result.output, "enable") | ||
|
||
result = runner.invoke(config.config.commands["yang_config_validation"], ["disable"]) | ||
print(result.output) | ||
assert result.exit_code == 0 | ||
assert self.__check_result(result.output, "disable") | ||
|
||
result = runner.invoke(config.config.commands["yang_config_validation"], ["invalid-input"]) | ||
print(result.output) | ||
assert result.exit_code != 0 | ||
assert self.__check_result(result.output, "invalid-input") |