Skip to content

Commit

Permalink
[GCU] Ignore bgpraw table in GCU operation (#2628)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wen587 authored and StormLiangMS committed Feb 10, 2023
1 parent c65bdc3 commit 6adcd3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion generic_config_updater/gu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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 6adcd3e

Please sign in to comment.