diff --git a/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_config_loader_UT.cpp b/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_config_loader_UT.cpp index 85c4e1b3c..fad631d1f 100644 --- a/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_config_loader_UT.cpp +++ b/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_config_loader_UT.cpp @@ -79,8 +79,8 @@ ::flatbuffers::Offset buildDefaultDeploymentConfig(::flatb auto sandbox = buildDefaultSandbox(fbb); return fb::CreateDeploymentConfig( fbb, - 1.0 /*ready_timeout*/, - 1.0 /*shutdown_timeout*/, + 1000 /*ready_timeout_ms*/, + 1000 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -111,8 +111,9 @@ std::vector buildConfigWithComponents( ::flatbuffers::FlatBufferBuilder& fbb, ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> comps) { - auto fallback = fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1.0 /*transition_timeout*/); - auto alive_sup = fb::CreateAliveSupervision(fbb, 1.0 /*evaluation_cycle*/); + auto fallback = + fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1000 /*transition_timeout_ms*/); + auto alive_sup = fb::CreateAliveSupervision(fbb, 1000 /*evaluation_cycle_ms*/); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto irt = fbb.CreateString("Startup"); auto config = fb::CreateLaunchManagerConfig( @@ -124,8 +125,9 @@ std::vector buildConfigWithRunTargets( ::flatbuffers::FlatBufferBuilder& fbb, ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> rts) { - auto fallback = fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1.0 /*transition_timeout*/); - auto alive_sup = fb::CreateAliveSupervision(fbb, 1.0 /*evaluation_cycle*/); + auto fallback = + fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1000 /*transition_timeout_ms*/); + auto alive_sup = fb::CreateAliveSupervision(fbb, 1000 /*evaluation_cycle_ms*/); auto comps = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto irt = fbb.CreateString("Startup"); auto config = fb::CreateLaunchManagerConfig( @@ -163,8 +165,8 @@ class FlatbufferConfigLoaderTest : public ::testing::Test ::flatbuffers::FlatBufferBuilder fbb; auto irt = fbb.CreateString(initial_run_target); auto fallback = - fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1.0 /*transition_timeout*/); - auto alive_sup = fb::CreateAliveSupervision(fbb, 1.0 /*evaluation_cycle*/); + fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1000 /*transition_timeout_ms*/); + auto alive_sup = fb::CreateAliveSupervision(fbb, 1000 /*evaluation_cycle_ms*/); auto comps = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto config = fb::CreateLaunchManagerConfig(fbb, schema_version, comps, rts, irt, fallback, alive_sup); @@ -204,7 +206,7 @@ TEST_F(FlatbufferConfigLoaderTest, LoadSingleComponent) ::flatbuffers::FlatBufferBuilder fbb; auto alive_sup = fb::CreateComponentAliveSupervision( - fbb, 0.5 /*reporting_cycle*/, 2 /*failed_cycles_tolerance*/, 1 /*min_indications*/, 3 /*max_indications*/); + fbb, 500 /*reporting_cycle_ms*/, 2 /*failed_cycles_tolerance*/, 1 /*min_indications*/, 3 /*max_indications*/); auto app_profile = fb::CreateApplicationProfile( fbb, fb::ApplicationType::Reporting_And_Supervised, true /*is_self_terminating*/, alive_sup); auto bin_name = fbb.CreateString("my_binary"); @@ -220,8 +222,8 @@ TEST_F(FlatbufferConfigLoaderTest, LoadSingleComponent) auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - 1.5 /*ready_timeout*/, - 2.5 /*shutdown_timeout*/, + 1500 /*ready_timeout_ms*/, + 2500 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -277,7 +279,7 @@ TEST_F(FlatbufferConfigLoaderTest, LoadRunTargets) auto rt_desc = fbb.CreateString("Initial state"); auto rt_dep = fbb.CreateString("component_a"); auto rt_deps = fbb.CreateVector(std::vector<::flatbuffers::Offset<::flatbuffers::String>>{rt_dep}); - auto rt = fb::CreateRunTarget(fbb, rt_name, rt_desc, rt_deps, 5.0 /*transition_timeout*/, switch_action); + auto rt = fb::CreateRunTarget(fbb, rt_name, rt_desc, rt_deps, 5000 /*transition_timeout_ms*/, switch_action); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{rt}); auto result = loadBuffer(buildConfigWithRunTargets(fbb, rts)); @@ -303,9 +305,9 @@ TEST_F(FlatbufferConfigLoaderTest, LoadFallbackRunTarget) auto fb_desc = fbb.CreateString("Fallback state"); auto fb_dep = fbb.CreateString("critical_comp"); auto fb_deps = fbb.CreateVector(std::vector<::flatbuffers::Offset<::flatbuffers::String>>{fb_dep}); - auto fallback = fb::CreateFallbackRunTarget(fbb, fb_desc, fb_deps, 10.0 /*transition_timeout*/); + auto fallback = fb::CreateFallbackRunTarget(fbb, fb_desc, fb_deps, 10000 /*transition_timeout_ms*/); - auto alive_sup = fb::CreateAliveSupervision(fbb, 1.0 /*evaluation_cycle*/); + auto alive_sup = fb::CreateAliveSupervision(fbb, 1000 /*evaluation_cycle_ms*/); auto comps = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto irt = fbb.CreateString("Startup"); @@ -328,8 +330,9 @@ TEST_F(FlatbufferConfigLoaderTest, LoadAliveSupervision) ::flatbuffers::FlatBufferBuilder fbb; - auto alive_sup = fb::CreateAliveSupervision(fbb, 0.25 /*evaluation_cycle*/); - auto fallback = fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1.0 /*transition_timeout*/); + auto alive_sup = fb::CreateAliveSupervision(fbb, 250 /*evaluation_cycle_ms*/); + auto fallback = + fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1000 /*transition_timeout_ms*/); auto comps = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto irt = fbb.CreateString("Startup"); @@ -350,10 +353,11 @@ TEST_F(FlatbufferConfigLoaderTest, LoadWatchdog) auto dev_path = fbb.CreateString("/dev/watchdog0"); auto watchdog = fb::CreateWatchdog( - fbb, dev_path, 30.0 /*max_timeout*/, true /*deactivate_on_shutdown*/, false /*require_magic_close*/); + fbb, dev_path, 30000 /*max_timeout_ms*/, true /*deactivate_on_shutdown*/, false /*require_magic_close*/); - auto fallback = fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1.0 /*transition_timeout*/); - auto alive_sup = fb::CreateAliveSupervision(fbb, 1.0 /*evaluation_cycle*/); + auto fallback = + fb::CreateFallbackRunTarget(fbb, 0 /*description*/, 0 /*depends_on*/, 1000 /*transition_timeout_ms*/); + auto alive_sup = fb::CreateAliveSupervision(fbb, 1000 /*evaluation_cycle_ms*/); auto comps = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto irt = fbb.CreateString("Startup"); @@ -378,14 +382,14 @@ TEST_F(FlatbufferConfigLoaderTest, LoadRestartRecoveryAction) ::flatbuffers::FlatBufferBuilder fbb; - auto restart = fb::CreateRestartAction(fbb, 3 /*number_of_attempts*/, 1.5 /*delay_before_restart*/); + auto restart = fb::CreateRestartAction(fbb, 3 /*number_of_attempts*/, 1500 /*delay_before_restart_ms*/); auto bin_dir = fbb.CreateString("/opt"); auto work_dir = fbb.CreateString("/tmp"); auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - 1.0 /*ready_timeout*/, - 1.0 /*shutdown_timeout*/, + 1000 /*ready_timeout_ms*/, + 1000 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -417,7 +421,7 @@ TEST_F(FlatbufferConfigLoaderTest, LoadSwitchRunTargetAction) auto switch_action = fb::CreateSwitchRunTargetAction(fbb, target_name); auto rt_name = fbb.CreateString("Startup"); auto rt = fb::CreateRunTarget( - fbb, rt_name, 0 /*description*/, 0 /*depends_on*/, 1.0 /*transition_timeout*/, switch_action); + fbb, rt_name, 0 /*description*/, 0 /*depends_on*/, 1000 /*transition_timeout_ms*/, switch_action); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{rt}); auto result = loadBuffer(buildConfigWithRunTargets(fbb, rts)); @@ -449,8 +453,8 @@ TEST_F(FlatbufferConfigLoaderTest, LoadSandbox) auto work_dir = fbb.CreateString("/tmp"); auto deploy = fb::CreateDeploymentConfig( fbb, - 0.5 /*ready_timeout*/, - 0.5 /*shutdown_timeout*/, + 500 /*ready_timeout_ms*/, + 500 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -487,7 +491,7 @@ TEST_F(FlatbufferConfigLoaderTest, LoadComponentAliveSupervision) ::flatbuffers::FlatBufferBuilder fbb; auto comp_alive_sup = fb::CreateComponentAliveSupervision( - fbb, 1.0 /*reporting_cycle*/, 3 /*failed_cycles_tolerance*/, 2 /*min_indications*/, 5 /*max_indications*/); + fbb, 1000 /*reporting_cycle_ms*/, 3 /*failed_cycles_tolerance*/, 2 /*min_indications*/, 5 /*max_indications*/); auto app_profile = fb::CreateApplicationProfile( fbb, fb::ApplicationType::Reporting_And_Supervised, false /*is_self_terminating*/, comp_alive_sup); auto bin_name = fbb.CreateString("supervised_bin"); @@ -530,8 +534,8 @@ TEST_F(FlatbufferConfigLoaderTest, LoadEnvironmentalVariables) auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - 0.5 /*ready_timeout*/, - 0.5 /*shutdown_timeout*/, + 500 /*ready_timeout_ms*/, + 500 /*shutdown_timeout_ms*/, env_vars, bin_dir, work_dir, @@ -682,8 +686,8 @@ TEST_F(FlatbufferConfigLoaderTest, MissingSchemaVersionReturnsInvalidFormat) ::flatbuffers::FlatBufferBuilder fbb; auto irt = fbb.CreateString("Startup"); - auto fallback = fb::CreateFallbackRunTarget(fbb, 0, 0, 1.0); - auto alive_sup = fb::CreateAliveSupervision(fbb, 1.0); + auto fallback = fb::CreateFallbackRunTarget(fbb, 0, 0, 1000); + auto alive_sup = fb::CreateAliveSupervision(fbb, 1000); auto comps = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{}); auto config = fb::CreateLaunchManagerConfig(fbb, std::nullopt, comps, rts, irt, fallback, alive_sup); diff --git a/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters.cpp b/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters.cpp index 6c5c4f0fd..158a263af 100644 --- a/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters.cpp +++ b/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -57,29 +56,6 @@ std::optional optionalScalarValue(const ::flatbuffers::Optional& field) namespace details { -constexpr double kSecondsToMilliseconds = 1000.0; - -score::cpp::expected secondsToMs(double seconds) -{ - if (seconds < 0.0) - { - LM_LOG_ERROR() << "Negative time value " << seconds << " seconds is not supported"; - return score::cpp::make_unexpected(IConfigLoader::Error::InvalidFormat); - } - if (seconds * kSecondsToMilliseconds > static_cast(std::numeric_limits::max())) - { - LM_LOG_ERROR() << "Time value " << seconds << " seconds exceeds maximum representable milliseconds"; - return score::cpp::make_unexpected(IConfigLoader::Error::InvalidFormat); - } - const auto result = static_cast(seconds * kSecondsToMilliseconds); - if (seconds > 0.0 && result == 0U) - { - LM_LOG_ERROR() << "Sub-millisecond time value " << seconds << " seconds rounds to 0ms"; - return score::cpp::make_unexpected(IConfigLoader::Error::InvalidFormat); - } - return result; -} - ApplicationType convertApplicationType(fb::ApplicationType fb_type) { switch (fb_type) @@ -198,18 +174,13 @@ score::cpp::expected, IConfigLoader::Error> convert { return score::cpp::make_unexpected(number_of_attempts.error()); } - auto delay_before_restart = requireScalarValue(ra->delay_before_restart(), "RestartAction::delay_before_restart"); + auto delay_before_restart = + requireScalarValue(ra->delay_before_restart_ms(), "RestartAction::delay_before_restart_ms"); if (!delay_before_restart.has_value()) { return score::cpp::make_unexpected(delay_before_restart.error()); } - auto delay_ms = secondsToMs(*delay_before_restart); - if (!delay_ms.has_value()) - { - LM_LOG_ERROR() << "Invalid value for RestartAction::delay_before_restart"; - return score::cpp::make_unexpected(delay_ms.error()); - } - return std::optional{RestartAction{*number_of_attempts, *delay_ms}}; + return std::optional{RestartAction{*number_of_attempts, *delay_before_restart}}; } std::optional convertSwitchRunTargetAction(const fb::SwitchRunTargetAction* sa) @@ -237,7 +208,7 @@ score::cpp::expected convertCom if (fb_cas != nullptr) { auto reporting_cycle = - requireScalarValue(fb_cas->reporting_cycle(), "ComponentAliveSupervision::reporting_cycle"); + requireScalarValue(fb_cas->reporting_cycle_ms(), "ComponentAliveSupervision::reporting_cycle_ms"); if (!reporting_cycle.has_value()) { return score::cpp::make_unexpected(reporting_cycle.error()); @@ -248,13 +219,7 @@ score::cpp::expected convertCom { return score::cpp::make_unexpected(failed_cycles_tolerance.error()); } - auto reporting_cycle_ms = secondsToMs(*reporting_cycle); - if (!reporting_cycle_ms.has_value()) - { - LM_LOG_ERROR() << "Invalid value for ComponentAliveSupervision::reporting_cycle"; - return score::cpp::make_unexpected(reporting_cycle_ms.error()); - } - result.reporting_cycle_ms = *reporting_cycle_ms; + result.reporting_cycle_ms = *reporting_cycle; result.failed_cycles_tolerance = *failed_cycles_tolerance; result.min_indications = optionalScalarValue(fb_cas->min_indications()); result.max_indications = optionalScalarValue(fb_cas->max_indications()); @@ -419,30 +384,19 @@ score::cpp::expected convertDeploymentCo "DeploymentConfig::working_dir must never be nullptr as it is required in the schema"); SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE( fb_dc->sandbox(), "DeploymentConfig::sandbox must never be nullptr as it is required in the schema"); - auto ready_timeout = requireScalarValue(fb_dc->ready_timeout(), "DeploymentConfig::ready_timeout"); + auto ready_timeout = requireScalarValue(fb_dc->ready_timeout_ms(), "DeploymentConfig::ready_timeout_ms"); if (!ready_timeout.has_value()) { return score::cpp::make_unexpected(ready_timeout.error()); } - auto shutdown_timeout = requireScalarValue(fb_dc->shutdown_timeout(), "DeploymentConfig::shutdown_timeout"); + auto shutdown_timeout = + requireScalarValue(fb_dc->shutdown_timeout_ms(), "DeploymentConfig::shutdown_timeout_ms"); if (!shutdown_timeout.has_value()) { return score::cpp::make_unexpected(shutdown_timeout.error()); } - auto ready_timeout_ms = secondsToMs(*ready_timeout); - if (!ready_timeout_ms.has_value()) - { - LM_LOG_ERROR() << "Invalid value for DeploymentConfig::ready_timeout"; - return score::cpp::make_unexpected(ready_timeout_ms.error()); - } - auto shutdown_timeout_ms = secondsToMs(*shutdown_timeout); - if (!shutdown_timeout_ms.has_value()) - { - LM_LOG_ERROR() << "Invalid value for DeploymentConfig::shutdown_timeout"; - return score::cpp::make_unexpected(shutdown_timeout_ms.error()); - } - result.ready_timeout_ms = *ready_timeout_ms; - result.shutdown_timeout_ms = *shutdown_timeout_ms; + result.ready_timeout_ms = *ready_timeout; + result.shutdown_timeout_ms = *shutdown_timeout; result.environmental_variables = convertEnvironmentalVariables(fb_dc->environmental_variables()); result.bin_dir = fb_dc->bin_dir()->str(); result.working_dir = fb_dc->working_dir()->str(); @@ -506,7 +460,8 @@ score::cpp::expected convertRunTarget(con SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE( fb_rt->recovery_action(), "RunTarget::recovery_action must never be nullptr as it is required in the schema"); - auto transition_timeout = requireScalarValue(fb_rt->transition_timeout(), "RunTarget::transition_timeout"); + auto transition_timeout = + requireScalarValue(fb_rt->transition_timeout_ms(), "RunTarget::transition_timeout_ms"); if (!transition_timeout.has_value()) { return score::cpp::make_unexpected(transition_timeout.error()); @@ -514,13 +469,7 @@ score::cpp::expected convertRunTarget(con result.name = fb_rt->name()->str(); result.description = safeString(fb_rt->description()); result.depends_on = convertStringVector(fb_rt->depends_on()); - auto transition_timeout_ms = secondsToMs(*transition_timeout); - if (!transition_timeout_ms.has_value()) - { - LM_LOG_ERROR() << "Invalid value for RunTarget::transition_timeout"; - return score::cpp::make_unexpected(transition_timeout_ms.error()); - } - result.transition_timeout_ms = *transition_timeout_ms; + result.transition_timeout_ms = *transition_timeout; result.recovery_action = convertRequiredSwitchRunTargetAction(fb_rt->recovery_action()); } return result; @@ -533,20 +482,14 @@ score::cpp::expected convertFallb if (fb_frt != nullptr) { auto transition_timeout = - requireScalarValue(fb_frt->transition_timeout(), "FallbackRunTarget::transition_timeout"); + requireScalarValue(fb_frt->transition_timeout_ms(), "FallbackRunTarget::transition_timeout_ms"); if (!transition_timeout.has_value()) { return score::cpp::make_unexpected(transition_timeout.error()); } result.description = safeString(fb_frt->description()); result.depends_on = convertStringVector(fb_frt->depends_on()); - auto transition_timeout_ms = secondsToMs(*transition_timeout); - if (!transition_timeout_ms.has_value()) - { - LM_LOG_ERROR() << "Invalid value for FallbackRunTarget::transition_timeout"; - return score::cpp::make_unexpected(transition_timeout_ms.error()); - } - result.transition_timeout_ms = *transition_timeout_ms; + result.transition_timeout_ms = *transition_timeout; } return result; } @@ -558,18 +501,12 @@ score::cpp::expected convertAliveS { return AliveSupervisionConfig{}; } - auto evaluation_cycle = requireScalarValue(fb_as->evaluation_cycle(), "AliveSupervision::evaluation_cycle"); + auto evaluation_cycle = requireScalarValue(fb_as->evaluation_cycle_ms(), "AliveSupervision::evaluation_cycle_ms"); if (!evaluation_cycle.has_value()) { return score::cpp::make_unexpected(evaluation_cycle.error()); } - auto evaluation_cycle_ms = secondsToMs(*evaluation_cycle); - if (!evaluation_cycle_ms.has_value()) - { - LM_LOG_ERROR() << "Invalid value for AliveSupervision::evaluation_cycle"; - return score::cpp::make_unexpected(evaluation_cycle_ms.error()); - } - return AliveSupervisionConfig{*evaluation_cycle_ms}; + return AliveSupervisionConfig{*evaluation_cycle}; } score::cpp::expected, IConfigLoader::Error> convertWatchdog(const fb::Watchdog* fb_wd) @@ -580,7 +517,7 @@ score::cpp::expected, IConfigLoader::Error> conver } SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE( fb_wd->device_file_path(), "Watchdog::device_file_path must never be nullptr as it is required in the schema"); - auto max_timeout = requireScalarValue(fb_wd->max_timeout(), "Watchdog::max_timeout"); + auto max_timeout = requireScalarValue(fb_wd->max_timeout_ms(), "Watchdog::max_timeout_ms"); if (!max_timeout.has_value()) { return score::cpp::make_unexpected(max_timeout.error()); @@ -598,13 +535,7 @@ score::cpp::expected, IConfigLoader::Error> conver } WatchdogConfig result{}; result.device_file_path = fb_wd->device_file_path()->str(); - auto max_timeout_ms = secondsToMs(*max_timeout); - if (!max_timeout_ms.has_value()) - { - LM_LOG_ERROR() << "Invalid value for Watchdog::max_timeout"; - return score::cpp::make_unexpected(max_timeout_ms.error()); - } - result.max_timeout_ms = *max_timeout_ms; + result.max_timeout_ms = *max_timeout; result.deactivate_on_shutdown = *deactivate_on_shutdown; result.require_magic_close = *require_magic_close; return std::optional{std::move(result)}; diff --git a/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters.hpp b/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters.hpp index e22431ec7..549544499 100644 --- a/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters.hpp +++ b/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters.hpp @@ -63,8 +63,6 @@ score::cpp::expected validateRange(int64_t value, // --- Scalar and enum helpers --- -/// @brief Converts a time value from seconds to milliseconds. -[[nodiscard]] score::cpp::expected secondsToMs(double seconds); /// @brief Converts a FlatBuffer ApplicationType enum to the config ApplicationType. [[nodiscard]] ApplicationType convertApplicationType(fb::ApplicationType fb_type); /// @brief Converts a FlatBuffer ProcessState enum to the config ProcessState. diff --git a/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters_UT.cpp b/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters_UT.cpp index 0fb421246..a78b1410f 100644 --- a/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters_UT.cpp +++ b/score/launch_manager/src/daemon/src/configuration/details/flatbuffer_type_converters_UT.cpp @@ -63,64 +63,6 @@ class TypeConverterTestBase : public ::testing::Test } }; -// ============================================================================ -// secondsToMs tests -// ============================================================================ - -class SecondsToMsTest : public TypeConverterTestBase -{ -}; - -TEST_F(SecondsToMsTest, ConvertsPositiveValue) -{ - RecordProperty("Description", "A positive seconds value converts to milliseconds."); - - auto result = details::secondsToMs(1.5); - - ASSERT_THAT(result.has_value(), IsTrue()); - EXPECT_THAT(*result, Eq(1500U)); -} - -TEST_F(SecondsToMsTest, ConvertsZero) -{ - RecordProperty("Description", "Zero seconds converts to zero milliseconds."); - - auto result = details::secondsToMs(0.0); - - ASSERT_THAT(result.has_value(), IsTrue()); - EXPECT_THAT(*result, Eq(0U)); -} - -TEST_F(SecondsToMsTest, RejectsNegativeValue) -{ - RecordProperty("Description", "A negative seconds value returns InvalidFormat."); - - auto result = details::secondsToMs(-1.0); - - ASSERT_THAT(result.has_value(), IsFalse()); - EXPECT_THAT(result.error(), Eq(IConfigLoader::Error::InvalidFormat)); -} - -TEST_F(SecondsToMsTest, RejectsOverflow) -{ - RecordProperty("Description", "A value exceeding uint32_t max milliseconds returns InvalidFormat."); - - auto result = details::secondsToMs(5000000.0); - - ASSERT_THAT(result.has_value(), IsFalse()); - EXPECT_THAT(result.error(), Eq(IConfigLoader::Error::InvalidFormat)); -} - -TEST_F(SecondsToMsTest, RejectsSubMillisecond) -{ - RecordProperty("Description", "A positive value that rounds to 0ms returns InvalidFormat."); - - auto result = details::secondsToMs(0.0001); - - ASSERT_THAT(result.has_value(), IsFalse()); - EXPECT_THAT(result.error(), Eq(IConfigLoader::Error::InvalidFormat)); -} - // ============================================================================ // Enum conversion tests // ============================================================================ @@ -369,7 +311,7 @@ TEST_F(ConverterTest, ConvertRestartActionValid) { RecordProperty("Description", "convertRestartAction with valid fields returns correct values."); ::flatbuffers::FlatBufferBuilder fbb; - auto ra = fb::CreateRestartAction(fbb, 3 /*number_of_attempts*/, 1.5 /*delay_before_restart*/); + auto ra = fb::CreateRestartAction(fbb, 3 /*number_of_attempts*/, 1500 /*delay_before_restart_ms*/); fbb.Finish(ra); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -428,7 +370,7 @@ TEST_F(ConverterTest, ConvertComponentAliveSupervisionValid) RecordProperty("Description", "convertComponentAliveSupervision maps all fields correctly."); ::flatbuffers::FlatBufferBuilder fbb; auto cas = fb::CreateComponentAliveSupervision( - fbb, 0.5 /*reporting_cycle*/, 2 /*failed_cycles_tolerance*/, 1 /*min_indications*/, 3 /*max_indications*/); + fbb, 500 /*reporting_cycle_ms*/, 2 /*failed_cycles_tolerance*/, 1 /*min_indications*/, 3 /*max_indications*/); fbb.Finish(cas); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -444,10 +386,10 @@ TEST_F(ConverterTest, ConvertComponentAliveSupervisionValid) TEST_F(ConverterTest, ConvertComponentAliveSupervisionMissingReportingCycleReturnsError) { - RecordProperty("Description", "Missing reporting_cycle returns InvalidFormat."); + RecordProperty("Description", "Missing reporting_cycle_ms returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; auto cas = fb::CreateComponentAliveSupervision( - fbb, ::flatbuffers::nullopt /*reporting_cycle*/, 3 /*failed_cycles_tolerance*/); + fbb, ::flatbuffers::nullopt /*reporting_cycle_ms*/, 3 /*failed_cycles_tolerance*/); fbb.Finish(cas); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -461,7 +403,7 @@ TEST_F(ConverterTest, ConvertComponentAliveSupervisionMissingToleranceReturnsErr RecordProperty("Description", "Missing failed_cycles_tolerance returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; auto cas = fb::CreateComponentAliveSupervision( - fbb, 1.0 /*reporting_cycle*/, ::flatbuffers::nullopt /*failed_cycles_tolerance*/); + fbb, 1000 /*reporting_cycle_ms*/, ::flatbuffers::nullopt /*failed_cycles_tolerance*/); fbb.Finish(cas); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -474,7 +416,7 @@ TEST_F(ConverterTest, ConvertComponentAliveSupervisionBothIndicationsAbsentRetur { RecordProperty("Description", "Both min/max_indications absent returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; - auto cas = fb::CreateComponentAliveSupervision(fbb, 1.0 /*reporting_cycle*/, 3 /*failed_cycles_tolerance*/); + auto cas = fb::CreateComponentAliveSupervision(fbb, 1000 /*reporting_cycle_ms*/, 3 /*failed_cycles_tolerance*/); fbb.Finish(cas); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -488,7 +430,7 @@ TEST_F(ConverterTest, ConvertComponentAliveSupervisionOnlyMinIndicationsPresent) RecordProperty("Description", "Only min_indications set is accepted, max_indications remains nullopt."); ::flatbuffers::FlatBufferBuilder fbb; auto cas = fb::CreateComponentAliveSupervision( - fbb, 1.0 /*reporting_cycle*/, 3 /*failed_cycles_tolerance*/, 2 /*min_indications*/); + fbb, 1000 /*reporting_cycle_ms*/, 3 /*failed_cycles_tolerance*/, 2 /*min_indications*/); fbb.Finish(cas); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -505,7 +447,7 @@ TEST_F(ConverterTest, ConvertComponentAliveSupervisionOnlyMaxIndicationsPresent) ::flatbuffers::FlatBufferBuilder fbb; auto cas = fb::CreateComponentAliveSupervision( fbb, - 1.0 /*reporting_cycle*/, + 1000 /*reporting_cycle_ms*/, 3 /*failed_cycles_tolerance*/, ::flatbuffers::nullopt /*min_indications*/, 5 /*max_indications*/); @@ -754,8 +696,8 @@ TEST_F(ConverterTest, ConvertDeploymentConfigValid) auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - 1.5 /*ready_timeout*/, - 2.5 /*shutdown_timeout*/, + 1500 /*ready_timeout_ms*/, + 2500 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -777,15 +719,15 @@ TEST_F(ConverterTest, ConvertDeploymentConfigValid) TEST_F(ConverterTest, ConvertDeploymentConfigMissingReadyTimeoutReturnsError) { - RecordProperty("Description", "Missing ready_timeout returns InvalidFormat."); + RecordProperty("Description", "Missing ready_timeout_ms returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; auto bin_dir = fbb.CreateString("/opt"); auto work_dir = fbb.CreateString("/tmp"); auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - ::flatbuffers::nullopt /*ready_timeout*/, - 1.0 /*shutdown_timeout*/, + ::flatbuffers::nullopt /*ready_timeout_ms*/, + 1000 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -802,15 +744,15 @@ TEST_F(ConverterTest, ConvertDeploymentConfigMissingReadyTimeoutReturnsError) TEST_F(ConverterTest, ConvertDeploymentConfigMissingShutdownTimeoutReturnsError) { - RecordProperty("Description", "Missing shutdown_timeout returns InvalidFormat."); + RecordProperty("Description", "Missing shutdown_timeout_ms returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; auto bin_dir = fbb.CreateString("/opt"); auto work_dir = fbb.CreateString("/tmp"); auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - 1.0 /*ready_timeout*/, - ::flatbuffers::nullopt /*shutdown_timeout*/, + 1000 /*ready_timeout_ms*/, + ::flatbuffers::nullopt /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -841,8 +783,8 @@ TEST_F(ConverterTest, ConvertComponentValid) auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - 1.0 /*ready_timeout*/, - 1.0 /*shutdown_timeout*/, + 1000 /*ready_timeout_ms*/, + 1000 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -881,8 +823,8 @@ TEST_F(ConverterTest, ConvertComponentsValid) auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - 1.0 /*ready_timeout*/, - 1.0 /*shutdown_timeout*/, + 1000 /*ready_timeout_ms*/, + 1000 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -925,8 +867,8 @@ TEST_F(ConverterTest, ConvertComponentsWithInvalidComponentReturnsError) auto sandbox = buildDefaultSandbox(fbb); auto deploy = fb::CreateDeploymentConfig( fbb, - 1.0 /*ready_timeout*/, - 1.0 /*shutdown_timeout*/, + 1000 /*ready_timeout_ms*/, + 1000 /*shutdown_timeout_ms*/, 0 /*environmental_variables*/, bin_dir, work_dir, @@ -955,7 +897,7 @@ TEST_F(ConverterTest, ConvertRunTargetsValid) auto switch_action = fb::CreateSwitchRunTargetAction(fbb, switch_target); auto rt_name = fbb.CreateString(name); return fb::CreateRunTarget( - fbb, rt_name, 0 /*description*/, 0 /*depends_on*/, 1.0 /*transition_timeout*/, switch_action); + fbb, rt_name, 0 /*description*/, 0 /*depends_on*/, 1000 /*transition_timeout_ms*/, switch_action); }; auto rt_a = build_rt("Startup", "SafeState"); @@ -987,7 +929,7 @@ TEST_F(ConverterTest, ConvertRunTargetsWithInvalidRunTargetReturnsError) rt_name, 0 /*description*/, 0 /*depends_on*/, - ::flatbuffers::nullopt /*transition_timeout*/, + ::flatbuffers::nullopt /*transition_timeout_ms*/, switch_action); auto rts = fbb.CreateVector(std::vector<::flatbuffers::Offset>{rt}); fbb.Finish(rts); @@ -1010,7 +952,7 @@ TEST_F(ConverterTest, ConvertRunTargetValid) auto rt_desc = fbb.CreateString("Initial state"); auto rt_dep = fbb.CreateString("component_a"); auto rt_deps = fbb.CreateVector(std::vector<::flatbuffers::Offset<::flatbuffers::String>>{rt_dep}); - auto rt = fb::CreateRunTarget(fbb, rt_name, rt_desc, rt_deps, 5.0 /*transition_timeout*/, switch_action); + auto rt = fb::CreateRunTarget(fbb, rt_name, rt_desc, rt_deps, 5000 /*transition_timeout_ms*/, switch_action); fbb.Finish(rt); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -1026,7 +968,7 @@ TEST_F(ConverterTest, ConvertRunTargetValid) TEST_F(ConverterTest, ConvertRunTargetMissingTransitionTimeoutReturnsError) { - RecordProperty("Description", "Missing transition_timeout returns InvalidFormat."); + RecordProperty("Description", "Missing transition_timeout_ms returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; auto switch_target = fbb.CreateString("SafeState"); auto switch_action = fb::CreateSwitchRunTargetAction(fbb, switch_target); @@ -1036,7 +978,7 @@ TEST_F(ConverterTest, ConvertRunTargetMissingTransitionTimeoutReturnsError) rt_name, 0 /*description*/, 0 /*depends_on*/, - ::flatbuffers::nullopt /*transition_timeout*/, + ::flatbuffers::nullopt /*transition_timeout_ms*/, switch_action); fbb.Finish(rt); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -1053,7 +995,7 @@ TEST_F(ConverterTest, ConvertFallbackRunTargetValid) auto desc = fbb.CreateString("Fallback state"); auto dep = fbb.CreateString("critical_comp"); auto deps = fbb.CreateVector(std::vector<::flatbuffers::Offset<::flatbuffers::String>>{dep}); - auto frt = fb::CreateFallbackRunTarget(fbb, desc, deps, 10.0 /*transition_timeout*/); + auto frt = fb::CreateFallbackRunTarget(fbb, desc, deps, 10000 /*transition_timeout_ms*/); fbb.Finish(frt); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -1067,7 +1009,7 @@ TEST_F(ConverterTest, ConvertFallbackRunTargetValid) TEST_F(ConverterTest, ConvertFallbackRunTargetMissingTimeoutReturnsError) { - RecordProperty("Description", "Missing transition_timeout returns InvalidFormat."); + RecordProperty("Description", "Missing transition_timeout_ms returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; auto frt = fb::CreateFallbackRunTarget(fbb); fbb.Finish(frt); @@ -1088,9 +1030,9 @@ TEST_F(ConverterTest, ConvertAliveSupervisionNullReturnsDefault) TEST_F(ConverterTest, ConvertAliveSupervisionValid) { - RecordProperty("Description", "convertAliveSupervision maps evaluation_cycle correctly."); + RecordProperty("Description", "convertAliveSupervision maps evaluation_cycle_ms correctly."); ::flatbuffers::FlatBufferBuilder fbb; - auto as = fb::CreateAliveSupervision(fbb, 0.25 /*evaluation_cycle*/); + auto as = fb::CreateAliveSupervision(fbb, 250 /*evaluation_cycle_ms*/); fbb.Finish(as); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -1101,7 +1043,7 @@ TEST_F(ConverterTest, ConvertAliveSupervisionValid) TEST_F(ConverterTest, ConvertAliveSupervisionMissingCycleReturnsError) { - RecordProperty("Description", "Missing evaluation_cycle returns InvalidFormat."); + RecordProperty("Description", "Missing evaluation_cycle_ms returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; auto as = fb::CreateAliveSupervision(fbb); fbb.Finish(as); @@ -1125,7 +1067,7 @@ TEST_F(ConverterTest, ConvertWatchdogValid) RecordProperty("Description", "convertWatchdog maps all fields correctly."); ::flatbuffers::FlatBufferBuilder fbb; auto dev_path = fbb.CreateString("/dev/watchdog0"); - auto wd = fb::CreateWatchdog(fbb, dev_path, 30.0 /*max_timeout*/, true /*deactivate*/, false /*magic_close*/); + auto wd = fb::CreateWatchdog(fbb, dev_path, 30000 /*max_timeout_ms*/, true /*deactivate*/, false /*magic_close*/); fbb.Finish(wd); const auto* ptr = ::flatbuffers::GetRoot(fbb.GetBufferPointer()); @@ -1140,13 +1082,13 @@ TEST_F(ConverterTest, ConvertWatchdogValid) TEST_F(ConverterTest, ConvertWatchdogMissingMaxTimeoutReturnsError) { - RecordProperty("Description", "Missing max_timeout returns InvalidFormat."); + RecordProperty("Description", "Missing max_timeout_ms returns InvalidFormat."); ::flatbuffers::FlatBufferBuilder fbb; auto dev_path = fbb.CreateString("/dev/watchdog0"); auto wd = fb::CreateWatchdog( fbb, dev_path, - ::flatbuffers::nullopt /*max_timeout*/, + ::flatbuffers::nullopt /*max_timeout_ms*/, true /*deactivate_on_shutdown*/, false /*require_magic_close*/); fbb.Finish(wd); @@ -1165,7 +1107,7 @@ TEST_F(ConverterTest, ConvertWatchdogMissingDeactivateReturnsError) auto wd = fb::CreateWatchdog( fbb, dev_path, - 30.0 /*max_timeout*/, + 30000 /*max_timeout_ms*/, ::flatbuffers::nullopt /*deactivate_on_shutdown*/, false /*require_magic_close*/); fbb.Finish(wd); @@ -1184,7 +1126,7 @@ TEST_F(ConverterTest, ConvertWatchdogMissingMagicCloseReturnsError) auto wd = fb::CreateWatchdog( fbb, dev_path, - 30.0 /*max_timeout*/, + 30000 /*max_timeout_ms*/, true /*deactivate_on_shutdown*/, ::flatbuffers::nullopt /*require_magic_close*/); fbb.Finish(wd); diff --git a/score/launch_manager/src/daemon/src/configuration/details/lm_flatcfg.fbs b/score/launch_manager/src/daemon/src/configuration/details/lm_flatcfg.fbs index 83529b05c..4da5f3b15 100644 --- a/score/launch_manager/src/daemon/src/configuration/details/lm_flatcfg.fbs +++ b/score/launch_manager/src/daemon/src/configuration/details/lm_flatcfg.fbs @@ -35,8 +35,8 @@ enum SchedulingPolicy : byte { // Defines the configuration parameters used for alive monitoring of a component. table ComponentAliveSupervision { - // Duration in seconds of the time interval used to verify alive notifications. - reporting_cycle:double = null; // required + // Duration in milliseconds of the time interval used to verify alive notifications. + reporting_cycle_ms:uint32 = null; // required // Maximum number of consecutive reporting cycle failures before recovery is triggered. failed_cycles_tolerance:uint32 = null; // required // Minimum number of checkpoints that must be reported within each reporting_cycle. @@ -74,8 +74,8 @@ table ComponentProperties { table RestartAction { // Maximum number of restart attempts before recovery is considered failed. number_of_attempts:uint32 = null; // required - // Delay in seconds before initiating a restart attempt. - delay_before_restart:double = null; // required + // Delay in milliseconds before initiating a restart attempt. + delay_before_restart_ms:uint32 = null; // required } // Recovery action that switches to a specified Run Target. @@ -112,10 +112,10 @@ table Sandbox { // Deployment configuration for a component. table DeploymentConfig { - // Maximum time in seconds for the component to reach its ready state. - ready_timeout:double = null; // required - // Maximum time in seconds for the component to terminate after SIGTERM. - shutdown_timeout:double = null; // required + // Maximum time in milliseconds for the component to reach its ready state. + ready_timeout_ms:uint32 = null; // required + // Maximum time in milliseconds for the component to terminate after SIGTERM. + shutdown_timeout_ms:uint32 = null; // required // Environment variables passed to the component at startup. environmental_variables:[EnvironmentalVariable]; // optional // Absolute path to the directory where the component is installed. @@ -138,8 +138,8 @@ table RunTarget { description:string; // optional // Names of components and Run Targets that must be activated with this Run Target. depends_on:[string]; // optional - // Time limit in seconds for the Run Target transition. - transition_timeout:double = null; // required + // Time limit in milliseconds for the Run Target transition. + transition_timeout_ms:uint32 = null; // required // Recovery action when a component in this Run Target fails. recovery_action:SwitchRunTargetAction (required); } @@ -156,16 +156,16 @@ table Component { // Global alive supervision configuration. table AliveSupervision { - // Length in seconds of the time window used to assess alive supervision reports. - evaluation_cycle:double = null; // required + // Length in milliseconds of the time window used to assess alive supervision reports. + evaluation_cycle_ms:uint32 = null; // required } // External watchdog device configuration. table Watchdog { // Path to the external watchdog device file (e.g., /dev/watchdog). device_file_path:string (required); // required - // Maximum timeout in seconds configured on the external watchdog. - max_timeout:double = null; // required + // Maximum timeout in milliseconds configured on the external watchdog. + max_timeout_ms:uint32 = null; // required // Whether the watchdog is deactivated during shutdown. deactivate_on_shutdown:bool = null; // required // Whether the magic close sequence is performed on intentional shutdown. @@ -179,8 +179,8 @@ table FallbackRunTarget { description:string; // optional // Names of components and Run Targets that must be activated. depends_on:[string]; // optional - // Time limit in seconds for the Run Target transition. - transition_timeout:double = null; // required + // Time limit in milliseconds for the Run Target transition. + transition_timeout_ms:uint32 = null; // required } // Root configuration table for the S-CORE Launch Manager. diff --git a/scripts/config_mapping/lifecycle_config.py b/scripts/config_mapping/lifecycle_config.py index ba1416c08..af2957ff7 100644 --- a/scripts/config_mapping/lifecycle_config.py +++ b/scripts/config_mapping/lifecycle_config.py @@ -106,6 +106,11 @@ def get_working_dir(deployment_config): return deployment_config.get("working_dir", deployment_config["bin_dir"]) +def sec_to_ms(sec: float) -> int: + """Convert a duration in seconds (float) to integer milliseconds.""" + return int(sec * 1000) + + def preprocess_defaults(global_defaults, config): """ This function takes the input configuration and fills in any missing fields with default values. @@ -272,7 +277,7 @@ def gen_config(output_dir, config, input_filename): if is_supervised(comp_props["application_profile"]["application_type"]): alive_sup = comp_props["application_profile"].get("alive_supervision", {}) app_profile["alive_supervision"] = { - "reporting_cycle": alive_sup["reporting_cycle"], + "reporting_cycle_ms": sec_to_ms(alive_sup["reporting_cycle"]), "failed_cycles_tolerance": alive_sup["failed_cycles_tolerance"], "min_indications": alive_sup["min_indications"], "max_indications": alive_sup["max_indications"], @@ -308,8 +313,8 @@ def gen_config(output_dir, config, input_filename): sandbox_out["max_cpu_usage"] = sandbox["max_cpu_usage"] deployment = { - "ready_timeout": depl_cfg["ready_timeout"], - "shutdown_timeout": depl_cfg["shutdown_timeout"], + "ready_timeout_ms": sec_to_ms(depl_cfg["ready_timeout"]), + "shutdown_timeout_ms": sec_to_ms(depl_cfg["shutdown_timeout"]), "bin_dir": depl_cfg["bin_dir"], # Default the working directory to bin_dir (the directory the # executable lives in) when not set explicitly. @@ -328,7 +333,7 @@ def gen_config(output_dir, config, input_filename): restart = rra.get("restart", rra) deployment["ready_recovery_action"] = { "number_of_attempts": restart.get("number_of_attempts", 0), - "delay_before_restart": restart.get("delay_before_restart", 0), + "delay_before_restart_ms": sec_to_ms(restart.get("delay_before_restart", 0)), } if "recovery_action" in depl_cfg: @@ -347,7 +352,7 @@ def gen_config(output_dir, config, input_filename): for rt_name, rt_config in config["run_targets"].items(): rt = { "name": rt_name, - "transition_timeout": rt_config.get("transition_timeout", 3), + "transition_timeout_ms": sec_to_ms(rt_config.get("transition_timeout", 3)), "recovery_action": { "run_target": rt_config.get("recovery_action", {}) .get("switch_run_target", {}) @@ -363,16 +368,19 @@ def gen_config(output_dir, config, input_filename): out["initial_run_target"] = config["initial_run_target"] fallback = config.get("fallback_run_target", {}) - out["fallback_run_target"] = { - key: fallback[key] - for key in ("transition_timeout", "description", "depends_on") - if key in fallback - } + fb_out = {} + if "transition_timeout" in fallback: + fb_out["transition_timeout_ms"] = sec_to_ms(fallback["transition_timeout"]) + if fallback.get("description"): + fb_out["description"] = fallback["description"] + if "depends_on" in fallback and fallback["depends_on"]: + fb_out["depends_on"] = fallback["depends_on"] + out["fallback_run_target"] = fb_out out["alive_supervision"] = { - "evaluation_cycle": config.get("alive_supervision", {}).get( + "evaluation_cycle_ms": sec_to_ms(config.get("alive_supervision", {}).get( "evaluation_cycle", 0.5 - ), + )), } watchdog_config = config.get("watchdog", {}) @@ -385,7 +393,7 @@ def gen_config(output_dir, config, input_filename): if watchdog_config and required_watchdog_fields.issubset(watchdog_config.keys()): out["watchdog"] = { "device_file_path": watchdog_config["device_file_path"], - "max_timeout": watchdog_config["max_timeout"], + "max_timeout_ms": sec_to_ms(watchdog_config["max_timeout"]), "deactivate_on_shutdown": watchdog_config["deactivate_on_shutdown"], "require_magic_close": watchdog_config["require_magic_close"], }