Skip to content

Commit

Permalink
[yang]Fixing sonic-cfg-help to handle nested container (sonic-net#17260)
Browse files Browse the repository at this point in the history
Why I did it
Fixing sonic-cfg-help to handle nested container scenario. In case of nested container, the inner container name acts as key for the table. For e.g.

"AUTO_TECHSUPPORT": {
        "GLOBAL": {
         }
}
Previous output

AUTO_TECHSUPPORT
Description: AUTO_TECHSUPPORT part of config_db.json

+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| Field                   | Description                                        | Mandatory   | Default   | Reference   |
+=========================+====================================================+=============+===========+=============+
| state                   | Knob to make techsupport invocation event-driven   |             |           |             |
|                         | based on core-dump generation                      |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| rate_limit_interval     | Minimum time in seconds between two successive     |             |           |             |
|                         | techsupport invocations. Configure 0 to explicitly |             |           |             |
|                         | disable                                            |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| max_techsupport_limit   | Max Limit in percentage for the cummulative size   |             |           |             |
|                         | of ts dumps. No cleanup is performed if the value  |             |           |             |
|                         | isn't configured or is 0.0                         |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| max_core_limit          | Max Limit in percentage for the cummulative size   |             |           |             |
|                         | of core dumps. No cleanup is performed if the      |             |           |             |
|                         | value isn't congiured or is 0.0                    |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| available_mem_threshold | Memory threshold; 0 to disable techsupport         |             | 10.0      |             |
|                         | invocation on memory usage threshold crossing      |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| min_available_mem       | Minimum Free memory (in MB) that should be         |             | 200       |             |
|                         | available for the techsupport execution to start   |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| since                   | Only collect the logs & core-dumps generated since |             |           |             |
|                         | the time provided. A default value of '2 days ago' |             |           |             |
|                         | is used if this value is not set explicitly or a   |             |           |             |
|                         | non-valid string is provided                       |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+


New output

AUTO_TECHSUPPORT
Description: AUTO_TECHSUPPORT part of config_db.json

key - GLOBAL
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| Field                   | Description                                        | Mandatory   | Default   | Reference   |
+=========================+====================================================+=============+===========+=============+
| state                   | Knob to make techsupport invocation event-driven   |             |           |             |
|                         | based on core-dump generation                      |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| rate_limit_interval     | Minimum time in seconds between two successive     |             |           |             |
|                         | techsupport invocations. Configure 0 to explicitly |             |           |             |
|                         | disable                                            |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| max_techsupport_limit   | Max Limit in percentage for the cummulative size   |             |           |             |
|                         | of ts dumps. No cleanup is performed if the value  |             |           |             |
|                         | isn't configured or is 0.0                         |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| max_core_limit          | Max Limit in percentage for the cummulative size   |             |           |             |
|                         | of core dumps. No cleanup is performed if the      |             |           |             |
|                         | value isn't congiured or is 0.0                    |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| available_mem_threshold | Memory threshold; 0 to disable techsupport         |             | 10.0      |             |
|                         | invocation on memory usage threshold crossing      |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| min_available_mem       | Minimum Free memory (in MB) that should be         |             | 200       |             |
|                         | available for the techsupport execution to start   |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| since                   | Only collect the logs & core-dumps generated since |             |           |             |
|                         | the time provided. A default value of '2 days ago' |             |           |             |
|                         | is used if this value is not set explicitly or a   |             |           |             |
|                         | non-valid string is provided                       |             |           |             |
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+


Work item tracking
Microsoft ADO (number only):
How I did it
Fixing sonic-cfg-help tool to handle nested container

How to verify it
Added UT to verify it.
  • Loading branch information
dgsudharsan authored Nov 23, 2023
1 parent c568ecd commit b86a1b3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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'))
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 @@ -19,6 +19,7 @@
AUTO_TECHSUPPORT
Description: AUTO_TECHSUPPORT part of config_db.json
key - GLOBAL
+-------------------------+----------------------------------------------------+-------------+-----------+-------------+
| Field | Description | Mandatory | Default | Reference |
+=========================+====================================================+=============+===========+=============+
Expand Down Expand Up @@ -56,6 +57,7 @@
AUTO_TECHSUPPORT
Description: AUTO_TECHSUPPORT part of config_db.json
key - GLOBAL
+---------+--------------------------------------------------+-------------+-----------+-------------+
| Field | Description | Mandatory | Default | Reference |
+=========+==================================================+=============+===========+=============+
Expand Down Expand Up @@ -112,6 +114,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 @@ -161,3 +182,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)

0 comments on commit b86a1b3

Please sign in to comment.