Add fan tests

Add basic fan tests.  These do not need a booted operating system
such as Ubuntu or RedHat.

Resolves  openbmc/openbmc-test-automation#1173
Change-Id: Ic836b88cee90429d2bc4c5b1116c27354bbeea64
Signed-off-by: Steven Sombar <ssombar@us.ibm.com>
diff --git a/lib/fan_utils.robot b/lib/fan_utils.robot
new file mode 100755
index 0000000..7eb9ad7
--- /dev/null
+++ b/lib/fan_utils.robot
@@ -0,0 +1,83 @@
+*** Settings ***
+Documentation     Utilities for fan tests.
+
+Library       ../lib/bmc_ssh_utils.py
+Variables     ../data/variables.py
+
+*** Keywords ***
+
+
+Is Water Cooled
+    [Documentation]  Return 1 if system is water cooled, 0 othersise.
+
+    ${water_cooled}=  Read Attribute
+    ...  ${HOST_INVENTORY_URI}/system/chassis  WaterCooled
+    [Return]  ${water_cooled}
+
+
+Get Number Of Fans
+    [Documentation]  Get the number of fans currently present in inventory.
+
+    ${num_fans}  Set Variable  ${0}
+    ${fan_uris}=  Get Endpoint Paths  ${HOST_INVENTORY_URI}/system  fan
+
+    : FOR  ${fan_uri}  IN  @{fan_uris}
+    \  ${fan_record}=  Read Properties  ${fan_uri}
+    \  Continue For Loop If  ${fan_record['Present']} != 1
+    \  ${num_fans}=  Set Variable  ${num_fans+1}
+    [Return]  ${num_fans}
+
+
+Verify Minimum Number Of Fans With Cooling Type
+    [Documentation]  Verify minimum number of fans.
+    [Arguments]  ${water_cooled}
+
+    # Description of argument(s):
+    # water_cooled   The value 1 if the system is water cooled,
+    #                the value 0 if air cooled.
+
+    # For a water cooled system.
+    ${min_fans_water}=  Set Variable  2
+
+    # For an air cooled system.
+    ${min_fans_air}=  Set Variable  3
+
+    ${num_fans}=  Get Number Of Fans
+
+    Rprintn
+    Rpvars  water_cooled  num_fans
+
+    # If water cooled must have at least min_fans_water fans, otherwise
+    # issue Fatal Error and terminate testing.
+    Run Keyword If  ${water_cooled} == 1 and ${num_fans} < ${min_fans_water}
+    ...  Fatal Error
+    ...  msg=Water cooled but less than ${min_fans_water} fans present.
+
+    # If air cooled must have at least min_fans_air fans.
+    Run Keyword If  ${water_cooled} == 0 and ${num_fans} < ${min_fans_air}
+    ...  Fatal Error
+    ...  msg=Air cooled but less than ${min_fans_air} fans present.
+
+
+Verify Fan Monitors With State
+    [Documentation]  Verify fan monitor daemons in the system state.
+    # The number of monitoring daemons is dependent upon the system
+    # power state.  If power is off there should be 0, if power
+    # is on there should be several.
+    [Arguments]  ${power_state}
+
+    # Description of argument(s):
+    # power_state   Power staet of the system, either "On" or "Off"
+
+    ${cmd}=  Catenate  systemctl list-units | grep phosphor-fan | wc -l
+    ${num_fan_daemons}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
+
+    Rpvars  power_state  num_fan_daemons
+
+    # Fail if system is On and there are no fan monitors.
+    Run Keyword If  '${power_state}' == 'On' and ${num_fan_daemons} == 0
+    ...  Fail  msg=No phosphor-fan monitors found at power on.
+
+    # Fail if system is Off and the fan monitors are present.
+    Run Keyword If  '${power_state}' == 'Off' and ${num_fan_daemons} != 0
+    ...  Fail  msg=Phosphor-fan monitors found at power off.
diff --git a/tests/test_fans.robot b/tests/test_fans.robot
new file mode 100755
index 0000000..98fc7ba
--- /dev/null
+++ b/tests/test_fans.robot
@@ -0,0 +1,36 @@
+*** Settings ***
+
+Documentation  Fan checks.
+
+# Test Parameters:
+# OPENBMC_HOST       The BMC host name or IP address.
+# OPENBMC_USERNAME   The userID for the BMC login.
+# OPENBMC_PASSWORD   The password for OPENBMC_USERNAME.
+#
+# Approximate run time:  15 seconds.
+
+Resource         ../lib/state_manager.robot
+Resource         ../lib/fan_utils.robot
+Resource         ../lib/openbmc_ffdc.robot
+
+Test Teardown    FFDC On Test Case Fail
+
+
+*** Test Cases ***
+
+Fan Base Check Number Of Fans
+    [Documentation]  Verify minimum number of fans.
+    [Tags]  Fan_Base_Check_Number_Of_Fans
+
+    # Determine if system is water cooled.
+    ${water_coooled}=  Is Water Cooled
+
+    Verify Minimum Number Of Fans With Cooling Type  ${water_coooled}
+
+
+Fan Base Check Number Of Fan Monitors
+    [Documentation]  Verify number of fan monitor daemons.
+    [Tags]  Fan_Base_Check_Number_Of_Fan_Monitors
+
+    ${power_state}=  Get Chassis Power State
+    Verify Fan Monitors With State  ${power_state}