summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-07-19 12:45:28 -0500
committerMatt Spinler <spinler@us.ibm.com>2019-08-05 12:49:54 -0500
commit2813f36ded0fce084df9620c972469dc8e096179 (patch)
treeb321ead4d3a501940e4c16154eec184fbabc96d8
parent475e574da95a75af6001fdc2198c1892c1bfc041 (diff)
downloadphosphor-logging-2813f36ded0fce084df9620c972469dc8e096179.tar.gz
phosphor-logging-2813f36ded0fce084df9620c972469dc8e096179.zip
PEL: New repository method to get PEL data
Add the getPELData() function on the Repository class to return PEL data based on a PEL ID or OBMC event log ID. The intended use for this will be a D-Bus method, mainly used for debug via the REST interface, to get the PEL data off the BMC when only the OpenBMC event log ID is known, which will be the case until the Redfish APIs are ready. Signed-off-by: Matt Spinler <spinler@us.ibm.com> Change-Id: Ia1d8bff627992fae16be9136f2814f01ea69009e
-rw-r--r--extensions/openpower-pels/repository.cpp22
-rw-r--r--extensions/openpower-pels/repository.hpp12
-rw-r--r--test/openpower-pels/repository_test.cpp23
3 files changed, 57 insertions, 0 deletions
diff --git a/extensions/openpower-pels/repository.cpp b/extensions/openpower-pels/repository.cpp
index aa6a18b..0810dd4 100644
--- a/extensions/openpower-pels/repository.cpp
+++ b/extensions/openpower-pels/repository.cpp
@@ -125,5 +125,27 @@ void Repository::remove(const LogID& id)
}
}
+std::optional<std::vector<uint8_t>> Repository::getPELData(const LogID& id)
+{
+ auto pel = findPEL(id);
+ if (pel != _idsToPELs.end())
+ {
+ std::ifstream file{pel->second.c_str()};
+ if (!file.good())
+ {
+ auto e = errno;
+ log<level::ERR>("Unable to open PEL file", entry("ERRNO=%d", e),
+ entry("PATH=%s", pel->second.c_str()));
+ throw file_error::Open();
+ }
+
+ std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
+ std::istreambuf_iterator<char>()};
+ return data;
+ }
+
+ return std::nullopt;
+}
+
} // namespace pels
} // namespace openpower
diff --git a/extensions/openpower-pels/repository.hpp b/extensions/openpower-pels/repository.hpp
index 289541c..d153400 100644
--- a/extensions/openpower-pels/repository.hpp
+++ b/extensions/openpower-pels/repository.hpp
@@ -136,6 +136,18 @@ class Repository
return findPEL(id) != _idsToPELs.end();
}
+ /**
+ * @brief Returns the PEL data based on its ID.
+ *
+ * If the data can't be found for that ID, then the optional object
+ * will be empty.
+ *
+ * @param[in] id - the LogID to get the PEL for, which can be either a
+ * PEL ID or OpenBMC log ID.
+ * @return std::optional<std::vector<uint8_t>> - the PEL data
+ */
+ std::optional<std::vector<uint8_t>> getPELData(const LogID& id);
+
private:
/**
* @brief Finds an entry in the _idsToPELs map.
diff --git a/test/openpower-pels/repository_test.cpp b/test/openpower-pels/repository_test.cpp
index 6963184..57952e3 100644
--- a/test/openpower-pels/repository_test.cpp
+++ b/test/openpower-pels/repository_test.cpp
@@ -138,3 +138,26 @@ TEST_F(RepositoryTest, RestoreTest)
EXPECT_FALSE(repo.hasPEL(ids[1]));
}
}
+
+TEST_F(RepositoryTest, TestGetPELData)
+{
+ using ID = Repository::LogID;
+ Repository repo{repoPath};
+
+ ID badID{ID::Pel(42)};
+ auto noData = repo.getPELData(badID);
+ EXPECT_FALSE(noData);
+
+ // Add a PEL to the repo, and get the data back with getPELData.
+ auto data = pelDataFactory(TestPelType::pelSimple);
+ auto dataCopy = *data;
+ auto pel = std::make_unique<PEL>(*data);
+ auto pelID = pel->id();
+ repo.add(pel);
+
+ ID id{ID::Pel(pelID)};
+ auto pelData = repo.getPELData(id);
+
+ ASSERT_TRUE(pelData);
+ EXPECT_EQ(dataCopy, *pelData);
+}
OpenPOWER on IntegriCloud