diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2018-05-03 10:55:11 -0500 |
---|---|---|
committer | Matthew Barth <msbarth@us.ibm.com> | 2018-05-03 16:56:43 -0500 |
commit | 33618bc1845e5e7c4e12a2d2ed7f1c47a6a03de1 (patch) | |
tree | 261917d3c3e836c080cd506ce6eb39bc25643b66 /monitor | |
parent | 81748b1425e453b6a815a7b8ed2fa861d3068ac7 (diff) | |
download | phosphor-fan-presence-33618bc1845e5e7c4e12a2d2ed7f1c47a6a03de1.tar.gz phosphor-fan-presence-33618bc1845e5e7c4e12a2d2ed7f1c47a6a03de1.zip |
Add generation of propertiesMatch condition
Update the mako template to generate conditions within the FanDefinition
sections when a condition is defined for a fan. Each supported condition
function's parameters are generated within a `getCondParams` mako
method, allowing easy support of additional conditions with differing
parameters.
Tested:
A given condition's function and parameters generate correctly
No condition function is generated on a fan where not defined
Resolves: openbmc/openbmc#2976
Change-Id: I3f0b30702fdcef6749929d85543270863eb26381
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'monitor')
-rw-r--r-- | monitor/example/monitor.yaml | 19 | ||||
-rwxr-xr-x | monitor/gen-fan-monitor-defs.py | 32 |
2 files changed, 50 insertions, 1 deletions
diff --git a/monitor/example/monitor.yaml b/monitor/example/monitor.yaml index 7676fde..59be7e6 100644 --- a/monitor/example/monitor.yaml +++ b/monitor/example/monitor.yaml @@ -30,6 +30,15 @@ # offset [The offset to add to calculate the expected fan speed. # Default is 0 for fan speed target; # Customized value for pwm target] +# condition: [optional condition function to create fan functional monitoring] +# name: [The name of an available condition function] +# properties: [The properties used in the condition function] +# - object: [Object path of property to use] +# interface: [Interface of property to use] +# property: +# name: [Property name] +# type: [Property data type] +# value: [Property value to check condition against] # #sensor_trust_groups: # - class: [Group class name @@ -63,6 +72,16 @@ # sensors: # - name: fan0 # has_target: true +# # Only create fan functional properties and monitor on air cooled +# condition: +# name: propertiesMatch +# properties: +# - object: /xyz/openbmc_project/inventory/system/chassis +# interface: xyz.openbmc_project.Inventory.Decorator.CoolingType +# property: +# name: WaterCooled +# type: bool +# value: false #sensor_trust_groups: # - class: NonzeroSpeed # group: diff --git a/monitor/gen-fan-monitor-defs.py b/monitor/gen-fan-monitor-defs.py index 83dcbc0..a5f225b 100755 --- a/monitor/gen-fan-monitor-defs.py +++ b/monitor/gen-fan-monitor-defs.py @@ -16,10 +16,32 @@ from the MRW. """ -tmpl = '''/* This is a generated file. */ +tmpl = '''\ +<%! +def indent(str, depth): + return ''.join(4*' '*depth+line for line in str.splitlines(True)) +%>\ +<%def name="getCondParams(cond)" buffered="True"> +%if (cond['name'] == 'propertiesMatch'): +std::vector<PropertyState>{ + %for i in cond['properties']: + PropertyState{ + { + "${i['object']}", + "${i['interface']}", + "${i['property']['name']}" + }, + static_cast<${i['property']['type']}>(${str(i['property']['value']).lower()}) + }, + %endfor +} +%endif +</%def>\ +/* This is a generated file. */ #include "fan_defs.hpp" #include "types.hpp" #include "groups.hpp" +#include "conditions.hpp" using namespace phosphor::fan::monitor; using namespace phosphor::fan::trust; @@ -50,6 +72,14 @@ const std::vector<FanDefinition> fanDefinitions ${offset}}, %endfor }, + %if ('condition' in fan_data) and \ + (fan_data['condition'] is not None): + make_condition(condition::${fan_data['condition']['name']}(\ + ${indent(getCondParams(cond=fan_data['condition']), 5)}\ + )) + %else: + {} + %endif }, %endfor }; |