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 Cold Reboot - Integrated tests #20690

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 33 additions & 0 deletions dockers/docker-framework/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-config-engine-bullseye-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}

ARG docker_container_name
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -f -y \
libdbus-1-3 \
libdbus-c++-1-0v5

{% if docker_framework_debs.strip() -%}
# Copy locally-built Debian package dependencies
{{ copy_files("debs/", docker_framework_debs.split(' '), "/debs/") }}

# Install locally-built Debian packages and implicitly install their dependencies
{{ install_debian_packages(docker_framework_debs.split(' ')) }}
{%- endif %}

RUN apt-get clean -y && \
apt-get autoclean - && \
apt-get autoremove -y && \
rm -rf /debs /var/lib/apt/lists/* /tmp/* ~/.cache/

COPY ["start.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
# COPY ["git_commits", "/usr"]

ENTRYPOINT ["/usr/local/bin/supervisord"]
3 changes: 3 additions & 0 deletions dockers/docker-framework/framework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

exec /usr/local/bin/framework --logtostderr
4 changes: 4 additions & 0 deletions dockers/docker-framework/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status
55 changes: 55 additions & 0 deletions dockers/docker-framework/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[supervisord]
logfile_maxbytes=1MB
logfile_backups=2
loglevel=warn
nodaemon=true

[eventlistener:dependent-startup]
command=python3 -m supervisord_dependent_startup --log-level warn
autostart=true
autorestart=unexpected
stdout_logfile=syslog
stderr_logfile=syslog
startretries=0
exitcodes=0,3
events=PROCESS_STATE
buffer_size=50

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener --container-name framework
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
stdout_logfile=syslog
stderr_logfile=syslog

[program:rsyslogd]
command=/usr/sbin/rsyslogd -n -iNONE
priority=1
autostart=false
autorestart=unexpected
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true

[program:start]
command=/usr/bin/start.sh
priority=2
autostart=false
autorestart=false
startsecs=0
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=rsyslogd:running

[program:rebootbackend]
command=/usr/bin/rebootbackend
priority=3
autostart=false
autorestart=true
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=start:exited

30 changes: 30 additions & 0 deletions src/sonic-framework/rebootbackend/gnoi_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/gnoi_reboot.py

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

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

<node name="/org/SONiC/HostService/gnoi_reboot">
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg direction="out" type="s" />
</method>
</interface>
<interface name="org.SONiC.HostService.gnoi_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>

72 changes: 72 additions & 0 deletions src/sonic-framework/rebootbackend/gnoi_reboot_dbus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

/*
* This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT!
*/

#ifndef __dbusxx__rebootbackend_gnoi_reboot_dbus_h__PROXY_MARSHAL_H
#define __dbusxx__rebootbackend_gnoi_reboot_dbus_h__PROXY_MARSHAL_H

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

namespace org {
namespace SONiC {
namespace HostService {

class gnoi_reboot_proxy
: public ::DBus::InterfaceProxy
{
public:

gnoi_reboot_proxy()
: ::DBus::InterfaceProxy("org.SONiC.HostService.gnoi_reboot")
{
}

public:

/* properties exported by this interface */
public:

/* methods exported by this interface,
* this functions will invoke the corresponding methods on the remote objects
*/
void issue_reboot(const std::vector< std::string >& options, int32_t& argout0, std::string& argout1)
{
::DBus::CallMessage call;
::DBus::MessageIter wi = call.writer();

wi << options;
call.member("issue_reboot");
::DBus::Message ret = invoke_method (call);
::DBus::MessageIter ri = ret.reader();

ri >> argout0;
ri >> argout1;
}

void get_reboot_status(int32_t& argout0, std::string& argout1)
{
::DBus::CallMessage call;
call.member("get_reboot_status");
::DBus::Message ret = invoke_method (call);
::DBus::MessageIter ri = ret.reader();

ri >> argout0;
ri >> argout1;
}


public:

/* signal handlers for this interface
*/

private:

/* unmarshalers (to unpack the DBus message before calling the actual signal handler)
*/
};

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

#include <mutex>
#include <thread>
#include <unordered_set>
#include <vector>

#include "dbconnector.h"
#include "notificationproducer.h"
#include "reboot_common.h"
#include "reboot_interfaces.h"
#include "redis_utils.h"
#include "select.h"
#include "selectableevent.h"
#include "selectabletimer.h"
#include "subscriberstatetable.h"
#include "system/system.pb.h"

namespace rebootbackend {

// Holds a thread safe representation of the InitThread internal state.
// Thread-safe: the expectation is one thread will write and multiple threads
// will read.
class InitThreadStatus {
public:
enum ThreadStatus {
NOT_STARTED = 0,
PENDING = 1,
WAITING_FOR_REGISTRATION = 2,
WAITING_FOR_RECONCILIATION = 3,
WAITING_FOR_STATE_VERIFICATION = 4,
WAITING_FOR_UNFREEZE = 5,
FINALIZE = 6,
DONE = 7,
ERROR = 8,
};

enum ErrorCondition {
NO_ERROR = 0,
UNKNOWN = 1,
INTERNAL_ERROR = 2,
REGISTRATION_FAILED = 3,
RECONCILIATION_FAILED = 4,
STATE_VERIFICATION_FAILED = 5,
UNFREEZE_FAILED = 6,
DETECTED_CRITICAL_STATE = 7,
};

struct DetailedStatus {
gnoi::system::RebootStatusResponse thread_state;
InitThreadStatus::ThreadStatus detailed_thread_status =
InitThreadStatus::ThreadStatus::NOT_STARTED;
InitThreadStatus::ErrorCondition detailed_thread_error_condition =
InitThreadStatus::ErrorCondition::NO_ERROR;
};

InitThreadStatus() {
m_status.detailed_thread_status = ThreadStatus::NOT_STARTED;
m_status.detailed_thread_error_condition = ErrorCondition::NO_ERROR;

m_status.thread_state.set_active(false);
m_status.thread_state.set_method(gnoi::system::RebootMethod::COLD);
m_status.thread_state.mutable_status()->set_status(
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS);
m_status.thread_state.mutable_status()->set_message("");
}

void set_start_status() {
const std::lock_guard<std::mutex> lock(m_mutex);
m_status.detailed_thread_status = ThreadStatus::PENDING;
m_status.detailed_thread_error_condition = ErrorCondition::NO_ERROR;

m_status.thread_state.set_active(true);
m_status.thread_state.set_method(gnoi::system::RebootMethod::NSF);
m_status.thread_state.mutable_status()->set_status(
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN);
m_status.thread_state.mutable_status()->set_message("");
}

bool get_active(void) {
const std::lock_guard<std::mutex> lock(m_mutex);
return m_status.thread_state.active();
}

void set_detailed_thread_status(ThreadStatus new_status) {
const std::lock_guard<std::mutex> lock(m_mutex);
if (m_status.thread_state.active()) {
m_status.detailed_thread_status = new_status;
}
}

void set_success() {
const std::lock_guard<std::mutex> lock(m_mutex);
if (m_status.thread_state.active()) {
m_status.detailed_thread_status = ThreadStatus::DONE;
m_status.thread_state.mutable_status()->set_status(
gnoi::system::RebootStatus_Status::
RebootStatus_Status_STATUS_SUCCESS);
}
}

void set_error(ErrorCondition error_condition,
const std::string &error_message) {
const std::lock_guard<std::mutex> lock(m_mutex);
if (m_status.thread_state.active()) {
m_status.detailed_thread_status = ThreadStatus::ERROR;
m_status.detailed_thread_error_condition = error_condition;
m_status.thread_state.mutable_status()->set_status(
gnoi::system::RebootStatus_Status::
RebootStatus_Status_STATUS_FAILURE);
m_status.thread_state.mutable_status()->set_message(error_message);
}
}

void set_inactive() {
const std::lock_guard<std::mutex> lock(m_mutex);
m_status.thread_state.set_active(false);
}

DetailedStatus get_detailed_thread_status() {
const std::lock_guard<std::mutex> lock(m_mutex);
return m_status;
}

gnoi::system::RebootStatusResponse get_response() {
const std::lock_guard<std::mutex> lock(m_mutex);
return m_status.thread_state;
}

private:
std::mutex m_mutex;
DetailedStatus m_status;
};


} // namespace rebootbackend
Loading
Loading