Skip to content

Commit

Permalink
fix getting hash from redis db (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytroxshevchuk authored Mar 19, 2021
1 parent be160cf commit c2ccaa3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
19 changes: 10 additions & 9 deletions common/configdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ map<string, map<string, string>> ConfigDBConnector_Native::get_table(string tabl
auto const& entry = client.hgetall<map<string, string>>(key);
size_t pos = key.find(TABLE_NAME_SEPARATOR);
string row;
if (pos != string::npos)
if (pos == string::npos)
{
row = key.substr(pos + 1);
continue;
}
row = key.substr(pos + 1);
data[row] = entry;
}
return data;
Expand Down Expand Up @@ -248,12 +249,11 @@ map<string, map<string, map<string, string>>> ConfigDBConnector_Native::get_conf
for (string key: keys)
{
size_t pos = key.find(TABLE_NAME_SEPARATOR);
string table_name = key.substr(0, pos);
string row;
if (pos != string::npos)
{
row = key.substr(pos + 1);
if (pos == string::npos) {
continue;
}
string table_name = key.substr(0, pos);
string row = key.substr(pos + 1);
auto const& entry = client.hgetall<map<string, string>>(key);

if (!entry.empty())
Expand Down Expand Up @@ -411,10 +411,11 @@ int ConfigDBPipeConnector_Native::_get_config(DBConnector& client, RedisTransact
size_t pos = key.find(TABLE_NAME_SEPARATOR);
string table_name = key.substr(0, pos);
string row;
if (pos != string::npos)
if (pos == string::npos)
{
row = key.substr(pos + 1);
continue;
}
row = key.substr(pos + 1);

auto reply = pipe.dequeueReply();
RedisReply r(reply);
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 @@ -263,6 +263,25 @@ def test_ConfigDBConnector():
allconfig = config_db.get_config()
assert len(allconfig) == 0

def test_ConfigDBConnectorSeparator():
db = swsscommon.DBConnector("APPL_DB", 0, True)
config_db = ConfigDBConnector()
config_db.db_connect("APPL_DB", False, False)
config_db.get_redis_client(config_db.APPL_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_ConfigDBPipeConnector():
config_db = ConfigDBPipeConnector()
config_db.connect(wait_for_init=False)
Expand Down

0 comments on commit c2ccaa3

Please sign in to comment.