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 KAVITHA RAMALINGAM committed Nov 25, 2024
1 parent c21569d commit 165ac73
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 146 deletions.
4 changes: 4 additions & 0 deletions src/sonic-framework/rebootbackend/rebootbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "reboot_interfaces.h"
#include "select.h"
#include "status_code_util.h"
#include "warm_restart.h"

namespace rebootbackend {

Expand Down Expand Up @@ -41,6 +42,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
93 changes: 0 additions & 93 deletions src/sonic-framework/rebootbackend/redis_utils.cpp

This file was deleted.

49 changes: 0 additions & 49 deletions src/sonic-framework/rebootbackend/redis_utils.h

This file was deleted.

67 changes: 66 additions & 1 deletion src/sonic-framework/tests/reboot_thread_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ 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(RebootMethod::WARM, "reboot because");

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

m_status.set_completed_status(
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(),
RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS);
EXPECT_EQ(0, response.when());
}

class RebootThreadTest : public ::testing::Test {
protected:
RebootThreadTest()
Expand Down Expand Up @@ -261,7 +289,7 @@ TEST_F(RebootThreadTest, TestUnsupportedRebootType) {
"RebootThread: Start rx'd unsupported method");
}

TEST_F(RebootThreadTest, TestInvalidMethodfDoReboot) {
TEST_F(RebootThreadTest, TestInvalidMethodDoReboot) {
set_start_status(RebootMethod::POWERUP, "time to reboot");
do_reboot();
force_inactive();
Expand All @@ -271,4 +299,41 @@ TEST_F(RebootThreadTest, TestInvalidMethodfDoReboot) {
IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, ""));
}

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

RebootRequest request;
request.set_method(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(RebootMethod::WARM, "time to reboot");
do_reboot();
force_inactive();
RebootStatusResponse response = m_reboot_thread.GetResponse();
EXPECT_THAT(
response,
IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, ""));
}

TEST_F(RebootThreadTest, TestWaitForRebootPositive) {
overwrite_reboot_timeout(1);
set_start_status(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 165ac73

Please sign in to comment.