[PATCH skeleton] skeleton: fixed hard-coding for master OCC hwmon sysfs path

Andrew Jeffery andrew at aj.id.au
Mon Feb 22 12:32:07 AEDT 2016


Hi Yi Li,

On Fri, 2016-02-19 at 13:10 -0600, OpenBMC Patches wrote:
> From: Yi Li <adamliyi at msn.com>
> 
> Currently master OCC hwmon sysfs path is hardcoded to '/sys/class/hwmon/hwmon3/'.
> This make the '/org/openbmc/sensors/host/PowerCap' interface cannot work when
> master OCC is initilized as hwmon device other than 'hwmon3'.
> 
> This would fix the issue: https://github.com/openbmc/skeleton/issues/42
> 
> Signed-off-by: Yi Li <adamliyi at msn.com>
> ---
>  bin/sensor_manager2.py | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/bin/sensor_manager2.py b/bin/sensor_manager2.py
> index b5aac53..4fc9dc2 100755
> --- a/bin/sensor_manager2.py
> +++ b/bin/sensor_manager2.py
> @@ -2,6 +2,7 @@
>  
>  import sys
>  import os
> +import glob
>  import gobject
>  import dbus
>  import dbus.service
> @@ -54,9 +55,13 @@ if __name__ == '__main__':
>  
>  > 	> obj_path = OBJ_PATH+"/host/PowerCap"
>  > 	> sensor_obj = Sensors.PowerCap(bus,obj_path)
> -> 	> ## hwmon3 is default for master OCC on Barreleye.
> -> 	> ## should rewrite sensor_manager to remove hardcode
> -> 	> sensor_obj.sysfs_attr = "/sys/class/hwmon/hwmon3/user_powercap"
> +> 	> ## scan hwmon sysfs for master occ's user_powercap attribute
> +> 	> for pcap_file in glob.glob('/sys/class/hwmon/*/user_powercap'):
> +> 	> 	> occ_i2c_dev = os.path.dirname(pcap_file)+'/device'
> +> 	> 	> occ_i2c_dev = os.path.realpath(occ_i2c_dev).split('/').pop()
> +> 	> 	> # master OCC address
> +> 	> 	> if occ_i2c_dev == '3-0050':
> +> 	> 	> 	> sensor_obj.sysfs_attr = pcap_file

Have you tested the code in the for loop? Because running the body in a
Python shell doesn't give me confidence the if-condition will ever be
satisfied:

    andrew at keelia    :~$ python
    Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
    [GCC 5.2.1 20151010] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> pcap_file =     "/sys/class/hwmon/hwmon3/user_powercap"
>>> os.path.dirname(pcap_file)+"/device"
'/sys/class/hwmon/hwmon3/device'
>>> os.path.realpath(_).split('/')
['', 'sys', 'class', 'hwmon', 'hwmon3', 'device']
>>> _.pop()
'device'
>>> 

I can't see how occ_i2c_dev will ever take the value '3-0050'? Are we
missing additional globbing and/or reading of files?

>  	root_sensor.add(obj_path,sensor_obj)

Have you given consideration to what should be done if the if-condition
in the for loop above never fires? Is it still valid to add sensor_obj?

Andrew

>  
>  > 	> obj_path = OBJ_PATH+"/host/BootProgress"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20160222/7dc1514c/attachment.sig>


More information about the openbmc mailing list