Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/sonic-yang-mgmt/sonic-cfg-help
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ class SonicCfgDescriber:
self.print_field_desc(table['list'], field)
print()
elif table.get('container') is not None:
self.print_field_desc(table.get('container'), field)
if isinstance(table['container'], dict):
print("key - " + table['container'].get('@name'))
self.print_field_desc(table.get('container'), field)
elif isinstance(table['container'], list):
for c in table['container']:
print("key - " + c.get('@name'))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we filter the common logic b/w these two, i.e. handling a single container dictinto a separate function and re-use in both the cases?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print_field_desc is purpose is to do that - print a container. In the list case we loop through the list and call this API. The only additional line is printing the key. I prefer to keep this outside of print_field_desc function and so you had one line of duplication.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, okay

self.print_field_desc(c, field)

print()

def get_referenced_table_field(self, ref):
Expand Down
26 changes: 26 additions & 0 deletions src/sonic-yang-mgmt/tests/test_cfghelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
AUTO_TECHSUPPORT
Description: AUTO_TECHSUPPORT part of config_db.json

key - GLOBAL
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| Field | Description | Mandatory | Default | Reference |
+=========================+====================================================+=============+===========+=============+
Expand Down Expand Up @@ -62,6 +63,7 @@
AUTO_TECHSUPPORT
Description: AUTO_TECHSUPPORT part of config_db.json

key - GLOBAL
+---------+--------------------------------------------------+-------------+-----------+-------------+
| Field | Description | Mandatory | Default | Reference |
+=========+==================================================+=============+===========+=============+
Expand Down Expand Up @@ -118,6 +120,25 @@

"""

snmp_table_output="""\

SNMP

key - CONTACT
+---------+----------------------+-------------+-----------+-------------+
| Field | Description | Mandatory | Default | Reference |
+=========+======================+=============+===========+=============+
| Contact | SNMP System Contact. | | | |
+---------+----------------------+-------------+-----------+-------------+
key - LOCATION
+----------+-----------------------+-------------+-----------+-------------+
| Field | Description | Mandatory | Default | Reference |
+==========+=======================+=============+===========+=============+
| Location | SNMP System Location. | | | |
+----------+-----------------------+-------------+-----------+-------------+

"""

class TestCfgHelp(TestCase):

def setUp(self):
Expand Down Expand Up @@ -167,3 +188,8 @@ def test_when_condition(self):
argument = ['-t', 'ACL_RULE', '-f', 'ICMP_TYPE']
output = self.run_script(argument)
self.assertEqual(output, acl_rule_table_field_output)

def test_nested_container(self):
argument = ['-t', 'SNMP']
output = self.run_script(argument)
self.assertEqual(output, snmp_table_output)