PEL: Create class to read from the journal
Create a Journal class that can extract messages out of the journal and
return them as a vector of strings that look like:
"Dec 14 15:58:17 systemd[1]: systemd-tmpfiles-clean.service: Deactivated
successfully."
It can either grab the previous N entries, or the previous N entries
that match a specific SYSLOG_IDENTIFIER value.
The class follows the same strategy as the DataInterface class where a
base class pointer is passed into the PEL Manager class so that during
unit test it can be mocked.
Future commits will capture the journal into PEL UserData sections.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I9f4bb304c4b213165049fa00de2e62f962ae67f1
diff --git a/test/openpower-pels/mocks.hpp b/test/openpower-pels/mocks.hpp
index de7f757..7a1ee35 100644
--- a/test/openpower-pels/mocks.hpp
+++ b/test/openpower-pels/mocks.hpp
@@ -1,5 +1,6 @@
#include "extensions/openpower-pels/data_interface.hpp"
#include "extensions/openpower-pels/host_interface.hpp"
+#include "extensions/openpower-pels/journal.hpp"
#include <fcntl.h>
@@ -278,5 +279,14 @@
size_t _cmdsProcessed = 0;
};
+class MockJournal : public JournalBase
+{
+ public:
+ MockJournal() {}
+
+ MOCK_METHOD(std::vector<std::string>, getMessages,
+ (const std::string&, size_t), (const override));
+};
+
} // namespace pels
} // namespace openpower
diff --git a/test/openpower-pels/pel_manager_test.cpp b/test/openpower-pels/pel_manager_test.cpp
index b27ca60..012e42c 100644
--- a/test/openpower-pels/pel_manager_test.cpp
+++ b/test/openpower-pels/pel_manager_test.cpp
@@ -131,10 +131,13 @@
std::unique_ptr<DataInterfaceBase> dataIface =
std::make_unique<MockDataInterface>();
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
// Create a PEL, write it to a file, and pass that filename into
// the create function.
@@ -173,10 +176,13 @@
std::unique_ptr<DataInterfaceBase> dataIface =
std::make_unique<MockDataInterface>();
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
// Create a PEL, write it to a file, and pass that filename into
// the create function.
@@ -282,10 +288,13 @@
EXPECT_CALL(*mockIface, checkDumpStatus(dumpType))
.WillRepeatedly(Return(std::vector<bool>{false, false, false}));
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
std::vector<std::string> additionalData{"FOO=BAR"};
std::vector<std::string> associations;
@@ -387,10 +396,13 @@
std::unique_ptr<DataInterfaceBase> dataIface =
std::make_unique<MockDataInterface>();
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
Manager manager{logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger,
std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3)};
+ std::placeholders::_3),
+ std::move(journal)};
// Create a PEL, write it to a file, and pass that filename into
// the create function so there's one in the repo.
@@ -610,10 +622,13 @@
std::unique_ptr<DataInterfaceBase> dataIface =
std::make_unique<MockDataInterface>();
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
{
std::string adItem = "ESEL=" + esel;
@@ -664,10 +679,13 @@
std::unique_ptr<DataInterfaceBase> dataIface =
std::make_unique<MockDataInterface>();
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
// Create 25 1000B (4096B on disk each, which is what is used for pruning)
// BMC non-informational PELs in the 100KB repository. After the 24th one,
@@ -738,10 +756,13 @@
std::unique_ptr<DataInterfaceBase> dataIface =
std::make_unique<MockDataInterface>();
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
auto data = pelDataFactory(TestPELType::pelSimple);
auto dir = makeTempDir();
@@ -814,10 +835,13 @@
std::unique_ptr<DataInterfaceBase> dataIface =
std::make_unique<MockDataInterface>();
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
auto data = pelDataFactory(TestPELType::pelSimple);
auto dir = makeTempDir();
@@ -890,10 +914,13 @@
EXPECT_CALL(*mockIface, checkDumpStatus(dumpType))
.WillRepeatedly(Return(std::vector<bool>{false, false, false}));
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
// Add a PEL with a callout as if hostboot added it
{
@@ -999,10 +1026,13 @@
std::unique_ptr<DataInterfaceBase> dataIface =
std::make_unique<MockDataInterface>();
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
for (int i = 0; i < 2; i++)
{
@@ -1084,10 +1114,13 @@
EXPECT_CALL(*mockIface, checkDumpStatus(dumpType))
.WillRepeatedly(Return(std::vector<bool>{false, false, false}));
+ std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
+
openpower::pels::Manager manager{
logManager, std::move(dataIface),
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)};
+ std::placeholders::_2, std::placeholders::_3),
+ std::move(journal)};
std::vector<std::string> additionalData{"FOO=BAR"};
std::vector<std::string> associations;