firmware: add expiration handle
Expiring the session aborts the process.
Tested: Only tested with unit-tests, not run on a real system.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I3a7ae54cfa04e162a2a1e591c0ddd4eca3d6d3db
diff --git a/bmc/firmware_handler.cpp b/bmc/firmware_handler.cpp
index 917dbc4..ffe40b1 100644
--- a/bmc/firmware_handler.cpp
+++ b/bmc/firmware_handler.cpp
@@ -755,7 +755,8 @@
bool FirmwareBlobHandler::expire(uint16_t session)
{
- return false;
+ abortProcess();
+ return true;
}
/*
diff --git a/bmc/test/firmware_state_notyetstarted_unittest.cpp b/bmc/test/firmware_state_notyetstarted_unittest.cpp
index b3cfc49..970ae2f 100644
--- a/bmc/test/firmware_state_notyetstarted_unittest.cpp
+++ b/bmc/test/firmware_state_notyetstarted_unittest.cpp
@@ -113,5 +113,18 @@
EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId));
}
+/*
+ * expire(session)
+ */
+TEST_F(FirmwareHandlerNotYetStartedTest, ExpireOnNotYetStartedAbortsProcess)
+{
+ ASSERT_TRUE(handler->expire(session));
+
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(startingBlobs));
+
+ expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+}
+
} // namespace
} // namespace ipmi_flash
diff --git a/bmc/test/firmware_state_updatecompleted_unittest.cpp b/bmc/test/firmware_state_updatecompleted_unittest.cpp
index 7136223..d002499 100644
--- a/bmc/test/firmware_state_updatecompleted_unittest.cpp
+++ b/bmc/test/firmware_state_updatecompleted_unittest.cpp
@@ -245,5 +245,19 @@
}
}
+/*
+ * expire(session)
+ */
+TEST_F(FirmwareHandlerUpdateCompletedTest, ExpireOnUpdateCompletedAbortsProcess)
+{
+ getToUpdateCompleted(ActionStatus::success);
+
+ ASSERT_TRUE(handler->expire(session));
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(startingBlobs));
+
+ expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+}
+
} // namespace
} // namespace ipmi_flash
diff --git a/bmc/test/firmware_state_updatepending_unittest.cpp b/bmc/test/firmware_state_updatepending_unittest.cpp
index 16a6498..5f43259 100644
--- a/bmc/test/firmware_state_updatepending_unittest.cpp
+++ b/bmc/test/firmware_state_updatepending_unittest.cpp
@@ -290,5 +290,20 @@
expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
}
+/*
+ * expire(session)
+ */
+TEST_F(FirmwareHandlerUpdatePendingTest, ExpireOnUpdatePendingAborstsProcess)
+{
+ getToUpdatePending();
+
+ EXPECT_CALL(*updateMockPtr, abort()).Times(0);
+
+ ASSERT_TRUE(handler->expire(session));
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(startingBlobs));
+ expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+}
+
} // namespace
} // namespace ipmi_flash
diff --git a/bmc/test/firmware_state_updatestarted_unittest.cpp b/bmc/test/firmware_state_updatestarted_unittest.cpp
index 3aa97ed..f187a8e 100644
--- a/bmc/test/firmware_state_updatestarted_unittest.cpp
+++ b/bmc/test/firmware_state_updatestarted_unittest.cpp
@@ -236,5 +236,22 @@
expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
}
+/*
+ * expire(session)
+ */
+TEST_F(FirmwareHandlerUpdateStartedTest,
+ ExpireOnUpdateDuringUpdateAbortsProcess)
+{
+ getToUpdateStarted();
+ EXPECT_CALL(*updateMockPtr, abort()).Times(0);
+
+ ASSERT_TRUE(handler->expire(session));
+
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(startingBlobs));
+
+ expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+}
+
} // namespace
} // namespace ipmi_flash
diff --git a/bmc/test/firmware_state_uploadinprogress_unittest.cpp b/bmc/test/firmware_state_uploadinprogress_unittest.cpp
index 994ddb1..d5bd3f3 100644
--- a/bmc/test/firmware_state_uploadinprogress_unittest.cpp
+++ b/bmc/test/firmware_state_uploadinprogress_unittest.cpp
@@ -277,5 +277,18 @@
}
}
+/*
+ * expire(session)
+ */
+TEST_F(FirmwareHandlerUploadInProgressTest, ExpireAbortsProcess)
+{
+ openToInProgress(staticLayoutBlobId);
+
+ ASSERT_TRUE(handler->expire(session));
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(startingBlobs));
+ expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+}
+
} // namespace
} // namespace ipmi_flash
diff --git a/bmc/test/firmware_state_verificationcompleted_unittest.cpp b/bmc/test/firmware_state_verificationcompleted_unittest.cpp
index f7b0998..f926223 100644
--- a/bmc/test/firmware_state_verificationcompleted_unittest.cpp
+++ b/bmc/test/firmware_state_verificationcompleted_unittest.cpp
@@ -307,5 +307,19 @@
UnorderedElementsAreArray(startingBlobs));
}
+/*
+ * expire(session)
+ */
+TEST_F(FirmwareHandlerVerificationCompletedTest,
+ ExpireAfterVerificationCompletedAborts)
+{
+ getToVerificationCompleted(ActionStatus::failed);
+
+ ASSERT_TRUE(handler->expire(session));
+ expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(startingBlobs));
+}
+
} // namespace
} // namespace ipmi_flash
diff --git a/bmc/test/firmware_state_verificationpending_unittest.cpp b/bmc/test/firmware_state_verificationpending_unittest.cpp
index 3b958c1..dc6f3d3 100644
--- a/bmc/test/firmware_state_verificationpending_unittest.cpp
+++ b/bmc/test/firmware_state_verificationpending_unittest.cpp
@@ -129,6 +129,24 @@
}
/*
+ * expire(session)
+ */
+TEST_F(FirmwareHandlerVerificationPendingTest,
+ ExpireVerificationPendingAbortsProcess)
+{
+ getToVerificationPending(staticLayoutBlobId);
+
+ EXPECT_CALL(*verifyMockPtr, abort()).Times(0);
+
+ EXPECT_TRUE(handler->expire(session));
+
+ std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId};
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(expectedBlobs));
+ expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+}
+
+/*
* stat(blob)
*/
TEST_F(FirmwareHandlerVerificationPendingTest, StatOnActiveImageReturnsFailure)
diff --git a/bmc/test/firmware_state_verificationstarted_unittest.cpp b/bmc/test/firmware_state_verificationstarted_unittest.cpp
index df2c422..4f69c89 100644
--- a/bmc/test/firmware_state_verificationstarted_unittest.cpp
+++ b/bmc/test/firmware_state_verificationstarted_unittest.cpp
@@ -284,5 +284,22 @@
expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
}
+/*
+ * expire(session)
+ */
+TEST_F(FirmwareHandlerVerificationStartedTest,
+ ExpireOnSessionDuringVerificationAbortsProcess)
+{
+ getToVerificationStarted(staticLayoutBlobId);
+ EXPECT_CALL(*verifyMockPtr, abort()).Times(0);
+
+ EXPECT_TRUE(handler->expire(session));
+
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(startingBlobs));
+
+ expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+}
+
} // namespace
} // namespace ipmi_flash