Add systest/collection test cases and utility functions needed

- Add systest data collection test cases.
- Add functions/keywords for displaying non informational error
  and event logs.
- Add URIs for inventory reading.

Signed-off-by: Joy Onyerikwu <Onyekachukwu.Joy.Onyerikwu@ibm.com>
Change-Id: Id4e7b131a029d7dd727c1e1511c60640b6007b2f
diff --git a/data/variables.py b/data/variables.py
index 6bfb02e..f62dd48 100755
--- a/data/variables.py
+++ b/data/variables.py
@@ -68,8 +68,10 @@
 # Image Upload Directory Path
 IMAGE_UPLOAD_DIR_PATH = '/tmp/images/'
 
-# Inventory URI
+# Inventory URI variables
 HOST_INVENTORY_URI = OPENBMC_BASE_URI + 'inventory/'
+CHASSIS_INVENTORY_URI = HOST_INVENTORY_URI + 'system/chassis/'
+MOTHERBOARD_INVENTORY_URI = CHASSIS_INVENTORY_URI + 'motherboard/'
 
 # Led URI variable
 LED_GROUPS_URI = OPENBMC_BASE_URI + 'led/groups/'
@@ -169,6 +171,8 @@
 REDFISH_CHASSIS_THERMAL_URI = REDFISH_CHASSIS_URI + REDFISH_CHASSIS_THERMAL
 REDFISH_CHASSIS_POWER = 'chassis/Power/'
 REDFISH_CHASSIS_POWER_URI = REDFISH_CHASSIS_URI + REDFISH_CHASSIS_POWER
+REDFISH_CHASSIS_SENSORS = 'chassis/Sensors'
+REDFISH_CHASSIS_SENSORS_URI = REDFISH_CHASSIS_URI + REDFISH_CHASSIS_SENSORS
 
 # Boot options and URI variables.
 POWER_ON = 'On'
diff --git a/lib/logging_utils.robot b/lib/logging_utils.robot
index b4c4076..c9266ff 100644
--- a/lib/logging_utils.robot
+++ b/lib/logging_utils.robot
@@ -204,6 +204,14 @@
     [Return]  ${members}
 
 
+Get Event Logs Not Ok
+    [Documentation]  Get all event logs where the 'Severity' is not 'OK'.
+
+    ${members}=  Get Event Logs
+    ${severe_logs}=  Evaluate  [elog for elog in $members if elog['Severity'] != 'OK']
+    [Return]  ${severe_logs}
+
+
 Get Number Of Event Logs
     [Documentation]  Return the number of EventLog members.
 
diff --git a/lib/openbmc_ffdc.robot b/lib/openbmc_ffdc.robot
index 70b7656..ecd3116 100755
--- a/lib/openbmc_ffdc.robot
+++ b/lib/openbmc_ffdc.robot
@@ -46,6 +46,10 @@
     ...                  EX: 20160822041250932049:Test:Test case 1:PASS
     ...                      20160822041250969913:Test:Test case 2:FAIL
     ...               3. Delete error logs and BMC dumps post FFDC collection.
+    [Arguments]  ${clean_up}=${TRUE}
+    # Description of argument(s):
+    # clean_up:    Boolean value indicating whether error logs and dumps should be deleted on test failure after
+    #              FFDC collection.
 
     ${OVERRIDE_FFDC_ON_TEST_CASE_FAIL}=  Get Environment Variable  OVERRIDE_FFDC_ON_TEST_CASE_FAIL  0
     ${OVERRIDE_FFDC_ON_TEST_CASE_FAIL}=  Convert To Integer  ${OVERRIDE_FFDC_ON_TEST_CASE_FAIL}
@@ -56,5 +60,5 @@
     Log Test Case Status
 
     # Clean up error logs and BMC dumps.
-    Run Keyword If  '${TEST_STATUS}' == 'FAIL'
+    Run Keyword If  '${TEST_STATUS}' == 'FAIL' and ${clean_up}
     ...  Run Keywords  Delete All Error Logs  AND  Delete All Dumps
diff --git a/lib/utils_files.py b/lib/utils_files.py
index f59849e..3395e65 100755
--- a/lib/utils_files.py
+++ b/lib/utils_files.py
@@ -119,7 +119,7 @@
     if robot_env == 1:
         BuiltIn().log_to_console("DIFF:\n" + out_buf)
     else:
-        print ("DIFF:\n", out_buf)
+        print("DIFF:\n", out_buf)
 
     file.write(out_buf)
     file.close()
diff --git a/systest/collection/bmc_collect_esels.robot b/systest/collection/bmc_collect_esels.robot
new file mode 100644
index 0000000..776f920
--- /dev/null
+++ b/systest/collection/bmc_collect_esels.robot
@@ -0,0 +1,76 @@
+*** Settings ***
+Documentation       BMC server health, collect eSELs.
+
+# Test Parameters:
+# OPENBMC_HOST      The BMC host name or IP address.
+
+Resource            ../../lib/bmc_redfish_resource.robot
+Resource            ../../lib/openbmc_ffdc.robot
+
+Suite Setup         Suite Setup Execution
+Suite Teardown      Suite Teardown Execution
+Test Setup          Printn
+
+*** Variables ***
+${QUIET}                       ${1}
+${error_logs_flagged_rest}     Rest error log collection excluded
+${event_logs_flagged_redfish}  Redfish event log collection excluded
+${rest_error_logs}             Rest error log collection excluded
+${redfish_event_logs}          Redfish error log collection excluded
+
+*** Test Cases ***
+
+Rest Collect eSELs
+    [Documentation]  Collect eSEL using the OpenBMC Rest API.
+    [Tags]  Rest_Collect_eSELs  rest
+    [Teardown]  FFDC On Test Case Fail  clean_up=${FALSE}
+
+    ${error_logs}=  Get Error Logs  ${QUIET}
+    ${rest_error_logs}=  gen_robot_print.Sprint Vars  error_logs
+    Set Suite Variable  ${rest_error_logs}
+    Log To Console  ${rest_error_logs}
+
+    # Filter out informational error logs.
+    ${non_informational_error_logs}=  Filter Struct  ${error_logs}  [('Severity', '\.Informational$')]
+    ...  regex=1  invert=1
+    ${error_logs_flagged_rest}=  gen_robot_print.Sprint Vars  non_informational_error_logs
+    Set Suite Variable  ${error_logs_flagged_rest}
+
+
+Redfish Collect eSELs
+    [Documentation]  Collect eSEL with Redfish.
+    [Tags]  Redfish_Collect_eSELs  redfish
+    [Setup]  Redfish.Login
+    [Teardown]  Redfish Test Teardown Execution
+
+    ${redfish_event_logs}=  Get Event Logs
+    ${redfish_event_logs}=  gen_robot_print.Sprint Vars  redfish_event_logs
+    Set Suite Variable  ${redfish_event_logs}
+    Log To Console  ${redfish_event_logs}
+    ${event_logs_flagged_redfish}=  Get Event Logs Not Ok
+    ${event_logs_flagged_redfish}=  gen_robot_print.Sprint Vars  event_logs_flagged_redfish
+    Set Suite Variable  ${event_logs_flagged_redfish}
+
+
+*** Keywords ***
+
+Suite Setup Execution
+    [Documentation]  Do test suite setup tasks.
+
+    Set Log Level  DEBUG
+    REST Power On  stack_mode=skip
+
+
+Suite Teardown Execution
+    [Documentation]  Do suite teardown tasks. Log error and event logs collected.
+
+    Log Many  ${rest_error_logs}  ${redfish_event_logs}
+    Log  Flagged error logs found via REST:${\n}${error_logs_flagged_rest}  console=true
+    Log  Flagged events logs found via Redfish:${\n}${event_logs_flagged_redfish}  console=true
+
+
+Redfish Test Teardown Execution
+    [Documentation]  Do the post test teardown for redfish.
+
+    Redfish.Logout
+    FFDC On Test Case Fail  clean_up=${FALSE}
diff --git a/systest/collection/bmc_collect_sensors.robot b/systest/collection/bmc_collect_sensors.robot
new file mode 100644
index 0000000..8862308
--- /dev/null
+++ b/systest/collection/bmc_collect_sensors.robot
@@ -0,0 +1,93 @@
+*** Settings ***
+Documentation       BMC server health, collect sensors.
+
+# Test Parameters:
+# OPENBMC_HOST      The BMC host name or IP address.
+
+Resource            ../../lib/bmc_redfish_resource.robot
+Resource            ../../lib/openbmc_ffdc.robot
+Library             Collections
+Library             ../syslib/utils_keywords.py
+
+Suite Setup         Suite Setup Execution
+Suite Teardown      Suite Teardown Execution
+Test Setup          Printn
+
+*** Variables ***
+${QUIET}                     ${1}
+${sensors_values_rest}       Rest sensors collection excluded
+${sensors_values_redfish}    Redfish sensors collection excluded
+${sensors_flagged_rest}      Rest sensors collection excluded
+${sensors_flagged_redfish}   Redfish sensors collection excluded
+
+
+*** Test Cases ***
+
+Rest Collect Sensors
+    [Documentation]  Collect the sensors values using the OpenBMC Rest API.
+    [Tags]  Rest_Collect_Sensors  rest
+    [Teardown]  FFDC On Test Case Fail  clean_up=${FALSE}
+
+    ${sensors}=  OpenBMC Get Request  ${SENSORS_URI}enumerate
+    ${sensors}=  Evaluate  $sensors.json()['data']
+    ${sensors_collected_via_rest}=  gen_robot_print.Sprint Vars  sensors
+    Log To Console  ${sensors_collected_via_rest}
+    ${fans}=  Filter Struct  ${sensors}  [('Unit', '\.RPMS$')]  regex=1
+    ${no_fans}=  Filter Struct  ${sensors}  [('WarningAlarmHigh', None),('WarningAlarmLow', None)]
+    ...  invert=${True}
+    Log  sensor values raw:${\n}${sensors}${\n}sensors no fans:${\n}${no_fans}${\n}fans:${\n}${fans}
+    ...  level=DEBUG
+
+    ${fans_flagged}=  Filter Struct  ${fans}
+    ...  [('CriticalAlarmHigh', False),('CriticalAlarmLow', False)]  invert=${True}
+    ${filter_str}=  Catenate  [('CriticalAlarmHigh', False),('CriticalAlarmLow', False),
+    ...  ('WarningAlarmHigh', False),('WarningAlarmLow', False)]
+    ${other_sensors_flagged}=  Filter Struct  ${no_fans}  ${filter_str}  invert=${True}
+    ${sensors_flagged_rest}=  gen_robot_print.Sprint Vars  fans_flagged  other_sensors_flagged
+    Set Suite Variable  ${sensors_flagged_rest}
+
+
+Redfish Collect Sensors
+    [Documentation]  Collect the sensor values using Redfish.
+    [Tags]  Redfish_Collect_Sensors  redfish
+    [Setup]  Redfish.Login
+    [Teardown]  Redfish Test Teardown Execution
+
+    ${redfish_chassis_power}=  Redfish_Utils.Enumerate Request  ${REDFISH_CHASSIS_POWER_URI}  ${0}
+    ${redfish_chassis_thermal}=  Redfish_Utils.Enumerate Request  ${REDFISH_CHASSIS_THERMAL_URI}  ${0}
+    ${redfish_chassis_sensors}=  Redfish_Utils.Enumerate Request  ${REDFISH_CHASSIS_SENSORS_URI}  ${0}
+    ${sensors_values_redfish}=  gen_robot_print.Sprint Vars
+    ...  redfish_chassis_power  redfish_chassis_thermal  redfish_chassis_sensors
+    Set Suite Variable  ${sensors_values_redfish}
+    Log To Console  ${sensors_values_redfish}
+
+    ${health_check_filter_dict}=  Create Dictionary  Health=OK
+    ${merged_dicts}=  Evaluate  {**$redfish_chassis_power, **$redfish_chassis_thermal}
+    Log  ${merged_dicts}  level=DEBUG
+    ${sensors_flagged_redfish}=  Filter Struct  ${merged_dicts}  ${health_check_filter_dict}  invert=${TRUE}
+    ${sensors_flagged_redfish}=  gen_robot_print.Sprint Vars  sensors_flagged_redfish
+    Set Suite Variable  ${sensors_flagged_redfish}
+
+
+*** Keywords ***
+
+Suite Setup Execution
+    [Documentation]  Do suite setup tasks.
+
+    Set Log Level  DEBUG
+    REST Power On  stack_mode=skip
+
+
+Suite Teardown Execution
+    [Documentation]  Do suite teardown tasks. Log sensor values collected.
+
+    Log Many  ${sensors_values_rest}  ${sensors_values_redfish}
+    Log  Sensors detected out of bounds via Rest:${\n}${sensors_flagged_rest}  console=true
+    Log  Sensors detected out of bounds via Redfish:${\n}${sensors_flagged_redfish}  console=true
+
+
+Redfish Test Teardown Execution
+    [Documentation]  Do the post test teardown for redfish.
+
+    Redfish.Logout
+    FFDC On Test Case Fail  clean_up=${FALSE}
diff --git a/systest/collection/bmc_collect_vpd_and_hw_status.robot b/systest/collection/bmc_collect_vpd_and_hw_status.robot
new file mode 100644
index 0000000..2ce8040
--- /dev/null
+++ b/systest/collection/bmc_collect_vpd_and_hw_status.robot
@@ -0,0 +1,75 @@
+*** Settings ***
+Documentation       BMC server health, collect VPD and hardware status.
+
+# Test Parameters:
+# OPENBMC_HOST      The BMC host name or IP address.
+
+Resource            ../../lib/bmc_redfish_resource.robot
+Resource            ../../lib/openbmc_ffdc.robot
+
+Suite Setup         Suite Setup Execution
+Suite Teardown      Suite Teardown Execution
+Test Setup          Printn
+
+*** Variables ***
+${QUIET}  ${1}
+${rest_collected_values}  Rest collection excluded
+${redfish_collected_values}  Redfish collection excluded
+
+*** Test Cases ***
+
+Rest Collect VPD And Hardware Status
+    [Documentation]  Collect VPD and hardware status using the OpenBMC Rest API.
+    [Tags]  Rest_Collect_VPD_And_Hardware_Status  rest
+    [Teardown]  FFDC On Test Case Fail  clean_up=${FALSE}
+
+    ${system_properties}=  OpenBMC Get Request  ${HOST_INVENTORY_URI}system
+    ${system_properties}=  Evaluate  $system_properties.json()
+    ${Type}=  Read Attribute  ${CHASSIS_INVENTORY_URI}  Type
+    ${WaterCooled}=  Read Attribute  ${CHASSIS_INVENTORY_URI}  WaterCooled
+    ${AirCooled}=  Read Attribute  ${CHASSIS_INVENTORY_URI}  AirCooled
+    ${system_chassis}=  OpenBMC Get Request  ${MOTHERBOARD_INVENTORY_URI}enumerate
+    ${system_chassis}=  Evaluate  $system_chassis.json()
+    Rprint Vars  system_properties  Type  WaterCooled  AirCooled  system_chassis
+    ${rest_collected_values}=  gen_robot_print.Sprint Vars
+    ...  system_properties  Type  WaterCooled  AirCooled  system_chassis
+    Set Global Variable  ${rest_collected_values}
+
+
+Redfish Collect VPD And Hardware Status
+    [Documentation]  Collect VPD and hardware status using Redfish.
+    [Tags]  Redfish_Collect_VPD_And_Hardware_Status  redfish
+    [Setup]  Redfish.Login
+    [Teardown]  Redfish Test Teardown Execution
+
+    ${system_properties}=  Redfish_Utils.Get Properties  ${SYSTEM_BASE_URI}
+    ${system_memory_info}=  Redfish_Utils.Enumerate Request  ${SYSTEM_BASE_URI}/Memory
+    ${system_processors_info}=  Redfish_Utils.Enumerate Request  ${SYSTEM_BASE_URI}/Processors
+    ${system_fans_info}=  Redfish_Utils.Get Attribute  ${REDFISH_CHASSIS_THERMAL_URI}  Fans
+    Rprint Vars  system_properties  system_memory_info  system_processors_info  system_fans_info
+    ${redfish_collected_values}=  gen_robot_print.Sprint Vars
+    ...  system_properties  system_memory_info  system_processors_info  system_fans_info
+    Set Global Variable  ${redfish_collected_values}
+
+
+*** Keywords ***
+
+Suite Setup Execution
+    [Documentation]  Do test case setup tasks.
+
+    Set Log Level  DEBUG
+    REST Power On  stack_mode=skip
+
+
+Suite Teardown Execution
+    [Documentation]  Do suite teardown tasks. Log values and data collected.
+
+    Log  Rest collected values:${\n}${rest_collected_values}
+    Log  Redfish collected values:${\n}${redfish_collected_values}
+
+
+Redfish Test Teardown Execution
+    [Documentation]  Do the post test teardown for redfish.
+
+    Redfish.Logout
+    FFDC On Test Case Fail  clean_up=${FALSE}