Skip to content

Commit

Permalink
To fix the issue: show_techsupport & saidump errors during testbed te…
Browse files Browse the repository at this point in the history
  • Loading branch information
JunhongMao committed Jun 11, 2024
1 parent 4f0fcaf commit 4b32eaf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
67 changes: 39 additions & 28 deletions saidump/saidump.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -502,37 +502,20 @@ static sai_status_t preProcessFile(const std::string file_name)
return SAI_STATUS_SUCCESS;
}

static sai_status_t dumpFromRedisRdbJson(const std::string file_name)
static void traverseJson(const json & jsn)
{
SWSS_LOG_ENTER();

std::ifstream input_file(file_name);

if (!input_file.is_open())
{
SWSS_LOG_ERROR_AND_STDERR("The file %s does not exist for dumping from Redis RDB JSON file.", file_name.c_str());
return SAI_STATUS_FAILURE;
}

try
if (jsn.is_object())
{
// Parse the JSON data from the file (validation)
nlohmann::json jsonData;
input_file >> jsonData;

SWSS_LOG_DEBUG("JSON file is valid.");

for (json::iterator it = jsonData.begin(); it != jsonData.end(); ++it)
for (auto it = jsn.begin(); it != jsn.end(); ++it)
{
json jj_key = it.key();

std::string keystr = jj_key;
std::string keystr = it.key();
std::string item_name = keystr;
size_t pos = keystr.find_first_of(":");

if (pos != std::string::npos)
{
if(ASIC_STATE_TABLE != keystr.substr(0, pos)) // filter out non ASIC_STATE
if(ASIC_STATE_TABLE != keystr.substr(0, pos)) // filter out non "ASIC_STATE" items
{
continue;
}
Expand All @@ -550,8 +533,7 @@ static sai_status_t dumpFromRedisRdbJson(const std::string file_name)
}

std::cout << item_name << " " << std::endl;

json jj = it.value();
json jsn_sub = it.value();

if (!it->is_object())
{
Expand All @@ -560,11 +542,11 @@ static sai_status_t dumpFromRedisRdbJson(const std::string file_name)

TableMap map;

for (json::iterator itt = jj.begin(); itt != jj.end(); ++itt)
for (auto it_sub = jsn_sub.begin(); it_sub != jsn_sub.end(); ++it_sub)
{
if (itt.key() != "NULL")
if (it_sub.key() != "NULL")
{
map[itt.key()] = itt.value();
map[it_sub.key()] = it_sub.value();
}
}

Expand All @@ -577,10 +559,39 @@ static sai_status_t dumpFromRedisRdbJson(const std::string file_name)
std::cout << str_indent << pad_string(field.first, max_len) << " : ";
std::cout << field.second << std::endl;
}

std::cout << std::endl;
}
}
else if(jsn.is_array())
{
for (const auto& element : jsn)
{
if (element.is_object() || element.is_array())
{
traverseJson(element);
}
}
}
}

static sai_status_t dumpFromRedisRdbJson(const std::string file_name)
{
SWSS_LOG_ENTER();

std::ifstream input_file(file_name);

if (!input_file.is_open())
{
SWSS_LOG_ERROR_AND_STDERR("The file %s does not exist for dumping from Redis RDB JSON file.", file_name.c_str());
return SAI_STATUS_FAILURE;
}

try
{
// Parse the JSON data from the file (validation)
json jsonData;
input_file >> jsonData;
traverseJson(jsonData);
return SAI_STATUS_SUCCESS;
}
catch (std::exception &ex)
Expand Down
18 changes: 8 additions & 10 deletions syncd/scripts/saidump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ save_saidump_by_rdb()
import json
with open('$filepath') as json_file:
data = json.load(json_file)
print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])")
print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])
json_file.close()")

# split
redis_config=(${redis_config// / })
Expand All @@ -19,19 +20,16 @@ with open('$filepath') as json_file:
local redis_dir=`dirname ${redis_config[2]}`
logger "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir"

logger "saidump.sh: [1] Config Redis consistency directory."
redis-cli -h $hostname -p $port CONFIG SET dir $redis_dir > /dev/null
logger "saidump.sh: [1] Get the remote backups of RDB file."
redis-cli -h $hostname -p $port --rdb $redis_dir/dump.rdb > /dev/null 2>&1

logger "saidump.sh: [2] SAVE."
redis-cli -h $hostname -p $port SAVE > /dev/null
logger "saidump.sh: [2] Run rdb-cli command to convert the dump files into JSON files."
rdb-cli $redis_dir/dump.rdb json | tee $redis_dir/dump.json > /dev/null

logger "saidump.sh: [3] Run rdb command to convert the dump files into JSON files."
rdb --command json $redis_dir/dump.rdb | tee $redis_dir/dump.json > /dev/null

logger "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output."
logger "saidump.sh: [3] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output."
saidump -r $redis_dir/dump.json -m 100

logger "saidump.sh: [5] Clear the temporary files."
logger "saidump.sh: [4] Clear the temporary files."
rm -f $redis_dir/dump.rdb
rm -f $redis_dir/dump.json
}
Expand Down

0 comments on commit 4b32eaf

Please sign in to comment.