Skip to content

Commit

Permalink
[GCU] Ignore bgpraw table in GCU operation (sonic-net#2628)
Browse files Browse the repository at this point in the history
What I did
After the previous fix sonic-net#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
  • Loading branch information
wen587 authored and isabelmsft committed Mar 23, 2023
1 parent 3db8c00 commit 1760991
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion generic_config_updater/change_applier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion generic_config_updater/gu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion tests/generic_config_updater/gu_common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1760991

Please sign in to comment.