diff --git a/config/main.py b/config/main.py index bea5016fdb..2e20b5dad6 100644 --- a/config/main.py +++ b/config/main.py @@ -1968,6 +1968,18 @@ def override_config_table(db, input_config_db, dry_run): validate_config_by_cm(cm, ns_config_input, "config_input") # Validate updated whole config validate_config_by_cm(cm, updated_config, "updated_config") + else: + cm = None + try: + # YANG validate of config minigraph generated + cm = ConfigMgmt(configdb=config_db) + cm.validateConfigData() + except Exception as ex: + log.log_warning("Failed to validate running config. Alerting: {}".format(ex)) + + # YANG validate config of minigraph generated overriden by golden config + if cm: + validate_config_by_cm_alerting(cm, updated_config, "updated_config") if dry_run: print(json.dumps(updated_config, sort_keys=True, @@ -1986,6 +1998,15 @@ def validate_config_by_cm(cm, config_json, jname): sys.exit(1) +def validate_config_by_cm_alerting(cm, config_json, jname): + tmp_config_json = copy.deepcopy(config_json) + try: + cm.loadData(tmp_config_json) + cm.validateConfigData() + except Exception as ex: + log.log_warning("Failed to validate {}. Alerting: {}".format(jname, ex)) + + def override_config_db(config_db, config_input): # Deserialized golden config to DB recognized format sonic_cfggen.FormatConverter.to_deserialized(config_input) diff --git a/tests/config_override_input/multi_asic_dm_rm.json b/tests/config_override_input/multi_asic_dm_rm.json deleted file mode 100644 index a4c0dd5fa7..0000000000 --- a/tests/config_override_input/multi_asic_dm_rm.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "localhost": { - "DEVICE_METADATA": {} - }, - "asic0": { - "DEVICE_METADATA": {} - }, - "asic1": { - "DEVICE_METADATA": {} - } -} diff --git a/tests/config_override_input/multi_asic_feature_rm.json b/tests/config_override_input/multi_asic_feature_rm.json new file mode 100644 index 0000000000..b29cdf952f --- /dev/null +++ b/tests/config_override_input/multi_asic_feature_rm.json @@ -0,0 +1,11 @@ +{ + "localhost": { + "FEATURE": {} + }, + "asic0": { + "FEATURE": {} + }, + "asic1": { + "FEATURE": {} + } +} diff --git a/tests/config_override_input/multi_asic_macsec_ov.json b/tests/config_override_input/multi_asic_macsec_ov.json index ba86f6ef60..9a4a5c478c 100644 --- a/tests/config_override_input/multi_asic_macsec_ov.json +++ b/tests/config_override_input/multi_asic_macsec_ov.json @@ -2,21 +2,30 @@ "localhost": { "MACSEC_PROFILE": { "profile": { - "key": "value" + "primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71", + "primary_ckn": "6162636465666768696A6B6C6D6E6F70", + "fallback_cak": "000000000000000000000000000000000000000000000000000000000000000000", + "fallback_ckn": "11111111111111111111111111111111" } } }, "asic0": { "MACSEC_PROFILE": { "profile": { - "key": "value" + "primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71", + "primary_ckn": "6162636465666768696A6B6C6D6E6F70", + "fallback_cak": "000000000000000000000000000000000000000000000000000000000000000000", + "fallback_ckn": "11111111111111111111111111111111" } } }, "asic1": { "MACSEC_PROFILE": { "profile": { - "key": "value" + "primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71", + "primary_ckn": "6162636465666768696A6B6C6D6E6F70", + "fallback_cak": "000000000000000000000000000000000000000000000000000000000000000000", + "fallback_ckn": "11111111111111111111111111111111" } } } diff --git a/tests/config_override_input/multi_asic_missing_asic.json b/tests/config_override_input/multi_asic_missing_asic.json index db8ba8ec80..a1eeb27f26 100644 --- a/tests/config_override_input/multi_asic_missing_asic.json +++ b/tests/config_override_input/multi_asic_missing_asic.json @@ -1,8 +1,8 @@ { "localhost": { - "DEVICE_METADATA": {} + "FEATURE": {} }, "asic0": { - "DEVICE_METADATA": {} + "FEATURE": {} } } diff --git a/tests/config_override_test.py b/tests/config_override_test.py index 19d2ddc197..ae120c9747 100644 --- a/tests/config_override_test.py +++ b/tests/config_override_test.py @@ -22,7 +22,7 @@ GOLDEN_INPUT_YANG_FAILURE = os.path.join(DATA_DIR, "golden_input_yang_failure.json") FINAL_CONFIG_YANG_FAILURE = os.path.join(DATA_DIR, "final_config_yang_failure.json") MULTI_ASIC_MACSEC_OV = os.path.join(DATA_DIR, "multi_asic_macsec_ov.json") -MULTI_ASIC_DEVICE_METADATA_RM = os.path.join(DATA_DIR, "multi_asic_dm_rm.json") +MULTI_ASIC_FEATURE_RM = os.path.join(DATA_DIR, "multi_asic_feature_rm.json") MULTI_ASIC_DEVICE_METADATA_GEN_SYSINFO = os.path.join(DATA_DIR, "multi_asic_dm_gen_sysinfo.json") MULTI_ASIC_MISSING_LOCALHOST_OV = os.path.join(DATA_DIR, "multi_asic_missing_localhost.json") MULTI_ASIC_MISSING_ASIC_OV = os.path.join(DATA_DIR, "multi_asic_missing_asic.json") @@ -104,7 +104,9 @@ def read_json_file_side_effect(filename): ['golden_config_db.json', '--dry-run']) assert result.exit_code == 0 - assert json.loads(result.output) == current_config + start_pos = result.output.find('{') + json_text = result.output[start_pos:] + assert json.loads(json_text) == current_config def test_golden_config_db_empty(self): db = Db() @@ -288,7 +290,15 @@ def read_json_file_side_effect(filename): # The profile_content was copied from MULTI_ASIC_MACSEC_OV, where all # ns sharing the same content: {"profile": {"key": "value"}} - profile_content = {"profile": {"key": "value"}} + profile_content = { + "profile": { + "primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71", + "primary_ckn": "6162636465666768696A6B6C6D6E6F70", + "fallback_cak": "000000000000000000000000000000000000000000000000000000000000000000", + "fallback_ckn": "11111111111111111111111111111111" + + } + } with mock.patch('config.main.read_json_file', mock.MagicMock(side_effect=read_json_file_side_effect)): @@ -300,16 +310,16 @@ def read_json_file_side_effect(filename): for ns, config_db in cfgdb_clients.items(): assert config_db.get_config()['MACSEC_PROFILE'] == profile_content - def test_device_metadata_table_rm(self): + def test_feature_table_rm(self): def read_json_file_side_effect(filename): - with open(MULTI_ASIC_DEVICE_METADATA_RM, "r") as f: - device_metadata = json.load(f) - return device_metadata + with open(MULTI_ASIC_FEATURE_RM, "r") as f: + feature = json.load(f) + return feature db = Db() cfgdb_clients = db.cfgdb_clients for ns, config_db in cfgdb_clients.items(): - assert 'DEVICE_METADATA' in config_db.get_config() + assert 'FEATURE' in config_db.get_config() with mock.patch('config.main.read_json_file', mock.MagicMock(side_effect=read_json_file_side_effect)): @@ -319,7 +329,7 @@ def read_json_file_side_effect(filename): assert result.exit_code == 0 for ns, config_db in cfgdb_clients.items(): - assert 'DEVICE_METADATA' not in config_db.get_config() + assert 'FEATURE' not in config_db.get_config() def test_device_metadata_keep_sysinfo(self): def read_json_file_side_effect(filename):