Create IBM ConfigFile base directory
The ConfigFile upload fails when the /var/lib/obmc directory is not
available at BMC
This commit changes the base directory to /var/lib/bmcweb
The subdirectories for the configfiles and locks
are created under this new path
Migration strategy of this directory and files:
This is IBM only feature, compiled under the IBM_MANAGEMENT_CONSOLE flag
There is no system out yet which is running this code
Internal IBM stake holders are in agreement with the changes
Tested by :
1. Tested configfile upload on a BMC where the base directory is not
available
2. Tested the configfile upload on a factory BMC. Verified it creates
the base directories and the upload is successful
3. Tested the configfile usecases for delete and delete-all
4. Tested the acquire-lock functionality
5. Ran lock unit test successfully
Signed-off-by: Sunitha Harish <sunharis@in.ibm.com>
Change-Id: Ic3f5f5d0ba0b37950fd397ec835b4fa7babdaa9b
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index 5e49a9a..d5ee590 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -42,47 +42,6 @@
constexpr size_t maxBroadcastMsgSize =
1000; // Allow Broadcast message size upto 1KB
-inline bool
- createSaveAreaPath(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
-{
- // The path /var/lib/obmc will be created by initrdscripts
- // Create the directories for the save-area files, when we get
- // first file upload request
- std::error_code ec;
- if (!std::filesystem::is_directory("/var/lib/obmc/bmc-console-mgmt", ec))
- {
- std::filesystem::create_directory("/var/lib/obmc/bmc-console-mgmt", ec);
- }
- if (ec)
- {
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- asyncResp->res.jsonValue["Description"] = internalServerError;
- BMCWEB_LOG_DEBUG
- << "handleIbmPost: Failed to prepare save-area directory. ec : "
- << ec;
- return false;
- }
-
- if (!std::filesystem::is_directory(
- "/var/lib/obmc/bmc-console-mgmt/save-area", ec))
- {
- std::filesystem::create_directory(
- "/var/lib/obmc/bmc-console-mgmt/save-area", ec);
- }
- if (ec)
- {
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- asyncResp->res.jsonValue["Description"] = internalServerError;
- BMCWEB_LOG_DEBUG
- << "handleIbmPost: Failed to prepare save-area directory. ec : "
- << ec;
- return false;
- }
- return true;
-}
-
inline void handleFilePut(const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& fileID)
@@ -101,7 +60,9 @@
BMCWEB_LOG_DEBUG
<< "handleIbmPut: Request to create/update the save-area file";
- if (!createSaveAreaPath(asyncResp))
+ std::string_view path =
+ "/var/lib/bmcweb/ibm-management-console/configfiles";
+ if (!crow::ibm_utils::createDirectory(path))
{
asyncResp->res.result(boost::beast::http::status::not_found);
asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg;
@@ -109,7 +70,8 @@
}
std::ofstream file;
- std::filesystem::path loc("/var/lib/obmc/bmc-console-mgmt/save-area");
+ std::filesystem::path loc(
+ "/var/lib/bmcweb/ibm-management-console/configfiles");
// Get the current size of the savearea directory
std::filesystem::recursive_directory_iterator iter(loc, ec);
@@ -234,6 +196,12 @@
}
file.open(loc, std::ofstream::out);
+
+ // set the permission of the file to 600
+ std::filesystem::perms permission = std::filesystem::perms::owner_write |
+ std::filesystem::perms::owner_read;
+ std::filesystem::permissions(loc, permission);
+
if (file.fail())
{
BMCWEB_LOG_DEBUG << "Error while opening the file for writing";
@@ -244,6 +212,7 @@
return;
}
file << data;
+
std::string origin = "/ibm/v1/Host/ConfigFiles/" + fileID;
// Push an event
if (fileExists)
@@ -268,7 +237,8 @@
handleConfigFileList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
std::vector<std::string> pathObjList;
- std::filesystem::path loc("/var/lib/obmc/bmc-console-mgmt/save-area");
+ std::filesystem::path loc(
+ "/var/lib/bmcweb/ibm-management-console/configfiles");
if (std::filesystem::exists(loc) && std::filesystem::is_directory(loc))
{
for (const auto& file : std::filesystem::directory_iterator(loc))
@@ -296,7 +266,8 @@
{
std::vector<std::string> pathObjList;
std::error_code ec;
- std::filesystem::path loc("/var/lib/obmc/bmc-console-mgmt/save-area");
+ std::filesystem::path loc(
+ "/var/lib/bmcweb/ibm-management-console/configfiles");
if (std::filesystem::exists(loc) && std::filesystem::is_directory(loc))
{
std::filesystem::remove_all(loc, ec);
@@ -334,8 +305,8 @@
const std::string& fileID)
{
BMCWEB_LOG_DEBUG << "HandleGet on SaveArea files on path: " << fileID;
- std::filesystem::path loc("/var/lib/obmc/bmc-console-mgmt/save-area/" +
- fileID);
+ std::filesystem::path loc(
+ "/var/lib/bmcweb/ibm-management-console/configfiles/" + fileID);
if (!std::filesystem::exists(loc))
{
BMCWEB_LOG_ERROR << loc << "Not found";
@@ -367,7 +338,8 @@
handleFileDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& fileID)
{
- std::string filePath("/var/lib/obmc/bmc-console-mgmt/save-area/" + fileID);
+ std::string filePath("/var/lib/bmcweb/ibm-management-console/configfiles/" +
+ fileID);
BMCWEB_LOG_DEBUG << "Removing the file : " << filePath << "\n";
std::ifstream fileOpen(filePath.c_str());
if (static_cast<bool>(fileOpen))