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/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);
-}