Skip to content

Commit

Permalink
gNOI Cold Reboot - Integrated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rkavitha-hcl authored and KAVITHA RAMALINGAM committed Nov 21, 2024
1 parent d6d5a19 commit 02b4273
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 194 deletions.
3 changes: 1 addition & 2 deletions src/sonic-framework/rebootbackend/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ DBGFLAGS = -g
endif

rebootbackend_SOURCES = rebootbackend.cpp rebootbe.cpp interfaces.cpp \
reboot_thread.cpp redis_utils.cpp \
reboot_common.cpp \
reboot_thread.cpp \
system/system.pb.cc types/types.pb.cc \
common/common.pb.cc

Expand Down
4 changes: 2 additions & 2 deletions src/sonic-framework/rebootbackend/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ constexpr char kContainerShutdownPath[] = "/org/SONiC/HostService/gnoi_container

// DBus::BusDispatcher dispatcher;
DBus::Connection& HostServiceDbus::getConnection(void) {
static DBus::Connection* ConnPtr = nullptr;
if (ConnPtr == nullptr) {
static DBus::Connection* connPtr = nullptr;
if (connPtr == nullptr) {
static DBus::BusDispatcher dispatcher;
DBus::default_dispatcher = &dispatcher;

Expand Down
4 changes: 1 addition & 3 deletions src/sonic-framework/rebootbackend/reboot_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

namespace rebootbackend {

//extern bool sigterm_requested;
bool sigterm_requested = false;

extern bool sigterm_requested;
struct NotificationResponse {
swss::StatusCode status;
std::string json_string;
Expand Down
5 changes: 2 additions & 3 deletions src/sonic-framework/rebootbackend/reboot_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "notificationproducer.h"
#include "reboot_common.h"
#include "reboot_interfaces.h"
#include "redis_utils.h"
#include "select.h"
#include "selectableevent.h"
#include "selectabletimer.h"
Expand All @@ -19,10 +18,10 @@ namespace rebootbackend {
using namespace ::gnoi::system;
using steady_clock = std::chrono::steady_clock;
using Progress = ::rebootbackend::RebootThread::Progress;
//using WarmBootStage = ::swss::WarmStart::WarmBootStage;
using WarmStartState = ::swss::WarmStart::WarmStartState;
namespace gpu = ::google::protobuf::util;

bool sigterm_requested = false;

RebootThread::RebootThread(DbusInterface &dbus_interface,
swss::SelectableEvent &m_finished)
: m_db("STATE_DB", 0),
Expand Down
1 change: 0 additions & 1 deletion src/sonic-framework/rebootbackend/reboot_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "notificationproducer.h"
#include "reboot_common.h"
#include "reboot_interfaces.h"
#include "redis_utils.h"
#include "select.h"
#include "selectableevent.h"
#include "selectabletimer.h"
Expand Down
5 changes: 1 addition & 4 deletions src/sonic-framework/rebootbackend/rebootbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
#include "reboot_interfaces.h"
#include "rebootbe.h"

using namespace ::rebootbackend::HostServiceDbus;
using namespace ::rebootbackend::RebootBE;

int main(int argc, char** argv) {
HostServiceDbus dbus_interface;
RebootBE rebootbe(dbus_interface);
::rebootbackend::RebootBE rebootbe(dbus_interface);
rebootbe.Start();
return 0;
}
11 changes: 3 additions & 8 deletions src/sonic-framework/rebootbackend/rebootbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ 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);
s.addSelectable(&m_Done);
Expand Down Expand Up @@ -85,15 +81,15 @@ bool RebootBE::RetrieveNotificationData(
SWSS_LOG_ENTER();

request.op = "";
request.ret_string = "";
request.retString = "";

std::string data;
std::vector<swss::FieldValueTuple> values;
consumer.pop(request.op, data, values);

for (auto &fv : values) {
if (DATA_TUPLE_KEY == fvField(fv)) {
request.ret_string = fvValue(fv);
request.retString = fvValue(fv);
return true;
}
}
Expand All @@ -118,8 +114,7 @@ void RebootBE::SendNotificationResponse(const std::string key,

NotificationResponse RebootBE::HandleRebootRequest(
const std::string &jsonRebootRequest) {
// using namespace google::protobuf::util;
using namespace gpu::;
using namespace gpu;

SWSS_LOG_ENTER();

Expand Down
12 changes: 6 additions & 6 deletions src/sonic-framework/rebootbackend/rebootbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace rebootbackend {

#define REBOOT_REQUEST_NOTIFICATION_CHANNEL "Reboot_Request_Channel"
#define REBOOT_RESPONSE_NOTIFICATION_CHANNEL "Reboot_Response_Channel"
#define REBOOT_KEY "Reboot"
#define REBOOT_STATUS_KEY "RebootStatus"
#define CANCEL_REBOOT_KEY "CancelReboot"
#define DATA_TUPLE_KEY "MESSAGE"
constexpr char REBOOT_REQUEST_NOTIFICATION_CHANNEL[] = "Reboot_Request_Channel";
constexpr char REBOOT_RESPONSE_NOTIFICATION_CHANNEL[] = "Reboot_Response_Channel";
constexpr char REBOOT_KEY[] = "Reboot";
constexpr char REBOOT_STATUS_KEY[] = "RebootStatus";
constexpr char CANCEL_REBOOT_KEY[] = "CancelReboot";
constexpr char DATA_TUPLE_KEY[] = "MESSAGE";

class RebootBE {
public:
Expand Down
80 changes: 0 additions & 80 deletions src/sonic-framework/rebootbackend/redis_utils.cpp

This file was deleted.

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

This file was deleted.

2 changes: 0 additions & 2 deletions src/sonic-framework/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ tests_SOURCES = test_utils_common.cpp \
$(top_srcdir)/rebootbackend/system/system.pb.cc \
$(top_srcdir)/rebootbackend/types/types.pb.cc \
$(top_srcdir)/rebootbackend/common/common.pb.cc \
redis_utils_test.cpp \
$(top_srcdir)/rebootbackend/redis_utils.cpp \
test_main.cpp

tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_COVERAGE) $(CFLAGS_SAI)
Expand Down
2 changes: 0 additions & 2 deletions src/sonic-framework/tests/reboot_thread_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "mock_reboot_interfaces.h"
#include "reboot_common.h"
#include "reboot_interfaces.h"
#include "redis_utils.h"
#include "select.h"
#include "selectableevent.h"
#include "status_code_util.h"
Expand Down Expand Up @@ -97,7 +96,6 @@ class RebootThreadTest : public ::testing::Test {
m_config_db("CONFIG_DB", 0),
m_reboot_thread(m_dbus_interface,
m_finished) {
swss::WarmStart::initialize("app1", "docker1");
sigterm_requested = false;
}

Expand Down
21 changes: 4 additions & 17 deletions src/sonic-framework/tests/rebootbe_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace rebootbackend {
#define ONE_SECOND_MS (1000)
#define FIFTEEN_HUNDRED_MS (1500)
#define TWO_SECONDS_MS (2000)
#define SELECT_TIMEOUT_250_MS (250)

namespace gpu = ::google::protobuf::util;
using namespace gnoi::system;
Expand Down Expand Up @@ -75,20 +76,6 @@ class RebootBETestWithoutStop : public ::testing::Test {
}
virtual ~RebootBETestWithoutStop() = default;

gnoi::system::RebootStatusResponse default_not_started_status() {
InitThreadStatus status;
return status.get_response();
}

gnoi::system::RebootStatusResponse default_done_status() {
InitThreadStatus status;
// We can't edit the status without it being active.
status.set_start_status();
status.set_success();
status.set_inactive();
return status.get_response();
}


void start_rebootbe() {
m_rebootbe_thread =
Expand All @@ -102,11 +89,11 @@ class RebootBETestWithoutStop : public ::testing::Test {
}

void overwrite_reboot_timeout(uint32_t timeout_seconds) {
m_rebootbe.m_reboot_thread.m_reboot_timeout = timeout_seconds;
m_rebootbe.m_RebootThread.m_reboot_timeout = timeout_seconds;
}


void send_stop_reboot_thread() { m_rebootbe.m_reboot_thread.Stop(); }
void send_stop_reboot_thread() { m_rebootbe.m_RebootThread.Stop(); }

void SendRebootRequest(const std::string &op, const std::string &data,
const std::string &field, const std::string &value) {
Expand Down Expand Up @@ -188,7 +175,7 @@ class RebootBETestWithoutStop : public ::testing::Test {
}

NotificationResponse handle_reboot_request(std::string &json_request) {
return m_rebootbe.handle_reboot_request(json_request);
return m_rebootbe.HandleRebootRequest(json_request);
}


Expand Down
23 changes: 0 additions & 23 deletions src/sonic-framework/tests/redis_utils_test.cpp

This file was deleted.

1 change: 0 additions & 1 deletion src/sonic-framework/tests/test_utils_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "dbconnector.h"
#include "notificationconsumer.h"
#include "redis_utils.h"
#include "select.h"
#include "selectableevent.h"
#include "table.h"
Expand Down

0 comments on commit 02b4273

Please sign in to comment.