Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gNOI Warm Reboot - Added tests #20801

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/sonic-framework/rebootbackend/interfaces.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "interfaces.h"

#include <dbus-c++/dbus.h> // DBus

// #include "component_state_helper.h"
#include "reboot_interfaces.h"

constexpr char kRebootBusName[] = "org.SONiC.HostService.reboot";
constexpr char kRebootPath[] = "/org/SONiC/HostService/reboot";

constexpr char kContainerShutdownBusName[] =
"org.SONiC.HostService.container_shutdown";
constexpr char kContainerShutdownPath[] =
"/org/SONiC/HostService/container_shutdown";

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

static DBus::Connection conn = DBus::Connection::SystemBus();
connPtr = &conn;
}
return *connPtr;
}

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

DbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath);
std::string retString;
std::vector<std::string> options;
options.push_back(jsonRebootRequest);
try {
reboot_client.issue_reboot(options, status, retString);
} catch (DBus::Error& ex) {
return DbusResponse{
DbusStatus::DBUS_FAIL,
"HostServiceDbus::Reboot: failed to call reboot host service"};
}

// reboot.py returns 0 for success, 1 for failure
if (status == 0) {
// Successful reboot response is an empty string.
return DbusResponse{DbusStatus::DBUS_SUCCESS, ""};
}
return DbusResponse{DbusStatus::DBUS_FAIL, retString};
}

DbusInterface::DbusResponse HostServiceDbus::RebootStatus(
const std::string& jsonStatusRequest) {
DbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath);
int32_t status;
std::string retString;

try {
reboot_client.get_reboot_status(status, retString);
} catch (DBus::Error& ex) {
return DbusResponse{
DbusStatus::DBUS_FAIL,
"HostServiceDbus::RebootStatus: failed to call reboot status "
"host service"};
}

// reboot.py returns 0 for success, 1 for failure
if (status == 0) {
return DbusResponse{DbusStatus::DBUS_SUCCESS, retString};
}
return DbusResponse{DbusStatus::DBUS_FAIL, retString};
}
39 changes: 39 additions & 0 deletions src/sonic-framework/rebootbackend/interfaces.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
#include <dbus-c++/dbus.h>

#include <string>

#include "reboot_dbus.h" // auto generated reboot_proxy
#include "reboot_interfaces.h"

/* Reboot is a request to the reboot sonic host service to request a reboot
from the platform. This takes as an argument a string based json formatted
Reboot request from
system.proto.’https://github.com/openconfig/gnoi/blob/73a1e7675c5f963e7810bd3828203f2758eb47e8/system/system.proto#L107
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link can easily go stale, suggest simply using https://github.com/openconfig/gnoi/blob/main/system/system.proto

*/

class DbusReboot : public org::SONiC::HostService::reboot_proxy,
public DBus::IntrospectableProxy,
public DBus::ObjectProxy {
public:
DbusReboot(DBus::Connection& connection, const char* dbus_bus_name_p,
const char* dbus_obj_name_p)
: DBus::ObjectProxy(connection, dbus_obj_name_p, dbus_bus_name_p) {}
};

/* DbusResponse consists of STATUS: success/fail: i.e. was the dbus request
successful DbusResponse.json_string: string based json formatted RebootResponse
defined here:
https://github.com/openconfig/gnoi/blob/73a1e7675c5f963e7810bd3828203f2758eb47e8/system/system.proto#L119
*/

class HostServiceDbus : public DbusInterface {
public:
DbusInterface::DbusResponse Reboot(
const std::string& json_reboot_request) override;
DbusInterface::DbusResponse RebootStatus(
const std::string& json_status_request) override;

private:
static DBus::Connection& getConnection(void);
};
30 changes: 30 additions & 0 deletions src/sonic-framework/rebootbackend/reboot.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?ignore
XML representation of dbus interface created by: sonic-host-services/host_modules/reboot.py

XML generated on switch by executing:
dbus-send --system --type=method_call --print-reply --dest=org.SONiC.HostService.reboot /org/SONiC/HostService/reboot org.freedesktop.DBus.Introspectable.Introspect

C++ header file generated by:
sudo apt-get install libdbus-c++-dev
dbusxx-xml2cpp ./reboot.xml --proxy=reboot_dbus.h
?>

<node name="/org/SONiC/HostService/reboot">
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg direction="out" type="s" />
</method>
</interface>
<interface name="org.SONiC.HostService.reboot">
<method name="issue_reboot">
<arg direction="in" type="as" name="options" />
<arg direction="out" type="i" />
<arg direction="out" type="s" />
</method>
<method name="get_reboot_status">
<arg direction="out" type="i" />
<arg direction="out" type="s" />
</method>
</interface>
</node>

15 changes: 15 additions & 0 deletions src/sonic-framework/rebootbackend/reboot_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <time.h>

#include "status_code_util.h"

namespace rebootbackend {

extern bool sigterm_requested;
struct NotificationResponse {
swss::StatusCode status;
std::string json_string;
};

} // namespace rebootbackend
20 changes: 20 additions & 0 deletions src/sonic-framework/rebootbackend/reboot_interfaces.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <string>

class DbusInterface {
public:
enum class DbusStatus {
DBUS_SUCCESS,
DBUS_FAIL,
};

struct DbusResponse {
DbusStatus status;
std::string json_string;
};

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