Skip to content

Commit e784820

Browse files
rkavitha-hclKAVITHA RAMALINGAM
authored and
KAVITHA RAMALINGAM
committed
gNOI Cold Reboot - Integrated tests
1 parent d6d5a19 commit e784820

16 files changed

+30
-194
lines changed

src/sonic-framework/rebootbackend/Makefile.am

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

1212
rebootbackend_SOURCES = rebootbackend.cpp rebootbe.cpp interfaces.cpp \
13-
reboot_thread.cpp redis_utils.cpp \
14-
reboot_common.cpp \
13+
reboot_thread.cpp \
1514
system/system.pb.cc types/types.pb.cc \
1615
common/common.pb.cc
1716

src/sonic-framework/rebootbackend/interfaces.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ constexpr char kContainerShutdownPath[] = "/org/SONiC/HostService/gnoi_container
1313

1414
// DBus::BusDispatcher dispatcher;
1515
DBus::Connection& HostServiceDbus::getConnection(void) {
16-
static DBus::Connection* ConnPtr = nullptr;
17-
if (ConnPtr == nullptr) {
16+
static DBus::Connection* connPtr = nullptr;
17+
if (connPtr == nullptr) {
1818
static DBus::BusDispatcher dispatcher;
1919
DBus::default_dispatcher = &dispatcher;
2020

src/sonic-framework/rebootbackend/interfaces.h

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include "gnoi_reboot_dbus.h" // auto generated gnoi_reboot_proxy
77
#include "reboot_interfaces.h"
88

9+
/* Reboot is a request to the reboot sonic host service to request a reboot
10+
from the platform. This takes as an argument a string based json formatted
11+
Reboot request from system.proto.’https://github.com/openconfig/gnoi/blob/73a1e7675c5f963e7810bd3828203f2758eb47e8/system/system.proto#L107 */
12+
913
class GnoiDbusReboot : public org::SONiC::HostService::gnoi_reboot_proxy,
1014
public DBus::IntrospectableProxy,
1115
public DBus::ObjectProxy {
@@ -15,6 +19,12 @@ class GnoiDbusReboot : public org::SONiC::HostService::gnoi_reboot_proxy,
1519
: DBus::ObjectProxy(connection, dbus_obj_name_p, dbus_bus_name_p) {}
1620
};
1721

22+
/* DbusResponse consists of STATUS: success/fail: i.e. was the dbus request
23+
successful DbusResponse.json_string: string based json formatted RebootResponse
24+
defined here:
25+
https://github.com/openconfig/gnoi/blob/73a1e7675c5f963e7810bd3828203f2758eb47e8/system/system.proto#L119 */
26+
27+
1828
class HostServiceDbus : public DbusInterface {
1929
public:
2030
DbusInterface::DbusResponse Reboot(

src/sonic-framework/rebootbackend/reboot_common.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
namespace rebootbackend {
88

9-
//extern bool sigterm_requested;
10-
bool sigterm_requested = false;
11-
9+
extern bool sigterm_requested;
1210
struct NotificationResponse {
1311
swss::StatusCode status;
1412
std::string json_string;

src/sonic-framework/rebootbackend/reboot_thread.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "notificationproducer.h"
77
#include "reboot_common.h"
88
#include "reboot_interfaces.h"
9-
#include "redis_utils.h"
109
#include "select.h"
1110
#include "selectableevent.h"
1211
#include "selectabletimer.h"
@@ -19,10 +18,10 @@ namespace rebootbackend {
1918
using namespace ::gnoi::system;
2019
using steady_clock = std::chrono::steady_clock;
2120
using Progress = ::rebootbackend::RebootThread::Progress;
22-
//using WarmBootStage = ::swss::WarmStart::WarmBootStage;
23-
using WarmStartState = ::swss::WarmStart::WarmStartState;
2421
namespace gpu = ::google::protobuf::util;
2522

23+
bool sigterm_requested = false;
24+
2625
RebootThread::RebootThread(DbusInterface &dbus_interface,
2726
swss::SelectableEvent &m_finished)
2827
: m_db("STATE_DB", 0),

src/sonic-framework/rebootbackend/reboot_thread.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "notificationproducer.h"
99
#include "reboot_common.h"
1010
#include "reboot_interfaces.h"
11-
#include "redis_utils.h"
1211
#include "select.h"
1312
#include "selectableevent.h"
1413
#include "selectabletimer.h"

src/sonic-framework/rebootbackend/rebootbackend.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
#include "reboot_interfaces.h"
33
#include "rebootbe.h"
44

5-
using namespace ::rebootbackend::HostServiceDbus;
6-
using namespace ::rebootbackend::RebootBE;
7-
85
int main(int argc, char** argv) {
96
HostServiceDbus dbus_interface;
10-
RebootBE rebootbe(dbus_interface);
7+
::rebootbackend::RebootBE rebootbe(dbus_interface);
118
rebootbe.Start();
129
return 0;
1310
}

src/sonic-framework/rebootbackend/rebootbe.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ void RebootBE::Start() {
4242
SWSS_LOG_ENTER();
4343
SWSS_LOG_NOTICE("--- Starting rebootbackend ---");
4444

45-
swss::WarmStart::initialize("rebootbackend", "sonic-framework");
46-
swss::WarmStart::checkWarmStart("rebootbackend", "sonic-framework",
47-
/*incr_restore_cnt=*/false);
48-
4945
swss::Select s;
5046
s.addSelectable(&m_NotificationConsumer);
5147
s.addSelectable(&m_Done);
@@ -85,15 +81,15 @@ bool RebootBE::RetrieveNotificationData(
8581
SWSS_LOG_ENTER();
8682

8783
request.op = "";
88-
request.ret_string = "";
84+
request.retString = "";
8985

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

9490
for (auto &fv : values) {
9591
if (DATA_TUPLE_KEY == fvField(fv)) {
96-
request.ret_string = fvValue(fv);
92+
request.retString = fvValue(fv);
9793
return true;
9894
}
9995
}
@@ -118,8 +114,7 @@ void RebootBE::SendNotificationResponse(const std::string key,
118114

119115
NotificationResponse RebootBE::HandleRebootRequest(
120116
const std::string &jsonRebootRequest) {
121-
// using namespace google::protobuf::util;
122-
using namespace gpu::;
117+
using namespace gpu;
123118

124119
SWSS_LOG_ENTER();
125120

src/sonic-framework/rebootbackend/rebootbe.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
namespace rebootbackend {
1212

13-
#define REBOOT_REQUEST_NOTIFICATION_CHANNEL "Reboot_Request_Channel"
14-
#define REBOOT_RESPONSE_NOTIFICATION_CHANNEL "Reboot_Response_Channel"
15-
#define REBOOT_KEY "Reboot"
16-
#define REBOOT_STATUS_KEY "RebootStatus"
17-
#define CANCEL_REBOOT_KEY "CancelReboot"
18-
#define DATA_TUPLE_KEY "MESSAGE"
13+
constexpr char REBOOT_REQUEST_NOTIFICATION_CHANNEL[] = "Reboot_Request_Channel";
14+
constexpr char REBOOT_RESPONSE_NOTIFICATION_CHANNEL[] = "Reboot_Response_Channel";
15+
constexpr char REBOOT_KEY[] = "Reboot";
16+
constexpr char REBOOT_STATUS_KEY[] = "RebootStatus";
17+
constexpr char CANCEL_REBOOT_KEY[] = "CancelReboot";
18+
constexpr char DATA_TUPLE_KEY[] = "MESSAGE";
1919

2020
class RebootBE {
2121
public:

src/sonic-framework/rebootbackend/redis_utils.cpp

-80
This file was deleted.

src/sonic-framework/rebootbackend/redis_utils.h

-40
This file was deleted.

src/sonic-framework/tests/Makefile.am

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ tests_SOURCES = test_utils_common.cpp \
3131
$(top_srcdir)/rebootbackend/system/system.pb.cc \
3232
$(top_srcdir)/rebootbackend/types/types.pb.cc \
3333
$(top_srcdir)/rebootbackend/common/common.pb.cc \
34-
redis_utils_test.cpp \
35-
$(top_srcdir)/rebootbackend/redis_utils.cpp \
3634
test_main.cpp
3735

3836
tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_COVERAGE) $(CFLAGS_SAI)

src/sonic-framework/tests/reboot_thread_test.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "mock_reboot_interfaces.h"
1313
#include "reboot_common.h"
1414
#include "reboot_interfaces.h"
15-
#include "redis_utils.h"
1615
#include "select.h"
1716
#include "selectableevent.h"
1817
#include "status_code_util.h"
@@ -97,7 +96,6 @@ class RebootThreadTest : public ::testing::Test {
9796
m_config_db("CONFIG_DB", 0),
9897
m_reboot_thread(m_dbus_interface,
9998
m_finished) {
100-
swss::WarmStart::initialize("app1", "docker1");
10199
sigterm_requested = false;
102100
}
103101

src/sonic-framework/tests/rebootbe_test.cpp

+4-17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace rebootbackend {
2727
#define ONE_SECOND_MS (1000)
2828
#define FIFTEEN_HUNDRED_MS (1500)
2929
#define TWO_SECONDS_MS (2000)
30+
#define SELECT_TIMEOUT_250_MS (250)
3031

3132
namespace gpu = ::google::protobuf::util;
3233
using namespace gnoi::system;
@@ -75,20 +76,6 @@ class RebootBETestWithoutStop : public ::testing::Test {
7576
}
7677
virtual ~RebootBETestWithoutStop() = default;
7778

78-
gnoi::system::RebootStatusResponse default_not_started_status() {
79-
InitThreadStatus status;
80-
return status.get_response();
81-
}
82-
83-
gnoi::system::RebootStatusResponse default_done_status() {
84-
InitThreadStatus status;
85-
// We can't edit the status without it being active.
86-
status.set_start_status();
87-
status.set_success();
88-
status.set_inactive();
89-
return status.get_response();
90-
}
91-
9279

9380
void start_rebootbe() {
9481
m_rebootbe_thread =
@@ -102,11 +89,11 @@ class RebootBETestWithoutStop : public ::testing::Test {
10289
}
10390

10491
void overwrite_reboot_timeout(uint32_t timeout_seconds) {
105-
m_rebootbe.m_reboot_thread.m_reboot_timeout = timeout_seconds;
92+
m_rebootbe.m_RebootThread.m_reboot_timeout = timeout_seconds;
10693
}
10794

10895

109-
void send_stop_reboot_thread() { m_rebootbe.m_reboot_thread.Stop(); }
96+
void send_stop_reboot_thread() { m_rebootbe.m_RebootThread.Stop(); }
11097

11198
void SendRebootRequest(const std::string &op, const std::string &data,
11299
const std::string &field, const std::string &value) {
@@ -188,7 +175,7 @@ class RebootBETestWithoutStop : public ::testing::Test {
188175
}
189176

190177
NotificationResponse handle_reboot_request(std::string &json_request) {
191-
return m_rebootbe.handle_reboot_request(json_request);
178+
return m_rebootbe.HandleRebootRequest(json_request);
192179
}
193180

194181

src/sonic-framework/tests/redis_utils_test.cpp

-23
This file was deleted.

src/sonic-framework/tests/test_utils_common.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "dbconnector.h"
1010
#include "notificationconsumer.h"
11-
#include "redis_utils.h"
1211
#include "select.h"
1312
#include "selectableevent.h"
1413
#include "table.h"

0 commit comments

Comments
 (0)