Verify machine name
Verifying machine name from os-release file vs MANIFEST file in
image. Also supporting backword compatibility for older version
where machine name is not defined.
Tested: tested this with latest image build and manifest file patch
Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
Change-Id: Icb0ac3f884ea1131e2ffd2bde6b8a37185dc55ea
diff --git a/image_manager.cpp b/image_manager.cpp
index 5b2ff49..422e1bf 100644
--- a/image_manager.cpp
+++ b/image_manager.cpp
@@ -106,6 +106,33 @@
return -1;
}
+ // Get running machine name
+ std::string currMachine = Version::getBMCMachine(OS_RELEASE_FILE);
+ if (currMachine.empty())
+ {
+ log<level::ERR>("Failed to read machine name from osRelease",
+ entry("FILENAME=%s", OS_RELEASE_FILE));
+ return -1;
+ }
+
+ // Get machine name for image to be upgraded
+ std::string machineStr =
+ Version::getValue(manifestPath.string(), "MachineName");
+ if (!machineStr.empty())
+ {
+ if (machineStr != currMachine)
+ {
+ log<level::ERR>("BMC upgrade: Machine name doesn't match",
+ entry("CURR_MACHINE=%s", currMachine.c_str()),
+ entry("NEW_MACHINE=%s", machineStr.c_str()));
+ return -1;
+ }
+ }
+ else
+ {
+ log<level::WARNING>("No machine name in Manifest file");
+ }
+
// Get purpose
auto purposeString = Version::getValue(manifestPath.string(), "purpose");
if (purposeString.empty())