bmc: abort from verificationStarted
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I649ad1779075ef07908740a1430ca285f856512c
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 865c045..03342aa 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -655,10 +655,12 @@
*/
break;
case UpdateState::verificationStarted:
- /* TODO: If they close this blob before verification finishes,
- * that's an abort.
+ /* Abort without checking to see if it happened to finish. Require
+ * the caller to stat() deliberately.
*/
- return false;
+ abortVerification();
+ abortProcess();
+ break;
case UpdateState::verificationCompleted:
if (lastVerificationStatus == ActionStatus::success)
{
@@ -723,6 +725,24 @@
return {};
}
+void FirmwareBlobHandler::abortProcess()
+{
+ /* Closing of open files is handled from close() -- Reaching here from
+ * delete may never be supported.
+ */
+ removeBlobId(verifyBlobId);
+ removeBlobId(updateBlobId);
+ removeBlobId(activeImageBlobId);
+ removeBlobId(activeHashBlobId);
+
+ state = UpdateState::notYetStarted;
+}
+
+void FirmwareBlobHandler::abortVerification()
+{
+ verification->abort();
+}
+
bool FirmwareBlobHandler::triggerVerification()
{
bool result = verification->trigger();
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index 1f7032b..8883176 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -156,6 +156,9 @@
bool stat(uint16_t session, blobs::BlobMeta* meta) override;
bool expire(uint16_t session) override;
+ void abortProcess();
+
+ void abortVerification();
bool triggerVerification();
bool triggerUpdate();
diff --git a/test/firmware_state_verificationstarted_unittest.cpp b/test/firmware_state_verificationstarted_unittest.cpp
index 03ceb99..ba76503 100644
--- a/test/firmware_state_verificationstarted_unittest.cpp
+++ b/test/firmware_state_verificationstarted_unittest.cpp
@@ -263,8 +263,22 @@
/*
* close(session) - close while state if verificationStarted without calling
* stat first will abort.
- * TODO: implement this test when we implement abort.
*/
+TEST_F(FirmwareHandlerVerificationStartedTest,
+ CloseOnVerifyDuringVerificationAbortsProcess)
+{
+ getToVerificationStarted(staticLayoutBlobId);
+ EXPECT_CALL(*verifyMockPtr, 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