Skip to content

Commit bab983c

Browse files
wen587StormLiangMS
authored andcommitted
Revert "Convert IPv6 addresses to lowercase in apply-patch (#2299)" (#2758)
This reverts commit 28b6ba5. There are some issues when GCU tries to remove the interface IP in some tests, such as add rack test. In the initial config, the INTERFACE's IPv6 was all loaded in uppercase by default. "INTERFACE": { "Ethernet68": {}, "Ethernet68|10.0.0.34/31": {}, "Ethernet68|FC00::45/126": {}, "Ethernet72": {}, "Ethernet72|10.0.0.36/31": {}, "Ethernet72|FC00::49/126": {}, GCU will never be able to remove that IP because IPv6 was always translated to lowercase due to #2299 . It reported the error can't remove a non-existent object, thus making GCU fail. #2299 is to deal with this issue: sonic-net/sonic-buildimage#11622. Although config CLI always translates uppercase to lowercase when adding an IP, the user can have two choices to remove that IP: One is to use config CLI to remove that IP no matter uppercase or lowercase. Another way is to use GCU. In order to use GCU, the user has to check the IP format saved in ConfigDB because GCU operation does differentiate between uppercase and lowercase. #### What I did Revert #2299
1 parent 721e26f commit bab983c

File tree

3 files changed

+0
-40
lines changed

3 files changed

+0
-40
lines changed

config/main.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,20 +1397,6 @@ def apply_patch(ctx, patch_file_path, format, dry_run, ignore_non_yang_tables, i
13971397
patch_as_json = json.loads(text)
13981398
patch = jsonpatch.JsonPatch(patch_as_json)
13991399

1400-
# convert IPv6 addresses to lowercase
1401-
for patch_line in patch:
1402-
if 'remove' == patch_line['op']:
1403-
match = re.search(r"(?P<prefix>/INTERFACE/\w+\|)(?P<ipv6_address>([a-fA-F0-9]{0,4}[:~]|::){1,7}[a-fA-F0-9]{0,4})"
1404-
"(?P<suffix>.*)", str.format(patch_line['path']))
1405-
if match:
1406-
prefix = match.group('prefix')
1407-
ipv6_address_str = match.group('ipv6_address')
1408-
suffix = match.group('suffix')
1409-
ipv6_address_str = ipv6_address_str.lower()
1410-
click.secho("converted ipv6 address to lowercase {} with prefix {} in value: {}"
1411-
.format(ipv6_address_str, prefix, patch_line['path']))
1412-
patch_line['path'] = prefix + ipv6_address_str + suffix
1413-
14141400
config_format = ConfigFormat[format.upper()]
14151401
GenericUpdater().apply_patch(patch, config_format, verbose, dry_run, ignore_non_yang_tables, ignore_path)
14161402

tests/ip_config_input/patch_ipv6.test

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/ip_config_test.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
import jsonpatch
31
import os
42
import traceback
53
from unittest import mock
@@ -14,9 +12,6 @@
1412
from utilities_common.db import Db
1513
import utilities_common.bgp_util as bgp_util
1614

17-
test_path = os.path.dirname(os.path.abspath(__file__))
18-
ip_config_input_path = os.path.join(test_path, "ip_config_input")
19-
2015
ERROR_MSG = "Error: IP address is not valid"
2116

2217
INVALID_VRF_MSG ="""\
@@ -243,21 +238,6 @@ def test_add_del_interface_shortened_ipv6_with_leading_zeros(self):
243238
assert result.exit_code != 0
244239
assert ('Ethernet68', '3000::1/64') not in db.cfgdb.get_table('INTERFACE')
245240

246-
def test_remove_interface_case_sensitive_mock_ipv6_w_apply_patch(self):
247-
runner = CliRunner()
248-
any_patch_as_json = [{"op": "remove", "path": "/INTERFACE/Ethernet12|FC00::1~1126"}]
249-
any_patch = jsonpatch.JsonPatch(any_patch_as_json)
250-
any_patch_as_text = json.dumps(any_patch_as_json)
251-
ipv6_patch_file = os.path.join(ip_config_input_path, 'patch_ipv6.test')
252-
253-
# config apply-patch patch
254-
mock_generic_updater = mock.Mock()
255-
with mock.patch('config.main.GenericUpdater', return_value=mock_generic_updater):
256-
with mock.patch('builtins.open', mock.mock_open(read_data=any_patch_as_text)):
257-
result = runner.invoke(config.config.commands["apply-patch"], [ipv6_patch_file], catch_exceptions=False)
258-
print(result.exit_code, result.output)
259-
assert "converted ipv6 address to lowercase fc00::1~1126 with prefix /INTERFACE/Ethernet12| in value: /INTERFACE/Ethernet12|FC00::1~1126" in result.output
260-
261241
def test_intf_vrf_bind_unbind(self):
262242
runner = CliRunner()
263243
db = Db()

0 commit comments

Comments
 (0)