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

Fix config save error for non-hash key. #485

Merged
merged 2 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions common/configdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ int ConfigDBPipeConnector_Native::_get_config(DBConnector& client, RedisTransact
pipe.multi();
for (auto const& key: keys)
{
if (key == INIT_INDICATOR)
size_t pos = key.find(m_table_name_separator);
Copy link
Contributor

Choose a reason for hiding this comment

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

pos

The fix looks good. Could you add unit testcase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (pos == string::npos)
{
continue;
}
Expand All @@ -413,11 +414,6 @@ int ConfigDBPipeConnector_Native::_get_config(DBConnector& client, RedisTransact

for (auto const& key: keys)
{
if (key == INIT_INDICATOR)
{
continue;
}

size_t pos = key.find(m_table_name_separator);
string table_name = key.substr(0, pos);
string row;
Expand Down
19 changes: 19 additions & 0 deletions tests/test_redis_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,25 @@ def test_ConfigDBPipeConnector():
allconfig = config_db.get_config()
assert len(allconfig) == 0

def test_ConfigDBPipeConnectorSeparator():
db = swsscommon.DBConnector("CONFIG_DB", 0, True)
config_db = ConfigDBPipeConnector()
config_db.db_connect("CONFIG_DB", False, False)
config_db.get_redis_client(config_db.CONFIG_DB).flushdb()
config_db.set_entry("TEST_PORT", "Ethernet222", {"alias": "etp2x"})
db.set("ItemWithoutSeparator", "item11")
allconfig = config_db.get_config()
assert "TEST_PORT" in allconfig
assert "ItemWithoutSeparator" not in allconfig

alltable = config_db.get_table("*")
assert "Ethernet222" in alltable

config_db.delete_table("TEST_PORT")
db.delete("ItemWithoutSeparator")
allconfig = config_db.get_config()
assert len(allconfig) == 0

def test_ConfigDBScan():
config_db = ConfigDBPipeConnector()
config_db.connect(wait_for_init=False)
Expand Down