Call update u-boot env once when a priority is changed

The recursive nature of calling the free priority function
would trigger setting the u-boot env multiple times.
Make a change so that the priorities are sorted and
updated once.

- Create a non-overriden priority setter function to be called
by the free priority function and by the function that creates
the dbus objects after a bmc reboot. There's no need to call
to free the priorities after reboot since the priorities are
preserved on the bmc, and if they're not they default to 0 or 255.
- When a dbus request is made to update the priority, update
the value, then call the free priority function, which will
sort the versions by priority and bump the priority of any
duplicate ones.

Resolves openbmc/openbmc#2535

Change-Id: Ib92cc0ca6c4d5f6e986f3cde7156d63b53844b46
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/activation.cpp b/activation.cpp
index 1ed765c..9859cd6 100644
--- a/activation.cpp
+++ b/activation.cpp
@@ -153,44 +153,18 @@
 
 uint8_t RedundancyPriority::priority(uint8_t value)
 {
-    parent.parent.freePriority(value, parent.versionId);
+    // Set the priority value so that the freePriority() function can order
+    // the versions by priority.
+    auto newPriority = softwareServer::RedundancyPriority::priority(value);
     storeToFile(parent.versionId, value);
-
-    // Update U-Boot env variable to point to this version if it has the
-    // lowest priority. Otherwise, reset the UbootEnvVars to find the lowest
-    // priority version and set that in U-Boot.
-    if (parent.parent.isLowestPriority(value))
-    {
-        parent.updateUbootEnvVars();
-    }
-    else
-    {
-        parent.parent.resetUbootEnvVars();
-    }
-
-    return softwareServer::RedundancyPriority::priority(value);
+    parent.parent.freePriority(value, parent.versionId);
+    return newPriority;
 }
 
-// TODO: openbmc/openbmc#2369 Add recovery policy to updateubootvars
-//       unit template.
-void Activation::updateUbootEnvVars()
+uint8_t RedundancyPriority::sdbusPriority(uint8_t value)
 {
-    auto method = bus.new_method_call(
-            SYSTEMD_BUSNAME,
-            SYSTEMD_PATH,
-            SYSTEMD_INTERFACE,
-            "StartUnit");
-    auto updateEnvVarsFile = "obmc-flash-bmc-updateubootvars@" + versionId +
-            ".service";
-    method.append(updateEnvVarsFile, "replace");
-    auto result = bus.call(method);
-
-    //Check that the bus call didn't result in an error
-    if (result.is_method_error())
-    {
-        log<level::ERR>("Failed to update u-boot env variables",
-                        entry("VERSIONID=%s", versionId));
-    }
+    storeToFile(parent.versionId, value);
+    return softwareServer::RedundancyPriority::priority(value);
 }
 
 void Activation::unitStateChange(sdbusplus::message::message& msg)