Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sonic-net/sonic-buildimage
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d4ba3f98a779166f890663bb7b76f98bb4b9485c
Choose a base ref
..
head repository: sonic-net/sonic-buildimage
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ad912265a1c15aa9f3fbe32b182a75415fcf04e3
Choose a head ref
20 changes: 10 additions & 10 deletions src/sonic-framework/rebootbackend/interfaces.cpp
Original file line number Diff line number Diff line change
@@ -25,15 +25,15 @@ DBus::Connection& HostServiceDbus::getConnection(void) {
}

DbusInterface::DbusResponse HostServiceDbus::Reboot(
const std::string& json_reboot_request) {
const std::string& jsonRebootRequest) {
int32_t status;

GnoiDbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath);
std::string ret_string;
std::string retString;
std::vector<std::string> options;
options.push_back(json_reboot_request);
options.push_back(jsonRebootRequest);
try {
reboot_client.issue_reboot(options, status, ret_string);
reboot_client.issue_reboot(options, status, retString);
} catch (DBus::Error& ex) {
return DbusResponse{
DbusStatus::DBUS_FAIL,
@@ -45,17 +45,17 @@ DbusInterface::DbusResponse HostServiceDbus::Reboot(
// Successful reboot response is an empty string.
return DbusResponse{DbusStatus::DBUS_SUCCESS, ""};
}
return DbusResponse{DbusStatus::DBUS_FAIL, ret_string};
return DbusResponse{DbusStatus::DBUS_FAIL, retString};
}

DbusInterface::DbusResponse HostServiceDbus::RebootStatus(
const std::string& json_status_request) {
const std::string& jsonStatusRequest) {

GnoiDbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath);
int32_t status;
std::string ret_string;
std::string retString;
try {
reboot_client.get_reboot_status(status, ret_string);
reboot_client.get_reboot_status(status, retString);
} catch (DBus::Error& ex) {
return DbusResponse{
DbusStatus::DBUS_FAIL,
@@ -65,8 +65,8 @@ DbusInterface::DbusResponse HostServiceDbus::RebootStatus(

// gnoi_reboot.py returns 0 for success, 1 for failure
if (status == 0) {
return DbusResponse{DbusStatus::DBUS_SUCCESS, ret_string};
return DbusResponse{DbusStatus::DBUS_SUCCESS, retString};
}
return DbusResponse{DbusStatus::DBUS_FAIL, ret_string};
return DbusResponse{DbusStatus::DBUS_FAIL, retString};
}

14 changes: 0 additions & 14 deletions src/sonic-framework/rebootbackend/reboot_common.cpp

This file was deleted.

7 changes: 2 additions & 5 deletions src/sonic-framework/rebootbackend/reboot_common.h
Original file line number Diff line number Diff line change
@@ -6,11 +6,8 @@

namespace rebootbackend {

#define ONE_THOUSAND (1000)

extern bool sigterm_requested;

extern timespec milliseconds_to_timespec(uint64_t time_ms);
//extern bool sigterm_requested;
bool sigterm_requested = false;

struct NotificationResponse {
swss::StatusCode status;
4 changes: 2 additions & 2 deletions src/sonic-framework/rebootbackend/reboot_interfaces.h
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ class DbusInterface {
};

virtual ~DbusInterface() = default;
virtual DbusResponse Reboot(const std::string& json_reboot_request) = 0;
virtual DbusResponse RebootStatus(const std::string& json_status_request) = 0;
virtual DbusResponse Reboot(const std::string& jsonRebootRequest) = 0;
virtual DbusResponse RebootStatus(const std::string& jsonStatusRequest) = 0;
};

3 changes: 0 additions & 3 deletions src/sonic-framework/rebootbackend/reboot_thread.h
Original file line number Diff line number Diff line change
@@ -17,9 +17,6 @@

namespace rebootbackend {

#define SELECT_TIMEOUT_250_MS (250)
#define SELECT_TIMEOUT_500_MS (500)

// Hold/manage the contents of a RebootStatusResponse as defined
// in system.proto
// Thread-safe: expectation is one thread will write and multiple
3 changes: 2 additions & 1 deletion src/sonic-framework/rebootbackend/rebootbackend.cpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@
#include "reboot_interfaces.h"
#include "rebootbe.h"

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

int main(int argc, char** argv) {
HostServiceDbus dbus_interface;
107 changes: 49 additions & 58 deletions src/sonic-framework/rebootbackend/rebootbe.cpp
Original file line number Diff line number Diff line change
@@ -18,26 +18,25 @@ namespace rebootbackend {

namespace gpu = ::google::protobuf::util;

bool sigterm_requested = false;

RebootBE::RebootBE(DbusInterface &dbus_interface)
: m_db("STATE_DB", 0),
m_rebootResponse(&m_db, REBOOT_RESPONSE_NOTIFICATION_CHANNEL),
m_notificationConsumer(&m_db, REBOOT_REQUEST_NOTIFICATION_CHANNEL),
m_RebootResponse(&m_db, REBOOT_RESPONSE_NOTIFICATION_CHANNEL),
m_NotificationConsumer(&m_db, REBOOT_REQUEST_NOTIFICATION_CHANNEL),
m_dbus(dbus_interface),
m_reboot_thread(dbus_interface,
m_reboot_thread_finished) {
m_RebootThread(dbus_interface,
m_RebootThreadFinished) {
swss::Logger::linkToDbNative("rebootbackend");
}

RebootBE::RebManagerStatus RebootBE::GetCurrentStatus() {
const std::lock_guard<std::mutex> lock(m_status_mutex);
return m_current_status;
const std::lock_guard<std::mutex> lock(m_StatusMutex);
return m_CurrentStatus;
}

void RebootBE::SetCurrentStatus(RebManagerStatus new_status) {
const std::lock_guard<std::mutex> lock(m_status_mutex);
m_current_status = new_status;
void RebootBE::SetCurrentStatus(RebManagerStatus newStatus) {
const std::lock_guard<std::mutex> lock(m_StatusMutex);
m_CurrentStatus = newStatus;
}

void RebootBE::Start() {
@@ -49,9 +48,9 @@ void RebootBE::Start() {
/*incr_restore_cnt=*/false);

swss::Select s;
s.addSelectable(&m_notificationConsumer);
s.addSelectable(&m_done);
s.addSelectable(&m_reboot_thread_finished);
s.addSelectable(&m_NotificationConsumer);
s.addSelectable(&m_Done);
s.addSelectable(&m_RebootThreadFinished);

SWSS_LOG_NOTICE("RebootBE entering operational loop");
while (true) {
@@ -62,12 +61,12 @@ void RebootBE::Start() {
if (ret == swss::Select::ERROR) {
SWSS_LOG_NOTICE("Error: %s!", strerror(errno));
} else if (ret == swss::Select::OBJECT) {
if (sel == &m_notificationConsumer) {
do_task(m_notificationConsumer);
} else if (sel == &m_reboot_thread_finished) {
handle_reboot_finish();
} else if (sel == &m_done) {
handle_done();
if (sel == &m_NotificationConsumer) {
DoTask(m_NotificationConsumer);
} else if (sel == &m_RebootThreadFinished) {
HandleRebootFinish();
} else if (sel == &m_Done) {
HandleDone();
break;
}
}
@@ -77,11 +76,11 @@ void RebootBE::Start() {

void RebootBE::Stop() {
SWSS_LOG_ENTER();
m_done.notify();
m_Done.notify();
return;
}

bool RebootBE::retrieve_notification_data(
bool RebootBE::RetrieveNotificationData(
swss::NotificationConsumer &consumer,
RebootBE::NotificationRequest &request) {
SWSS_LOG_ENTER();
@@ -107,20 +106,21 @@ bool RebootBE::retrieve_notification_data(
// code is swss::StatusCode, hopefully SWSS_RC_SUCCESS.
// message is json formatted RebootResponse, RebootStatusResponse
// or CancelRebootResponse as defined in system.proto
void RebootBE::send_notification_response(const std::string key,
void RebootBE::SendNotificationResponse(const std::string key,
const swss::StatusCode code,
const std::string message) {
SWSS_LOG_ENTER();

std::vector<swss::FieldValueTuple> ret_values;
ret_values.push_back(swss::FieldValueTuple(DATA_TUPLE_KEY, message));

m_rebootResponse.send(key, swss::statusCodeToStr(code), ret_values);
m_RebootResponse.send(key, swss::statusCodeToStr(code), ret_values);
}

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

SWSS_LOG_ENTER();

@@ -130,20 +130,20 @@ NotificationResponse RebootBE::handle_reboot_request(
.json_string = ""};

gnoi::system::RebootRequest request;
Status status = gpu::JsonStringToMessage(json_reboot_request, &request);
Status status = gpu::JsonStringToMessage(jsonRebootRequest, &request);

if (!status.ok()) {
std::string error_string =
"unable to convert json to rebootRequest protobuf: " +
status.message().as_string();
SWSS_LOG_ERROR("%s", error_string.c_str());
SWSS_LOG_ERROR("json = |%s|", json_reboot_request.c_str());
SWSS_LOG_ERROR("json = |%s|", jsonRebootRequest.c_str());
response.status = swss::StatusCode::SWSS_RC_INTERNAL,
response.json_string = error_string;
return response;
}

if (!reboot_allowed(request.method())) {
if (!RebootAllowed(request.method())) {
response.status = swss::StatusCode::SWSS_RC_IN_USE;
response.json_string =
"Reboot not allowed at this time. Reboot or "
@@ -154,7 +154,7 @@ NotificationResponse RebootBE::handle_reboot_request(

SWSS_LOG_NOTICE("Forwarding request to RebootThread: %s",
request.DebugString().c_str());
response = m_reboot_thread.Start(request);
response = m_RebootThread.Start(request);
if (response.status == swss::StatusCode::SWSS_RC_SUCCESS) {
if (request.method() == gnoi::system::RebootMethod::COLD) {
SetCurrentStatus(RebManagerStatus::COLD_REBOOT_IN_PROGRESS);
@@ -165,15 +165,15 @@ NotificationResponse RebootBE::handle_reboot_request(
return response;
}

bool RebootBE::reboot_allowed(const gnoi::system::RebootMethod reboot_method) {
bool RebootBE::RebootAllowed(const gnoi::system::RebootMethod rebMethod) {
RebManagerStatus current_status = GetCurrentStatus();
switch (current_status) {
case RebManagerStatus::COLD_REBOOT_IN_PROGRESS:
case RebManagerStatus::WARM_REBOOT_IN_PROGRESS: {
return false;
}
case RebManagerStatus::WARM_INIT_WAIT: {
return reboot_method == gnoi::system::RebootMethod::COLD;
return rebMethod == gnoi::system::RebootMethod::COLD;
}
case RebManagerStatus::IDLE: {
return true;
@@ -184,12 +184,12 @@ bool RebootBE::reboot_allowed(const gnoi::system::RebootMethod reboot_method) {
}
}

NotificationResponse RebootBE::handle_status_request(
const std::string &json_status_request) {
NotificationResponse RebootBE::HandleStatusRequest(
const std::string &jsonStatusRequest) {
SWSS_LOG_ENTER();

gnoi::system::RebootStatusResponse reboot_response =
m_reboot_thread.GetResponse();
m_RebootThread.GetResponse();

std::string json_reboot_response_string;
google::protobuf::util::Status status =
@@ -211,8 +211,8 @@ NotificationResponse RebootBE::handle_status_request(
return response;
}

NotificationResponse RebootBE::handle_cancel_request(
const std::string &json_cancel_request) {
NotificationResponse RebootBE::HandleCancelRequest(
const std::string &jsonCancelRequest) {
SWSS_LOG_ENTER();

NotificationResponse response;
@@ -225,59 +225,50 @@ NotificationResponse RebootBE::handle_cancel_request(
return response;
}

void RebootBE::do_task(swss::NotificationConsumer &consumer) {
void RebootBE::DoTask(swss::NotificationConsumer &consumer) {
SWSS_LOG_ENTER();

NotificationResponse response;
RebootBE::NotificationRequest request;

if (!retrieve_notification_data(consumer, request)) {
if (!RetrieveNotificationData(consumer, request)) {
// Response is simple string (not json) on error.
response.json_string =
"MESSAGE not present in reboot notification request message, op = " +
request.op;
SWSS_LOG_ERROR("%s", response.json_string.c_str());
response.status = swss::StatusCode::SWSS_RC_INVALID_PARAM;
} else if (request.op == REBOOT_KEY) {
response = handle_reboot_request(request.ret_string);
response = HandleRebootRequest(request.retString);
} else if (request.op == REBOOT_STATUS_KEY) {
response = handle_status_request(request.ret_string);
response = HandleStatusRequest(request.retString);
} else if (request.op == CANCEL_REBOOT_KEY) {
response = handle_cancel_request(request.ret_string);
response = HandleCancelRequest(request.retString);
} else {
// Response is simple string (not json) on error.
response.json_string =
"Unrecognized op in reboot request, op = " + request.op;
SWSS_LOG_ERROR("%s", response.json_string.c_str());
response.status = swss::StatusCode::SWSS_RC_INVALID_PARAM;
}
send_notification_response(request.op, response.status, response.json_string);
SendNotificationResponse(request.op, response.status, response.json_string);
}

void RebootBE::handle_init_finish() {
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("Receieved notification that InitThread is done");
RebManagerStatus current_status = GetCurrentStatus();
if (current_status == RebManagerStatus::WARM_INIT_WAIT) {
SetCurrentStatus(RebManagerStatus::IDLE);
}
}

void RebootBE::handle_reboot_finish() {
void RebootBE::HandleRebootFinish() {
SWSS_LOG_ENTER();
SWSS_LOG_WARN(
"Receieved notification that reboot has finished. This probably means "
"something is wrong");
m_reboot_thread.Join();
m_RebootThread.Join();
SetCurrentStatus(RebManagerStatus::IDLE);
}

void RebootBE::handle_done() {
void RebootBE::HandleDone() {
SWSS_LOG_INFO("RebootBE received signal to stop");

if (m_reboot_thread.GetResponse().active()) {
m_reboot_thread.Stop();
m_reboot_thread.Join();
if (m_RebootThread.GetResponse().active()) {
m_RebootThread.Stop();
m_RebootThread.Join();
}
}

Loading