Skip to content

Commit

Permalink
[generic_config_updater]Add empty input fixture to verify configDB be…
Browse files Browse the repository at this point in the history
…fore GCU tests (#5506)

Summary: Add empty input fixture for GCU tests to check if current configDB is valid and GCU feature

What is the motivation for this PR?
During PR test, it will fail on all GCU tests if the configDB does not pass yang validation.
This empty input fixture is to verify if there is invalid config before test.

How did you do it?
Add empty input fixture.

How did you verify/test it?
Run test of sonic-mgmt/tests/generic_config_updater/test_*.py on KVM with invalid config
to see if it fail immediately.
  • Loading branch information
wen587 authored Apr 13, 2022
1 parent c41fff2 commit a12aa9e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/generic_config_updater/conftest.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit a12aa9e

Please sign in to comment.