Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[debug dump util] Module implementation Logic and Port Module #1667

Merged
merged 27 commits into from
Aug 30, 2021

Conversation

vivekrnv
Copy link
Contributor

@vivekrnv vivekrnv commented Jun 11, 2021

Signed-off-by: Vivek Reddy Karri vkarri@nvidia.com

DEBUG DUMP UTIL PR SEQ: 2

NOTE: PLEASE MERGE #1666 BEFORE MERGING THIS

What I did

HLD for Dump Utility: HLD.
For More Info on adding new modules, Check this section in the HLD:
MatchInfra

How I did it

How to verify it

tests/dump_tests/module_tests/port_test.py::TestPortModule::test_all_args PASSED [ 86%]
tests/dump_tests/module_tests/port_test.py::TestPortModule::test_missing_asic_hostif PASSED [ 86%]
tests/dump_tests/module_tests/port_test.py::TestPortModule::test_missing_asic_port PASSED [ 86%]
tests/dump_tests/module_tests/port_test.py::TestPortModule::test_missing_state_and_appl PASSED [ 86%]
tests/dump_tests/module_tests/port_test.py::TestPortModule::test_no_port PASSED [ 86%]
tests/dump_tests/module_tests/port_test.py::TestPortModule::test_working_state PASSED [ 86%]

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)

admin@sonic:~$ dump state port Ethernet0
{
    "Ethernet0": {
        "CONFIG_DB": {
            "keys": [
                {
                    "PORT|Ethernet0": {
                        "admin_status": "up",
                        "alias": "etp1",
                        "index": "1",
                        "lanes": "0",
                        "speed": "25000"
                    }
                }
            ],
            "tables_not_found": []
        },
        "APPL_DB": {
            "keys": [
                {
                    "PORT_TABLE:Ethernet0": {
                        "admin_status": "up",
                        "alias": "etp1",
                        "description": "",
                        "index": "1",
                        "lanes": "0",
                        "mtu": "9100",
                        "oper_status": "up",
                        "speed": "25000"
                    }
                }
            ],
            "tables_not_found": []
        },
        "ASIC_DB": {
            "keys": [
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd000000000a21": {
                        "SAI_HOSTIF_ATTR_NAME": "Ethernet0",
                        "SAI_HOSTIF_ATTR_OBJ_ID": "oid:0x10000000008d4",
                        "SAI_HOSTIF_ATTR_OPER_STATUS": "true",
                        "SAI_HOSTIF_ATTR_TYPE": "SAI_HOSTIF_TYPE_NETDEV"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x10000000008d4": {
                        "NULL": "NULL",
                        "SAI_PORT_ATTR_ADMIN_STATE": "true",
                        "SAI_PORT_ATTR_MTU": "9122",
                        "SAI_PORT_ATTR_SPEED": "25000"
                    }
                }
            ],
            "tables_not_found": [],
            "vidtorid": {
                "oid:0xd000000000a21": "oid:0xd",
                "oid:0x10000000008d4": "oid:0x1690000000001"
            }
        },
        "STATE_DB": {
            "keys": [
                {
                    "PORT_TABLE|Ethernet0": {
                        "netdev_oper_status": "up",
                        "state": "ok"
                    }
                }
            ],
            "tables_not_found": []
        }
    }
}

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
@lgtm-com
Copy link

lgtm-com bot commented Jun 11, 2021

This pull request introduces 1 alert when merging 6d76514 into a425ca2 - view on LGTM.com

new alerts:

  • 1 for Unused import

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
@vivekrnv
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 1667 in repo Azure/sonic-utilities

@liat-grozovik
Copy link
Collaborator

/app run

@vivekrnv
Copy link
Contributor Author

Request for 202106

dump/plugins/port.py Outdated Show resolved Hide resolved
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Copy link
Contributor

@arlakshm arlakshm left a comment

Choose a reason for hiding this comment

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

As comments

dump/plugins/__init__.py Outdated Show resolved Hide resolved
dump/plugins/executor.py Outdated Show resolved Hide resolved
dump/plugins/port.py Outdated Show resolved Hide resolved
tests/dump_input/port/appl_db.json Outdated Show resolved Hide resolved
tests/dump_input/port/asic_db.json Show resolved Hide resolved
tests/dump_input/port/state_db.json Outdated Show resolved Hide resolved
from utilities_common.constants import DEFAULT_NAMESPACE

class MockSonicV2Connector():
def __init__(self, dedicated_dbs, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need to introduce a new class for mocking Sonicv2connector. Can we add new functionality to dbconnector.py

Copy link
Contributor Author

@vivekrnv vivekrnv Aug 13, 2021

Choose a reason for hiding this comment

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

Testing Use case for these modules is to read from a separate json files as opposed to other tests which read from the default json files inside mock_tables directory.

I did see there is a dedicated_db list used inside one of the dbconnector methods

global dedicated_dbs
if dedicated_dbs and dedicated_dbs.get(db_name):
        self.dbintf.redis_kwargs['db_name'] = dedicated_dbs[db_name]
else:
        self.dbintf.redis_kwargs['db_name'] = db_name

The only test which uses this is db_migrator_test.py. However in that test, it was initializing the SonicV2Connector class directly inside the test, whereas in dump_module_tests it is being initialized in the methods defined in the actual classes.

And probably because of the complex redirection used in the dbconnector.py to mock the SonicV2Connector, i was not able to get the dump_module_tests tests running on custom json files. I've also worked with stephan who introduced that change but couldn't get it running.

Hence, decided to add a new mock class.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found a couple of examples of using the dedicated_dbs recently added recently

https://github.com/Azure/sonic-utilities/blob/master/tests/config_int_ip_test.py
https://github.com/Azure/sonic-utilities/blob/5002745beb89a99a1cdf420f34a495c2c0cb31bd/tests/mpls_test.py#L60-L67

Can you check if we can follow a similar approach here?
I feel we should try and avoid duplicate mock classes if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info. I was able to remove the extra mock and use the default mock. I couldn't get it to directly read the custom json files, but i've handled it nevertheless.

Regarding the connection pooling optimization, i've recently observed when operating at scale, (i.e. route, had around 10k routes to parse for the dump utility) i've observed a significant amount of time spent in connect calls. With this optimization, the number of connect calls can be effectively reduced from (number_of_routes*number_of_calls_per_route) to 4 (number of db's the module is looking into) and thus offering a significant improvement in performance.
This design change infact helped me to use the default mock as well.

@SuvarnaMeenakshi and @arlakshm , please provide your comments on the changes.

tests/dump_tests/module_tests/mock_sonicv2connector.py Outdated Show resolved Hide resolved
tests/dump_tests/module_tests/mock_sonicv2connector.py Outdated Show resolved Hide resolved
tests/dump_tests/module_tests/port_test.py Outdated Show resolved Hide resolved
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi left a comment

Choose a reason for hiding this comment

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

As comments.

dump/plugins/port.py Show resolved Hide resolved
tests/dump_input/port/appl_db.json Outdated Show resolved Hide resolved
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
@lgtm-com
Copy link

lgtm-com bot commented Aug 19, 2021

This pull request introduces 3 alerts when merging 0082da2 into 29f4a16 - view on LGTM.com

new alerts:

  • 2 for First parameter of a method is not named 'self'
  • 1 for Unused import

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi left a comment

Choose a reason for hiding this comment

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

lgtm

@dgsudharsan
Copy link
Collaborator

@arlakshm Can you please sign off if the changes are good?

@dgsudharsan
Copy link
Collaborator

@SuvarnaMeenakshi Can we merge this?

@SuvarnaMeenakshi SuvarnaMeenakshi merged commit 720b650 into sonic-net:master Aug 30, 2021
SuvarnaMeenakshi pushed a commit that referenced this pull request Nov 10, 2021
What I did
Implemented vlan and vlan_member modules for debug dump utility.

How I did it
Used infrastructure and followed examples in
#1666
#1667
#1668
#1669
#1670

How to verify it
On switch: dump state vlan <vlan_name>
dump state vlan_member '<vlan_name|<member_name>'
Unit test: pytest-3 dump_tests/module_tests/vlan_test.py (same test file covers both vlan and vlan_member)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants