tools: Add ignoreUpdate parameter
Adds ignoreUpdate flag to skip checking the update status and always
return success instead. This is needed for platforms that use the reboot
json and encounters an update failure due to IPMI going down during
shutdown.
Tested: Tried out an update with and without --ignore-update to verify
that the flag ignores the update status and returns success.
Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: Ie20774f997229cd5ff8ae9082dc8a747079f9a2c
diff --git a/tools/handler.cpp b/tools/handler.cpp
index 65596f5..711e2f3 100644
--- a/tools/handler.cpp
+++ b/tools/handler.cpp
@@ -106,7 +106,7 @@
blob->closeBlob(session);
}
-bool UpdateHandler::verifyFile(const std::string& target)
+bool UpdateHandler::verifyFile(const std::string& target, bool ignoreStatus)
{
std::uint16_t session;
bool success = false;
@@ -137,6 +137,13 @@
std::string(b.what()));
}
+ if (ignoreStatus)
+ {
+ // Skip checking the blob for status if ignoreStatus is enabled
+ blob->closeBlob(session);
+ return true;
+ }
+
std::fprintf(stderr, "Calling stat on %s session to check status\n",
target.c_str());
diff --git a/tools/handler.hpp b/tools/handler.hpp
index 2335977..a0dae56 100644
--- a/tools/handler.hpp
+++ b/tools/handler.hpp
@@ -36,9 +36,11 @@
*
* @param[in] target - the verification blob id (may support multiple in the
* future.
+ * @param[in] ignoreStatus - determines whether to ignore the verification
+ * status.
* @return true if verified, false if verification errors.
*/
- virtual bool verifyFile(const std::string& target) = 0;
+ virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0;
/**
* Cleanup the artifacts by triggering this action.
@@ -67,7 +69,7 @@
/**
* @throw ToolException on failure (TODO: throw on timeout.)
*/
- bool verifyFile(const std::string& target) override;
+ bool verifyFile(const std::string& target, bool ignoreStatus) override;
void cleanArtifacts() override;
diff --git a/tools/main.cpp b/tools/main.cpp
index ae85c1b..f73bcad 100644
--- a/tools/main.cpp
+++ b/tools/main.cpp
@@ -53,7 +53,8 @@
std::fprintf(
stderr,
"Usage: %s --command <command> --interface <interface> --image "
- "<image file> --sig <signature file> --type <layout>\n",
+ "<image file> --sig <signature file> --type <layout> "
+ "[--ignore-update]\n",
program);
std::fprintf(stderr, "interfaces: ");
@@ -86,6 +87,7 @@
long length = 0;
std::uint32_t hostAddress = 0;
std::uint32_t hostLength = 0;
+ bool ignoreUpdate = false;
while (1)
{
@@ -98,12 +100,13 @@
{"address", required_argument, 0, 'a'},
{"length", required_argument, 0, 'l'},
{"type", required_argument, 0, 't'},
+ {"ignore-update", no_argument, 0, 'u'},
{0, 0, 0, 0}
};
// clang-format on
int option_index = 0;
- int c = getopt_long(argc, argv, "c:i:m:s:a:l:t:", long_options,
+ int c = getopt_long(argc, argv, "c:i:m:s:a:l:t:u", long_options,
&option_index);
if (c == -1)
{
@@ -168,6 +171,9 @@
case 't':
type = std::string{optarg};
break;
+ case 'u':
+ ignoreUpdate = true;
+ break;
default:
usage(argv[0]);
exit(EXIT_FAILURE);
@@ -232,7 +238,8 @@
try
{
host_tool::UpdateHandler updater(&blob, handler.get());
- host_tool::updaterMain(&updater, imagePath, signaturePath, type);
+ host_tool::updaterMain(&updater, imagePath, signaturePath, type,
+ ignoreUpdate);
}
catch (const host_tool::ToolException& e)
{
diff --git a/tools/test/tools_updater_unittest.cpp b/tools/test/tools_updater_unittest.cpp
index 0c9e6b5..706a4c3 100644
--- a/tools/test/tools_updater_unittest.cpp
+++ b/tools/test/tools_updater_unittest.cpp
@@ -87,7 +87,7 @@
.WillOnce(Return(verificationResponse));
EXPECT_CALL(blobMock, closeBlob(session)).WillOnce(Return());
- EXPECT_TRUE(updater.verifyFile(ipmi_flash::verifyBlobId));
+ EXPECT_TRUE(updater.verifyFile(ipmi_flash::verifyBlobId, false));
}
class UpdaterTest : public ::testing::Test
@@ -95,6 +95,7 @@
protected:
ipmiblob::BlobInterfaceMock blobMock;
std::uint16_t session = 0xbeef;
+ bool defaultIgnore = false;
};
TEST_F(UpdaterTest, UpdateMainReturnsSuccessIfAllSuccess)
@@ -106,12 +107,30 @@
EXPECT_CALL(handler, checkAvailable(_)).WillOnce(Return(true));
EXPECT_CALL(handler, sendFile(_, image)).WillOnce(Return());
EXPECT_CALL(handler, sendFile(_, signature)).WillOnce(Return());
- EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId))
+ EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId, defaultIgnore))
.WillOnce(Return(true));
- EXPECT_CALL(handler, verifyFile(ipmi_flash::updateBlobId))
+ EXPECT_CALL(handler, verifyFile(ipmi_flash::updateBlobId, defaultIgnore))
.WillOnce(Return(true));
- updaterMain(&handler, image, signature, "static");
+ updaterMain(&handler, image, signature, "static", defaultIgnore);
+}
+
+TEST_F(UpdaterTest, UpdateMainReturnsSuccessWithIgnoreUpdate)
+{
+ const std::string image = "image.bin";
+ const std::string signature = "signature.bin";
+ UpdateHandlerMock handler;
+ bool updateIgnore = true;
+
+ EXPECT_CALL(handler, checkAvailable(_)).WillOnce(Return(true));
+ EXPECT_CALL(handler, sendFile(_, image)).WillOnce(Return());
+ EXPECT_CALL(handler, sendFile(_, signature)).WillOnce(Return());
+ EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId, defaultIgnore))
+ .WillOnce(Return(true));
+ EXPECT_CALL(handler, verifyFile(ipmi_flash::updateBlobId, updateIgnore))
+ .WillOnce(Return(true));
+
+ updaterMain(&handler, image, signature, "static", updateIgnore);
}
TEST_F(UpdaterTest, UpdateMainCleansUpOnFailure)
@@ -123,12 +142,13 @@
EXPECT_CALL(handler, checkAvailable(_)).WillOnce(Return(true));
EXPECT_CALL(handler, sendFile(_, image)).WillOnce(Return());
EXPECT_CALL(handler, sendFile(_, signature)).WillOnce(Return());
- EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId))
+ EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId, defaultIgnore))
.WillOnce(Return(false));
EXPECT_CALL(handler, cleanArtifacts()).WillOnce(Return());
- EXPECT_THROW(updaterMain(&handler, image, signature, "static"),
- ToolException);
+ EXPECT_THROW(
+ updaterMain(&handler, image, signature, "static", defaultIgnore),
+ ToolException);
}
} // namespace host_tool
diff --git a/tools/test/updater_mock.hpp b/tools/test/updater_mock.hpp
index d67991b..9469c62 100644
--- a/tools/test/updater_mock.hpp
+++ b/tools/test/updater_mock.hpp
@@ -14,7 +14,7 @@
public:
MOCK_METHOD1(checkAvailable, bool(const std::string&));
MOCK_METHOD2(sendFile, void(const std::string&, const std::string&));
- MOCK_METHOD1(verifyFile, bool(const std::string&));
+ MOCK_METHOD2(verifyFile, bool(const std::string&, bool));
MOCK_METHOD0(cleanArtifacts, void());
};
diff --git a/tools/updater.cpp b/tools/updater.cpp
index 0fcfe6f..25f7dab 100644
--- a/tools/updater.cpp
+++ b/tools/updater.cpp
@@ -36,7 +36,7 @@
void updaterMain(UpdateHandlerInterface* updater, const std::string& imagePath,
const std::string& signaturePath,
- const std::string& layoutType)
+ const std::string& layoutType, bool ignoreUpdate)
{
/* TODO: validate the layoutType isn't a special value such as: 'update',
* 'verify', or 'hash'
@@ -63,7 +63,7 @@
/* Trigger the verification by opening and committing the verify file.
*/
std::fprintf(stderr, "Opening the verification file\n");
- if (updater->verifyFile(ipmi_flash::verifyBlobId))
+ if (updater->verifyFile(ipmi_flash::verifyBlobId, false))
{
std::fprintf(stderr, "succeeded\n");
}
@@ -75,7 +75,7 @@
/* Trigger the update by opening and committing the update file. */
std::fprintf(stderr, "Opening the update file\n");
- if (updater->verifyFile(ipmi_flash::updateBlobId))
+ if (updater->verifyFile(ipmi_flash::updateBlobId, ignoreUpdate))
{
std::fprintf(stderr, "succeeded\n");
}
diff --git a/tools/updater.hpp b/tools/updater.hpp
index 331b551..4cae534 100644
--- a/tools/updater.hpp
+++ b/tools/updater.hpp
@@ -15,10 +15,11 @@
* @param[in] imagePath - the path to the image file.
* @param[in] signaturePath - the path to the signature file.
* @param[in] layoutType - the image update layout type (static/ubi/other)
+ * @param[in] ignoreUpdate - determines whether to ignore the update status
* @throws ToolException on failures.
*/
void updaterMain(UpdateHandlerInterface* updater, const std::string& imagePath,
const std::string& signaturePath,
- const std::string& layoutType);
+ const std::string& layoutType, bool ignoreUpdate);
} // namespace host_tool