Skip to content

Commit b5f6845

Browse files
rkavitha-hclKAVITHA RAMALINGAM
authored and
KAVITHA RAMALINGAM
committed
gNOI Warm Reboot - Added tests
1 parent 9204b2b commit b5f6845

File tree

6 files changed

+260
-147
lines changed

6 files changed

+260
-147
lines changed

src/sonic-framework/rebootbackend/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ DBGFLAGS = -g
1010
endif
1111

1212
rebootbackend_SOURCES = rebootbackend.cpp rebootbe.cpp interfaces.cpp \
13-
reboot_thread.cpp redis_utils.cpp \
13+
reboot_thread.cpp \
1414
reboot_common.cpp \
1515
system/system.pb.cc types/types.pb.cc \
1616
common/common.pb.cc

src/sonic-framework/rebootbackend/redis_utils.cpp

-93
This file was deleted.

src/sonic-framework/rebootbackend/redis_utils.h

-49
This file was deleted.

src/sonic-framework/tests/reboot_thread_test.cpp

+66-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,34 @@ TEST_F(RebootStatusTest, TestGetStatus) {
8989
EXPECT_EQ(0, response.when());
9090
}
9191

92+
TEST_F(RebootStatusTest, TestGetWarmStatus) {
93+
std::chrono::nanoseconds curr_ns = std::chrono::high_resolution_clock::now().time_since_epoch();
94+
95+
m_status.set_start_status(RebootMethod::WARM, "reboot because");
96+
97+
RebootStatusResponse response = m_status.get_response();
98+
EXPECT_EQ(response.status().status(),
99+
RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN);
100+
101+
m_status.set_completed_status(
102+
RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS, "anything");
103+
104+
response = m_status.get_response();
105+
106+
// message should be empty while reboot is active
107+
EXPECT_THAT(response.status().message(), StrEq(""));
108+
109+
uint64_t reboot_ns = response.when();
110+
EXPECT_TRUE(reboot_ns > (uint64_t)curr_ns.count());
111+
112+
m_status.set_inactive();
113+
response = m_status.get_response();
114+
EXPECT_THAT(response.status().message(), StrEq("anything"));
115+
EXPECT_EQ(response.status().status(),
116+
RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS);
117+
EXPECT_EQ(0, response.when());
118+
}
119+
92120
class RebootThreadTest : public ::testing::Test {
93121
protected:
94122
RebootThreadTest()
@@ -263,7 +291,7 @@ TEST_F(RebootThreadTest, TestUnsupportedRebootType) {
263291
"RebootThread: Start rx'd unsupported method");
264292
}
265293

266-
TEST_F(RebootThreadTest, TestInvalidMethodfDoReboot) {
294+
TEST_F(RebootThreadTest, TestInvalidMethodDoReboot) {
267295
set_start_status(RebootMethod::POWERUP, "time to reboot");
268296
do_reboot();
269297
force_inactive();
@@ -273,4 +301,41 @@ TEST_F(RebootThreadTest, TestInvalidMethodfDoReboot) {
273301
IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, ""));
274302
}
275303

304+
TEST_F(RebootThreadTest, TestNoWarmIfNonRetriableFailure) {
305+
set_start_status(RebootMethod::WARM, "time to reboot");
306+
set_completed_status(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE,
307+
"failed to warm reboot");
308+
force_inactive();
309+
310+
RebootRequest request;
311+
request.set_method(RebootMethod::WARM);
312+
313+
NotificationResponse response = m_reboot_thread.Start(request);
314+
EXPECT_EQ(response.status, swss::StatusCode::SWSS_RC_FAILED_PRECONDITION);
315+
EXPECT_EQ(response.json_string,
316+
"RebootThread: last WARM reboot failed with non-retriable failure");
317+
}
318+
319+
TEST_F(RebootThreadTest, TestSigTermStartofDoReboot) {
320+
sigterm_requested = true;
321+
set_start_status(RebootMethod::WARM, "time to reboot");
322+
do_reboot();
323+
force_inactive();
324+
RebootStatusResponse response = m_reboot_thread.GetResponse();
325+
EXPECT_THAT(
326+
response,
327+
IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, ""));
328+
}
329+
330+
TEST_F(RebootThreadTest, TestWaitForRebootPositive) {
331+
overwrite_reboot_timeout(1);
332+
set_start_status(RebootMethod::WARM, "time to reboot");
333+
swss::Select s;
334+
swss::SelectableEvent m_stop;
335+
s.addSelectable(&m_stop);
336+
RebootThread::Progress progress = wait_for_platform_reboot(s);
337+
EXPECT_EQ(progress, RebootThread::Progress::PROCEED);
338+
}
339+
340+
276341
} // namespace rebootbackend

0 commit comments

Comments
 (0)