Wait for obmc-flash-bmc-updateubootvars@.service

The service file obmc-flash-bmc-updateubootvars@.service
updates the boot environment variables to point to the
newly updated image. Need to wait for this service to finish
before marking the update as complete. Otherwise the user may
reboot the system while the env vars are being updated thinking
that the update has completed because the Activation value would
be set to Active.

Resolves openbmc/openbmc#2764

Change-Id: Ic33cf62e46555c9925385bb5d9d28de9aeee85a1
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/activation.cpp b/activation.cpp
index ecfcda4..33bb84d 100644
--- a/activation.cpp
+++ b/activation.cpp
@@ -87,35 +87,41 @@
         }
         else if (rwVolumeCreated == true && roVolumeCreated == true)
         {
-            activationProgress->progress(90);
-
-            if (!redundancyPriority)
+            if (ubootEnvVarsUpdated == false)
             {
-                redundancyPriority =
-                          std::make_unique<RedundancyPriority>(
-                                    bus,
-                                    path,
-                                    *this,
-                                    0);
+                activationProgress->progress(90);
+
+                if (!redundancyPriority)
+                {
+                    redundancyPriority =
+                              std::make_unique<RedundancyPriority>(
+                                        bus,
+                                        path,
+                                        *this,
+                                        0);
+                }
             }
+            else
+            {
+                activationProgress->progress(100);
 
-            activationProgress->progress(100);
+                activationBlocksTransition.reset(nullptr);
+                activationProgress.reset(nullptr);
 
-            activationBlocksTransition.reset(nullptr);
-            activationProgress.reset(nullptr);
+                rwVolumeCreated = false;
+                roVolumeCreated = false;
+                ubootEnvVarsUpdated = false;
+                Activation::unsubscribeFromSystemdSignals();
 
-            rwVolumeCreated = false;
-            roVolumeCreated = false;
-            Activation::unsubscribeFromSystemdSignals();
+                // Remove version object from image manager
+                Activation::deleteImageManagerObject();
 
-            // Remove version object from image manager
-            Activation::deleteImageManagerObject();
+                // Create active association
+                parent.createActiveAssociation(path);
 
-            // Create active association
-            parent.createActiveAssociation(path);
-
-            return softwareServer::Activation::activation(
-                    softwareServer::Activation::Activations::Active);
+                return softwareServer::Activation::activation(
+                        softwareServer::Activation::Activations::Active);
+            }
         }
     }
     else
@@ -148,6 +154,7 @@
 {
     rwVolumeCreated = false;
     roVolumeCreated = false;
+    ubootEnvVarsUpdated = false;
 
     if ((value == softwareServer::Activation::RequestedActivations::Active) &&
         (softwareServer::Activation::requestedActivation() !=
@@ -200,6 +207,8 @@
 
     auto rwServiceFile = "obmc-flash-bmc-ubirw.service";
     auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
+    auto ubootVarsServiceFile = "obmc-flash-bmc-updateubootvars@" + versionId +
+                                ".service";
 
     if (newStateUnit == rwServiceFile && newStateResult == "done")
     {
@@ -213,14 +222,22 @@
         activationProgress->progress(activationProgress->progress() + 50);
     }
 
-    if (newStateUnit == rwServiceFile || newStateUnit == roServiceFile)
+    if (newStateUnit == ubootVarsServiceFile && newStateResult == "done")
+    {
+        ubootEnvVarsUpdated = true;
+    }
+
+    if (newStateUnit == rwServiceFile ||
+        newStateUnit == roServiceFile ||
+        newStateUnit == ubootVarsServiceFile)
     {
         if (newStateResult == "failed" || newStateResult == "dependency")
         {
             Activation::activation(
                     softwareServer::Activation::Activations::Failed);
         }
-        else if (rwVolumeCreated && roVolumeCreated)
+        else if ((rwVolumeCreated && roVolumeCreated) || // Volumes were created
+                 (ubootEnvVarsUpdated)) // Enviroment variables were updated
         {
             Activation::activation(
                     softwareServer::Activation::Activations::Activating);
diff --git a/activation.hpp b/activation.hpp
index 9c1fde9..c62b747 100644
--- a/activation.hpp
+++ b/activation.hpp
@@ -317,6 +317,10 @@
         /** @brief Tracks whether the read-only volume has been created as
          * part of the activation process. **/
         bool roVolumeCreated = false;
+
+        /** @brief Tracks if the service that updates the U-Boot environment
+         *         variables has completed. **/
+        bool ubootEnvVarsUpdated = false;
 };
 
 } // namespace updater