From 41a925ed86ff1ef795c4640075033518807fb07e Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Thu, 28 Jan 2016 16:44:27 -0600 Subject: Add system_state dbus property Add system_state property to keep track of the system state across reboots. Include the generated settings_file.py since some build machines cannot have the yaml python module installed. This file will be removed once the code is ported to C in the next rework. Add the path where the settings will be stored in bmc: /var/lib/obmc/ Address review comments from the initial commit. --- settings_manager.py | 77 ++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 42 deletions(-) (limited to 'settings_manager.py') diff --git a/settings_manager.py b/settings_manager.py index 53ce7fb..e49b466 100755 --- a/settings_manager.py +++ b/settings_manager.py @@ -4,6 +4,8 @@ import gobject import dbus import dbus.service import dbus.mainloop.glib +import os +import os.path as path import Openbmc import settings_file as s @@ -11,14 +13,14 @@ DBUS_NAME = 'org.openbmc.settings.Host' OBJ_NAME = '/org/openbmc/settings/host0' CONTROL_INTF = 'org.openbmc.Settings' -# TODO Save settings in tmp until persistant storage is available -# Path where the settings are stored in the BMC -SETTINGS_PATH = '/tmp/' - class HostSettingsObject(Openbmc.DbusProperties): - def __init__(self,bus,name): + def __init__(self, bus, name, settings, path): Openbmc.DbusProperties.__init__(self) - dbus.service.Object.__init__(self,bus,name) + dbus.service.Object.__init__(self, bus, name) + + self.path = path + if not os.path.exists(path): + os.mkdir(path) # Listen to changes in the property values and sync them to the BMC bus.add_signal_receiver(self.settings_signal_handler, @@ -27,58 +29,49 @@ class HostSettingsObject(Openbmc.DbusProperties): path = "/org/openbmc/settings/host0") # Create the dbus properties - for i in s.SETTINGS['host'].iterkeys(): - self.sname = s.SETTINGS['host'][i]['name'] - self.stype = s.SETTINGS['host'][i]['type'] - self.svalue = s.SETTINGS['host'][i]['default'] - self.bmcvalue = self.svalue # Default BMC value to file value - self.set_settings_property() + for i in settings['host'].iterkeys(): + shk = settings['host'][i] + self.set_settings_property(shk['name'], + shk['type'], + shk['default']) - # Check if the requested value is the same as the current one in the BMC - def check_settings_need_update(self): - filepath = SETTINGS_PATH + self.sname - update = True + def get_bmc_value(self, name): try: - with open(filepath, 'r') as f: - self.bmcvalue = f.read() # Upate BMC value with value on system - if self.bmcvalue == self.svalue: - update = False + with open(path.join(self.path, name), 'r') as f: + return f.read() except (IOError): pass - return update + return None # Create dbus properties based on bmc value. This will be either a value # previously set, or the default file value if the BMC value does not exist. - def set_settings_property(self): - update = self.check_settings_need_update() - if update == True: - self.svalue = self.bmcvalue # Update svalue with the value that will be used - if self.stype=="i": - self.Set(DBUS_NAME,self.sname,self.svalue) - elif self.stype=="s": - self.Set(DBUS_NAME,self.sname,str(self.svalue)) + def set_settings_property(self, name, type, value): + bmcv = self.get_bmc_value(name) + if bmcv: + value = bmcv + if type=="i": + self.Set(DBUS_NAME, name, value) + elif type=="s": + self.Set(DBUS_NAME, name, str(value)) # Save the settings to the BMC. This will write the settings value in # individual files named by the property name to the BMC. - def set_system_settings(self): - update = self.check_settings_need_update() - if update == True: - filepath = SETTINGS_PATH + self.sname + def set_system_settings(self, name, value): + bmcv = self.get_bmc_value(name) + if bmcv != value: + filepath = path.join(self.path, name) with open(filepath, 'w') as f: - f.write(str(self.svalue)) + f.write(str(value)) # Signal handler for when one ore more settings properties were updated. # This will sync the changes to the BMC. def settings_signal_handler(self, interface_name, changed_properties, invalidated_properties): - data = changed_properties - for i in data: - self.sname = i - self.svalue = data[i] - self.set_system_settings() + for name, value in changed_properties.items(): + self.set_system_settings(name, value) # Placeholder signal. Needed to register the settings interface. - @dbus.service.signal(DBUS_NAME,signature='s') - def SettingsUpdated(self,sname): + @dbus.service.signal(DBUS_NAME, signature='s') + def SettingsUpdated(self, sname): pass if __name__ == '__main__': @@ -86,7 +79,7 @@ if __name__ == '__main__': bus = Openbmc.getDBus() name = dbus.service.BusName(DBUS_NAME, bus) - obj = HostSettingsObject(bus, OBJ_NAME) + obj = HostSettingsObject(bus, OBJ_NAME, s.SETTINGS, "/var/lib/obmc/") mainloop = gobject.MainLoop() print "Running HostSettingsService" -- cgit v1.2.1