bmc: config: add skip action

If you specify the action for one of the three fields as "skip" it'll
create a handler object for that action that always returns success and
has no effect.  This action therefore "skips" the step, moving the state
machine forward as though it was a successful real action.

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ib4c1091745eb96b8381a332bbeb0562625d3bfbe
diff --git a/bmc/test/Makefile.am b/bmc/test/Makefile.am
index 9f1aa37..cbac3eb 100644
--- a/bmc/test/Makefile.am
+++ b/bmc/test/Makefile.am
@@ -42,7 +42,8 @@
 	firmware_state_updatecompleted_unittest \
 	firmware_state_notyetstarted_tarball_unittest \
 	firmware_multiplebundle_unittest \
-	firmware_json_unittest
+	firmware_json_unittest \
+	firmware_skip_unittest
 
 TESTS = $(check_PROGRAMS)
 
@@ -108,3 +109,6 @@
 
 firmware_json_unittest_SOURCES = firmware_json_unittest.cpp
 firmware_json_unittest_LDADD = $(top_builddir)/bmc/libfirmwareblob_common.la
+
+firmware_skip_unittest_SOURCES = firmware_skip_unittest.cpp
+firmware_skip_unittest_LDADD = $(top_builddir)/bmc/libfirmwareblob_common.la
diff --git a/bmc/test/firmware_json_unittest.cpp b/bmc/test/firmware_json_unittest.cpp
index d56a20a..8f3ea30 100644
--- a/bmc/test/firmware_json_unittest.cpp
+++ b/bmc/test/firmware_json_unittest.cpp
@@ -1,5 +1,6 @@
 #include "buildjson.hpp"
 #include "general_systemd.hpp"
+#include "skip_action.hpp"
 
 #include <nlohmann/json.hpp>
 
@@ -581,5 +582,39 @@
     EXPECT_THAT(updater->getMode(), "replace-fake");
 }
 
+TEST(FirmwareJsonTest, VerifySkipFields)
+{
+    // In this configuration, nothing happens because all actions are set to
+    // skip.
+    auto j2 = R"(
+        [{
+            "blob" : "/flash/image",
+            "handler" : {
+                "type" : "file",
+                "path" : "/run/initramfs/bmc-image"
+            },
+            "actions" : {
+                "preparation" : {
+                    "type" : "skip"
+                },
+                "verification" : {
+                    "type" : "skip"
+                },
+                "update" : {
+                    "type" : "skip"
+                }
+            }
+         }]
+    )"_json;
+
+    auto h = buildHandlerFromJson(j2);
+    EXPECT_EQ(h[0].blobId, "/flash/image");
+    EXPECT_FALSE(h[0].handler == nullptr);
+    EXPECT_FALSE(h[0].actions == nullptr);
+    EXPECT_FALSE(h[0].actions->preparation == nullptr);
+    EXPECT_FALSE(h[0].actions->verification == nullptr);
+    EXPECT_FALSE(h[0].actions->update == nullptr);
+}
+
 } // namespace
 } // namespace ipmi_flash
diff --git a/bmc/test/firmware_skip_unittest.cpp b/bmc/test/firmware_skip_unittest.cpp
new file mode 100644
index 0000000..a549582
--- /dev/null
+++ b/bmc/test/firmware_skip_unittest.cpp
@@ -0,0 +1,36 @@
+#include "skip_action.hpp"
+#include "status.hpp"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace ipmi_flash
+{
+namespace
+{
+
+TEST(SkipActionTest, ValidateTriggerReturnsTrue)
+{
+    SkipAction skip;
+    EXPECT_TRUE(skip.trigger());
+    EXPECT_TRUE(skip.trigger());
+}
+
+TEST(SkipActionTest, ValidateStatusAlwaysSuccess)
+{
+    SkipAction skip;
+    EXPECT_EQ(ActionStatus::success, skip.status());
+    EXPECT_TRUE(skip.trigger());
+    EXPECT_EQ(ActionStatus::success, skip.status());
+}
+
+TEST(SkipActionTest, AbortHasNoImpactOnStatus)
+{
+    SkipAction skip;
+    EXPECT_EQ(ActionStatus::success, skip.status());
+    skip.abort();
+    EXPECT_EQ(ActionStatus::success, skip.status());
+}
+
+} // namespace
+} // namespace ipmi_flash