REST and Redfish supported driver

Changes:
    - Added REDFISH_REST_SUPPORTED global var as part of the
      lib/bmc_redfish_utils.py init function.
    - Update boot test to select supported BMC REST or Reddfish
      fucntions to set.

There are driver still out there in community which supports both
legacy REST (/xyz/openbmc_project/) and new redfish (/redfish/v1/).
This new logic is to derieve early in the program and use in the
functional and boot test path.

Tested:
    - Disable REST and test the change.
    - Test the change in current latest level of driver.

Change-Id: I0e0b480b97b64df8a264a3d54e7159e90b33f4af
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/bmc_redfish_utils.py b/lib/bmc_redfish_utils.py
index b9a39a2..f8d2a94 100644
--- a/lib/bmc_redfish_utils.py
+++ b/lib/bmc_redfish_utils.py
@@ -11,13 +11,28 @@
 
 class bmc_redfish_utils(object):
 
+    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
+
     def __init__(self):
         r"""
         Initialize the bmc_redfish_utils object.
         """
         # Obtain a reference to the global redfish object.
+        self.__inited__ = False
         self._redfish_ = BuiltIn().get_library_instance('redfish')
 
+        # There is a possibility that a given driver support both redfish and
+        # legacy REST.
+        self._redfish_.login()
+        self._rest_response_ = \
+            self._redfish_.get("/xyz/openbmc_project/", valid_status_codes=[200, 404])
+
+        # If REST URL /xyz/openbmc_project/ is supported.
+        if self._rest_response_.status == 200:
+            self.__inited__ = True
+
+        BuiltIn().set_global_variable("${REDFISH_REST_SUPPORTED}", self.__inited__)
+
     def get_redfish_session_info(self):
         r"""
         Returns redfish sessions info dictionary.
diff --git a/lib/obmc_boot_test.py b/lib/obmc_boot_test.py
index 68db581..936855d 100755
--- a/lib/obmc_boot_test.py
+++ b/lib/obmc_boot_test.py
@@ -65,14 +65,17 @@
 if status_dir_path != "":
     status_dir_path = os.path.normpath(status_dir_path) + os.sep
 redfish_supported = BuiltIn().get_variable_value("${REDFISH_SUPPORTED}", default=False)
+redfish_rest_supported = BuiltIn().get_variable_value("${REDFISH_REST_SUPPORTED}", default=False)
 if redfish_supported:
     redfish = BuiltIn().get_library_instance('redfish')
     default_power_on = "Redfish Power On"
     default_power_off = "Redfish Power Off"
-    delete_errlogs_cmd = "Delete Error Logs"
-    # TODO: delete_errlogs_cmd="Redfish Purge Event Log"
-    # TODO: default_set_power_policy = "Redfish Set Power Restore Policy  AlwaysOff"
-    default_set_power_policy = "Set BMC Power Policy  ALWAYS_POWER_OFF"
+    if redfish_rest_supported:
+        delete_errlogs_cmd = "Delete Error Logs"
+        default_set_power_policy = "Set BMC Power Policy  ALWAYS_POWER_OFF"
+    else:
+        delete_errlogs_cmd = "Redfish Purge Event Log"
+        default_set_power_policy = "Redfish Set Power Restore Policy  AlwaysOff"
 else:
     default_power_on = "REST Power On"
     default_power_off = "REST Power Off"