PEL: On remove() call, return the removed LogID
Have Repository::remove(const LogID& id), which is used to remove
a PEL, return the full LogID of the removed PEL instead of not
returning anything.
That input id only has to have a filled in PEL ID or OpenBMC event log
ID field, but not both, so returning the full LogID of the removed PEL
ensure the calling code will have both values.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: If869c59acd59563db137d7c9523210539b51a040
diff --git a/extensions/openpower-pels/repository.cpp b/extensions/openpower-pels/repository.cpp
index 59b3eaa..7fd509b 100644
--- a/extensions/openpower-pels/repository.cpp
+++ b/extensions/openpower-pels/repository.cpp
@@ -207,11 +207,14 @@
}
}
-void Repository::remove(const LogID& id)
+std::optional<Repository::LogID> Repository::remove(const LogID& id)
{
+ std::optional<LogID> actualID;
+
auto pel = findPEL(id);
if (pel != _pelAttributes.end())
{
+ actualID = pel->first;
updateRepoStats(pel->second, false);
log<level::DEBUG>("Removing PEL from repository",
@@ -228,6 +231,8 @@
entry("PEL_ID=0x%X", id.pelID.id),
entry("OBMC_LOG_ID=%d", id.obmcID.id));
}
+
+ return actualID;
}
std::optional<std::vector<uint8_t>> Repository::getPELData(const LogID& id)
diff --git a/extensions/openpower-pels/repository.hpp b/extensions/openpower-pels/repository.hpp
index c7cb39a..96f951c 100644
--- a/extensions/openpower-pels/repository.hpp
+++ b/extensions/openpower-pels/repository.hpp
@@ -176,9 +176,15 @@
/**
* @brief Removes a PEL from the repository
*
+ * Note that the returned LogID is the fully filled in LogID, i.e.
+ * it has both the PEL and OpenBMC IDs, unlike the passed in LogID
+ * which can just have one or the other.
+ *
* @param[in] id - the ID (either the pel ID, OBMC ID, or both) to remove
+ *
+ * @return std::optional<LogID> - The LogID of the removed PEL
*/
- void remove(const LogID& id);
+ std::optional<LogID> remove(const LogID& id);
/**
* @brief Generates the filename to use for the PEL ID and BCDTime.
diff --git a/test/openpower-pels/repository_test.cpp b/test/openpower-pels/repository_test.cpp
index 3fa2290..4bc3282 100644
--- a/test/openpower-pels/repository_test.cpp
+++ b/test/openpower-pels/repository_test.cpp
@@ -87,6 +87,33 @@
EXPECT_EQ(*newData, pelData);
}
+TEST_F(RepositoryTest, RemoveTest)
+{
+ using pelID = Repository::LogID::Pel;
+ using obmcID = Repository::LogID::Obmc;
+
+ // Add and remove a PEL from the repo
+
+ Repository repo{repoPath};
+
+ auto data = pelDataFactory(TestPELType::pelSimple);
+ auto pel = std::make_unique<PEL>(data, 1);
+
+ pel->assignID();
+ Repository::LogID id{pelID{pel->id()}, obmcID{pel->obmcLogID()}};
+
+ repo.add(pel);
+
+ auto removedID = repo.remove(id);
+ ASSERT_TRUE(removedID);
+ EXPECT_EQ(*removedID, id);
+
+ EXPECT_FALSE(repo.hasPEL(id));
+
+ // Try to remove it again, not there
+ EXPECT_FALSE(repo.remove(id));
+}
+
TEST_F(RepositoryTest, RestoreTest)
{
using pelID = Repository::LogID::Pel;
@@ -137,6 +164,9 @@
id.pelID.id = 99;
id.obmcID.id = 100;
EXPECT_FALSE(repo.hasPEL(id));
+
+ // Try to remove it anyway
+ EXPECT_FALSE(repo.remove(id));
}
{