diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2016-09-06 21:47:05 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2016-09-27 18:43:35 +0000 |
commit | 520f8b05742916b920f20ac916a0e20fb981ce56 (patch) | |
tree | a95f89d7450e96de4513f2038c509cbc130f682d /pysystemmgr | |
parent | a7ac805b407617f7a83eb152ff823f44d243a9b2 (diff) | |
download | talos-skeleton-520f8b05742916b920f20ac916a0e20fb981ce56.tar.gz talos-skeleton-520f8b05742916b920f20ac916a0e20fb981ce56.zip |
Fix for Power Restore Policy
This fix is to make the Restore_last_state of Power Restore Policy
to working properly.
eg:- if the last state is Host_powered_on/off and system goes for pdu
reboot then system should reach to the Host_Powred_On/Off state.
Fixes openbmc/openbmc#196
Change-Id: If4bdb65a21452d7aa041312fcdbb1daa1b1b0424
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
Diffstat (limited to 'pysystemmgr')
-rw-r--r-- | pysystemmgr/system_manager.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/pysystemmgr/system_manager.py b/pysystemmgr/system_manager.py index 4f9b261..a26c325 100644 --- a/pysystemmgr/system_manager.py +++ b/pysystemmgr/system_manager.py @@ -18,6 +18,9 @@ OBJ_NAME = '/org/openbmc/managers/System' INTF_SENSOR = 'org.openbmc.SensorValue' INTF_ITEM = 'org.openbmc.InventoryItem' +SYS_STATE_FILE = '/var/lib/obmc/last-system-state' +POWER_OFF = "0" + class SystemManager(DbusProperties, DbusObjectManager): def __init__(self, bus, obj_name): @@ -32,9 +35,16 @@ class SystemManager(DbusProperties, DbusObjectManager): bus.add_signal_receiver( self.SystemStateHandler, signal_name="GotoSystemState") - self.Set(DBUS_NAME, "current_state", "") + bus.add_signal_receiver( + self.chassisPowerStateHandler, + dbus_interface="org.freedesktop.DBus.Properties", + signal_name="PropertiesChanged", + path="/org/openbmc/control/power0") - ## replace symbolic path in ID_LOOKUP + self.Set(DBUS_NAME, "current_state", "") + self.Set(DBUS_NAME, "system_last_state", POWER_OFF) + self.import_system_state_from_disk() + # replace symbolic path in ID_LOOKUP for category in System.ID_LOOKUP: for key in System.ID_LOOKUP[category]: val = System.ID_LOOKUP[category][key] @@ -46,6 +56,12 @@ class SystemManager(DbusProperties, DbusObjectManager): print "SystemManager Init Done" + def chassisPowerStateHandler(self, interface_name, changed_properties, + invalidated_properties): + value = changed_properties.get('state') + if value is not None: + self.write_to_disk_and_update(str(value)) + def SystemStateHandler(self, state_name): print "Running System State: "+state_name @@ -71,6 +87,24 @@ class SystemManager(DbusProperties, DbusObjectManager): print "SystemManager Goto System State: "+new_state_name self.SystemStateHandler(new_state_name) + def import_system_state_from_disk(self): + state = str(POWER_OFF) + try: + with open(SYS_STATE_FILE, 'r+') as f: + state = f.readline().rstrip('\n') + except IOError: + pass + self.Set(DBUS_NAME, "system_last_state", state) + return state + + def write_to_disk_and_update(self, state): + try: + with open(SYS_STATE_FILE, 'w+') as f: + f.write(str(state)) + self.Set(DBUS_NAME, "system_last_state", state) + except IOError: + pass + @dbus.service.method(DBUS_NAME, in_signature='', out_signature='s') def getSystemState(self): return self.Get(DBUS_NAME, "current_state") |