power-restore: always honor AlwaysOn policy

An internal bug was opened recently noting that when the
only-run-apr-on-power-loss config option was set, the AlwaysOn policy
was not executed. This didn't make sense because the AlwaysOn policy is
specifically saying to always power the system on. This commit changes
the logic to always power on, no matter what, if the user has set the
policy to AlwaysOn.

This change fixes a subtle bug in the one-time logic as well. Prior
to this change, the one-time setting would always be executed even if
the only-run-apr-on-power-loss config option was set. The reasoning
behind the bug was that the one-time did need to always be executed,
when it was set to AlwaysOn. The one-time is used in situations where
host or BMC firmware needs to reboot the BMC but ensure the system boots
back up after the BMC reboot (inband code update, brownout conditions).
This commit ensures we continue to execute that behavior but also
ensures we do not run the one-time otherwise when
only-run-apr-on-power-loss is set and there was not an AC loss.

Tested:
  - Verified AlwaysOn always powered on system
  - Verified power was only "Restored" when there was an AC loss

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: Ic5ba84cf2d4fe80fc60ebf9440520a80d91c9ed9
diff --git a/discover_system_state.cpp b/discover_system_state.cpp
index c94faaf..6227ddf 100644
--- a/discover_system_state.cpp
+++ b/discover_system_state.cpp
@@ -124,14 +124,6 @@
             // one_time is set to None so use the customer setting
             info("One time not set, check user setting of power policy");
 
-#ifdef ONLY_RUN_APR_ON_POWER_LOSS
-            if (!phosphor::state::manager::utils::checkACLoss(hostId))
-            {
-                info(
-                    "Chassis power was not on prior to BMC reboot so do not run any power policy");
-                return 0;
-            }
-#endif
             auto reply = bus.call(methodUserSetting);
             reply.read(result);
             powerPolicy = std::get<std::string>(result);
@@ -183,6 +175,17 @@
                 bus, hostPath, HOST_BUSNAME, "RequestedHostTransition",
                 convertForMessage(server::Host::Transition::On));
         }
+        // Always execute power on if AlwaysOn is set, otherwise check config
+        // option (and AC loss status) on whether to execute other policy
+        // settings
+#ifdef ONLY_RUN_APR_ON_POWER_LOSS
+        else if (!phosphor::state::manager::utils::checkACLoss(hostId))
+        {
+            info(
+                "Chassis power was not on prior to BMC reboot so do not run any further power policy");
+            return 0;
+        }
+#endif
         else if (RestorePolicy::Policy::AlwaysOff ==
                  RestorePolicy::convertPolicyFromString(powerPolicy))
         {