Remove the code which updates resolv.conf for dhcp supplied DNS

Earlier in openbmc stack we did't have the systemd-resolved
which updates the resolv.conf automatically for DHCP supplied
nameservers or static nameservers.

Now openBMC stack is having the systemd-resolved enabled
This code is not required, it is unnecessary overwriting
some entries.

Change-Id: I532a4d00d4ec6dcc32f69f7cc5be0a41378214b8
Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 9dcba8e..f609b9d 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -461,15 +461,9 @@
         EthernetInterfaceIntf::nameservers(value);
 
         writeConfigurationFile();
-
-        // Currently we don't have systemd-resolved enabled
-        // in the openbmc. Once we update the network conf file,
-        // it should be read by systemd-resolved.service.
-
-        // The other reason to write the resolv conf is,
-        // we don't want to restart the networkd for nameserver change.
-        // as restarting of systemd-networkd takes more then 2 secs
-        writeDNSEntries(value, resolvConfFile);
+        // resolved reads the DNS server configuration from the
+        // network file.
+        manager.restartSystemdUnit(networkdService);
     }
     catch (InternalFailure& e)
     {
@@ -498,24 +492,6 @@
     return servers;
 }
 
-void EthernetInterface::writeDNSEntries(const ServerList& dnsList,
-                                        const std::string& file)
-{
-    std::fstream outStream(file, std::fstream::out);
-    if (!outStream.is_open())
-    {
-        log<level::ERR>("Unable to open the file",
-                        entry("FILE=%s", file.c_str()));
-        elog<InternalFailure>();
-    }
-
-    outStream << "### Generated manually via dbus settings ###\n";
-    for (const auto& server : dnsList)
-    {
-        outStream << "nameserver " << server << "\n";
-    }
-}
-
 void EthernetInterface::loadVLAN(VlanId id)
 {
     std::string vlanInterfaceName = interfaceName() + "." + std::to_string(id);
diff --git a/ethernet_interface.hpp b/ethernet_interface.hpp
index e48fddb..60c56e3 100644
--- a/ethernet_interface.hpp
+++ b/ethernet_interface.hpp
@@ -267,12 +267,6 @@
      */
     ServerList getNTPServersFromConf();
 
-    /** @brief write the DNS entries to resolver file.
-     *  @param[in] dnsList - DNS server list which needs to be written.
-     *  @param[in] file    - File to write the name server entries to.
-     */
-    void writeDNSEntries(const ServerList& dnsList, const std::string& file);
-
     /** @brief get the name server details from the network conf
      *
      */
diff --git a/network_manager_main.cpp b/network_manager_main.cpp
index 1b85bfa..fedb73d 100644
--- a/network_manager_main.cpp
+++ b/network_manager_main.cpp
@@ -1,6 +1,5 @@
 #include "config.h"
 
-#include "dns_updater.hpp"
 #include "network_manager.hpp"
 #include "rtnetlink_server.hpp"
 #include "types.hpp"
@@ -23,7 +22,6 @@
 using phosphor::logging::log;
 using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 
-constexpr char NETWORK_STATE_FILE[] = "/run/systemd/netif/state";
 constexpr char NETWORK_CONF_DIR[] = "/etc/systemd/network";
 
 constexpr char DEFAULT_OBJPATH[] = "/xyz/openbmc_project/network";
@@ -136,17 +134,5 @@
     // RTNETLINK event handler
     phosphor::network::rtnetlink::Server svr(eventPtr, smartSock);
 
-    // DNS entry handler
-    phosphor::network::inotify::Watch watch(
-        eventPtr, NETWORK_STATE_FILE,
-        std::bind(&phosphor::network::dns::updater::processDNSEntries,
-                  std::placeholders::_1));
-
-    // At this point, we have registered for the notifications for future
-    // events. However, if the file is already populated before this, then
-    // they won't ever get notified and thus we need to read once before
-    // waiting on change events
-    phosphor::network::dns::updater::processDNSEntries(NETWORK_STATE_FILE);
-
     sd_event_loop(eventPtr.get());
 }
diff --git a/test/Makefile.am b/test/Makefile.am
index 842f8ca..45dab5f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -2,7 +2,7 @@
 
 TESTS = $(check_PROGRAMS)
 
-check_PROGRAMS = test test_dns_updater test_watch
+check_PROGRAMS = test
 
 test_SOURCES = \
 	test_util.cpp \
@@ -15,9 +15,6 @@
 	test_config_parser.cpp \
 	test_vlan_interface.cpp
 
-test_dns_updater_SOURCES = test_dns_updater.cpp
-test_watch_SOURCES = test_watch.cpp
-
 generic_cpp_flags = -Igtest $(GTEST_CPPFLAGS) $(AM_CPPFLAGS)
 
 generic_cxx_flags = $(PTHREAD_CFLAGS) \
@@ -39,14 +36,6 @@
 test_CXXFLAGS = ${generic_cxx_flags}
 test_LDFLAGS  = ${generic_ld_flags} -ldl
 
-test_dns_updater_CPPFLAGS = ${generic_cpp_flags}
-test_dns_updater_CXXFLAGS = ${generic_cxx_flags}
-test_dns_updater_LDFLAGS  = ${generic_ld_flags}
-
-test_watch_CPPFLAGS = ${generic_cpp_flags}
-test_watch_CXXFLAGS = ${generic_cxx_flags}
-test_watch_LDFLAGS  = ${generic_ld_flags}
-
 test_LDADD = $(top_builddir)/ethernet_interface.o \
 			$(top_builddir)/network_manager.o \
 			$(top_builddir)/network_config.o \
@@ -63,6 +52,3 @@
 			$(top_builddir)/xyz/openbmc_project/Network/VLAN/Create/phosphor_network_manager-server.o \
 			$(top_builddir)/xyz/openbmc_project/Network/IP/Create/phosphor_network_manager-server.o \
 			$(top_builddir)/xyz/openbmc_project/Network/Neighbor/CreateStatic/phosphor_network_manager-server.o
-
-test_dns_updater_LDADD = $(top_builddir)/dns_updater.o
-test_watch_LDADD = $(top_builddir)/watch.o
diff --git a/test/test_dns_updater.cpp b/test/test_dns_updater.cpp
deleted file mode 100644
index 2a425c0..0000000
--- a/test/test_dns_updater.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "dns_updater.hpp"
-
-#include <experimental/filesystem>
-#include <fstream>
-
-#include <gtest/gtest.h>
-
-static constexpr auto IN_FILE = "/tmp/" __BASE_FILE__ "netif_state";
-static constexpr auto OUT_FILE = "/tmp/" __BASE_FILE__ "resolv.conf";
-static constexpr auto COMPARE_FILE =
-    "/tmp/" __BASE_FILE__ "resolv_compare.conf";
-static constexpr auto DNS_ENTRY_1 = "DNS=1.2.3.4\n";
-static constexpr auto DNS_ENTRY_2 = "DNS=5.6.7.8\n";
-
-namespace fs = std::experimental::filesystem;
-
-class DnsUpdateTest : public ::testing::Test
-{
-  public:
-    // Gets called as part of each TEST_F construction
-    DnsUpdateTest()
-    {
-        // Create a file containing DNS entries like in netif/state
-        std::ofstream file(IN_FILE);
-        file << DNS_ENTRY_1;
-        file << DNS_ENTRY_2;
-
-        // Create a file to compare the results against
-        std::ofstream compare(COMPARE_FILE);
-        compare << "### Generated by phosphor-networkd ###\n";
-        compare << "nameserver 1.2.3.4\n";
-        compare << "nameserver 5.6.7.8\n";
-    }
-
-    // Gets called as part of each TEST_F destruction
-    ~DnsUpdateTest()
-    {
-        if (fs::exists(IN_FILE))
-        {
-            fs::remove(IN_FILE);
-        }
-        if (fs::exists(OUT_FILE))
-        {
-            fs::remove(OUT_FILE);
-        }
-        if (fs::exists(COMPARE_FILE))
-        {
-            fs::remove(COMPARE_FILE);
-        }
-    }
-};
-
-/** @brief Makes outfile is updated with right contents
- */
-TEST_F(DnsUpdateTest, validateOutFile)
-{
-    phosphor::network::dns::updater::updateDNSEntries(IN_FILE, OUT_FILE);
-
-    // Read files and compare
-    std::ifstream resolv(OUT_FILE);
-    std::ifstream compare(COMPARE_FILE);
-
-    // From actual file
-    std::string resolvEntry{};
-    std::string resolvContent{};
-    while (std::getline(resolv, resolvEntry))
-    {
-        resolvContent += resolvEntry;
-    }
-
-    // From compare file
-    std::string compareEntry{};
-    std::string compareContent{};
-    while (std::getline(compare, compareEntry))
-    {
-        compareContent += compareEntry;
-    }
-    EXPECT_EQ(resolvContent, compareContent);
-}
diff --git a/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index 5ea7f7a..30dee8a 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -101,29 +101,6 @@
     {
         interface.iP(addressType, ipaddress, subnetMask, gateway);
     }
-
-    // Validates if the DNS entries have been correctly processed
-    void validateResolvFile(ServerList values)
-    {
-        // Check whether the entries has been written to resolv.conf
-        fs::path resolvFile = confDir;
-        resolvFile /= "resolv.conf";
-
-        // Passed in "value" is what is read from the config file
-        interface.writeDNSEntries(values, resolvFile);
-        std::string expectedServers =
-            "### Generated manually via dbus settings ###";
-        expectedServers +=
-            "nameserver 9.1.1.1nameserver 9.2.2.2nameserver 9.3.3.3";
-
-        std::string actualServers{};
-        std::fstream stream(resolvFile.string().c_str(), std::fstream::in);
-        for (std::string line; std::getline(stream, line);)
-        {
-            actualServers += line;
-        }
-        EXPECT_EQ(expectedServers, actualServers);
-    }
 };
 
 TEST_F(TestEthernetInterface, NoIPaddress)
@@ -185,6 +162,7 @@
 TEST_F(TestEthernetInterface, addNameServers)
 {
     ServerList servers = {"9.1.1.1", "9.2.2.2", "9.3.3.3"};
+    EXPECT_CALL(manager, restartSystemdUnit(networkdService)).Times(1);
     interface.nameservers(servers);
     fs::path filePath = confDir;
     filePath /= "00-bmc-test0.network";
@@ -193,8 +171,6 @@
     config::ValueList values;
     std::tie(rc, values) = parser.getValues("Network", "DNS");
     EXPECT_EQ(servers, values);
-
-    validateResolvFile(values);
 }
 
 TEST_F(TestEthernetInterface, addNTPServers)
diff --git a/test/test_watch.cpp b/test/test_watch.cpp
deleted file mode 100644
index 167c903..0000000
--- a/test/test_watch.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-#include "types.hpp"
-#include "watch.hpp"
-
-#include <experimental/filesystem>
-#include <fstream>
-
-#include <gtest/gtest.h>
-
-static constexpr auto TRIGGER_FILE = "/tmp/" __BASE_FILE__ "netif_state";
-
-namespace fs = std::experimental::filesystem;
-
-class WatchTest : public ::testing::Test
-{
-  public:
-    // systemd event handler
-    sd_event* events;
-
-    // Need this so that events can be initialized.
-    int rc;
-
-    // Gets called as part of each TEST_F construction
-    WatchTest() : rc(sd_event_default(&events)), eventPtr(events)
-    {
-        // Create a file containing DNS entries like in netif/state
-        std::ofstream file(TRIGGER_FILE);
-        file << "";
-
-        // Check for successful creation of
-        // event handler
-        EXPECT_GE(rc, 0);
-    }
-
-    // Gets called as part of each TEST_F destruction
-    ~WatchTest()
-    {
-        if (fs::exists(TRIGGER_FILE))
-        {
-            fs::remove(TRIGGER_FILE);
-        }
-    }
-
-    // unique_ptr for sd_event
-    phosphor::network::EventPtr eventPtr;
-
-    // Count of callback invocation
-    int count = 0;
-
-    // This is supposed to get hit twice
-    // Once at the beginning to see if there is anything
-    // and the second time when the data is fired.
-    void callBackHandler(const fs::path& file)
-    {
-        count++;
-
-        // Expect that the file is what we wanted
-        EXPECT_EQ(file, TRIGGER_FILE);
-    }
-};
-
-/** @brief Makes sure that the inotify event is fired
- */
-TEST_F(WatchTest, validateEventNotification)
-{
-    // Create a watch object and register the handler
-    phosphor::network::inotify::Watch watch(
-        eventPtr, TRIGGER_FILE,
-        std::bind(&WatchTest::callBackHandler, this, std::placeholders::_1));
-
-    // Reading the event post subscription
-    callBackHandler(TRIGGER_FILE);
-
-    // Callback function must have hit by now
-    EXPECT_EQ(1, count);
-
-    // Make a run and see that no changes
-    sd_event_run(eventPtr.get(), 10);
-    EXPECT_EQ(1, count);
-
-    // Pump the data and get notification
-    {
-        std::ofstream file(TRIGGER_FILE);
-        file << "DNS=1.2.3.4\n";
-    }
-
-    sd_event_run(eventPtr.get(), 10);
-    EXPECT_EQ(2, count);
-}