Skip to content

Commit 46eb26e

Browse files
authored
gNOI Warm Reboot - rebootbackend changes (#20786)
Enabled Rebootbackend to support gNOI Warm Reboot. Adding HALT method support in sonic-buildimage.
1 parent 23a6d00 commit 46eb26e

20 files changed

+2131
-1
lines changed

.gitmodules

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,7 @@
132132
url = https://github.com/Marvell-switching/sonic-platform-marvell.git
133133
[submodule "platform/vpp"]
134134
path = platform/vpp
135-
url = https://github.com/sonic-net/sonic-platform-vpp.git
135+
url = https://github.com/sonic-net/sonic-platform-vpp.git
136+
[submodule "src/sonic-framework/gnoi"]
137+
path = src/sonic-framework/gnoi
138+
url = https://github.com/openconfig/gnoi
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
2+
FROM docker-config-engine-bookworm-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}
3+
4+
ARG docker_container_name
5+
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf
6+
7+
## Make apt-get non-interactive
8+
ENV DEBIAN_FRONTEND=noninteractive
9+
10+
RUN apt-get update && \
11+
apt-get install -f -y \
12+
libdbus-1-3 \
13+
libdbus-c++-1-0v5
14+
15+
{% if docker_framework_debs.strip() -%}
16+
# Copy locally-built Debian package dependencies
17+
{{ copy_files("debs/", docker_framework_debs.split(' '), "/debs/") }}
18+
19+
# Install locally-built Debian packages and implicitly install their dependencies
20+
{{ install_debian_packages(docker_framework_debs.split(' ')) }}
21+
{%- endif %}
22+
23+
RUN apt-get clean -y && \
24+
apt-get autoclean - && \
25+
apt-get autoremove -y && \
26+
rm -rf /debs /var/lib/apt/lists/* /tmp/* ~/.cache/
27+
28+
# creating sonic conig_status file.
29+
RUN mkdir -p /var/sonic
30+
RUN echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status
31+
32+
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
33+
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
34+
COPY ["critical_processes", "/etc/supervisor"]
35+
36+
ENTRYPOINT ["/usr/local/bin/supervisord"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
program:rebootbackend

dockers/docker-framework/framework.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
4+
exec /usr/local/bin/framework --logtostderr
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[supervisord]
2+
logfile_maxbytes=1MB
3+
logfile_backups=2
4+
loglevel=warn
5+
nodaemon=true
6+
7+
[eventlistener:dependent-startup]
8+
command=python3 -m supervisord_dependent_startup --log-level warn
9+
autostart=true
10+
autorestart=unexpected
11+
stdout_logfile=syslog
12+
stderr_logfile=syslog
13+
startretries=0
14+
exitcodes=0,3
15+
events=PROCESS_STATE
16+
buffer_size=50
17+
18+
[eventlistener:supervisor-proc-exit-listener]
19+
command=/usr/bin/supervisor-proc-exit-listener --container-name framework
20+
events=PROCESS_STATE_EXITED
21+
autostart=true
22+
autorestart=unexpected
23+
stdout_logfile=syslog
24+
stderr_logfile=syslog
25+
26+
[program:rsyslogd]
27+
command=/usr/sbin/rsyslogd -n -iNONE
28+
priority=1
29+
autostart=false
30+
autorestart=unexpected
31+
stdout_logfile=syslog
32+
stderr_logfile=syslog
33+
dependent_startup=true
34+
35+
[program:rebootbackend]
36+
command=/usr/bin/rebootbackend
37+
priority=2
38+
autostart=false
39+
autorestart=true
40+
stdout_logfile=syslog
41+
stderr_logfile=syslog
42+
dependent_startup=true
43+
dependent_startup_wait_for=start:exited

src/sonic-framework/gnoi

Submodule gnoi added at 73a1e76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "interfaces.h"
2+
3+
#include <dbus-c++/dbus.h> // DBus
4+
5+
#include "reboot_interfaces.h"
6+
7+
constexpr char kRebootBusName[] = "org.SONiC.HostService.reboot";
8+
constexpr char kRebootPath[] = "/org/SONiC/HostService/reboot";
9+
10+
constexpr char kContainerShutdownBusName[] =
11+
"org.SONiC.HostService.container_shutdown";
12+
constexpr char kContainerShutdownPath[] =
13+
"/org/SONiC/HostService/container_shutdown";
14+
15+
DBus::Connection& HostServiceDbus::getConnection(void) {
16+
static DBus::Connection* connPtr = nullptr;
17+
if (connPtr == nullptr) {
18+
static DBus::BusDispatcher dispatcher;
19+
DBus::default_dispatcher = &dispatcher;
20+
21+
static DBus::Connection conn = DBus::Connection::SystemBus();
22+
connPtr = &conn;
23+
}
24+
return *connPtr;
25+
}
26+
27+
DbusInterface::DbusResponse HostServiceDbus::Reboot(
28+
const std::string& jsonRebootRequest) {
29+
int32_t status;
30+
31+
DbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath);
32+
std::string retString;
33+
std::vector<std::string> options;
34+
options.push_back(jsonRebootRequest);
35+
try {
36+
reboot_client.issue_reboot(options, status, retString);
37+
} catch (DBus::Error& ex) {
38+
return DbusResponse{
39+
DbusStatus::DBUS_FAIL,
40+
"HostServiceDbus::Reboot: failed to call reboot host service"};
41+
}
42+
43+
// reboot.py returns 0 for success, 1 for failure
44+
if (status == 0) {
45+
// Successful reboot response is an empty string.
46+
return DbusResponse{DbusStatus::DBUS_SUCCESS, ""};
47+
}
48+
return DbusResponse{DbusStatus::DBUS_FAIL, retString};
49+
}
50+
51+
DbusInterface::DbusResponse HostServiceDbus::RebootStatus(
52+
const std::string& jsonStatusRequest) {
53+
DbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath);
54+
int32_t status;
55+
std::string retString;
56+
57+
try {
58+
reboot_client.get_reboot_status(status, retString);
59+
} catch (DBus::Error& ex) {
60+
return DbusResponse{
61+
DbusStatus::DBUS_FAIL,
62+
"HostServiceDbus::RebootStatus: failed to call reboot status "
63+
"host service"};
64+
}
65+
66+
// reboot.py returns 0 for success, 1 for failure
67+
if (status == 0) {
68+
return DbusResponse{DbusStatus::DBUS_SUCCESS, retString};
69+
}
70+
return DbusResponse{DbusStatus::DBUS_FAIL, retString};
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include <dbus-c++/dbus.h>
3+
4+
#include <string>
5+
6+
#include "reboot_dbus.h" // auto generated reboot_proxy
7+
#include "reboot_interfaces.h"
8+
9+
class DbusReboot : public org::SONiC::HostService::reboot_proxy,
10+
public DBus::IntrospectableProxy,
11+
public DBus::ObjectProxy {
12+
public:
13+
DbusReboot(DBus::Connection& connection, const char* dbus_bus_name_p,
14+
const char* dbus_obj_name_p)
15+
: DBus::ObjectProxy(connection, dbus_obj_name_p, dbus_bus_name_p) {}
16+
};
17+
18+
class HostServiceDbus : public DbusInterface {
19+
public:
20+
DbusInterface::DbusResponse Reboot(
21+
const std::string& json_reboot_request) override;
22+
DbusInterface::DbusResponse RebootStatus(
23+
const std::string& json_status_request) override;
24+
25+
private:
26+
static DBus::Connection& getConnection(void);
27+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?ignore
2+
XML representation of dbus interface created by: sonic-host-services/host_modules/reboot.py
3+
4+
XML generated on switch by executing:
5+
dbus-send --system --type=method_call --print-reply --dest=org.SONiC.HostService.reboot /org/SONiC/HostService/reboot org.freedesktop.DBus.Introspectable.Introspect
6+
7+
C++ header file generated by:
8+
sudo apt-get install libdbus-c++-dev
9+
dbusxx-xml2cpp ./reboot.xml --proxy=reboot_dbus.h
10+
?>
11+
12+
<node name="/org/SONiC/HostService/reboot">
13+
<interface name="org.freedesktop.DBus.Introspectable">
14+
<method name="Introspect">
15+
<arg direction="out" type="s" />
16+
</method>
17+
</interface>
18+
<interface name="org.SONiC.HostService.reboot">
19+
<method name="issue_reboot">
20+
<arg direction="in" type="as" name="options" />
21+
<arg direction="out" type="i" />
22+
<arg direction="out" type="s" />
23+
</method>
24+
<method name="get_reboot_status">
25+
<arg direction="out" type="i" />
26+
<arg direction="out" type="s" />
27+
</method>
28+
</interface>
29+
</node>
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <time.h>
4+
5+
#include "status_code_util.h"
6+
7+
namespace rebootbackend {
8+
9+
extern bool sigterm_requested;
10+
struct NotificationResponse {
11+
swss::StatusCode status;
12+
std::string json_string;
13+
};
14+
15+
} // namespace rebootbackend
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
class DbusInterface {
6+
public:
7+
enum class DbusStatus {
8+
DBUS_SUCCESS,
9+
DBUS_FAIL,
10+
};
11+
12+
struct DbusResponse {
13+
DbusStatus status;
14+
std::string json_string;
15+
};
16+
17+
virtual ~DbusInterface() = default;
18+
virtual DbusResponse Reboot(const std::string& jsonRebootRequest) = 0;
19+
virtual DbusResponse RebootStatus(const std::string& jsonStatusRequest) = 0;
20+
};

0 commit comments

Comments
 (0)