PEL: Don't send PELs to host when flag disabled

Don't put any PELs on the queue to send to the host when the setting to
send event logs to the host has been set to false.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I37be53f54c354e2c440ac3a932630a4905e311f1
diff --git a/test/openpower-pels/host_notifier_test.cpp b/test/openpower-pels/host_notifier_test.cpp
index c51d560..d3018dc 100644
--- a/test/openpower-pels/host_notifier_test.cpp
+++ b/test/openpower-pels/host_notifier_test.cpp
@@ -45,6 +45,8 @@
         auto r = sd_event_default(&event);
         EXPECT_TRUE(r >= 0);
 
+        ON_CALL(dataIface, getHostPELEnablement).WillByDefault(Return(true));
+
         hostIface =
             std::make_unique<NiceMock<MockHostInterface>>(event, dataIface);
 
@@ -678,3 +680,54 @@
         EXPECT_EQ(notifier.queueSize(), 0);
     }
 }
+
+// Test that sending PELs can be disabled
+TEST_F(HostNotifierTest, TestDisable)
+{
+    // Turn off sending the PELs except for once in the middle
+    EXPECT_CALL(dataIface, getHostPELEnablement())
+        .WillOnce(Return(false))
+        .WillOnce(Return(false))
+        .WillOnce(Return(true))
+        .WillOnce(Return(false))
+        .WillOnce(Return(false))
+        .WillOnce(Return(false));
+
+    {
+        HostNotifier notifier{repo, dataIface, std::move(hostIface)};
+
+        // Add a PEL with the host off
+        auto pel = makePEL();
+        repo.add(pel);
+
+        // Not added to the send queue
+        EXPECT_EQ(notifier.queueSize(), 0);
+
+        dataIface.changeHostState(true);
+
+        // Try again with the host on
+        pel = makePEL();
+        repo.add(pel);
+
+        EXPECT_EQ(notifier.queueSize(), 0);
+
+        // Now getHostPELEnablement() will return true for the new PEL
+        pel = makePEL();
+        repo.add(pel);
+
+        EXPECT_EQ(notifier.queueSize(), 1);
+    }
+
+    // getHostPELEnablement is back to returning false.
+    // Create a new second instance and make sure the 3 existing PELs
+    // aren't put on the queue on startup
+    {
+        Repository repo1{repoPath};
+        std::unique_ptr<HostInterface> hostIface1 =
+            std::make_unique<MockHostInterface>(event, dataIface);
+
+        HostNotifier notifier{repo1, dataIface, std::move(hostIface1)};
+
+        EXPECT_EQ(notifier.queueSize(), 0);
+    }
+}
diff --git a/test/openpower-pels/mocks.hpp b/test/openpower-pels/mocks.hpp
index 8b055dd..5c3bdb1 100644
--- a/test/openpower-pels/mocks.hpp
+++ b/test/openpower-pels/mocks.hpp
@@ -24,6 +24,7 @@
     MOCK_METHOD(std::string, getServerFWVersion, (), (const override));
     MOCK_METHOD(std::string, getBMCFWVersion, (), (const override));
     MOCK_METHOD(std::string, getBMCFWVersionID, (), (const override));
+    MOCK_METHOD(bool, getHostPELEnablement, (), (const override));
 
     void changeHostState(bool newState)
     {