From b751f32d06cb8804bdd4344f3868ca284c0c9e68 Mon Sep 17 00:00:00 2001 From: Gunnar Mills Date: Tue, 6 Jun 2017 15:14:11 -0500 Subject: Check for zone number and condition Only add events to the zone if the conditions and zone number are correct. Resolves openbmc/openbmc#1500 Change-Id: Ia040fcbdd9093d25d4ed1773d5fea0ed8a95ba2b Signed-off-by: Gunnar Mills --- control/gen-fan-zone-defs.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'control/gen-fan-zone-defs.py') diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py index 293bb02..694477b 100755 --- a/control/gen-fan-zone-defs.py +++ b/control/gen-fan-zone-defs.py @@ -113,7 +113,7 @@ const std::vector Manager::_zoneLayouts ''' -def getEventsInZone(zone_num, events_data): +def getEventsInZone(zone_num, zone_conditions, events_data): """ Constructs the event entries defined for each zone using the events yaml provided. @@ -122,9 +122,19 @@ def getEventsInZone(zone_num, events_data): if 'events' in events_data: for e in events_data['events']: - for z in e['zone_conditions']: - if zone_num not in z['zones']: - continue + + # Zone numbers are optional in the events yaml but skip if this + # zone's zone number is not in the event's zone numbers + if all('zones' in z and z['zones'] is not None and + zone_num not in z['zones'] for z in e['zone_conditions']): + continue + + # Zone conditions are optional in the events yaml but skip if this + # event's condition is not in this zone's conditions + if all('name' in z and z['name'] is not None and + not any(c['name'] == z['name'] for c in zone_conditions) + for z in e['zone_conditions']): + continue event = {} # Add set speed event group @@ -257,7 +267,7 @@ def buildZoneData(zone_data, fan_data, events_data, zone_conditions_data): for c in group['zone_conditions']: if not zone_conditions_data: - sys.exit("No zone_conditions YAML file but" + + sys.exit("No zone_conditions YAML file but " + "zone_conditions used in zone YAML") condition = getConditionInZoneConditions(c['name'], @@ -291,7 +301,8 @@ def buildZoneData(zone_data, fan_data, events_data, zone_conditions_data): profiles = z['cooling_profiles'] fans = getFansInZone(z['zone'], profiles, fan_data) - events = getEventsInZone(z['zone'], events_data) + events = getEventsInZone(z['zone'], group['zone_conditions'], + events_data) if len(fans) == 0: sys.exit("Didn't find any fans in zone " + str(zone['num'])) -- cgit v1.2.1