Skip to content

Commit

Permalink
[sonic-cli-gen] fix failure "Error: digits_class" when field "digit_c…
Browse files Browse the repository at this point in the history
…lass" does not exist in DB (#2054)

here

Signed-off-by: Stepan Blyschak <[email protected]>
  • Loading branch information
stepanblyschak authored Mar 27, 2022
1 parent f71ef64 commit 8389c81
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sonic-utilities-data/templates/sonic-cli-gen/config.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def update_entry_validated(db, table, key, data, create_if_not_exists=False):

entry_changed = False
for attr, value in data.items():
if value == cfg[table][key][attr]:
if value == cfg[table][key].get(attr):
continue
entry_changed = True
if value is None:
Expand Down
12 changes: 6 additions & 6 deletions tests/cli_autogen_input/autogen_test/show_cmd_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@


show_device_metadata_localhost="""\
HWSKU DEFAULT BGP STATUS DOCKER ROUTING CONFIG MODE HOSTNAME PLATFORM MAC DEFAULT PFCWD STATUS BGP ASN DEPLOYMENT ID TYPE BUFFER MODEL FRR MGMT FRAMEWORK CONFIG
----------- -------------------- ---------------------------- ---------- ---------------------- ----------------- ---------------------- --------- --------------- --------- -------------- ---------------------------
ACS-MSN2100 up N/A r-sonic-01 x86_64-mlnx_msn2100-r0 ff:ff:ff:ff:ff:00 disable N/A N/A ToRRouter traditional N/A
HWSKU DEFAULT BGP STATUS DOCKER ROUTING CONFIG MODE HOSTNAME PLATFORM MAC DEFAULT PFCWD STATUS BGP ASN DEPLOYMENT ID NON EXISTING FIELD TYPE BUFFER MODEL FRR MGMT FRAMEWORK CONFIG
----------- -------------------- ---------------------------- ---------- ---------------------- ----------------- ---------------------- --------- --------------- -------------------- --------- -------------- ---------------------------
ACS-MSN2100 up N/A r-sonic-01 x86_64-mlnx_msn2100-r0 ff:ff:ff:ff:ff:00 disable N/A N/A N/A ToRRouter traditional N/A
"""


show_device_metadata_localhost_changed_buffer_model="""\
HWSKU DEFAULT BGP STATUS DOCKER ROUTING CONFIG MODE HOSTNAME PLATFORM MAC DEFAULT PFCWD STATUS BGP ASN DEPLOYMENT ID TYPE BUFFER MODEL FRR MGMT FRAMEWORK CONFIG
----------- -------------------- ---------------------------- ---------- ---------------------- ----------------- ---------------------- --------- --------------- --------- -------------- ---------------------------
ACS-MSN2100 up N/A r-sonic-01 x86_64-mlnx_msn2100-r0 ff:ff:ff:ff:ff:00 disable N/A N/A ToRRouter dynamic N/A
HWSKU DEFAULT BGP STATUS DOCKER ROUTING CONFIG MODE HOSTNAME PLATFORM MAC DEFAULT PFCWD STATUS BGP ASN DEPLOYMENT ID NON EXISTING FIELD TYPE BUFFER MODEL FRR MGMT FRAMEWORK CONFIG
----------- -------------------- ---------------------------- ---------- ---------------------- ----------------- ---------------------- --------- --------------- -------------------- --------- -------------- ---------------------------
ACS-MSN2100 up N/A r-sonic-01 x86_64-mlnx_msn2100-r0 ff:ff:ff:ff:ff:00 disable N/A N/A N/A ToRRouter dynamic N/A
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ module sonic-device_metadata {
type uint32;
}

leaf non_existing_field {
type uint32;
}

leaf type {
type string {
length 1..255;
Expand Down
12 changes: 12 additions & 0 deletions tests/cli_autogen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ def test_config_device_metadata(self):
assert result.exit_code == SUCCESS
assert result.output == show_cmd_output.show_device_metadata_localhost_changed_buffer_model

def test_config_device_metadata_non_existing_field(self):
dbconnector.dedicated_dbs['CONFIG_DB'] = mock_db_path
db = Db()
runner = CliRunner()

result = runner.invoke(
config_main.config.commands['device-metadata'].commands['localhost'].commands['non-existing-field'], ['12'], obj=db
)

logger.debug("\n" + result.output)
logger.debug(result.exit_code)
assert result.exit_code == SUCCESS

@pytest.mark.parametrize("parameter,value", [
('default-bgp-status', INVALID_VALUE),
Expand Down

0 comments on commit 8389c81

Please sign in to comment.