-
Notifications
You must be signed in to change notification settings - Fork 56
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
Use swsscommon API to read database configuration #176
Conversation
} | ||
return separator.(string) | ||
separator := swsscommon.SonicDBConfigGetSeparator(db_name, ns) | ||
return separator | ||
} | ||
|
||
func GetDbId(db_name string, ns string) int { | ||
if !sonic_db_init { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this block removed, there is no value to define this function. We can remove the caller code to swsscommon function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/sonic-net/sonic-swss-common/blob/master/common/dbconnector.cpp#L218-L227
swsscommon API like getDbInfo does not use initializeGlobalConfig, so we still need to initialize SonicDBConfig before using swsscommon API.
@@ -79,23 +80,3 @@ func TestGetDbMultiNs(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestOverrideDbConfigFile(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/sonic-net/sonic-swss-common/blob/master/tests/main.cpp#L24-L34
swss-common has the unit test for nonexisting db config file.
if err != nil { | ||
t.Fatalf("failed to get addr %v", err) | ||
} | ||
db, err := sdcfg.GetDbId("COUNTERS_DB", namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
":=" is used for declaration of "db".
If I use "=" instead, I need to declare "db" at first:
var db int
db, err = sdcfg.GetDbId("COUNTERS_DB", namespace)
sonic_data_client/virtual_db.go
Outdated
@@ -145,7 +149,7 @@ func getPfcwdMap() (map[string]map[string]string, error) { | |||
} | |||
|
|||
for _, key := range resp { | |||
name := key[7:] | |||
name := key[13:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like Zain recently fixed a bug, but you branch is up-to-date. Could you rebase or merge master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
e840963
to
3e176ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refer below comment.
if err != nil { | ||
return "", err | ||
} | ||
port, err := GetDbPort(db_name, ns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep using err instead of new err variable here GetDbHostName() and GetDbPort()? since CatchException(&err) seems to be overwritten ambiguously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CatchException should be removed.
Why I did it sonic_db_config/db_config.go reads from database configuration json to get database configuration, but swsscommon has provided the same feature. How I did it Use swsscommon API to read database configuration. Pending on below PR to clear database configuration for unit test. sonic-net/sonic-swss-common#843 How to verify it Run unit test.
Why I did it
sonic_db_config/db_config.go reads from database configuration json to get database configuration, but swsscommon has provided the same feature.
How I did it
Use swsscommon API to read database configuration.
Pending on below PR to clear database configuration for unit test.
sonic-net/sonic-swss-common#843
How to verify it
Run unit test.
Which release branch to backport (provide reason below if selected)
Description for the changelog
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)