Sync PSU images on service startup

On service startup, it shall check the PSU images, find a latest
version, and update to the PSUs that are not with this version.

Tested: With dummy image and service, test on Witherspoon with 2
        different running PSU software:
* When startup without stored image, the serive tries to update an older
PSU but it does not have PSU image, so it's skipped with below journal
log:
    Automatically update PSU
    No image for the activation, skipped
* When startup with an older image stored in BMC, it behaves the same as
above.
* When startup with a new image stored in BMC, it updates the PSUs, with
below example journal log:
    Automatically update PSU
    Starting Update PSU
    /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0
    /var/lib/obmc/psu/2B1D...
    Started Update PSU
    /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0
    /var/lib/obmc/psu/2B1D.
    Starting Update PSU
    /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1
    /var/lib/obmc/psu/2B1D...
    Started Update PSU
    /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1
    /var/lib/obmc/psu/2B1D.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I6d676c5a4441685fb2b5920455f439c00f6097af
diff --git a/src/activation.cpp b/src/activation.cpp
index efff61b..cab9acd 100644
--- a/src/activation.cpp
+++ b/src/activation.cpp
@@ -49,7 +49,11 @@
         (SoftwareActivation::requestedActivation() !=
          SoftwareActivation::RequestedActivations::Active))
     {
-        if ((activation() == Status::Ready) || (activation() == Status::Failed))
+        // PSU image could be activated even when it's in active,
+        // e.g. in case a PSU is replaced and has a older image, it will be
+        // updated with the running PSU image that is stored in BMC.
+        if ((activation() == Status::Ready) ||
+            (activation() == Status::Failed) || activation() == Status::Active)
         {
             activation(Status::Activating);
         }
@@ -141,6 +145,13 @@
 
 Activation::Status Activation::startActivation()
 {
+    // Check if the activation has file path
+    if (path().empty())
+    {
+        log<level::WARNING>("No image for the activation, skipped",
+                            entry("VERSION_ID=%s", versionId.c_str()));
+        return activation(); // Return the previous activation status
+    }
     if (!activationProgress)
     {
         activationProgress = std::make_unique<ActivationProgress>(bus, objPath);
@@ -162,6 +173,12 @@
     {
         if (isCompatible(p))
         {
+            if (utils::isAssociated(p, associations()))
+            {
+                log<level::NOTICE>("PSU already running the image, skipping",
+                                   entry("PSU=%s", p.c_str()));
+                continue;
+            }
             psuQueue.push(p);
         }
         else
@@ -173,8 +190,8 @@
 
     if (psuQueue.empty())
     {
-        log<level::ERR>("No PSU compatible with the software");
-        return Status::Failed;
+        log<level::WARNING>("No PSU compatible with the software");
+        return activation(); // Return the previous activation status
     }
 
     // The progress to be increased for each successful update of PSU