Skip to content

Commit ba55f24

Browse files
rkavitha-hclKAVITHA RAMALINGAM
authored and
KAVITHA RAMALINGAM
committed
gNOI Warm Reboot - rebootbackend changes
1 parent fde27b3 commit ba55f24

File tree

6 files changed

+61
-36
lines changed

6 files changed

+61
-36
lines changed

src/sonic-framework/rebootbackend/reboot_thread.cpp

+30-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ void RebootThread::do_reboot(void) {
115115

116116
if (m_request.method() == RebootMethod::COLD) {
117117
do_cold_reboot(s);
118+
} else if (m_request.method() == RebootMethod::WARM) {
119+
do_warm_reboot(s);
118120
} else {
119121
// This shouldn't be possible. Reference check_start_preconditions()
120122
SWSS_LOG_ERROR("Received unrecognized method type = %s",
@@ -161,11 +163,28 @@ void RebootThread::do_cold_reboot(swss::Select &s) {
161163
// We shouldn't be here. Platform reboot should've killed us.
162164
log_error_and_set_non_retry_failure("platform failed to reboot");
163165

164-
// Set critical state
165-
//m_critical_interface.report_critical_state("platform failed to reboot");
166166
return;
167167
}
168168

169+
void RebootThread::do_warm_reboot(swss::Select &s) {
170+
SWSS_LOG_ENTER();
171+
SWSS_LOG_NOTICE("Sending warm reboot request to platform");
172+
if (send_dbus_reboot_request() == Progress::EXIT_EARLY) {
173+
return;
174+
}
175+
176+
// Wait for warm reboot. If we return, reboot failed.
177+
if (wait_for_platform_reboot(s) == Progress::EXIT_EARLY) {
178+
return;
179+
}
180+
181+
// We shouldn't be here. Platform reboot should've killed us.
182+
log_error_and_set_non_retry_failure("failed to warm reboot");
183+
184+
return;
185+
}
186+
187+
169188
void RebootThread::reboot_thread(void) {
170189
SWSS_LOG_ENTER();
171190

@@ -188,6 +207,15 @@ bool RebootThread::check_start_preconditions(const RebootRequest &request,
188207
request.method() != RebootMethod::WARM) {
189208
response.json_string = "RebootThread: Start rx'd unsupported method";
190209
response.status = swss::StatusCode::SWSS_RC_INVALID_PARAM;
210+
} else if (request.method() == RebootMethod::WARM) {
211+
if (m_status.get_last_reboot_status() ==
212+
RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE) {
213+
// If the last reboot failed with a non-retriable failure, don't retry.
214+
// But, we will allow a cold boot to recover.
215+
response.json_string =
216+
"RebootThread: last WARM reboot failed with non-retriable failure";
217+
response.status = swss::StatusCode::SWSS_RC_FAILED_PRECONDITION;
218+
}
191219
} else if (request.delay() != 0) {
192220
response.json_string = "RebootThread: delayed start not supported";
193221
response.status = swss::StatusCode::SWSS_RC_INVALID_PARAM;

src/sonic-framework/rebootbackend/reboot_thread.h

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class RebootThread {
165165
void do_reboot(void);
166166
Progress send_dbus_reboot_request();
167167
void do_cold_reboot(swss::Select &s);
168+
void do_warm_reboot(swss::Select &s);
168169

169170
// Inner loop select handler to wait for platform reboot.
170171
// wait for timeout

src/sonic-framework/rebootbackend/rebootbe.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ void RebootBE::Start() {
5353
s.addSelectable(&m_done);
5454
s.addSelectable(&m_reboot_thread_finished);
5555

56+
57+
if (swss::WarmStart::isWarmStart()) {
58+
SWSS_LOG_NOTICE("Launching init thread for warm start");
59+
SetCurrentStatus(RebManagerStatus::WARM_INIT_WAIT);
60+
} else {
61+
SWSS_LOG_NOTICE("Warm restart not enabled");
62+
}
63+
5664
SWSS_LOG_NOTICE("RebootBE entering operational loop");
5765
while (true) {
5866
swss::Selectable *sel;

src/sonic-framework/rebootbackend/redis_utils.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,17 @@ bool get_docker_app_from_key(const std::string &key,
7777
return true;
7878
}
7979

80+
void set_warm_restart_counter(swss::DBConnector &db, int count) {
81+
swss::Table table(&db, "BOOT_INFO");
82+
table.hset("system", "warmboot-count", std::to_string(count));
83+
}
84+
85+
std::string get_warm_restart_counter(swss::DBConnector &db) {
86+
swss::Table warmRestartTable(&db, "BOOT_INFO");
87+
std::string counter;
88+
warmRestartTable.hget("system", "warmboot-count", counter);
89+
return counter;
90+
}
91+
92+
8093
} // namespace rebootbackend

src/sonic-framework/rebootbackend/redis_utils.h

+9
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,14 @@ bool is_valid_key(const std::string &key, const std::string &separator);
3636
bool get_docker_app_from_key(const std::string &key,
3737
const std::string &separator, std::string &docker,
3838
std::string &app);
39+
// Sets the warm restart count in the database.
40+
void set_warm_restart_counter(swss::DBConnector &db, int count);
41+
42+
// Returns the current warm restart count from the database. Returns an empty
43+
// string if the warm restart count is not set, and a string representation
44+
// of an integer otherwise.
45+
std::string get_warm_restart_counter(swss::DBConnector &db);
46+
47+
3948

4049
} // namespace rebootbackend

src/sonic-framework/tests/rebootbe_test.cpp

-34
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class RebootBETestWithoutStop : public ::testing::Test {
6363
m_rebootbeReponseChannel(&m_db, REBOOT_RESPONSE_NOTIFICATION_CHANNEL),
6464
m_rebootbe(m_dbus_interface) {
6565
sigterm_requested = false;
66-
// TestUtils::clear_tables(m_db);
6766

6867

6968
m_s.addSelectable(&m_rebootbeReponseChannel);
@@ -75,21 +74,6 @@ class RebootBETestWithoutStop : public ::testing::Test {
7574
}
7675
virtual ~RebootBETestWithoutStop() = default;
7776

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-
92-
9377
void start_rebootbe() {
9478
m_rebootbe_thread =
9579
std::make_unique<std::thread>(&RebootBE::Start, &m_rebootbe);
@@ -227,26 +211,8 @@ class RebootBEAutoStartTest : public RebootBETest,
227211
RebootBEAutoStartTest() {
228212
//force_warm_start_state(GetParam());
229213

230-
/* if (GetParam()) {
231-
EXPECT_CALL(*m_init_thread, Start())
232-
.WillOnce(Return(swss::StatusCode::SWSS_RC_SUCCESS));
233-
EXPECT_CALL(*m_init_thread, Join()).WillOnce(Return(true));
234-
EXPECT_CALL(*m_init_thread, GetResponse())
235-
.WillOnce(Return(default_running_status()))
236-
.WillRepeatedly(Return(default_done_status()));
237-
} else {
238-
EXPECT_CALL(*m_init_thread, GetResponse())
239-
.WillRepeatedly(Return(default_not_started_status()));
240-
} */
241-
242214
start_rebootbe();
243215

244-
/* if (GetParam()) {
245-
get_stack_unfrozen_select().notify();
246-
std::this_thread::sleep_for(std::chrono::milliseconds(50));
247-
get_init_done_select().notify();
248-
} */
249-
250216
std::this_thread::sleep_for(std::chrono::milliseconds(50));
251217
EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE);
252218
}

0 commit comments

Comments
 (0)