From 17609919fd461521090113d1de6a77d5062905c9 Mon Sep 17 00:00:00 2001 From: jingwenxie Date: Fri, 27 Jan 2023 15:48:15 +0800 Subject: [PATCH] [GCU] Ignore bgpraw table in GCU operation (#2628) What I did After the previous fix #2623 , GCU still fails in the rollback operation. The bgpraw table should be discard in all GCU operation. Thus, I change get_config_db_as_json function to crop out "bgpraw" table. How I did it Pop "bgpraw" table if exists. How to verify it Unittest --- generic_config_updater/change_applier.py | 1 - generic_config_updater/gu_common.py | 4 +++- tests/generic_config_updater/gu_common_test.py | 14 +++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/generic_config_updater/change_applier.py b/generic_config_updater/change_applier.py index 30d81f9119..f5a365d59f 100644 --- a/generic_config_updater/change_applier.py +++ b/generic_config_updater/change_applier.py @@ -76,7 +76,6 @@ class ChangeApplier: def __init__(self): self.config_db = get_config_db() self.backend_tables = [ - "bgpraw", "BUFFER_PG", "BUFFER_PROFILE", "FLEX_COUNTER_TABLE" diff --git a/generic_config_updater/gu_common.py b/generic_config_updater/gu_common.py index d2561d0532..743253ccaf 100644 --- a/generic_config_updater/gu_common.py +++ b/generic_config_updater/gu_common.py @@ -54,7 +54,9 @@ def __init__(self, yang_dir = YANG_DIR): def get_config_db_as_json(self): text = self._get_config_db_as_text() - return json.loads(text) + config_db_json = json.loads(text) + config_db_json.pop("bgpraw", None) + return config_db_json def _get_config_db_as_text(self): # TODO: Getting configs from CLI is very slow, need to get it from sonic-cffgen directly diff --git a/tests/generic_config_updater/gu_common_test.py b/tests/generic_config_updater/gu_common_test.py index 398558bd65..dc18323661 100644 --- a/tests/generic_config_updater/gu_common_test.py +++ b/tests/generic_config_updater/gu_common_test.py @@ -3,12 +3,24 @@ import jsonpatch import sonic_yang import unittest -from unittest.mock import MagicMock, Mock +from unittest.mock import MagicMock, Mock, patch from .gutest_helpers import create_side_effect_dict, Files import generic_config_updater.gu_common as gu_common class TestDryRunConfigWrapper(unittest.TestCase): + @patch('generic_config_updater.gu_common.subprocess.Popen') + def test_get_config_db_as_json(self, mock_popen): + config_wrapper = gu_common.DryRunConfigWrapper() + mock_proc = MagicMock() + mock_proc.communicate = MagicMock( + return_value=('{"PORT": {}, "bgpraw": ""}', None)) + mock_proc.returncode = 0 + mock_popen.return_value = mock_proc + actual = config_wrapper.get_config_db_as_json() + expected = {"PORT": {}} + self.assertDictEqual(actual, expected) + def test_get_config_db_as_json__returns_imitated_config_db(self): # Arrange config_wrapper = gu_common.DryRunConfigWrapper(Files.CONFIG_DB_AS_JSON)