Skip to content

Commit

Permalink
gNOI Warm Reboot - Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rkavitha-hcl authored and VSuryaprasad-HCL committed Jan 27, 2025
1 parent f4610bf commit 0918d69
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 175 deletions.
136 changes: 0 additions & 136 deletions src/sonic-framework/rebootbackend/init_thread.h

This file was deleted.

37 changes: 0 additions & 37 deletions src/sonic-framework/rebootbackend/reboot_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,43 +188,6 @@ void RebootThread::do_warm_reboot(swss::Select &s) {
return;
}

void RebootThread::do_warm_reboot(swss::Select &s) {
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("Sending warm reboot request to platform");
if (send_dbus_reboot_request() == Progress::EXIT_EARLY) {
return;
}

// Wait for warm reboot. If we return, reboot failed.
if (wait_for_platform_reboot(s) == Progress::EXIT_EARLY) {
return;
}

// We shouldn't be here. Platform reboot should've killed us.
log_error_and_set_non_retry_failure("failed to warm reboot");

return;
}

void RebootThread::do_warm_reboot(swss::Select &s) {
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("Sending warm reboot request to platform");
if (send_dbus_reboot_request() == Progress::EXIT_EARLY) {
return;
}

// Wait for warm reboot. If we return, reboot failed.
if (wait_for_platform_reboot(s) == Progress::EXIT_EARLY) {
return;
}

// We shouldn't be here. Platform reboot should've killed us.
log_error_and_set_non_retry_failure("failed to warm reboot");

return;
}


void RebootThread::reboot_thread(void) {
SWSS_LOG_ENTER();

Expand Down
4 changes: 3 additions & 1 deletion src/sonic-framework/rebootbackend/rebootbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ RebootBE::RebootBE(DbusInterface &dbus_interface)
}

RebootBE::RebManagerStatus RebootBE::GetCurrentStatus() {
const std::lock_guard<std::mutex> lock(m_StatusMutex);
return m_CurrentStatus;
}

Expand All @@ -42,6 +41,9 @@ void RebootBE::SetCurrentStatus(RebManagerStatus newStatus) {
void RebootBE::Start() {
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("--- Starting rebootbackend ---");
swss::WarmStart::initialize("rebootbackend", "sonic-framework");
swss::WarmStart::checkWarmStart("rebootbackend", "sonic-framework",
/*incr_restore_cnt=*/false);

swss::Select s;
s.addSelectable(&m_NotificationConsumer);
Expand Down
71 changes: 71 additions & 0 deletions src/sonic-framework/tests/reboot_thread_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ TEST_F(RebootStatusTest, TestGetStatus) {
EXPECT_EQ(0, response.when());
}

TEST_F(RebootStatusTest, TestGetWarmStatus) {
std::chrono::nanoseconds curr_ns =
std::chrono::high_resolution_clock::now().time_since_epoch();

m_status.set_start_status(gnoi::system::RebootMethod::WARM, "reboot because");

gnoi::system::RebootStatusResponse response = m_status.get_response();
EXPECT_EQ(
response.status().status(),
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN);

m_status.set_completed_status(
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS,
"anything");

response = m_status.get_response();

// message should be empty while reboot is active
EXPECT_THAT(response.status().message(), StrEq(""));

uint64_t reboot_ns = response.when();
EXPECT_TRUE(reboot_ns > (uint64_t)curr_ns.count());

m_status.set_inactive();
response = m_status.get_response();
EXPECT_THAT(response.status().message(), StrEq("anything"));
EXPECT_EQ(
response.status().status(),
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS);
EXPECT_EQ(0, response.when());
}

class RebootThreadTest : public ::testing::Test {
protected:
RebootThreadTest()
Expand Down Expand Up @@ -285,4 +317,43 @@ TEST_F(RebootThreadTest, TestInvalidMethodfDoReboot) {
""));
}

TEST_F(RebootThreadTest, TestNoWarmIfNonRetriableFailure) {
set_start_status(gnoi::system::RebootMethod::WARM, "time to reboot");
set_completed_status(
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE,
"failed to warm reboot");
force_inactive();

gnoi::system::RebootRequest request;
request.set_method(gnoi::system::RebootMethod::WARM);

NotificationResponse response = m_reboot_thread.Start(request);
EXPECT_EQ(response.status, swss::StatusCode::SWSS_RC_FAILED_PRECONDITION);
EXPECT_EQ(response.json_string,
"RebootThread: last WARM reboot failed with non-retriable failure");
}

TEST_F(RebootThreadTest, TestSigTermStartofDoReboot) {
sigterm_requested = true;
set_start_status(gnoi::system::RebootMethod::WARM, "time to reboot");
do_reboot();
force_inactive();
gnoi::system::RebootStatusResponse response = m_reboot_thread.GetResponse();
EXPECT_THAT(
response,
IsStatus(
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN,
""));
}

TEST_F(RebootThreadTest, TestWaitForRebootPositive) {
overwrite_reboot_timeout(1);
set_start_status(gnoi::system::RebootMethod::WARM, "time to reboot");
swss::Select s;
swss::SelectableEvent m_stop;
s.addSelectable(&m_stop);
RebootThread::Progress progress = wait_for_platform_reboot(s);
EXPECT_EQ(progress, RebootThread::Progress::PROCEED);
}

} // namespace rebootbackend
Loading

0 comments on commit 0918d69

Please sign in to comment.