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

Dbconnector namespace support #376

Merged
merged 8 commits into from
Aug 19, 2020
Merged

Conversation

judyjoseph
Copy link
Collaborator

@judyjoseph judyjoseph commented Aug 14, 2020

Why:
The commit for support for namespaces in DBConnector (#371) class was reverted earlier as it failed couple of tests in swss. It was found that the SWSS docker virtual switch API's create the DBConnector object using the constructor API's which was present before the multi-DB changes went in. During those times, the DBConnector classes used dbId alone and dbName was not filled. (https://github.com/Azure/sonic-swss/blob/eac1d898e12d03040cd7b4e3c4059960dbf0ae8d/tests/dvslib/dvs_database.py#L30)

The reason for the tests failure was because the dbName was coming as NULL when we try to create newConnector().

Couple of sonic-build issues also was triaged and fixed while trying to push this commit ( These were causing the swss tests to fail when we tried to this namespace support PR earlier )
Azure/sonic-build-tools#152
Azure/sonic-build-tools#147

What:
Added the check to see if the dbName, namespace is empty, if so create the DBConnector using the old constructors which takes dbId as input. If not call the new constructor where we pass the dbName and namespaceName.

With the above changes -- no further change needed in sonic-swss/tests/mock_tests/mock_dbconnector.cpp

How:
Recreated the swss tests setup locally and saw the tests cases were passing.

johnar@c1ac715ae2d8:/sonic/swss/tests$ sudo make -j1 check
Making check in mock_tests
make[1]: Entering directory '/sonic/swss/tests/mock_tests'
make  check-TESTS
make[2]: Entering directory '/sonic/swss/tests/mock_tests'
make[3]: Entering directory '/sonic/swss/tests/mock_tests'
PASS: tests
============================================================================
Testsuite summary for sonic-swss 1.0
============================================================================
# TOTAL: 1
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
make[3]: Leaving directory '/sonic/swss/tests/mock_tests'
make[2]: Leaving directory '/sonic/swss/tests/mock_tests'
make[1]: Leaving directory '/sonic/swss/tests/mock_tests'
make[1]: Entering directory '/sonic/swss/tests'
make  check-TESTS
make[2]: Entering directory '/sonic/swss/tests'
make[3]: Entering directory '/sonic/swss/tests'
PASS: tests
============================================================================
Testsuite summary for sonic-swss 1.0
============================================================================
# TOTAL: 1
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
make[3]: Leaving directory '/sonic/swss/tests'
make[2]: Leaving directory '/sonic/swss/tests'
make[1]: Leaving directory '/sonic/swss/tests'


jujoseph@jujoseph-Virtual-Machine:~/TRIAL/swss_PR/swss/tests$ sudo python -m pytest 
================================================================ test session starts ================================================================
platform linux -- Python 3.6.9, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/jujoseph/TRIAL/swss_PR/swss/tests
plugins: flaky-3.7.0
collected 270 items                                                                                                                                 

test_acl.py ......................                                                                                                            [  8%]
test_acl_ctrl.py .                                                                                                                            [  8%]
test_acl_egress_table.py ...........                                                                                                          [ 12%]
test_acl_mclag.py ..                                                                                                                          [ 13%]
test_acl_portchannel.py ...                                                                                                                   [ 14%]
test_admin_status.py .                                                                                                                        [ 14%]
test_crm.py .........................                                                                                                         [ 24%]
test_dirbcast.py .                                                                                                                            [ 24%]
test_drop_counters.py ...............                                                                                                         [ 30%]
test_dtel.py .....                                                                                                                            [ 31%]
test_fdb.py ..                                                                                                                                [ 32%]
test_fdb_update.py ...                                                                                                                        [ 33%]
test_interface.py ........s.........                                                                                                          [ 40%]
test_intf_mac.py ....                                                                                                                         [ 41%]
test_mirror.py .......                                                                                                                        [ 44%]
test_mirror_ipv6_combined.py .....                                                                                                            [ 46%]
test_mirror_ipv6_separate.py .......                                                                                                          [ 48%]
test_mirror_policer.py ..                                                                                                                     [ 49%]
test_mirror_port_erspan.py ......                                                                                                             [ 51%]
test_mirror_port_span.py ........                                                                                                             [ 54%]
test_nat.py ..........x                                                                                                                       [ 58%]
test_neighbor.py ....                                                                                                                         [ 60%]
**test_nhg.py .F**                                                                                                                                [ 61%]
test_pfc.py .                                                                                                                                 [ 61%]
test_policer.py .                                                                                                                             [ 61%]
test_port.py ......                                                                                                                           [ 64%]
test_port_an.py ..                                                                                                                            [ 64%]
test_port_buffer_rel.py .                                                                                                                     [ 65%]
test_port_config.py ..                                                                                                                        [ 65%]
test_port_dpb.py .Xs                                                                                                                          [ 67%]
test_port_dpb_acl.py .....                                                                                                                    [ 68%]
test_port_dpb_vlan.py ....                                                                                                                    [ 70%]
test_port_mac_learn.py ..                                                                                                                     [ 71%]
test_portchannel.py ..                                                                                                                        [ 71%]
test_qos_map.py ..                                                                                                                            [ 72%]
test_route.py .....                                                                                                                           [ 74%]
test_setro.py .                                                                                                                               [ 74%]
test_sflow.py ......                                                                                                                          [ 77%]
test_speed.py .                                                                                                                               [ 77%]
test_sub_port_intf.py .....                                                                                                                   [ 79%]
test_switch.py .                                                                                                                              [ 79%]
test_tunnel.py ....                                                                                                                           [ 81%]
test_vlan.py ...................s.....                                                                                                        [ 90%]
test_vnet.py ...s.                                                                                                                            [ 92%]
test_vnet_bitmap.py ...s.                                                                                                                     [ 94%]
test_vrf.py ...X                                                                                                                              [ 95%]
test_vxlan_tunnel.py .                                                                                                                        [ 95%]
test_warm_reboot.py ......X.                                                                                                                  [ 98%]
test_watermark.py .ss                                                                                                                         [100%]
==================================== 1 failed, 258 passed, 7 skipped, 1 xfailed, 3 xpassed in 8701.99s (2:25:01) ====================================

jujoseph@jujoseph-Virtual-Machine:~/TRIAL/swss_PR/swss/tests$ 
jujoseph@jujoseph-Virtual-Machine:~/TRIAL/swss_PR/swss/tests$ sudo python -m pytest **test_nhg.py**
[sudo] password for jujoseph: 
================================================================ test session starts ================================================================
platform linux -- Python 3.6.9, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/jujoseph/TRIAL/swss_PR/swss/tests
plugins: flaky-3.7.0
collected 2 items                                                                                                                                   

test_nhg.py ..                                                                                                                                [100%]

=========================================================== 2 passed in 90.28s (0:01:30) ============================================================


**ROUND 2**

jujoseph@jujoseph-Virtual-Machine:~/TRIAL/swss_PR/swss/tests$ sudo python -m pytest
[sudo] password for jujoseph: 
================================================================ test session starts ================================================================
platform linux -- Python 3.6.9, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/jujoseph/TRIAL/swss_PR/swss/tests
plugins: flaky-3.7.0
collected 270 items                                                                                                                                 

test_acl.py ......................                                                                                                            [  8%]
test_acl_ctrl.py .                                                                                                                            [  8%]
test_acl_egress_table.py ...........                                                                                                          [ 12%]
test_acl_mclag.py ..                                                                                                                          [ 13%]
test_acl_portchannel.py ...                                                                                                                   [ 14%]
test_admin_status.py .                                                                                                                        [ 14%]
test_crm.py .........................                                                                                                         [ 24%]
test_dirbcast.py .                                                                                                                            [ 24%]
test_drop_counters.py ...............                                                                                                         [ 30%]
test_dtel.py .....                                                                                                                            [ 31%]
test_fdb.py ..                                                                                                                                [ 32%]
test_fdb_update.py ...                                                                                                                        [ 33%]
test_interface.py ........s.........                                                                                                          [ 40%]
test_intf_mac.py ....                                                                                                                         [ 41%]
test_mirror.py .......                                                                                                                        [ 44%]
test_mirror_ipv6_combined.py .....                                                                                                            [ 46%]
test_mirror_ipv6_separate.py .......                                                                                                          [ 48%]
test_mirror_policer.py ..                                                                                                                     [ 49%]
test_mirror_port_erspan.py ......                                                                                                             [ 51%]
test_mirror_port_span.py ........                                                                                                             [ 54%]
test_nat.py ..........x                                                                                                                       [ 58%]
test_neighbor.py ....                                                                                                                         [ 60%]
test_nhg.py ..                                                                                                                                [ 61%]
test_pfc.py .                                                                                                                                 [ 61%]
test_policer.py .                                                                                                                             [ 61%]
test_port.py ......                                                                                                                           [ 64%]
test_port_an.py ..                                                                                                                            [ 64%]
test_port_buffer_rel.py .                                                                                                                     [ 65%]
test_port_config.py ..                                                                                                                        [ 65%]
test_port_dpb.py .Xs                                                                                                                          [ 67%]
test_port_dpb_acl.py .....                                                                                                                    [ 68%]
test_port_dpb_vlan.py ....                                                                                                                    [ 70%]
test_port_mac_learn.py ..                                                                                                                     [ 71%]
test_portchannel.py ..                                                                                                                        [ 71%]
test_qos_map.py ..                                                                                                                            [ 72%]
test_route.py .....                                                                                                                           [ 74%]
test_setro.py .                                                                                                                               [ 74%]
test_sflow.py ......                                                                                                                          [ 77%]
test_speed.py .                                                                                                                               [ 77%]
test_sub_port_intf.py .....                                                                                                                   [ 79%]
test_switch.py .                                                                                                                              [ 79%]
test_tunnel.py ....                                                                                                                           [ 81%]
test_vlan.py ...................s.....                                                                                                        [ 90%]
test_vnet.py ...s.                                                                                                                            [ 92%]
test_vnet_bitmap.py ...s.                                                                                                                     [ 94%]
test_vrf.py ...X                                                                                                                              [ 95%]
test_vxlan_tunnel.py .                                                                                                                        [ 95%]
test_warm_reboot.py ......X.                                                                                                                  [ 98%]
test_watermark.py .ss                                                                                                                         [100%]

========================================= 259 passed, 7 skipped, 1 xfailed, 3 xpassed in 8686.49s (2:24:46) =========================================

…-swss#1363

Also changes to allign the dbConnector class here with that of sonic-py-swssdk
   1. Ignore if the database_global.json file is not present.
   2. validate the namespace before using it.
…ey were creating

DBConnector object using the earlier constructors before Multi-DB, Multi-NS design.
eg:
 conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

Here the first argument is dbid, second is redis unix socket, third is timeout.
common/dbconnector.h Outdated Show resolved Hide resolved
cout<<"testing "<<dbName<<endl;
cout<<ns_name<<"#"<<dbId<<dbName<<"#"<<m_inst_info[instName].unixSocketPath<<"#"<<m_inst_info[instName].hostname<<"#"<<m_inst_info[instName].port<<endl;
// dbInst info matches between get api and context in json file
EXPECT_EQ(instName, SonicDBConfig::getDbInst(dbName, ns_name));
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 17, 2020

Choose a reason for hiding this comment

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

dbName [](start = 64, length = 6)

Please also add some negative test cases, such as dbName=='' or dbName=='NOT_EXISTS' #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

How about dbName=='NOT_EXISTS'


In reply to: 471706596 [](ancestors = 471706596)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -60,12 +79,14 @@ class DBConnector
DBConnector(int dbId, const std::string &hostname, int port, unsigned int timeout);
DBConnector(int dbId, const std::string &unixPath, unsigned int timeout);
DBConnector(const std::string &dbName, unsigned int timeout, bool isTcpConn = false);
DBConnector(const std::string &dbName, unsigned int timeout, bool isTcpConn, const std::string &nameSpace);
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 17, 2020

Choose a reason for hiding this comment

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

DBConnector [](start = 4, length = 11)

Add test cases for new code #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Had already added redis_multi_ns_ut.cpp which covers the cases with namespace, will add couple of negative cases for db_name not exists.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is still applicable. There is no test case for explicit netns.


In reply to: 471706833 [](ancestors = 471706833)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, have added explicit testcase TEST(DBConnector, multi_ns_table_test) which does table/entry creation in a DB in a particular namespace.

Copy link
Contributor

@qiluo-msft qiluo-msft 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

@qiluo-msft qiluo-msft dismissed their stale review August 19, 2020 02:31

Unblock, need to improve test.

@judyjoseph judyjoseph merged commit 49a7c9d into sonic-net:master Aug 19, 2020
@abdosi abdosi deleted the db_connect_NS branch August 19, 2020 21:38
abdosi pushed a commit that referenced this pull request Aug 19, 2020
* Adding back PR#364

* Kept the old definition of  >>DBConnector(const std::string &dbName, unsigned int timeout, bool isTcpConn = false) << intact , so that we don't the issue (sonic-net/sonic-swss#1363)

* Also changes to allign the dbConnector class here with that of sonic-py-swssdk
   1. Ignore if the database_global.json file is not present.
   2. validate the namespace before using it.

* Fixes to take care of case where certain SWSS tests where failing as they were creating DBConnector object using the earlier constructors before Multi-DB design where the first argument is dbid
eg: conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

* Change the variable naming --> netns, use the old logic in newConnector()

* Couple of more testcase scenarios added.
@@ -20,6 +20,8 @@ class RedisSelect : public Selectable
bool hasCachedData() override;
bool initializedWithData() override;
void updateAfterRead() override;
int getDbConnectorId() override;
std::string getDbNamespace() override;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why they are added? How are they used?

Copy link
Contributor

Choose a reason for hiding this comment

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

@qiluo-msft
getDbNamespace() was added to find Namespace when select returns the object.
eg: https://github.com/Azure/sonic-buildimage/blob/master/files/image_config/caclmgrd/caclmgrd#L484

getDbConnectorId() is not being used as of now but it is useful if we want to check on DBId of select return object.

Copy link
Collaborator Author

@judyjoseph judyjoseph Aug 29, 2020

Choose a reason for hiding this comment

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

virtual std::string getDbNamespace()
{
return std::string();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In concept, Selectable has nothing todo with Redis. We need to remove these virtual functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

@qiluo-msft will check and update.

abdosi added a commit to abdosi/sonic-swss-common that referenced this pull request Sep 1, 2020
sonic-net#376
to remove DB specific API from selectable class
which is generic.

However to access to the Derviced Class Redis Select
API via python we need to downcast the the Selectable Object.

Added Helpfer function to do same.

Ref: http://www.swig.org/Doc3.0/Python.html

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
abdosi added a commit that referenced this pull request Sep 2, 2020
* Address Review comments
#376
to remove DB specific API from selectable class
which is generic.

However to access to the Derviced Class Redis Select
API via python we need to downcast the the Selectable Object.

Added Helpfer function to do same.

Ref: http://www.swig.org/Doc3.0/Python.html

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>

* Align the code properly

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>

* Address Review Comments. Return the DBConnector Pointer.
Since the DBConnector is unique_ptr return the
reference to the contained object, or a non owning pointer

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
abdosi added a commit that referenced this pull request Sep 3, 2020
* Address Review comments
#376
to remove DB specific API from selectable class
which is generic.

However to access to the Derviced Class Redis Select
API via python we need to downcast the the Selectable Object.

Added Helpfer function to do same.

Ref: http://www.swig.org/Doc3.0/Python.html

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>

* Align the code properly

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>

* Address Review Comments. Return the DBConnector Pointer.
Since the DBConnector is unique_ptr return the
reference to the contained object, or a non owning pointer

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants