Sep_24_2023-Dev

This commit is contained in:
Ned Wright
2023-09-24 10:28:57 +00:00
parent a4d1fb6f7f
commit 582791e37a
106 changed files with 12287 additions and 169 deletions

View File

@@ -21,6 +21,7 @@
#include <sys/syscall.h>
#include <dirent.h>
#include <sstream>
#include <algorithm>
#include "debug.h"
@@ -49,6 +50,24 @@ exists(const string &path)
return false;
}
bool
isDirectory(const string &path)
{
dbgFlow(D_INFRA_UTILS) << "Checking if path is a directory. Path: " << path;
struct stat buffer;
if (stat(path.c_str(), &buffer) != 0) {
dbgTrace(D_INFRA_UTILS) << "Path does not exists. Path: " << path;
return false;
}
if (buffer.st_mode & S_IFDIR) {
dbgTrace(D_INFRA_UTILS) << "Path is a directory. Path: " << path;
return true;
}
return false;
}
bool
makeDir(const string &path, mode_t permission)
{
@@ -356,4 +375,20 @@ regexReplace(const char *file, int line, const string &sample, const regex &rege
}// namespace Regex
namespace Strings
{
string
removeTrailingWhitespaces(string str)
{
str.erase(
find_if(str.rbegin(), str.rend(), [] (char c) { return !isspace(c); }).base(),
str.end()
);
return str;
}
} // namespace Strings
} // namespace NGEN

View File

@@ -98,8 +98,20 @@ TEST_F(AgentCoreUtilUT, printTest)
EXPECT_EQ(NGEN::Filesystem::convertToHumanReadable(1024*gigabyte), "1024.00 GB");
}
TEST_F(AgentCoreUtilUT, fileBasenameTest)
{
EXPECT_EQ(NGEN::Filesystem::getFileName("/test/base/file/name"), "name");
}
TEST_F(AgentCoreUtilUT, isDirectoryTest)
{
mkdir("./test", 0400);
EXPECT_EQ(NGEN::Filesystem::isDirectory("/test/base/file/name"), false);
EXPECT_EQ(NGEN::Filesystem::isDirectory("./test"), true);
}
TEST_F(AgentCoreUtilUT, removeTrailingWhitespacesTest)
{
string str_with_trailing_whitespace = "str_with_trailing_whitespace\n\n\n\r \n\n\r";
EXPECT_EQ(NGEN::Strings::removeTrailingWhitespaces(str_with_trailing_whitespace), "str_with_trailing_whitespace");
}

View File

@@ -141,7 +141,6 @@ Environment::Impl::init()
void
Environment::Impl::fini()
{
global.deactivate();
}
void

View File

@@ -143,7 +143,8 @@ enum class Notification {
SDWAN_POLICY_UPDATE,
SDWAN_POLICY_UPDATE_ERROR,
SDWAN_POLICY_UPDATE_LOG,
SDWAN_POLICY_UPDATE_ERROR_LOG
SDWAN_POLICY_UPDATE_ERROR_LOG,
SDWAN_POLICY_WARNING_LOG
};
enum class IssuingEngine {

View File

@@ -25,6 +25,7 @@ namespace Filesystem
{
bool exists(const std::string &path);
bool isDirectory(const std::string &path);
bool makeDir(const std::string &path, mode_t permission = S_IRWXU);
bool makeDirRecursive(const std::string &path, mode_t permission = S_IRWXU);
@@ -75,6 +76,13 @@ regexReplace(
} // namespace Regex
namespace Strings
{
std::string removeTrailingWhitespaces(std::string str);
} // namespace Strings
} // namespace NGEN
#endif // __AGENT_CORE_UTILITIES_H__

View File

@@ -19,7 +19,10 @@ extern const string unnamed_service;
LogGen::~LogGen()
{
if (send_log) Singleton::Consume<I_Logging>::by<LogGen>()->sendLog(log);
try {
if (send_log) Singleton::Consume<I_Logging>::by<LogGen>()->sendLog(log);
} catch (...) {
}
}
LogGen &

View File

@@ -252,6 +252,7 @@ TagAndEnumManagement::convertToString(const Notification &notification)
case Notification::SDWAN_POLICY_UPDATE_ERROR: return "8d2db6ea-30b7-11ec-8d3d-0242ac130003";
case Notification::SDWAN_POLICY_UPDATE_LOG: return "97cb79e1-e873-4f28-b123-5e19f8dd6f99";
case Notification::SDWAN_POLICY_UPDATE_ERROR_LOG: return "44ca5755-07a2-483c-b756-b7df444e175c";
case Notification::SDWAN_POLICY_WARNING_LOG: return "c58d490e-6aa0-43da-bfaa-7edad0a57b7a";
}
dbgAssert(false) << "Reached impossible notification value of: " << static_cast<int>(notification);