From 821106a104eed25f4ed8b36442531f8f73b0af46 Mon Sep 17 00:00:00 2001 From: Kavitha Ramalingam Date: Thu, 24 Oct 2024 11:30:11 +0530 Subject: [PATCH] gNOI Cold Reboot - Integrated gNOI repository --- .gitmodules | 6 +- src/sonic-framework/gnoi | 1 + .../rebootbackend/init_thread.h | 136 ------------------ .../tests/reboot_thread_test.cpp | 1 - 4 files changed, 6 insertions(+), 138 deletions(-) create mode 160000 src/sonic-framework/gnoi delete mode 100644 src/sonic-framework/rebootbackend/init_thread.h diff --git a/.gitmodules b/.gitmodules index f8d10f3af4ab..2bd72c88a430 100644 --- a/.gitmodules +++ b/.gitmodules @@ -132,4 +132,8 @@ url = https://github.com/Marvell-switching/sonic-platform-marvell.git [submodule "platform/vpp"] path = platform/vpp - url = https://github.com/sonic-net/sonic-platform-vpp.git \ No newline at end of file + url = https://github.com/sonic-net/sonic-platform-vpp.git +[submodule "src/sonic-framework/gnoi"] + path = src/sonic-framework/gnoi + url = https://github.com/openconfig/gnoi + diff --git a/src/sonic-framework/gnoi b/src/sonic-framework/gnoi new file mode 160000 index 000000000000..73a1e7675c5f --- /dev/null +++ b/src/sonic-framework/gnoi @@ -0,0 +1 @@ +Subproject commit 73a1e7675c5f963e7810bd3828203f2758eb47e8 diff --git a/src/sonic-framework/rebootbackend/init_thread.h b/src/sonic-framework/rebootbackend/init_thread.h deleted file mode 100644 index 50c27d6c8c34..000000000000 --- a/src/sonic-framework/rebootbackend/init_thread.h +++ /dev/null @@ -1,136 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#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 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 lock(m_mutex); - return m_status.thread_state.active(); - } - - void set_detailed_thread_status(ThreadStatus new_status) { - const std::lock_guard lock(m_mutex); - if (m_status.thread_state.active()) { - m_status.detailed_thread_status = new_status; - } - } - - void set_success() { - const std::lock_guard 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 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 lock(m_mutex); - m_status.thread_state.set_active(false); - } - - DetailedStatus get_detailed_thread_status() { - const std::lock_guard lock(m_mutex); - return m_status; - } - - gnoi::system::RebootStatusResponse get_response() { - const std::lock_guard lock(m_mutex); - return m_status.thread_state; - } - - private: - std::mutex m_mutex; - DetailedStatus m_status; -}; - - -} // namespace rebootbackend diff --git a/src/sonic-framework/tests/reboot_thread_test.cpp b/src/sonic-framework/tests/reboot_thread_test.cpp index 983a18be3ea3..b040914f79ef 100644 --- a/src/sonic-framework/tests/reboot_thread_test.cpp +++ b/src/sonic-framework/tests/reboot_thread_test.cpp @@ -20,7 +20,6 @@ namespace rebootbackend { - namespace gpu = ::google::protobuf::util; using Progress = ::rebootbackend::RebootThread::Progress; using RebootThread = ::rebootbackend::RebootThread;