From 4db3b9a3ffcd527104ff89558f274488caa49608 Mon Sep 17 00:00:00 2001 From: Jingwen Xie Date: Wed, 25 Jan 2023 09:16:53 +0000 Subject: [PATCH 1/4] Revert "[GCU] Ignore bgpraw in GCU applier (#2623)" This reverts commit f4f857e103daa746ab4f2e7a908c1aefc299a713. --- generic_config_updater/change_applier.py | 1 - 1 file changed, 1 deletion(-) 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" From b9a1c3e16755eb8377f840c8153e2ad257fe0cd1 Mon Sep 17 00:00:00 2001 From: Jingwen Xie Date: Wed, 25 Jan 2023 09:23:15 +0000 Subject: [PATCH 2/4] [GCU] change to sonic-cfggen for config_db --- generic_config_updater/gu_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generic_config_updater/gu_common.py b/generic_config_updater/gu_common.py index d2561d0532..5067c6cd64 100644 --- a/generic_config_updater/gu_common.py +++ b/generic_config_updater/gu_common.py @@ -57,8 +57,8 @@ def get_config_db_as_json(self): return json.loads(text) def _get_config_db_as_text(self): - # TODO: Getting configs from CLI is very slow, need to get it from sonic-cffgen directly - cmd = "show runningconfiguration all" + # Use sonic-cfggen to generate data only from CONFIG_DB + cmd = "sonic-cfggen -d --print-data" result = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) text, err = result.communicate() return_code = result.returncode From 263de0ef1e1fbe7969294ae33054c1db14669ec4 Mon Sep 17 00:00:00 2001 From: Jingwen Xie Date: Thu, 26 Jan 2023 01:09:59 +0000 Subject: [PATCH 3/4] Revert "[GCU] change to sonic-cfggen for config_db" This reverts commit b9a1c3e16755eb8377f840c8153e2ad257fe0cd1. --- generic_config_updater/gu_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generic_config_updater/gu_common.py b/generic_config_updater/gu_common.py index 5067c6cd64..d2561d0532 100644 --- a/generic_config_updater/gu_common.py +++ b/generic_config_updater/gu_common.py @@ -57,8 +57,8 @@ def get_config_db_as_json(self): return json.loads(text) def _get_config_db_as_text(self): - # Use sonic-cfggen to generate data only from CONFIG_DB - cmd = "sonic-cfggen -d --print-data" + # TODO: Getting configs from CLI is very slow, need to get it from sonic-cffgen directly + cmd = "show runningconfiguration all" result = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) text, err = result.communicate() return_code = result.returncode From 354188259dac964f26dd826c1f40948778522a48 Mon Sep 17 00:00:00 2001 From: Jingwen Xie Date: Thu, 26 Jan 2023 05:36:46 +0000 Subject: [PATCH 4/4] resolve comment --- generic_config_updater/gu_common.py | 4 +++- tests/generic_config_updater/gu_common_test.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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)