Backend changes for Populating Nameservers(DNS & Static)

- As per the proposed design :
https://lists.ozlabs.org/pipermail/openbmc/2019-September/018399.html

Depends on :
https://gerrit.openbmc-project.xyz/#/c/openbmc/phosphor-dbus-interfaces/+/26060/

The idea of this commit is to

- Support NameServers(Read Only) property to display current
  Nameservers (both DHCP provided& Static) configured on the
  interface.

- Support StaticNameServers(Writable) property by which user
  can set the Nameservers on an interface.

Tested By:

1.Configure a DNS via DHCP Server & Make sure NameServer property
  populates accordingly.
2.With DNS from DHCP existing, set a name server using PATCH on
  StaticNameServer property & make sure both properties populate
  the data as per the proposal.
3.Make sure /etc/resolv.conf is populated with the right content
  in case of DHCP/Static and DHCP & Static (Co-existing)
4.Make sure network configuration file is updated properly when
  user sets a staic name server.

Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: If10b9aa683d2b50e51780e91323c6d10a5ec3710
diff --git a/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index 30dee8a..d0beef7 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -12,6 +12,7 @@
 #include <exception>
 #include <fstream>
 #include <sdbusplus/bus.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
 
 #include <gtest/gtest.h>
 
@@ -25,7 +26,7 @@
   public:
     sdbusplus::bus::bus bus;
     MockManager manager;
-    EthernetInterface interface;
+    MockEthernetInterface interface;
     std::string confDir;
     TestEthernetInterface() :
         bus(sdbusplus::bus::new_default()),
@@ -53,12 +54,12 @@
 
     static constexpr ether_addr mac{0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
 
-    static EthernetInterface makeInterface(sdbusplus::bus::bus& bus,
-                                           MockManager& manager)
+    static MockEthernetInterface makeInterface(sdbusplus::bus::bus& bus,
+                                               MockManager& manager)
     {
         mock_clear();
         mock_addIF("test0", 1, mac);
-        return {bus, "/xyz/openbmc_test/network/test0", false, manager};
+        return {bus, "/xyz/openbmc_test/network/test0", false, manager, true};
     }
 
     int countIPObjects()
@@ -159,11 +160,11 @@
     EXPECT_EQ(expectedObjectPath, getObjectPath(ipaddress, prefix, gateway));
 }
 
-TEST_F(TestEthernetInterface, addNameServers)
+TEST_F(TestEthernetInterface, addStaticNameServers)
 {
     ServerList servers = {"9.1.1.1", "9.2.2.2", "9.3.3.3"};
     EXPECT_CALL(manager, restartSystemdUnit(networkdService)).Times(1);
-    interface.nameservers(servers);
+    interface.staticNameServers(servers);
     fs::path filePath = confDir;
     filePath /= "00-bmc-test0.network";
     config::Parser parser(filePath.string());
@@ -173,6 +174,21 @@
     EXPECT_EQ(servers, values);
 }
 
+TEST_F(TestEthernetInterface, addDynamicNameServers)
+{
+    using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+    ServerList servers = {"9.1.1.1", "9.2.2.2", "9.3.3.3"};
+    EXPECT_THROW(interface.nameservers(servers), NotAllowed);
+}
+
+TEST_F(TestEthernetInterface, getDynamicNameServers)
+{
+    ServerList servers = {"9.1.1.1", "9.2.2.2", "9.3.3.3"};
+    EXPECT_CALL(interface, getNameServerFromResolvd())
+        .WillRepeatedly(testing::Return(servers));
+    EXPECT_EQ(interface.getNameServerFromResolvd(), servers);
+}
+
 TEST_F(TestEthernetInterface, addNTPServers)
 {
     ServerList servers = {"10.1.1.1", "10.2.2.2", "10.3.3.3"};