Trigger the propertyChanged method of TestManager
propertyChanged is Disabled by default, and UT is not executed,
optimize the code and enable it.
Tested: Verify that the propertyChanged method of Testmanager
executes UT successfully.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I1bb9241c7f8f37de0ee151d26156c9876627f0fb
diff --git a/manager.cpp b/manager.cpp
index f8cd289..5f23208 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -69,15 +69,16 @@
void Manager::updateNtpSetting(const std::string& value)
{
- bool isNtp =
- (value == "xyz.openbmc_project.Time.Synchronization.Method.NTP");
- auto method = bus.new_method_call(SYSTEMD_TIME_SERVICE, SYSTEMD_TIME_PATH,
- SYSTEMD_TIME_INTERFACE, METHOD_SET_NTP);
- method.append(isNtp, false); // isNtp: 'true/false' means Enable/Disable
- // 'false' meaning no policy-kit
-
try
{
+ bool isNtp =
+ (value == "xyz.openbmc_project.Time.Synchronization.Method.NTP");
+ auto method =
+ bus.new_method_call(SYSTEMD_TIME_SERVICE, SYSTEMD_TIME_PATH,
+ SYSTEMD_TIME_INTERFACE, METHOD_SET_NTP);
+ method.append(isNtp, false); // isNtp: 'true/false' means Enable/Disable
+ // 'false' meaning no policy-kit
+
bus.call_noreply(method);
lg2::info("Updated NTP setting: {ENABLED}", "ENABLED", isNtp);
}
@@ -89,17 +90,22 @@
bool Manager::setCurrentTimeMode(const std::string& mode)
{
- auto newMode = utils::strToMode(mode);
- if (newMode != timeMode)
+ try
{
- lg2::info("Time mode has been changed to {MODE}", "MODE", newMode);
- timeMode = newMode;
- return true;
+ auto newMode = utils::strToMode(mode);
+ if (newMode != timeMode)
+ {
+ lg2::info("Time mode has been changed to {MODE}", "MODE", newMode);
+ timeMode = newMode;
+ return true;
+ }
}
- else
+ catch (const sdbusplus::exception_t& ex)
{
- return false;
+ lg2::error("Failed to convert mode from string: {ERROR}", "ERROR", ex);
}
+
+ return false;
}
void Manager::onTimeModeChanged(const std::string& mode)
@@ -111,9 +117,19 @@
std::string Manager::getSetting(const char* path, const char* interface,
const char* setting) const
{
- std::string settingManager = utils::getService(bus, path, interface);
- return utils::getProperty<std::string>(bus, settingManager.c_str(), path,
- interface, setting);
+ try
+ {
+ std::string settingManager = utils::getService(bus, path, interface);
+ return utils::getProperty<std::string>(bus, settingManager.c_str(),
+ path, interface, setting);
+ }
+ catch (const std::exception& ex)
+ {
+ lg2::error(
+ "Failed to get property: {ERROR}, path: {PATH}, interface: {INTERFACE}, name: {NAME}",
+ "ERROR", ex, "PATH", path, "INTERFACE", interface, "NAME", setting);
+ return {};
+ }
}
} // namespace time
diff --git a/settings.cpp b/settings.cpp
index b8b3a0d..0d368d1 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -44,7 +44,6 @@
if (result.empty())
{
lg2::error("Invalid response from mapper");
- elog<InternalFailure>();
}
for (const auto& iter : result)
diff --git a/test/TestManager.cpp b/test/TestManager.cpp
index b879d3a..2f5990c 100644
--- a/test/TestManager.cpp
+++ b/test/TestManager.cpp
@@ -33,7 +33,7 @@
}
};
-TEST_F(TestManager, DISABLED_propertyChanged)
+TEST_F(TestManager, propertyChanged)
{
notifyPropertyChanged(
"TimeSyncMethod",