Create active association on startup

Create active association on startup for
active BMC versions. Moved creating the association inside
the for loop. The association is only needed
if there is an active image so should be inside the for loop
to check if it is an active image.

Change-Id: Iba7519ba08cb79dc06607caa8b44a0a3022c0ddc
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 64bd270..4507bcf 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -103,17 +103,18 @@
         auto activationState = server::Activation::Activations::Invalid;
         ItemUpdater::ActivationStatus result =
                 ItemUpdater::validateSquashFSImage(filePath);
+        AssociationList associations = {};
+
         if (result == ItemUpdater::ActivationStatus::ready)
         {
             activationState = server::Activation::Activations::Ready;
+            // Create an association to the BMC inventory item
+            associations.emplace_back(std::make_tuple(
+                                              ACTIVATION_FWD_ASSOCIATION,
+                                              ACTIVATION_REV_ASSOCIATION,
+                                              bmcInventoryPath));
         }
 
-        // Create an association to the BMC inventory item
-        AssociationList associations{(std::make_tuple(
-                                          ACTIVATION_FWD_ASSOCIATION,
-                                          ACTIVATION_REV_ASSOCIATION,
-                                          bmcInventoryPath))};
-
         activations.insert(std::make_pair(
                                versionId,
                                std::make_unique<Activation>(
@@ -142,12 +143,6 @@
 
 void ItemUpdater::processBMCImage()
 {
-    // Create an association to the BMC inventory item
-    AssociationList associations{(std::make_tuple(
-                                      ACTIVATION_FWD_ASSOCIATION,
-                                      ACTIVATION_REV_ASSOCIATION,
-                                      bmcInventoryPath))};
-
     // Read os-release from folders under /media/ to get
     // BMC Software Versions.
     for(const auto& iter : fs::directory_iterator(MEDIA_DIR))
@@ -181,6 +176,20 @@
             auto purpose = server::Version::VersionPurpose::BMC;
             auto path = fs::path(SOFTWARE_OBJPATH) / id;
 
+            AssociationList associations = {};
+
+            if (activationState == server::Activation::Activations::Active)
+            {
+                // Create an association to the BMC inventory item
+                associations.emplace_back(std::make_tuple(
+                                                  ACTIVATION_FWD_ASSOCIATION,
+                                                  ACTIVATION_REV_ASSOCIATION,
+                                                  bmcInventoryPath));
+
+                // Create an active association since this image is active
+                createActiveAssociation(path);
+            }
+
             // Create Activation instance for this version.
             activations.insert(std::make_pair(
                                    id,