Power policy: Determine old or new location.
The Power Policy value is moving from its old location:
/org/openbmc/settings/host0/attr/power_policy
To a new location:
/xyz/openbmc_project/control/host0/power_restore_policy/attr/PowerRestorePolicy
This change allows power policy keywords to figure out whether the new
location is legitimate. If so, it will read/write the value using the
new location.
Change-Id: I0cba136219ad22e47ff2c58a6d0b6dacec4e7451
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/utils.py b/lib/utils.py
new file mode 100644
index 0000000..6a3b809
--- /dev/null
+++ b/lib/utils.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+r"""
+Companion file to utils.robot.
+"""
+
+import gen_print as gp
+import gen_robot_keyword as grk
+from robot.libraries.BuiltIn import BuiltIn
+
+
+###############################################################################
+def set_power_policy_method():
+
+ r"""
+ Set the global bmc_power_policy_method to either 'Old' or 'New'.
+
+ The power policy data has moved from an 'org' location to an 'xyz'
+ location. This keyword will determine whether the new method of getting
+ the power policy is valid and will set the global bmc_power_policy_method
+ variable accordingly. If power_policy_setup is already set (by a prior
+ call to this function), this keyword will simply return.
+
+ If bmc_power_policy_method is "Old", this function will adjust the global
+ policy variables from data/variables.py: RESTORE_LAST_STATE,
+ ALWAYS_POWER_ON, ALWAYS_POWER_OFF.
+ """
+
+ # Retrieve global variables.
+ power_policy_setup = \
+ int(BuiltIn().get_variable_value("${power_policy_setup}",
+ default=0))
+ bmc_power_policy_method = \
+ BuiltIn().get_variable_value("${bmc_power_policy_method}",
+ default=0)
+ gp.dpvar(power_policy_setup)
+
+ # If this function has already been run once, we need not continue.
+ if power_policy_setup:
+ return
+
+ gp.dpvar(bmc_power_policy_method, 1)
+
+ # The user has not set bmc_power_policy_method via a -v parm so we will
+ # determine what it should be.
+ if bmc_power_policy_method == "":
+ status, ret_values = grk.run_key_u("New Get Power Policy", ignore=1)
+ if status == 'PASS':
+ bmc_power_policy_method = 'New'
+ else:
+ bmc_power_policy_method = 'Old'
+
+ gp.qpvar(bmc_power_policy_method)
+ # For old style, we will rewrite these global variable settings to old
+ # values.
+ if bmc_power_policy_method == "Old":
+ BuiltIn().set_global_variable("${RESTORE_LAST_STATE}",
+ "RESTORE_LAST_STATE")
+ BuiltIn().set_global_variable("${ALWAYS_POWER_ON}",
+ "ALWAYS_POWER_ON")
+ BuiltIn().set_global_variable("${ALWAYS_POWER_OFF}",
+ "ALWAYS_POWER_OFF")
+
+ # Set global variables to control subsequent calls to this function.
+ BuiltIn().set_global_variable("${bmc_power_policy_method}",
+ bmc_power_policy_method)
+ BuiltIn().set_global_variable("${power_policy_setup}", 1)
+
+
+###############################################################################
+
+
+###############################################################################
+def translate_power_policy_value(policy):
+
+ r"""
+ Translate the policy value and return the result.
+
+ Using old style functions, callers might call like this with a hard-
+ code value for policy:
+
+ Set BMC Power Policy RESTORE_LAST_STATE
+
+ This function will get the value of the corresponding global variable (if
+ it exists) and return it.
+
+ This will allow the old style call to still work on systems using the new
+ method of storing the policy value.
+ """
+
+ valid_power_policy_vars = \
+ BuiltIn().get_variable_value("${valid_power_policy_vars}")
+
+ if policy not in valid_power_policy_vars:
+ return policy
+
+ status, ret_values = grk.run_key_u("Get Variable Value ${" + policy + "}",
+ quiet=1)
+ return ret_values
+
+###############################################################################