Update Asset Tag On Factory Resets
The default asset tag of the system is of the form
"Server-<MTM>-<System serial>". This commit restores the default
asset tag into the Decorator.AssetTag interface when the system VPD
service detects we are booting out of a factory reset.
This asset tag is thereafter used to set the pvm_system_name
BIOS attribute.
Signed-off-by: Santosh Puranik <santosh.puranik@in.ibm.com>
Change-Id: I415d58ca2253f2e6fc3a67746d5e9305403a4988
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index ba03318..ecbe110 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -572,6 +572,31 @@
}
/**
+ * @brief Fills the Decorator.AssetTag property into the interfaces map
+ *
+ * This function should only be called in cases where we did not find a JSON
+ * symlink. A missing symlink in /var/lib will be considered as a factory reset
+ * and this function will be used to default the AssetTag property.
+ *
+ * @param interfaces A possibly pre-populated map of inetrfaces to properties.
+ * @param vpdMap A VPD map of the system VPD data.
+ */
+static void fillAssetTag(inventory::InterfaceMap& interfaces,
+ const Parsed& vpdMap)
+{
+ // Read the system serial number and MTM
+ // Default asset tag is Server-MTM-System Serial
+ inventory::Interface assetIntf{
+ "xyz.openbmc_project.Inventory.Decorator.AssetTag"};
+ inventory::PropertyMap assetTagProps;
+ std::string defaultAssetTag =
+ std::string{"Server-"} + getKwVal(vpdMap, "VSYS", "TM") +
+ std::string{"-"} + getKwVal(vpdMap, "VSYS", "SE");
+ assetTagProps.emplace("AssetTag", defaultAssetTag);
+ insertOrMerge(interfaces, assetIntf, std::move(assetTagProps));
+}
+
+/**
* @brief Set certain one time properties in the inventory
* Use this function to insert the Functional and Enabled properties into the
* inventory map. This function first checks if the object in question already
@@ -1194,6 +1219,8 @@
}
}
+ auto processFactoryReset = false;
+
if (isSystemVpd)
{
string systemJsonName{};
@@ -1206,6 +1233,9 @@
fs::path target = systemJsonName;
fs::path link = INVENTORY_JSON_SYM_LINK;
+ // If the symlink does not exist, we treat that as a factory reset
+ processFactoryReset = !fs::exists(INVENTORY_JSON_SYM_LINK);
+
// Create the directory for hosting the symlink
fs::create_directories(VPD_FILES_PATH);
// unlink the symlink previously created (if any)
@@ -1338,6 +1368,15 @@
insertOrMerge(interfaces, invItemIntf, move(presProp));
}
+ if constexpr (is_same<T, Parsed>::value)
+ {
+ // Restore asset tag, if needed
+ if (processFactoryReset && objectPath == "/system")
+ {
+ fillAssetTag(interfaces, vpdMap);
+ }
+ }
+
objects.emplace(move(object), move(interfaces));
}