Skip to content
9 changes: 8 additions & 1 deletion src/cm/communication/cloudprotocol/tests/alerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ std::unique_ptr<AlertVariant> CreateCoreAlert()
auto alertVariant = std::make_unique<AlertVariant>();
auto coreAlert = std::make_unique<CoreAlert>();

coreAlert->mTimestamp = Time::Unix(0);
coreAlert->mNodeID.Assign("test_node");
coreAlert->mCoreComponent = CoreComponentEnum::eCM;
coreAlert->mMessage.Assign("Test core alert message");
Expand All @@ -40,6 +41,7 @@ std::unique_ptr<AlertVariant> CreateResourceAllocateAlert()
auto alertVariant = std::make_unique<AlertVariant>();
auto alert = std::make_unique<ResourceAllocateAlert>();

alert->mTimestamp = Time::Unix(0);
alert->mItemID = "itemID";
alert->mSubjectID = "subjectID";
alert->mInstance = 1;
Expand All @@ -58,7 +60,8 @@ std::unique_ptr<AlertVariant> CreateDownloadAlert(const Optional<String>& reason
auto alertVariant = std::make_unique<AlertVariant>();
auto alert = std::make_unique<DownloadAlert>();

alert->mDigest = "testDigest";
alert->mTimestamp = Time::Unix(0);
alert->mDigest = "testDigest";
alert->mURL.Assign("http://example.com/download");
alert->mDownloadedBytes = 100;
alert->mTotalBytes = 1000;
Expand All @@ -80,6 +83,7 @@ std::unique_ptr<AlertVariant> CreateInstanceQuotaAlert()
auto alertVariant = std::make_unique<AlertVariant>();
auto alert = std::make_unique<InstanceQuotaAlert>();

alert->mTimestamp = Time::Unix(0);
alert->mItemID = "itemID";
alert->mSubjectID = "subjectID";
alert->mInstance = 1;
Expand All @@ -97,6 +101,7 @@ std::unique_ptr<AlertVariant> CreateInstanceAlert()
auto alertVariant = std::make_unique<AlertVariant>();
auto alert = std::make_unique<InstanceAlert>();

alert->mTimestamp = Time::Unix(0);
alert->mItemID = "itemID";
alert->mSubjectID = "subjectID";
alert->mInstance = 1;
Expand All @@ -114,6 +119,7 @@ std::unique_ptr<AlertVariant> CreateSystemAlert()
auto alertVariant = std::make_unique<AlertVariant>();
auto alert = std::make_unique<SystemAlert>();

alert->mTimestamp = Time::Unix(0);
alert->mNodeID.Assign("test_node");
alert->mMessage.Assign("Test system alert message");

Expand All @@ -127,6 +133,7 @@ std::unique_ptr<AlertVariant> CreateSystemQuotaAlert()
auto alertVariant = std::make_unique<AlertVariant>();
auto alert = std::make_unique<SystemQuotaAlert>();

alert->mTimestamp = Time::Unix(0);
alert->mNodeID.Assign("test_node");
alert->mParameter.Assign("test_parameter");
alert->mValue = 100;
Expand Down
8 changes: 7 additions & 1 deletion src/sm/alerts/tests/alerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ struct CheckAlertEqual : StaticVisitor<bool> {
{
}

bool Visit(const AlertType& src) const { return src == mVal; }
bool Visit(const AlertType& src) const
{
auto copy = src;
copy.mTimestamp = mVal.mTimestamp; // ignore timestamp in comparison

return copy == mVal;
}

template <typename T>
bool Visit(const T& src) const
Expand Down
12 changes: 3 additions & 9 deletions src/sm/launcher/runtimes/boot/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <common/utils/filesystem.hpp>
#include <common/utils/utils.hpp>

#include <sm/launcher/runtimes/utils/utils.hpp>

#include "boot.hpp"
#include "efibootcontroller.hpp"
#include "partitionmanager.hpp"
Expand Down Expand Up @@ -302,18 +304,10 @@ Error BootRuntime::CreateRuntimeInfo()
return AOS_ERROR_WRAP(err);
}

auto runtimeID = mConfig.mType + "-" + nodeInfo->mNodeID.CStr();

if (auto err = mRuntimeInfo.mRuntimeID.Assign(common::utils::NameUUID(runtimeID).c_str()); !err.IsNone()) {
return AOS_ERROR_WRAP(err);
}

if (auto err = mRuntimeInfo.mRuntimeType.Assign(mConfig.mType.c_str()); !err.IsNone()) {
if (auto err = utils::CreateRuntimeInfo(mConfig.mType, *nodeInfo, cMaxNumInstances, mRuntimeInfo); !err.IsNone()) {
return AOS_ERROR_WRAP(err);
}

mRuntimeInfo.mMaxInstances = 1;

mDefaultInstanceIdent.mType = UpdateItemTypeEnum::eComponent;
mDefaultInstanceIdent.mInstance = 0;
mDefaultInstanceIdent.mItemID = mRuntimeInfo.mRuntimeType;
Expand Down
1 change: 1 addition & 0 deletions src/sm/launcher/runtimes/boot/boot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class BootRuntime : public RuntimeItf {
static constexpr auto cImagesDir = "images";
static constexpr auto cMountDirName = "mnt";
static constexpr auto cUpdateStateFile = "update.state";
static constexpr auto cMaxNumInstances = 1;

struct BootData : public InstanceIdent {
StaticString<cVersionLen> mVersion;
Expand Down
2 changes: 1 addition & 1 deletion src/sm/launcher/runtimes/boot/efivar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef AOS_SM_LAUNCHER_RUNTIMES_BOOT_EFICONTROLLER_HPP_
#define AOS_SM_LAUNCHER_RUNTIMES_BOOT_EFICONTROLLER_HPP_

#include <efivar/efivar-types.h>
#include <efivar/efivar.h>

#include "itf/efivar.hpp"

Expand Down
8 changes: 8 additions & 0 deletions src/sm/launcher/runtimes/boot/tests/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ class BootRuntimeTest : public Test {
mNodeInfo.mNodeID = "node1";
mNodeInfo.mNodeType = "nodeType";

mNodeInfo.mCPUs.EmplaceBack();
mNodeInfo.mCPUs[0].mArchInfo.mArchitecture = "amd64";

mNodeInfo.mOSInfo.mOS = "linux";

EXPECT_CALL(mCurrentNodeInfoProvider, GetCurrentNodeInfo)
.WillRepeatedly(DoAll(SetArgReferee<0>(mNodeInfo), Return(ErrorEnum::eNone)));
}
Expand Down Expand Up @@ -240,6 +245,9 @@ TEST_F(BootRuntimeTest, GetRuntimeInfo)
EXPECT_EQ(info->mMaxInstances, 1u);
EXPECT_STREQ(info->mRuntimeID.CStr(), cRuntimeID);

EXPECT_STREQ(info->mArchInfo.mArchitecture.CStr(), "amd64");
EXPECT_STREQ(info->mOSInfo.mOS.CStr(), "linux");

err = mBootRuntime.Stop();
ASSERT_TRUE(err.IsNone()) << tests::utils::ErrorToStr(err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sm/launcher/runtimes/boot/tests/efibootcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

extern "C" {
#include <efivar/efiboot.h>
#include <efivar/efivar.h>
}
#include <efivar/efivar.h>

#include <gtest/gtest.h>

Expand Down
2 changes: 1 addition & 1 deletion src/sm/launcher/runtimes/container/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(SOURCES
# Libraries
# ######################################################################################################################

set(LIBRARIES Poco::JSON aos::common::utils aos::sm::utils)
set(LIBRARIES Poco::JSON aos::common::utils aos::sm::runtimes::utils aos::sm::utils)

# ######################################################################################################################
# Target
Expand Down
21 changes: 4 additions & 17 deletions src/sm/launcher/runtimes/container/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <common/utils/json.hpp>
#include <common/utils/utils.hpp>

#include <sm/launcher/runtimes/utils/utils.hpp>

#include "container.hpp"
#include "filesystem.hpp"
#include "monitoring.hpp"
Expand Down Expand Up @@ -37,7 +39,7 @@ Error ContainerRuntime::Init(const RuntimeConfig& config,
iamclient::CurrentNodeInfoProviderItf& currentNodeInfoProvider, // cppcheck-suppress constParameterReference
imagemanager::ItemInfoProviderItf& itemInfoProvider, networkmanager::NetworkManagerItf& networkManager,
iamclient::PermHandlerItf& permHandler, resourcemanager::ResourceInfoProviderItf& resourceInfoProvider,
oci::OCISpecItf& ociSpec, InstanceStatusReceiverItf& instanceStatusReceiver, utils::SystemdConnItf& systemdConn)
oci::OCISpecItf& ociSpec, InstanceStatusReceiverItf& instanceStatusReceiver, sm::utils::SystemdConnItf& systemdConn)
{
try {
LOG_DBG() << "Init runtime" << Log::Field("type", config.mType.c_str());
Expand Down Expand Up @@ -323,25 +325,10 @@ std::shared_ptr<MonitoringItf> ContainerRuntime::CreateMonitoring()

Error ContainerRuntime::CreateRuntimeInfo(const std::string& runtimeType, const NodeInfo& nodeInfo)
{
auto runtimeID = runtimeType + "-" + nodeInfo.mNodeID.CStr();

if (auto err = mRuntimeInfo.mRuntimeID.Assign(common::utils::NameUUID(runtimeID).c_str()); !err.IsNone()) {
return AOS_ERROR_WRAP(err);
}

if (auto err = mRuntimeInfo.mRuntimeType.Assign(runtimeType.c_str()); !err.IsNone()) {
if (auto err = utils::CreateRuntimeInfo(runtimeType, nodeInfo, cMaxNumInstances, mRuntimeInfo); !err.IsNone()) {
return AOS_ERROR_WRAP(err);
}

mRuntimeInfo.mOSInfo = nodeInfo.mOSInfo;

if (nodeInfo.mCPUs.IsEmpty()) {
return AOS_ERROR_WRAP(Error(ErrorEnum::eInvalidArgument, "can't define runtime arch info"));
}

mRuntimeInfo.mArchInfo = nodeInfo.mCPUs[0].mArchInfo;
mRuntimeInfo.mMaxInstances = cMaxNumInstances;

LOG_INF() << "Runtime info" << Log::Field("runtimeID", mRuntimeInfo.mRuntimeID)
<< Log::Field("runtimeType", mRuntimeInfo.mRuntimeType)
<< Log::Field("architecture", mRuntimeInfo.mArchInfo.mArchitecture)
Expand Down
2 changes: 1 addition & 1 deletion src/sm/launcher/runtimes/container/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ContainerRuntime : public RuntimeItf,
imagemanager::ItemInfoProviderItf& itemInfoProvider, networkmanager::NetworkManagerItf& networkManager,
aos::iamclient::PermHandlerItf& permHandler, resourcemanager::ResourceInfoProviderItf& resourceInfoProvider,
oci::OCISpecItf& ociSpec, InstanceStatusReceiverItf& instanceStatusReceiver,
utils::SystemdConnItf& systemdConn);
sm::utils::SystemdConnItf& systemdConn);

/**
* Starts runtime.
Expand Down
2 changes: 1 addition & 1 deletion src/sm/launcher/runtimes/container/itf/runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class RunnerItf {
* @param systemdConn systemd connection.
* @return Error.
*/
virtual Error Init(RunStatusReceiverItf& receiver, utils::SystemdConnItf& systemdConn) = 0;
virtual Error Init(RunStatusReceiverItf& receiver, sm::utils::SystemdConnItf& systemdConn) = 0;

/**
* Starts runner.
Expand Down
5 changes: 0 additions & 5 deletions src/sm/launcher/runtimes/container/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ Error Runner::StopInstance(const std::string& instanceID)
return err;
}

std::shared_ptr<utils::SystemdConnItf> Runner::CreateSystemdConn()
{
return std::make_shared<utils::SystemdConn>();
}

std::string Runner::GetSystemdDropInsDir() const
{
return cSystemdDropInsDir;
Expand Down
15 changes: 7 additions & 8 deletions src/sm/launcher/runtimes/container/runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Runner : public RunnerItf {
* @param systemdConn systemd connection.
* @return Error.
*/
Error Init(RunStatusReceiverItf& receiver, utils::SystemdConnItf& systemdConn) override;
Error Init(RunStatusReceiverItf& receiver, sm::utils::SystemdConnItf& systemdConn) override;

/**
* Starts monitoring thread.
Expand Down Expand Up @@ -81,8 +81,7 @@ class Runner : public RunnerItf {
static constexpr auto cSystemdDropInsDir = "/run/systemd/system";
static constexpr auto cParametersFileName = "parameters.conf";

virtual std::shared_ptr<utils::SystemdConnItf> CreateSystemdConn();
virtual std::string GetSystemdDropInsDir() const;
virtual std::string GetSystemdDropInsDir() const;

void MonitorUnits();
std::vector<RunStatus>& GetRunningInstances() const;
Expand All @@ -95,7 +94,7 @@ class Runner : public RunnerItf {

struct StartingUnitData {
std::condition_variable mCondVar;
utils::UnitState mRunState;
sm::utils::UnitState mRunState;
Optional<int32_t> mExitCode;
};

Expand All @@ -106,10 +105,10 @@ class Runner : public RunnerItf {

RunStatusReceiverItf* mRunStatusReceiver = nullptr;

utils::SystemdConnItf* mSystemd = {};
std::thread mMonitoringThread;
std::mutex mMutex;
std::condition_variable mCondVar;
sm::utils::SystemdConnItf* mSystemd = {};
std::thread mMonitoringThread;
std::mutex mMutex;
std::condition_variable mCondVar;

std::map<std::string, StartingUnitData> mStartingUnits;
std::map<std::string, RunningUnitData> mRunningUnits;
Expand Down
13 changes: 4 additions & 9 deletions src/sm/launcher/runtimes/rootfs/rootfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <common/utils/json.hpp>
#include <common/utils/utils.hpp>

#include <sm/launcher/runtimes/utils/utils.hpp>

#include "config.hpp"
#include "rootfs.hpp"

Expand Down Expand Up @@ -295,18 +297,11 @@ Error RootfsRuntime::CreateRuntimeInfo()
return AOS_ERROR_WRAP(err);
}

auto runtimeID = mRuntimeConfig.mType + "-" + nodeInfo->mNodeID.CStr();

if (auto err = mRuntimeInfo.mRuntimeID.Assign(common::utils::NameUUID(runtimeID).c_str()); !err.IsNone()) {
return AOS_ERROR_WRAP(err);
}

if (auto err = mRuntimeInfo.mRuntimeType.Assign(mRuntimeConfig.mType.c_str()); !err.IsNone()) {
if (auto err = utils::CreateRuntimeInfo(mRuntimeConfig.mType, *nodeInfo, cMaxNumInstances, mRuntimeInfo);
!err.IsNone()) {
return AOS_ERROR_WRAP(err);
}

mRuntimeInfo.mMaxInstances = 1;

mDefaultInstanceIdent.mType = UpdateItemTypeEnum::eComponent;
mDefaultInstanceIdent.mInstance = 0;
mDefaultInstanceIdent.mItemID = mRuntimeInfo.mRuntimeType;
Expand Down
1 change: 1 addition & 0 deletions src/sm/launcher/runtimes/rootfs/rootfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class RootfsRuntime : public RuntimeItf {
static constexpr auto cIncrementalMediaTypePrefix = "vnd.aos.image.component.inc";
static constexpr auto cInstalledInstanceFileName = "installed_instance.json";
static constexpr auto cPendingInstanceFileName = "pending_instance.json";
static constexpr auto cMaxNumInstances = 1;

/**
* Action type type.
Expand Down
7 changes: 7 additions & 0 deletions src/sm/launcher/runtimes/rootfs/tests/rootfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class RootfsRuntimeTest : public Test {
nodeInfo.mNodeID = "nodeId";
nodeInfo.mNodeType = "nodeType";

nodeInfo.mCPUs.EmplaceBack();
nodeInfo.mCPUs[0].mArchInfo.mArchitecture = "amd64";

nodeInfo.mOSInfo.mOS = "linux";

return ErrorEnum::eNone;
}));
}
Expand Down Expand Up @@ -209,6 +214,8 @@ TEST_F(RootfsRuntimeTest, GetRuntimeInfo)
EXPECT_EQ(info->mMaxInstances, 1u);
EXPECT_STREQ(info->mRuntimeID.CStr(), GetExpectedRuntimeID().c_str());

EXPECT_STREQ(info->mArchInfo.mArchitecture.CStr(), "amd64");
EXPECT_STREQ(info->mOSInfo.mOS.CStr(), "linux");
err = mRootfsRuntime.Stop();
ASSERT_TRUE(err.IsNone()) << tests::utils::ErrorToStr(err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sm/launcher/runtimes/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(TARGET_NAME utils)
# Sources
# ######################################################################################################################

set(SOURCES systemdrebooter.cpp systemdupdatechecker.cpp)
set(SOURCES systemdrebooter.cpp systemdupdatechecker.cpp utils.cpp)

# ######################################################################################################################
# Libraries
Expand Down
2 changes: 1 addition & 1 deletion src/sm/launcher/runtimes/utils/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(TARGET_NAME utils_test)
# Sources
# ######################################################################################################################

set(SOURCES systemdrebooter.cpp systemdupdatechecker.cpp)
set(SOURCES systemdrebooter.cpp systemdupdatechecker.cpp utils.cpp)

# ######################################################################################################################
# Libraries
Expand Down
Loading
Loading