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 Bibhuprasad Singh committed Jan 6, 2025
1 parent 79d4162 commit 14eb980
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 230 deletions.
72 changes: 0 additions & 72 deletions src/sonic-framework/rebootbackend/gnoi_reboot_dbus.h

This file was deleted.

136 changes: 0 additions & 136 deletions src/sonic-framework/rebootbackend/init_thread.h

This file was deleted.

19 changes: 0 additions & 19 deletions src/sonic-framework/rebootbackend/reboot_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,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::reboot_thread(void) {
SWSS_LOG_ENTER();

Expand Down
7 changes: 5 additions & 2 deletions src/sonic-framework/rebootbackend/rebootbe.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "rebootbe.h"

#include <google/protobuf/util/json_util.h>
#include <unistd.h>

Expand Down Expand Up @@ -29,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 @@ -41,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 All @@ -51,7 +54,7 @@ void RebootBE::Start() {
SetCurrentStatus(RebManagerStatus::WARM_INIT_WAIT);
} else {
SWSS_LOG_NOTICE("Warm restart not enabled");
}
}

SWSS_LOG_NOTICE("RebootBE entering operational loop");
while (true) {
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 @@ -89,6 +89,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 @@ -283,4 +315,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 14eb980

Please sign in to comment.