Adding system configuration object & UT
This commit adds the system config object that implements
the SystemConfiguration interface.
The hostname property under this interface will initially
be set from the bios table when the service starts.
Whenever user sets the property, the same will be updated
in the bios table.
busctl tree xyz.openbmc_project.Network.Hypervisor
└─/xyz
└─/xyz/openbmc_project
└─/xyz/openbmc_project/network
└─/xyz/openbmc_project/network/hypervisor
└─/xyz/openbmc_project/network/hypervisor/config
Tested By:
busctl set-property xyz.openbmc_project.Network.Hypervisor
/xyz/openbmc_project/network/hypervisor/config
xyz.openbmc_project.Network.SystemConfiguration HostName s "vmi HN"
busctl introspect xyz.openbmc_project.Network.Hypervisor /xyz/openbmc_project/network/hypervisor/config
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -
xyz.openbmc_project.Network.SystemConfiguration interface - - -
.DefaultGateway property s "" emits-change writable
.DefaultGateway6 property s "" emits-change writable
.HostName property s "vmi HN" emits-change writable
busctl call xyz.openbmc_project.BIOSConfigManager /xyz/openbmc_project/bios_config/manager xyz.openbmc_project.BIOSConfig.Manager GetAttribute s vmi_hostname
svv "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.String" s "vmi HN" s ""
Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: Ib3afaef2da039d18cc672a1759b721698f9c14e2
diff --git a/test/ibm/hypervisor-network-mgr-test/meson.build b/test/ibm/hypervisor-network-mgr-test/meson.build
index b7f97b0..d0ea5a1 100644
--- a/test/ibm/hypervisor-network-mgr-test/meson.build
+++ b/test/ibm/hypervisor-network-mgr-test/meson.build
@@ -2,11 +2,13 @@
hyp_tests = [
'hyp_network_manager',
+ 'hyp_sys_config',
]
hyp_test_src = declare_dependency(
sources: [
- '../../../src/ibm/hypervisor-network-mgr-src/hyp_network_manager.cpp'])
+ '../../../src/ibm/hypervisor-network-mgr-src/hyp_network_manager.cpp',
+ '../../../src/ibm/hypervisor-network-mgr-src/hyp_sys_config.cpp'])
foreach t : hyp_tests
test(
diff --git a/test/ibm/hypervisor-network-mgr-test/mock_hyp_sys_config.hpp b/test/ibm/hypervisor-network-mgr-test/mock_hyp_sys_config.hpp
new file mode 100644
index 0000000..e5bd42d
--- /dev/null
+++ b/test/ibm/hypervisor-network-mgr-test/mock_hyp_sys_config.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "config.h"
+
+#include "hyp_sys_config.hpp"
+
+#include <gmock/gmock.h>
+
+namespace phosphor
+{
+namespace network
+{
+
+class MockHypSysConfig : public phosphor::network::HypSysConfig
+{
+ public:
+ MockHypSysConfig(sdbusplus::bus::bus& bus, const std::string& objPath,
+ HypNetworkMgr& parent) :
+ HypSysConfig(bus, objPath, parent)
+ {
+ }
+
+ void setHostname(std::string hn)
+ {
+ SysConfigIntf::hostName(hn);
+ manager.setBIOSTableAttr("vmi_hostname", hn, "String");
+ }
+
+ const std::string getHostname()
+ {
+ return SysConfigIntf::hostName();
+ }
+};
+} // namespace network
+} // namespace phosphor
diff --git a/test/ibm/hypervisor-network-mgr-test/test_hyp_sys_config.cpp b/test/ibm/hypervisor-network-mgr-test/test_hyp_sys_config.cpp
new file mode 100644
index 0000000..b09d024
--- /dev/null
+++ b/test/ibm/hypervisor-network-mgr-test/test_hyp_sys_config.cpp
@@ -0,0 +1,52 @@
+#include "mock_hyp_sys_config.hpp"
+
+#include <net/if.h>
+
+#include <sdbusplus/bus.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+
+#include <gtest/gtest.h>
+
+namespace phosphor
+{
+namespace network
+{
+
+class TestHypSysConfig : public testing::Test
+{
+ public:
+ sdbusplus::bus::bus bus;
+ HypNetworkMgr manager;
+ MockHypSysConfig sysConfigObj;
+ sdeventplus::Event event = sdeventplus::Event::get_default();
+ TestHypSysConfig() :
+ bus(sdbusplus::bus::new_default()),
+ manager(bus, event, "/xyz/openbmc_test/network/hypervisor"),
+ sysConfigObj(bus, "/xyz/openbmc_test/network/hypervisor/config",
+ manager)
+ {
+ manager.setDefaultHostnameInBIOSTableAttrs();
+ }
+
+ ~TestHypSysConfig() = default;
+};
+
+TEST_F(TestHypSysConfig, setAndGetHostName)
+{
+ std::string newHostName = "hostname1";
+ sysConfigObj.setHostname(newHostName);
+
+ biosTableType biosAttrs = manager.getBIOSTableAttrs();
+ auto itr = biosAttrs.find("vmi_hostname");
+ if (itr != biosAttrs.end())
+ {
+ std::string biosAttrValue = std::get<std::string>(itr->second);
+ EXPECT_EQ(biosAttrValue, "hostname1");
+ }
+
+ std::string updatedHostName = sysConfigObj.getHostname();
+ EXPECT_EQ(updatedHostName, newHostName);
+}
+
+} // namespace network
+} // namespace phosphor