Skip to content

Commit 01a9dde

Browse files
authored
[config db] Trim garbage charactor in "DEVICE_METADATA" of config db (#3748)
<!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "closes #xxxx", "fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related issue when the PR is merged. If you are adding/modifying/removing any command or utility script, please also make sure to add/modify/remove any unit tests from the tests directory as appropriate. If you are modifying or removing an existing 'show', 'config' or 'sonic-clear' subcommand, or you are adding a new subcommand, please make sure you also update the Command Line Reference Guide (doc/Command-Reference.md) to reflect your changes. Please provide the following information: --> This is to prevent a user error in ADO: 28004860 where there was an extra "\n" at the end of mac, in "DEVICE_METADATA" section. ![image](https://github.com/sonic-net/sonic-utilities/assets/91497961/41e634d4-1ae0-48bc-9824-72915d10dc25) #### What I did 1. the garbage char could be generated with "load_minigraph" if '-override-config' is specified, and if golden_config has garbage char. 2. it could also be introduced by "config reload" #### How I did it in both cases, add the strip method for "mac" as well as "platform" whenever the DEVICE_METADATA tends to be modified. to trim the extra "\n" #### How to verify it 1. add an extra "\n" at end of mac, in config db 2. did config reload, garbage char exists 3. apply changes in this PR #### Previous command output (if the output of a command-line utility has changed) #### New command output (if the output of a command-line utility has changed)
1 parent 6a959e6 commit 01a9dde

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

config/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,8 +2174,8 @@ def generate_sysinfo(cur_config, config_input, ns=None):
21742174
if not platform:
21752175
platform = device_info.get_platform()
21762176

2177-
device_metadata['localhost']['mac'] = mac
2178-
device_metadata['localhost']['platform'] = platform
2177+
device_metadata['localhost']['mac'] = mac.rstrip('\n')
2178+
device_metadata['localhost']['platform'] = platform.rstrip('\n')
21792179

21802180
return
21812181

tests/config_override_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,10 @@ def read_json_file_side_effect(filename):
386386

387387
with mock.patch('config.main.read_json_file',
388388
mock.MagicMock(side_effect=read_json_file_side_effect)),\
389-
mock.patch('sonic_py_common.device_info.get_platform',
389+
mock.patch('sonic_py_common.device_info.get_platform',
390390
return_value="multi_asic"),\
391-
mock.patch('sonic_py_common.device_info.get_system_mac',
392-
return_value="11:22:33:44:55:66"):
391+
mock.patch('sonic_py_common.device_info.get_system_mac',
392+
return_value="11:22:33:44:55:66\n"):
393393
runner = CliRunner()
394394
result = runner.invoke(config.config.commands["override-config-table"],
395395
['golden_config_db.json'], obj=db)

0 commit comments

Comments
 (0)