Redfish: Verify Able To Load Certificates Via Eth1 IP Address

Change-Id: Ib27044b92a30bbf31f526feac50625d0b81543e2
Signed-off-by: Anves Kumar rayankula <anvesr77@in.ibm.com>
diff --git a/redfish/managers/test_multiple_interfaces.robot b/redfish/managers/test_multiple_interfaces.robot
index dec02d7..9d72d25 100644
--- a/redfish/managers/test_multiple_interfaces.robot
+++ b/redfish/managers/test_multiple_interfaces.robot
@@ -14,7 +14,9 @@
 Resource        ../../lib/bmc_ldap_utils.robot
 Resource        ../../lib/snmp/resource.robot
 Resource        ../../lib/snmp/redfish_snmp_utils.robot
+Resource        ../../lib/certificate_utils.robot
 Library         ../../lib/jobs_processing.py
+Library         OperatingSystem
 
 Suite Setup     Suite Setup Execution
 Test Teardown   FFDC On Test Case Fail
@@ -129,6 +131,19 @@
     ${status2}=  Run IPMI  ${OPENBMC_HOST_1}  power status
     Should Be Equal  ${status1}  ${status2}
 
+
+Verify Able To Load Certificates Via Eth1 IP Address
+    [Documentation]  Verify able to load certifcates via eth1 IP address.
+    [Setup]   Create Directory  certificate_dir
+    [Tags]  Verify_Able_To_Load_Certificates_Via_Eth1_IP_Address
+    [Teardown]  Run Keywords  Remove Directory  certificate_dir  recursive=True
+    ...  AND  FFDC On Test Case Fail
+    [Template]  Install Certificate Via Redfish And Verify
+
+    # cert_type  cert_format                         expected_status
+    CA           Valid Certificate                   ok
+    Client       Valid Certificate Valid Privatekey  ok
+
 *** Keywords ***
 
 Get Network Configuration Using Channel Number
@@ -205,3 +220,40 @@
     Should Be Equal As Strings  ${rc}  0
     [Return]  ${output}
 
+
+Install Certificate Via Redfish And Verify
+    [Documentation]  Install and verify certificate using Redfish.
+    [Arguments]  ${cert_type}  ${cert_format}  ${expected_status}  ${delete_cert}=${True}
+
+    # Description of argument(s):
+    # cert_type           Certificate type (e.g. "Client" or "CA").
+    # cert_format         Certificate file format
+    #                     (e.g. "Valid_Certificate_Valid_Privatekey").
+    # expected_status     Expected status of certificate replace Redfish
+    #                     request (i.e. "ok" or "error").
+    # delete_cert         Certificate will be deleted before installing if this True.
+
+    # AUTH_URI is a global variable defined in lib/resource.robot
+    Set Test Variable  ${AUTH_URI}  https://${OPENBMC_HOST_1}
+    Run Keyword If  '${cert_type}' == 'CA' and '${delete_cert}' == '${True}'
+    ...  Delete All CA Certificate Via Redfish
+    ...  ELSE IF  '${cert_type}' == 'Client' and '${delete_cert}' == '${True}'
+    ...  Delete Certificate Via BMC CLI  ${cert_type}
+
+    ${cert_file_path}=  Generate Certificate File Via Openssl  ${cert_format}
+    ${bytes}=  OperatingSystem.Get Binary File  ${cert_file_path}
+    ${file_data}=  Decode Bytes To String  ${bytes}  UTF-8
+
+    ${certificate_uri}=  Set Variable If
+    ...  '${cert_type}' == 'Client'  ${REDFISH_LDAP_CERTIFICATE_URI}
+    ...  '${cert_type}' == 'CA'  ${REDFISH_CA_CERTIFICATE_URI}
+
+    ${cert_id}=  Install Certificate File On BMC  ${certificate_uri}  ${expected_status}  data=${file_data}
+    Logging  Installed certificate id: ${cert_id}
+
+    Sleep  30s
+    ${cert_file_content}=  OperatingSystem.Get File  ${cert_file_path}
+    ${bmc_cert_content}=  Run Keyword If  '${expected_status}' == 'ok'  redfish_utils.Get Attribute
+    ...  ${certificate_uri}/${cert_id}  CertificateString
+    Run Keyword If  '${expected_status}' == 'ok'  Should Contain  ${cert_file_content}  ${bmc_cert_content}
+    [Return]  ${cert_id}