network_manager: Refactor config rewriting
This re-arranges the code to disconnect config resetting from default
config file writing.
Change-Id: I7106da19fab29982f2efd3cd9871bcd651fb7216
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index 89925b2..c32c36e 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -51,27 +51,11 @@
setConfDir(confDir);
}
-bool Manager::createDefaultNetworkFiles(bool force)
+bool Manager::createDefaultNetworkFiles()
{
auto isCreated = false;
try
{
- // Directory would have created before with
- // setConfDir function.
- if (force)
- {
- // Factory Reset case
- // we need to forcefully write the files
- // so delete the existing ones.
- if (fs::is_directory(confDir))
- {
- for (const auto& file : fs::directory_iterator(confDir))
- {
- fs::remove(file.path());
- }
- }
- }
-
auto interfaceStrList = getInterfaces();
for (const auto& interface : interfaceStrList)
{
@@ -89,10 +73,8 @@
filePath /= fileName;
// create the interface specific network file
- // if not exist or we forcefully wants to write
- // the network file.
-
- if (force || !fs::is_regular_file(filePath.string()))
+ // if not existing.
+ if (!fs::is_regular_file(filePath.string()))
{
bmc::writeDHCPDefault(filePath.string(), interface);
log<level::INFO>("Created the default network file.",
@@ -211,14 +193,15 @@
void Manager::reset()
{
- if (!createDefaultNetworkFiles(true))
+ if (fs::is_directory(confDir))
{
- log<level::ERR>("Network Factory Reset failed.");
- return;
- // TODO: openbmc/openbmc#1721 - Log ResetFailed error here.
+ for (const auto& file : fs::directory_iterator(confDir))
+ {
+ fs::remove(file.path());
+ }
}
-
- log<level::INFO>("Network Factory Reset done.");
+ createDefaultNetworkFiles();
+ log<level::INFO>("Network Factory Reset queued.");
}
// Need to merge the below function with the code which writes the
diff --git a/src/network_manager.hpp b/src/network_manager.hpp
index 7ca9939..47a1e4d 100644
--- a/src/network_manager.hpp
+++ b/src/network_manager.hpp
@@ -102,13 +102,9 @@
}
/** @brief create the default network files for each interface
- * @detail if force param is true then forcefully create the network
- * files otherwise if network file doesn't exist then
- * create it.
- * @param[in] force - forcefully create the file
* @return true if network file created else false
*/
- bool createDefaultNetworkFiles(bool force);
+ bool createDefaultNetworkFiles();
/** @brief This function gets the MAC address from the VPD and
* sets it on the corresponding ethernet interface during first
diff --git a/src/network_manager_main.cpp b/src/network_manager_main.cpp
index 2c0918a..fa4efe5 100644
--- a/src/network_manager_main.cpp
+++ b/src/network_manager_main.cpp
@@ -294,9 +294,7 @@
// create the default network files if the network file
// is not there for any interface.
- // Parameter false means don't create the network
- // files forcefully.
- if (phosphor::network::manager->createDefaultNetworkFiles(false))
+ if (phosphor::network::manager->createDefaultNetworkFiles())
{
phosphor::network::manager->reloadConfigs();
}