From f0609653edc9d122bf99f7ad8078d2c0f97523a9 Mon Sep 17 00:00:00 2001 From: Jingwen Xie Date: Sat, 2 Apr 2022 04:33:08 +0000 Subject: [PATCH 1/2] Add GCU empty input test to verify functional usage and valid configDB --- .../test_empty_input.py | 41 +++++++++++++++++++ tests/kvmtest.sh | 1 + 2 files changed, 42 insertions(+) create mode 100644 tests/generic_config_updater/test_empty_input.py diff --git a/tests/generic_config_updater/test_empty_input.py b/tests/generic_config_updater/test_empty_input.py new file mode 100644 index 00000000000..839018deeef --- /dev/null +++ b/tests/generic_config_updater/test_empty_input.py @@ -0,0 +1,41 @@ +import logging +import pytest + +from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success +from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile +from tests.generic_config_updater.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload + +logger = logging.getLogger(__name__) + +@pytest.fixture(autouse=True) +def setup_env(duthosts, rand_one_dut_hostname): + """ + Setup/teardown fixture for empty input= + + Args: + duthosts: list of DUTs. + rand_selected_dut: The fixture returns a randomly selected DuT. + """ + duthost = duthosts[rand_one_dut_hostname] + create_checkpoint(duthost) + + yield + + try: + logger.info("Rolled back to original checkpoint") + rollback_or_reload(duthost) + + finally: + delete_checkpoint(duthost) + +def test_tc1_empty_input(duthost): + json_patch = [] + + tmpfile = generate_tmpfile(duthost) + logger.info("tmpfile {}".format(tmpfile)) + + try: + output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) + expect_op_success(duthost, output) + finally: + delete_tmpfile(duthost, tmpfile) \ No newline at end of file diff --git a/tests/kvmtest.sh b/tests/kvmtest.sh index e8dfb9f1b5e..d985caabcf3 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -152,6 +152,7 @@ test_t0() { container_checker/test_container_checker.py \ process_monitoring/test_critical_process_monitoring.py \ system_health/test_system_status.py \ + generic_config_updater/test_empty_input.py \ generic_config_updater/test_aaa.py \ generic_config_updater/test_bgpl.py \ generic_config_updater/test_bgp_prefix.py \ From 0a086f759040bdf35a034e95f6cdf9bcd286a87e Mon Sep 17 00:00:00 2001 From: Jingwen Xie Date: Wed, 13 Apr 2022 06:58:37 +0000 Subject: [PATCH 2/2] change empty input check with fixture --- tests/generic_config_updater/conftest.py | 27 ++++++++++++ .../test_empty_input.py | 41 ------------------- tests/kvmtest.sh | 1 - 3 files changed, 27 insertions(+), 42 deletions(-) delete mode 100644 tests/generic_config_updater/test_empty_input.py diff --git a/tests/generic_config_updater/conftest.py b/tests/generic_config_updater/conftest.py index 824daf86fe9..a365db62928 100644 --- a/tests/generic_config_updater/conftest.py +++ b/tests/generic_config_updater/conftest.py @@ -1,6 +1,8 @@ import pytest from tests.common.utilities import skip_release +from tests.generic_config_updater.gu_utils import apply_patch +from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile @pytest.fixture(autouse=True) def ignore_expected_loganalyzer_exceptions(duthost, loganalyzer): @@ -53,3 +55,28 @@ def cfg_facts(duthosts, rand_one_dut_hostname): """ duthost = duthosts[rand_one_dut_hostname] return duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts'] + + +@pytest.fixture(scope="module", autouse=True) +def verify_configdb_with_empty_input(duthost): + """Fail immediately if empty input test failure + + Args: + duthost: Hostname of DUT. + + Returns: + None. + """ + json_patch = [] + tmpfile = generate_tmpfile(duthost) + + try: + output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) + if output['rc'] or "Patch applied successfully" not in output['stdout']: + pytest.fail( + "SETUP FAILURE: ConfigDB fail to validate Yang. rc:{} msg:{}" + .format(output['rc'], output['stdout']) + ) + + finally: + delete_tmpfile(duthost, tmpfile) diff --git a/tests/generic_config_updater/test_empty_input.py b/tests/generic_config_updater/test_empty_input.py deleted file mode 100644 index 839018deeef..00000000000 --- a/tests/generic_config_updater/test_empty_input.py +++ /dev/null @@ -1,41 +0,0 @@ -import logging -import pytest - -from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success -from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile -from tests.generic_config_updater.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload - -logger = logging.getLogger(__name__) - -@pytest.fixture(autouse=True) -def setup_env(duthosts, rand_one_dut_hostname): - """ - Setup/teardown fixture for empty input= - - Args: - duthosts: list of DUTs. - rand_selected_dut: The fixture returns a randomly selected DuT. - """ - duthost = duthosts[rand_one_dut_hostname] - create_checkpoint(duthost) - - yield - - try: - logger.info("Rolled back to original checkpoint") - rollback_or_reload(duthost) - - finally: - delete_checkpoint(duthost) - -def test_tc1_empty_input(duthost): - json_patch = [] - - tmpfile = generate_tmpfile(duthost) - logger.info("tmpfile {}".format(tmpfile)) - - try: - output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) - expect_op_success(duthost, output) - finally: - delete_tmpfile(duthost, tmpfile) \ No newline at end of file diff --git a/tests/kvmtest.sh b/tests/kvmtest.sh index d985caabcf3..e8dfb9f1b5e 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -152,7 +152,6 @@ test_t0() { container_checker/test_container_checker.py \ process_monitoring/test_critical_process_monitoring.py \ system_health/test_system_status.py \ - generic_config_updater/test_empty_input.py \ generic_config_updater/test_aaa.py \ generic_config_updater/test_bgpl.py \ generic_config_updater/test_bgp_prefix.py \