Merge pull request #98 from bradbishop/upload-state
Inventory upload fixes
diff --git a/bin/Barreleye.py b/bin/Barreleye.py
index 66691fa..c23f657 100755
--- a/bin/Barreleye.py
+++ b/bin/Barreleye.py
@@ -18,6 +18,7 @@
'BMC_READY',
'HOST_POWERING_ON',
'HOST_POWERED_ON',
+ 'INVENTORY_UPLOADED',
'HOST_BOOTING',
'HOST_BOOTED',
'HOST_POWERED_OFF',
@@ -42,7 +43,7 @@
## method will be called when state is entered
ENTER_STATE_CALLBACK = {
- 'HOST_POWERED_ON' : {
+ 'INVENTORY_UPLOADED' : {
'boot' : {
'bus_name' : 'org.openbmc.control.Host',
'obj_name' : '/org/openbmc/control/host0',
@@ -95,10 +96,17 @@
'process_name' : 'inventory_items.py',
'args' : [ SYSTEM_NAME ]
},
- 'pcie_present' : {
+ 'inventory_upload' : {
'system_state' : 'HOST_POWERED_ON',
'start_process' : True,
'monitor_process' : False,
+ 'process_name' : 'goto_system_state.py',
+ 'args' : [ 'INVENTORY_UPLOADED', 'inventory_upload.py' ]
+ },
+ 'pcie_present' : {
+ 'system_state' : 'INVENTORY_UPLOADED',
+ 'start_process' : True,
+ 'monitor_process' : False,
'process_name' : 'pcie_slot_present.exe',
},
'fan_control' : {
diff --git a/bin/goto_system_state.py b/bin/goto_system_state.py
new file mode 100644
index 0000000..4efa1c6
--- /dev/null
+++ b/bin/goto_system_state.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+
+import sys
+import subprocess
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+import gobject
+
+
+class Goto(dbus.service.Object):
+ def __init__(self, connection, path, loop, state, cmdline):
+ super(Goto, self).__init__(connection, path)
+ self.loop = loop
+ self.state = state
+ self.cmdline = cmdline
+ gobject.idle_add(self.go)
+
+ def go(self):
+ if self.cmdline:
+ subprocess.call(self.cmdline)
+
+ if self.state:
+ self.GotoSystemState(self.state)
+
+ self.loop.quit()
+
+ @dbus.service.signal('org.openbmc.Control', signature='s')
+ def GotoSystemState(self, state):
+ pass
+
+if __name__ == '__main__':
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ bus = dbus.SystemBus()
+ cmdline = None
+ state = None
+
+ if len(sys.argv) > 1:
+ state = sys.argv[1]
+ if len(sys.argv) > 2:
+ cmdline = sys.argv[2:]
+
+ loop = gobject.MainLoop()
+ o = Goto(bus, '/org/openbmc/goto', loop, state, cmdline)
+ loop.run()
diff --git a/bin/hwmon.py b/bin/hwmon.py
index 08c6f06..1209d46 100755
--- a/bin/hwmon.py
+++ b/bin/hwmon.py
@@ -44,6 +44,7 @@
self.hwmon_root = { }
self.scanDirectory()
gobject.timeout_add(DIR_POLL_INTERVAL, self.scanDirectory)
+ self.cache = {}
def readAttribute(self,filename):
val = ""
@@ -56,17 +57,29 @@
with open(filename, 'w') as f:
f.write(str(value)+'\n')
+ def should_update(attribute, value):
+ if attribute not in self.cache:
+ self.cache[attribute] = value
+ return True
+
+ update = (value != self.cache[attribute])
+ self.cache[attribute] = value
+
+ return update
def poll(self,objpath,attribute):
try:
raw_value = int(self.readAttribute(attribute))
- obj = bus.get_object(SENSOR_BUS,objpath,introspect=False)
- intf = dbus.Interface(obj,HwmonSensor.IFACE_NAME)
- rtn = intf.setByPoll(raw_value)
- if (rtn[0] == True):
- self.writeAttribute(attribute,rtn[1])
+ if self.should_update(attribute, raw_value):
+ obj = bus.get_object(SENSOR_BUS,objpath,introspect=False)
+ intf = dbus.Interface(obj,HwmonSensor.IFACE_NAME)
+ rtn = intf.setByPoll(raw_value)
+ if (rtn[0] == True):
+ self.writeAttribute(attribute,rtn[1])
except:
print "HWMON: Attibute no longer exists: "+attribute
+ if attribute in self.cache:
+ del self.cache[attribute]
return False