bmc: abort from updateStarted

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ib5cd094415af4e0c6b2bb3067fadef6b1a5af757
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 03342aa..64279a2 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -678,7 +678,11 @@
              * uninteresting. */
             break;
         case UpdateState::updateStarted:
-            /* TODO: handle closing while update is running!. */
+            /* Abort without checking to see if it happened to finish. Require
+             * the caller to stat() deliberately.
+             */
+            abortUpdate();
+            abortProcess();
             break;
         case UpdateState::updateCompleted:
             if (lastUpdateStatus == ActionStatus::failed)
@@ -754,6 +758,11 @@
     return result;
 }
 
+void FirmwareBlobHandler::abortUpdate()
+{
+    update->abort();
+}
+
 bool FirmwareBlobHandler::triggerUpdate()
 {
     bool result = update->trigger();
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index 8883176..5790c13 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -160,6 +160,7 @@
 
     void abortVerification();
     bool triggerVerification();
+    void abortUpdate();
     bool triggerUpdate();
 
     /** Allow grabbing the current state. */
diff --git a/test/firmware_state_updatestarted_unittest.cpp b/test/firmware_state_updatestarted_unittest.cpp
index 420d7a7..51a3c20 100644
--- a/test/firmware_state_updatestarted_unittest.cpp
+++ b/test/firmware_state_updatestarted_unittest.cpp
@@ -212,8 +212,22 @@
 }
 
 /*
- * TODO: close(session) - this will abort.
+ * close(session) - this will abort.
  */
+TEST_F(FirmwareHandlerUpdateStartedTest, CloseOnUpdateDuringUpdateAbortsProcess)
+{
+    getToUpdateStarted();
+    EXPECT_CALL(*updateMockPtr, abort()).Times(1);
+
+    EXPECT_TRUE(handler->close(session));
+
+    std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId};
+
+    EXPECT_THAT(handler->getBlobIds(),
+                UnorderedElementsAreArray(expectedBlobs));
+
+    expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+}
 
 } // namespace
 } // namespace ipmi_flash