From c2aa8fd2a08d9b367b740edbd353511b88afdca5 Mon Sep 17 00:00:00 2001 From: bingwang-ms <66248323+bingwang-ms@users.noreply.github.com> Date: Wed, 8 Jun 2022 21:28:14 +0800 Subject: [PATCH] Revert "[tests/override_config_table] load_minigraph with Golden Config test (#5625)" This reverts commit e9e1190c446e09d15d76e105c88c195875204b44. --- tests/kvmtest.sh | 1 - .../test_override_config_table.py | 155 ------------------ 2 files changed, 156 deletions(-) delete mode 100644 tests/override_config_table/test_override_config_table.py diff --git a/tests/kvmtest.sh b/tests/kvmtest.sh index 8bf709814c8..2b07e7c48e6 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -164,7 +164,6 @@ test_t0() { generic_config_updater/test_portchannel_interface.py \ generic_config_updater/test_syslog.py \ generic_config_updater/test_vlan_interface.py \ - override_config_table/test_override_config_table.py \ process_monitoring/test_critical_process_monitoring.py \ show_techsupport/test_techsupport_no_secret.py \ system_health/test_system_status.py" diff --git a/tests/override_config_table/test_override_config_table.py b/tests/override_config_table/test_override_config_table.py deleted file mode 100644 index 584328c3f32..00000000000 --- a/tests/override_config_table/test_override_config_table.py +++ /dev/null @@ -1,155 +0,0 @@ -import json -import logging -import pytest - -from tests.common.helpers.assertions import pytest_assert -from tests.common.config_reload import config_reload - -GOLDEN_CONFIG = "/etc/sonic/golden_config_db.json" -GOLDEN_CONFIG_BACKUP = "/etc/sonic/golden_config_db.json_before_override" -CONFIG_DB = "/etc/sonic/config_db.json" -CONFIG_DB_BACKUP = "/etc/sonic/config_db.json_before_override" - -logger = logging.getLogger(__name__) - - -def file_exists_on_dut(duthost, filename): - return duthost.stat(path=filename).get('stat', {}).get('exists', False) - - -@pytest.fixture(scope="module") -def golden_config_exists_on_dut(duthost): - return file_exists_on_dut(duthost, GOLDEN_CONFIG) - - -def backup_config(duthost, config, config_backup): - logger.info("Backup {} to {} on {}".format( - config, config_backup, duthost.hostname)) - duthost.shell("cp {} {}".format(config, config_backup)) - - -def restore_config(duthost, config, config_backup): - logger.info("Restore {} with {} on {}".format( - config, config_backup, duthost.hostname)) - duthost.shell("mv {} {}".format(config_backup, config)) - - -def get_running_config(duthost): - return json.loads(duthost.shell("sonic-cfggen -d --print-data")['stdout']) - - -def reload_minigraph_with_golden_config(duthost, json_data): - duthost.copy(content=json.dumps(json_data, indent=4), dest=GOLDEN_CONFIG) - config_reload(duthost, config_source="minigraph", safe_reload=True) - - -@pytest.fixture(scope="module") -def setup_env(duthosts, rand_one_dut_hostname, golden_config_exists_on_dut): - """ - Setup/teardown - Args: - duthosts: list of DUTs. - rand_selected_dut: The fixture returns a randomly selected DuT. - """ - duthost = duthosts[rand_one_dut_hostname] - - # Backup configDB - backup_config(duthost, CONFIG_DB, CONFIG_DB_BACKUP) - # Backup Golden Config if exists. - if golden_config_exists_on_dut: - backup_config(duthost, GOLDEN_CONFIG, GOLDEN_CONFIG_BACKUP) - - # Reload test env with minigraph - config_reload(duthost, config_source="minigraph", safe_reload=True) - running_config = get_running_config(duthost) - - yield running_config - - # Restore configDB after test. - restore_config(duthost, CONFIG_DB, CONFIG_DB_BACKUP) - # Restore Golden Config after test, else cleanup test file. - if golden_config_exists_on_dut: - restore_config(duthost, GOLDEN_CONFIG, GOLDEN_CONFIG_BACKUP) - else: - duthost.file(path=GOLDEN_CONFIG, state='absent') - - # Restore config before test - config_reload(duthost) - - -def load_minigraph_with_golden_empty_input(duthost): - """Test Golden Config with empty input - """ - initial_config = get_running_config(duthost) - - empty_input = {} - reload_minigraph_with_golden_config(duthost, empty_input) - - current_config = get_running_config(duthost) - pytest_assert(initial_config == current_config, - "Running config differs.") - - -def load_minigraph_with_golden_partial_config(duthost): - """Test Golden Config with partial config. - - Here we assume all config contain SYSLOG_SERVER table - """ - partial_config = { - "SYSLOG_SERVER": { - "10.0.0.100": {}, - "10.0.0.200": {} - } - } - reload_minigraph_with_golden_config(duthost, partial_config) - - current_config = get_running_config(duthost) - pytest_assert( - current_config['SYSLOG_SERVER'] == partial_config['SYSLOG_SERVER'], - "Partial config override fail: {}".format(current_config['SYSLOG_SERVER']) - ) - - -def load_minigraph_with_golden_new_feature(duthost): - """Test Golden Config with new feature - """ - new_feature_config = { - "NEW_FEATURE_TABLE": { - "entry": { - "field": "value", - "state": "disabled" - } - } - } - reload_minigraph_with_golden_config(duthost, new_feature_config) - - current_config = get_running_config(duthost) - pytest_assert( - 'NEW_FEATURE_TABLE' in current_config and - current_config['NEW_FEATURE_TABLE'] == new_feature_config['NEW_FEATURE_TABLE'], - "new feature config update fail: {}".format(current_config['NEW_FEATURE_TABLE']) - ) - - -def load_minigraph_with_golden_full_config(duthost, full_config): - """Test Golden Config fully override minigraph config - """ - # Test if the config has been override by full_config - reload_minigraph_with_golden_config(duthost, full_config) - - current_config = get_running_config(duthost) - for table in full_config: - pytest_assert( - full_config[table] == current_config[table], - "full config override fail! {}".format(table) - ) - - -def test_load_minigraph_with_golden_config(duthost, setup_env): - """Test Golden Config override during load minigraph - """ - load_minigraph_with_golden_empty_input(duthost) - load_minigraph_with_golden_partial_config(duthost) - load_minigraph_with_golden_new_feature(duthost) - full_config = setup_env - load_minigraph_with_golden_full_config(duthost, full_config)