diff --git a/generic_config_updater/change_applier.py b/generic_config_updater/change_applier.py index 9261fa198d..9871e554b2 100644 --- a/generic_config_updater/change_applier.py +++ b/generic_config_updater/change_applier.py @@ -147,8 +147,8 @@ def apply(self, change): ret = self._services_validate(run_data, upd_data, upd_keys) if not ret: run_data = self._get_running_config() - upd_data = self.get_config_without_backend_tables(upd_data) - run_data = self.get_config_without_backend_tables(run_data) + self.remove_backend_tables_from_config(upd_data) + self.remove_backend_tables_from_config(run_data) if upd_data != run_data: self._report_mismatch(run_data, upd_data) ret = -1 @@ -157,11 +157,9 @@ def apply(self, change): return ret - def get_config_without_backend_tables(self, data): - cropped_data = { - k: v for k, v in data.items() if k not in self.backend_tables - } - return cropped_data + def remove_backend_tables_from_config(self, data): + for key in self.backend_tables: + data.pop(key, None) def _get_running_config(self): diff --git a/generic_config_updater/generic_updater.py b/generic_config_updater/generic_updater.py index 9cbe063f9e..56297039aa 100644 --- a/generic_config_updater/generic_updater.py +++ b/generic_config_updater/generic_updater.py @@ -77,8 +77,8 @@ def apply(self, patch): # Validate config updated successfully self.logger.log_notice("Verifying patch updates are reflected on ConfigDB.") new_config = self.config_wrapper.get_config_db_as_json() - target_config = self.changeapplier.get_config_without_backend_tables(target_config) - new_config = self.changeapplier.get_config_without_backend_tables(new_config) + self.changeapplier.remove_backend_tables_from_config(target_config) + self.changeapplier.remove_backend_tables_from_config(new_config) if not(self.patch_wrapper.verify_same_json(target_config, new_config)): raise GenericConfigUpdaterError(f"After applying patch to config, there are still some parts not updated") diff --git a/tests/generic_config_updater/generic_updater_test.py b/tests/generic_config_updater/generic_updater_test.py index 1b4383c04c..aab2eae275 100644 --- a/tests/generic_config_updater/generic_updater_test.py +++ b/tests/generic_config_updater/generic_updater_test.py @@ -73,8 +73,6 @@ def __create_patch_applier(self, changeapplier = Mock() changeapplier.apply.side_effect = create_side_effect_dict({(str(changes[0]),): 0, (str(changes[1]),): 0}) - changeapplier.get_config_without_backend_tables.side_effect = \ - [Files.CONFIG_DB_AFTER_MULTI_PATCH, Files.CONFIG_DB_AFTER_MULTI_PATCH] return gu.PatchApplier(patchsorter, changeapplier, config_wrapper, patch_wrapper)