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

Update scripts in sonic-buildimage from py-swsssdk to swsscommon #11215

Merged

Conversation

liuh-80
Copy link
Contributor

@liuh-80 liuh-80 commented Jun 22, 2022

Why I did it

Update scripts in sonic-buildimage from py-swsssdk to swsscommon

How I did it

Change code to use swsscommon.

How to verify it

Pass all E2E test case

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205

Description for the changelog

Update scripts in sonic-buildimage from py-swsssdk to swsscommon

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@lgtm-com

This comment was marked as duplicate.

@lgtm-com

This comment was marked as duplicate.

@lgtm-com

This comment was marked as duplicate.

@lgtm-com

This comment was marked as outdated.

@lgtm-com

This comment was marked as outdated.

@lgtm-com

This comment was marked as duplicate.

@lgtm-com

This comment was marked as duplicate.

@lgtm-com

This comment was marked as duplicate.

@lgtm-com

This comment was marked as duplicate.

@lgtm-com

This comment was marked as duplicate.

self.db.connect(self.db.STATE_DB, False)
client = self.db.get_redis_client(self.db.STATE_DB)
self.pipe = client.pipeline()
self.pipe = self.db.get_redis_client(self.db.STATE_DB)
Copy link
Contributor Author

@liuh-80 liuh-80 Jul 4, 2022

Choose a reason for hiding this comment

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

Remove pipe because in flush_pipe(self, data) has following code:
if value is None:
# delete case
self.pipe.delete(key)
else:
# Add or Modify case
self.db.hmset(self.pipe.STATE_DB. key, value)

This is because swsscommon not using pyredis, and self.db.get_redis_client(self.db.STATE_DB) will return StrictRedis. so the StrictRedis.pipeline() method does not exist in swss-common, in swss-common get_redis_client will return DBConnector.

Also another reason is the DBConnector only has following 1 method in swsscommon.py:
def hmset(self, multiHash):
return _swsscommon.DBConnector_hmset(self, multiHash)

Also DBConnector using redisContext from lib hredis to handle all redis operation, which doesn't not provide hmemset and delete operation.

@lgtm-com

This comment was marked as duplicate.

@liuh-80
Copy link
Contributor Author

liuh-80 commented Jul 4, 2022

This pull request introduces 1 alert and fixes 3 when merging d557724 into 1568667 - view on LGTM.com

new alerts:

  • 1 for Module is imported more than once

fixed alerts:

  • 3 for Unused import

Fixed.

@lgtm-com
Copy link

lgtm-com bot commented Jul 4, 2022

This pull request fixes 3 alerts when merging ddf1c0b9b5f32b906d7be3bfda081c5a30fb24e6 into 1568667 - view on LGTM.com

fixed alerts:

  • 3 for Unused import

@liuh-80 liuh-80 force-pushed the dev/liuh/replace-swsssdk-in-scripts branch from 4e8ea6a to cde3633 Compare July 4, 2022 06:26
@lgtm-com
Copy link

lgtm-com bot commented Jul 4, 2022

This pull request fixes 3 alerts when merging cde36331c6869fd5431fcf1895d6b6576bbc2004 into 8fb534e - view on LGTM.com

fixed alerts:

  • 3 for Unused import

@liuh-80 liuh-80 changed the title [WIP] update scripts in sonic-buildimage from py-swsssdk to swsscommon Update scripts in sonic-buildimage from py-swsssdk to swsscommon Jul 5, 2022
@liuh-80 liuh-80 marked this pull request as ready for review July 5, 2022 01:09
from getopt import getopt


# TODO: move to dbsync project.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lgtm-com

This comment was marked as duplicate.

@qiluo-msft
Copy link
Collaborator

led_control.py

We can move all the changes in platform/ and device/ paths into another PR. Those changes need to be tested with proper hardware, reviewed and approved by platform vendors.

Other platform-independent changes are relative easy to test.


Refers to: device/accton/x86_64-accton_minipack-r0/plugins/led_control.py:1 in 1bcf1fd. [](commit_id = 1bcf1fd7cd9aa83264e4c99182c0dc5287ce2f3d, deletion_comment = False)

@@ -106,11 +104,10 @@ def flush_pipe(self, data):
for key, value in data.items():
if value is None:
# delete case
self.pipe.delete(key)
self.db.delete(self.db.STATE_DB, key)
Copy link
Collaborator

Choose a reason for hiding this comment

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

db

Pipeline is more efficient on a batch of similar operations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not an exact replacement of redis-py pipe, but you may check if RedisPipeline satisfy the usage here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The RedisPipeline not have delete and hmset methods, to use RedisPipeline we need build a new RedisCommand command and run the command with RedisPipeline. that basically rewrite the delete and hmset method in DBConnector:

https://github.com/Azure/sonic-swss-common/blob/15c0f729648ee9f26ac9aea767d5712db34ca298/common/dbconnector.cpp#L862

Copy link
Collaborator

Choose a reason for hiding this comment

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

delete should be straightforward. We need more discussion on hmset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will check if we can improve current hmset without using lua script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found the hmset here actually using following API which is not lua script based:

template
void DBConnector::hmset(const std::string &key, InputIterator start, InputIterator stop)
{
RedisCommand shmset;
shmset.formatHMSET(key, start, stop);
RedisReply r(this, shmset, REDIS_REPLY_STATUS);
}

So maybe we can finish this PR first, and improve the lua based hmset with another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you postpone this change to another future PR? we can merge the other files in this PR first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, change in this file reverted.

@@ -0,0 +1,196 @@
"""
Bridge/Port mapping utility library.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If these files are simply moved from another repo, let's separate them into a standalone PR, not to mix with other changes not of the same nature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, create a new PR here: #11347
Also, will update this PR to only contains sonic script change, and split vender HW related change to different PRs.

@liuh-80
Copy link
Contributor Author

liuh-80 commented Jul 6, 2022

led_control.py

We can move all the changes in platform/ and device/ paths into another PR. Those changes need to be tested with proper hardware, reviewed and approved by platform vendors.

Other platform-independent changes are relative easy to test.

Refers to: device/accton/x86_64-accton_minipack-r0/plugins/led_control.py:1 in 1bcf1fd. [](commit_id = 1bcf1fd, deletion_comment = False)

All hardware related change move to following PRs for different vender:
[Accton] Remove unused swsssdk import from accton device code by liuh-80 · Pull Request #11348 · Azure/sonic-buildimage (github.com)
[AlphaNetworks] Replace swsssdk with swsscommon in alphanetworks devices by liuh-80 · Pull Request #11349 · Azure/sonic-buildimage (github.com)
[Centec] Replace swsssdk with swsscommon in centec devices. by liuh-80 · Pull Request #11350 · Azure/sonic-buildimage (github.com)

@liuh-80 liuh-80 force-pushed the dev/liuh/replace-swsssdk-in-scripts branch from 1bcf1fd to 659e24f Compare July 6, 2022 02:14
@@ -5,7 +5,7 @@
import traceback
from sonic_py_common.logger import Logger
from socket import if_nametoindex
from swsssdk import SonicV2Connector, port_util
from sonic_py_common import port_util
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The port_util change split to another PR, this PR need wait for another PR merge first:
#11347

@liuh-80 liuh-80 force-pushed the dev/liuh/replace-swsssdk-in-scripts branch from 659e24f to 4089311 Compare July 8, 2022 02:18
@liuh-80 liuh-80 merged commit a9b7a1f into sonic-net:master Jul 11, 2022
@liuh-80 liuh-80 deleted the dev/liuh/replace-swsssdk-in-scripts branch September 15, 2022 00:03
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.

2 participants