summaryrefslogtreecommitdiffstats
path: root/test/openpower-pels/pel_manager_test.cpp
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-07-17 13:54:30 -0500
committerMatt Spinler <spinler@us.ibm.com>2019-08-05 12:49:54 -0500
commit89fa082a68c975128db6fa96eab33200c6bc7bb6 (patch)
tree30ef8f010c8431536b631c47fa54bab43ecc2f51 /test/openpower-pels/pel_manager_test.cpp
parentcb6b059eec52ddfe099221de003d7dca86ce1db0 (diff)
downloadphosphor-logging-89fa082a68c975128db6fa96eab33200c6bc7bb6.tar.gz
phosphor-logging-89fa082a68c975128db6fa96eab33200c6bc7bb6.zip
PEL: Add repository to save PELs
Create the Repository class that can save PELs in (and later retrieve them from) the filesystem. It provides an add() method that can add a PEL object to the repository. Now, when the Manager class sees an OpenBMC event log created with the RAWPEL metadata in the AdditionalData property that points at a file that contains a PEL, it can save that PEL. Before the PEL is saved, the log ID and commit timestamp fields in the PEL will be updated - the log ID to a unique value, and the timestamp to the current time. Change-Id: I8dbaddf0f155bcb6d40b933294ada83feb75ce53
Diffstat (limited to 'test/openpower-pels/pel_manager_test.cpp')
-rw-r--r--test/openpower-pels/pel_manager_test.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/openpower-pels/pel_manager_test.cpp b/test/openpower-pels/pel_manager_test.cpp
new file mode 100644
index 0000000..a5b16f5
--- /dev/null
+++ b/test/openpower-pels/pel_manager_test.cpp
@@ -0,0 +1,66 @@
+#include "extensions/openpower-pels/manager.hpp"
+#include "log_manager.hpp"
+#include "pel_utils.hpp"
+
+#include <fstream>
+#include <regex>
+
+#include <gtest/gtest.h>
+
+using namespace openpower::pels;
+namespace fs = std::filesystem;
+
+class ManagerTest : public CleanPELFiles
+{
+};
+
+fs::path makeTempDir()
+{
+ char path[] = "/tmp/tempnameXXXXXX";
+ std::filesystem::path dir = mkdtemp(path);
+ return dir;
+}
+
+// Test that using the RAWPEL=<file> with the Manager::create() call gets
+// a PEL saved in the repository.
+TEST_F(ManagerTest, TestCreateWithPEL)
+{
+ auto bus = sdbusplus::bus::new_default();
+ phosphor::logging::internal::Manager logManager(bus, "logging_path");
+
+ openpower::pels::Manager manager{logManager};
+
+ // Create a PEL, write it to a file, and pass that filename into
+ // the create function.
+ auto data = pelDataFactory(TestPelType::pelSimple);
+
+ fs::path pelFilename = makeTempDir() / "rawpel";
+ std::ofstream pelFile{pelFilename};
+ pelFile.write(reinterpret_cast<const char*>(data->data()), data->size());
+ pelFile.close();
+
+ std::string adItem = "RAWPEL=" + pelFilename.string();
+ std::vector<std::string> additionalData{adItem};
+ std::vector<std::string> associations;
+
+ manager.create("error message", 42, 0, Entry::Level::Error, additionalData,
+ associations);
+
+ // We don't know the exact name, but a file should have been added to the
+ // repo of the form <timestamp>_<ID>
+ std::regex expr{"\\d+_\\d+"};
+
+ bool found = false;
+ for (auto& f : fs::directory_iterator(getPELRepoPath() / "logs"))
+ {
+ if (std::regex_search(f.path().string(), expr))
+ {
+ found = true;
+ break;
+ }
+ }
+
+ EXPECT_TRUE(found);
+
+ fs::remove_all(pelFilename.parent_path());
+}
OpenPOWER on IntegriCloud