Skip to content

Commit d9314dd

Browse files
jipanyangyxieca
authored andcommitted
Add retryCount option for orchagent_restart_check program. (sonic-net#833)
Signed-off-by: Jipan Yang <[email protected]>
1 parent 5206374 commit d9314dd

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

orchagent/orchagent_restart_check.cpp

+41-25
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ void printUsage()
2121
std::cout << " Skip pending task dependency check for orchagent" << std::endl;
2222
std::cout << " -w --waitTime" << std::endl;
2323
std::cout << " Wait time for response from orchagent, in milliseconds. Default value: 1000" << std::endl;
24+
std::cout << " -r --retryCount" << std::endl;
25+
std::cout << " Number of retries for the request to orchagent. Default value: 0" << std::endl;
2426
std::cout << " -h --help:" << std::endl;
2527
std::cout << " Print out this message" << std::endl;
2628
}
@@ -48,14 +50,16 @@ int main(int argc, char **argv)
4850
std::string noFreeze = "false";
4951
/* Default wait time is 1000 millisecond */
5052
int waitTime = 1000;
53+
int retryCount = 0;
5154

52-
const char* const optstring = "nsw:";
55+
const char* const optstring = "nsw:r:";
5356
while(true)
5457
{
5558
static struct option long_options[] =
5659
{
5760
{ "noFreeze", no_argument, 0, 'n' },
5861
{ "skipPendingTaskCheck", no_argument, 0, 's' },
62+
{ "retryCount", required_argument, 0, 'r' },
5963
{ "waitTime", required_argument, 0, 'w' }
6064
};
6165

@@ -82,6 +86,10 @@ int main(int argc, char **argv)
8286
SWSS_LOG_NOTICE("Wait time for response from orchagent set to %s milliseconds", optarg);
8387
waitTime = atoi(optarg);
8488
break;
89+
case 'r':
90+
SWSS_LOG_NOTICE("Number of retries for the request to orchagent is set to %s", optarg);
91+
retryCount = atoi(optarg);
92+
break;
8593
case 'h':
8694
printUsage();
8795
exit(EXIT_SUCCESS);
@@ -103,42 +111,50 @@ int main(int argc, char **argv)
103111
// Will listen for the reply on "RESTARTCHECKREPLY" channel
104112
swss::NotificationConsumer restartQueryReply(&db, "RESTARTCHECKREPLY");
105113

114+
swss::Select s;
115+
s.addSelectable(&restartQueryReply);
116+
swss::Selectable *sel;
117+
106118
std::vector<swss::FieldValueTuple> values;
107119
values.emplace_back("NoFreeze", noFreeze);
108120
values.emplace_back("SkipPendingTaskCheck", skipPendingTaskCheck);
109121
std::string op = "orchagent";
110-
SWSS_LOG_NOTICE("requested %s to do warm restart state check", op.c_str());
111-
restartQuery.send(op, op, values);
112122

123+
int retries = 0;
113124

114-
swss::Select s;
115-
s.addSelectable(&restartQueryReply);
116-
swss::Selectable *sel;
117-
std::string op_ret, data;
118-
values.clear();
119-
int result = s.select(&sel, waitTime);
120-
if (result == swss::Select::OBJECT)
125+
while (retries <= retryCount)
121126
{
122-
restartQueryReply.pop(op_ret, data, values);
123-
if (data == "READY")
127+
SWSS_LOG_NOTICE("requested %s to do warm restart state check, retry count: %d", op.c_str(), retries);
128+
restartQuery.send(op, op, values);
129+
130+
std::string op_ret, data;
131+
std::vector<swss::FieldValueTuple> values_ret;
132+
int result = s.select(&sel, waitTime);
133+
if (result == swss::Select::OBJECT)
134+
{
135+
restartQueryReply.pop(op_ret, data, values_ret);
136+
if (data == "READY")
137+
{
138+
SWSS_LOG_NOTICE("RESTARTCHECK success, %s is frozen and ready for warm restart", op_ret.c_str());
139+
std::cout << "RESTARTCHECK succeeded" << std::endl;
140+
return EXIT_SUCCESS;
141+
}
142+
else
143+
{
144+
SWSS_LOG_NOTICE("RESTARTCHECK failed, %s is not ready for warm restart with status %s",
145+
op_ret.c_str(), data.c_str());
146+
}
147+
}
148+
else if (result == swss::Select::TIMEOUT)
124149
{
125-
SWSS_LOG_NOTICE("RESTARTCHECK success, %s is frozen and ready for warm restart", op_ret.c_str());
126-
std::cout << "RESTARTCHECK succeeded" << std::endl;
127-
return EXIT_SUCCESS;
150+
SWSS_LOG_NOTICE("RESTARTCHECK for %s timed out", op_ret.c_str());
128151
}
129152
else
130153
{
131-
SWSS_LOG_NOTICE("RESTARTCHECK failed, %s is not ready for warm restart with status %s",
132-
op_ret.c_str(), data.c_str());
154+
SWSS_LOG_NOTICE("RESTARTCHECK for %s error", op_ret.c_str());
133155
}
134-
}
135-
else if (result == swss::Select::TIMEOUT)
136-
{
137-
SWSS_LOG_NOTICE("RESTARTCHECK for %s timed out", op_ret.c_str());
138-
}
139-
else
140-
{
141-
SWSS_LOG_NOTICE("RESTARTCHECK for %s error", op_ret.c_str());
156+
retries++;
157+
values_ret.clear();
142158
}
143159
std::cout << "RESTARTCHECK failed" << std::endl;
144160
return EXIT_FAILURE;

0 commit comments

Comments
 (0)