Added teardown method to delete certificate

Change-Id: I77a20586856b97a4578fbede2086b31a9e69eba8
Signed-off-by: Rahul Maheshwari <rahulmaheshwari@in.ibm.com>
diff --git a/lib/certificate_utils.robot b/lib/certificate_utils.robot
index 4e0a83c..942d722 100755
--- a/lib/certificate_utils.robot
+++ b/lib/certificate_utils.robot
@@ -69,25 +69,29 @@
 Generate Certificate File Via Openssl
     [Documentation]  Create certificate file via openssl with required content
     ...              and returns its path.
-    [Arguments]  ${cert_format}  ${time}=365
+    [Arguments]  ${cert_format}  ${time}=365  ${cert_dir_name}=certificate_dir
 
     # Description of argument(s):
     # cert_format          Certificate file format
     #                      e.g. Valid_Certificate_Empty_Privatekey.
     # time                 Number of days to certify the certificate for.
+    # cert_dir_name        The name of the sub-directory where the certificate
+    #                      is stored.
 
     Check If Openssl Tool Exist
 
     ${openssl_cmd}=  Catenate  openssl req -x509 -sha256 -newkey rsa:2048
     ...  ${SPACE}-nodes -days ${time}
-    ...  ${SPACE}-keyout cert.pem -out cert.pem
+    ...  ${SPACE}-keyout ${cert_dir_name}/cert.pem -out ${cert_dir_name}/cert.pem
     ...  ${SPACE}-subj "/O=XYZ Corporation /CN=www.xyz.com"
 
     ${rc}  ${output}=  Run And Return RC and Output  ${openssl_cmd}
     Should Be Equal  ${rc}  ${0}  msg=${output}
-    OperatingSystem.File Should Exist  ${EXECDIR}${/}cert.pem
+    OperatingSystem.File Should Exist
+    ...  ${EXECDIR}${/}${cert_dir_name}${/}cert.pem
 
-    ${file_content}=  OperatingSystem.Get File  ${EXECDIR}${/}cert.pem
+    ${file_content}=  OperatingSystem.Get File
+    ...  ${EXECDIR}${/}${cert_dir_name}${/}cert.pem
     ${result}=  Fetch From Left  ${file_content}  -----END CERTIFICATE-----
     ${cert_content}=  Fetch From Right  ${result}  -----BEGIN CERTIFICATE-----
 
@@ -96,7 +100,7 @@
 
     ${cert_data}=
     ...  Run Keyword if  '${cert_format}' == 'Valid Certificate Valid Privatekey'
-    ...  OperatingSystem.Get File  ${EXECDIR}${/}cert.pem
+    ...  OperatingSystem.Get File  ${EXECDIR}${/}${cert_dir_name}${/}cert.pem
     ...  ELSE IF  '${cert_format}' == 'Empty Certificate Valid Privatekey'
     ...  Remove String  ${file_content}  ${cert_content}
     ...  ELSE IF  '${cert_format}' == 'Valid Certificate Empty Privatekey'
@@ -104,13 +108,13 @@
     ...  ELSE IF  '${cert_format}' == 'Empty Certificate Empty Privatekey'
     ...  Remove String  ${file_content}  ${cert_content}  ${private_key_content}
     ...  ELSE IF  '${cert_format}' == 'Expired Certificate'
-    ...  OperatingSystem.Get File  ${EXECDIR}${/}cert.pem
+    ...  OperatingSystem.Get File  ${EXECDIR}${/}${cert_dir_name}${/}cert.pem
 
     ${random_name}=  Generate Random String  8
     ${cert_name}=  Catenate  SEPARATOR=  ${random_name}  .pem
-    Create File  ${cert_name}  ${cert_data}
+    Create File  ${cert_dir_name}/${cert_name}  ${cert_data}
 
-    [Return]  ${EXECDIR}${/}${cert_name}
+    [Return]  ${EXECDIR}${/}${cert_dir_name}${/}${cert_name}
 
 
 Get Certificate Content From File
diff --git a/test_lists/skip_test_witherspoon b/test_lists/skip_test_witherspoon
index 37332e8..5dd743d 100644
--- a/test_lists/skip_test_witherspoon
+++ b/test_lists/skip_test_witherspoon
@@ -11,6 +11,7 @@
 # NA test case for Witherspoon
 -e io_board_Present
 -e io_board_Fault
+-e Certificate_Test
 # System LED test cases which are NA for Witherspoon system.
 -e Test_Heartbeat_LED_And_Verify_Via_REST
 -e Test_Beep_LED_And_Verify_Via_REST
diff --git a/test_lists/witherspoon/regression_bucket b/test_lists/witherspoon/regression_bucket
index 5933659..e3247d4 100644
--- a/test_lists/witherspoon/regression_bucket
+++ b/test_lists/witherspoon/regression_bucket
@@ -196,3 +196,14 @@
 -i Check_Number_Of_Fans_With_Power_On
 -i Check_Number_Of_Fan_Monitors_With_Power_On
 -i Check_Fan_Speed
+# Certificate
+-i Test_Server_Certificate_Install_With_Valid_Certificate_And_Valid_Private_Key
+-i Test_Server_Certificate_Install_With_Empty_Certificate_And_Valid_Private_Key
+-i Test_Server_Certificate_Install_With_Valid_Certificate_And_Empty_Private_Key
+-i Test_Server_Certificate_Install_With_Empty_Certificate_And_Empty_Private_Key
+-i Test_Client_Certificate_Install_With_Valid_Certificate_And_Valid_Private_Key
+-i Test_Client_Certificate_Install_With_Empty_Certificate_And_Valid_Private_Key
+-i Test_Client_Certificate_Install_With_Valid_Certificate_And_Empty_Private_Key
+-i Test_Client_Certificate_Install_With_Empty_Certificate_And_Empty_Private_Key
+-i Test_Delete_Server_Certificate
+-i Test_Delete_Client_Certificate
diff --git a/tests/test_certificate.robot b/tests/test_certificate.robot
index 3104251..fbb3752 100755
--- a/tests/test_certificate.robot
+++ b/tests/test_certificate.robot
@@ -7,7 +7,10 @@
 Resource       ../lib/openbmc_ffdc.robot
 Resource       ../lib/certificate_utils.robot
 
-Test Teardown  FFDC On Test Case Fail
+Suite Setup    Suite Setup Execution
+Test Teardown  Test Teardown Execution
+
+Force Tags     Certificate_Test
 
 
 *** Test Cases ***
@@ -120,7 +123,7 @@
 
     OpenBMC Delete Request  ${SERVER_CERTIFICATE_URI}
     # Adding delay after certificate deletion
-    Sleep  10s
+    Sleep  30s
 
     ${bmc_cert_content}=  Get Certificate Content From BMC Via Openssl
     Should Not Contain  ${cert_file_content}  ${bmc_cert_content}
@@ -152,7 +155,7 @@
     [Documentation]  Stress server certificate installtion.
     [Tags]  Test_Continuous_Server_Certificate_Install
 
-    Repeat Keyword  50 times  Certificate Install Via REST
+    Repeat Keyword  3 times  Certificate Install Via REST
     ...  Server  Valid Certificate Valid Privatekey  ok
 
 
@@ -160,7 +163,7 @@
     [Documentation]  Stress client certificate installtion.
     [Tags]  Test_Continuous_Client_Certificate_Install
 
-    Repeat Keyword  50 times  Certificate Install Via REST
+    Repeat Keyword  3 times  Certificate Install Via REST
     ...  Client  Valid Certificate Valid Privatekey  ok
 
 
@@ -204,3 +207,18 @@
     ...  Should Contain  ${cert_file_content}  ${bmc_cert_content}
     ...  ELSE IF  '${expected_status}' == 'error'
     ...  Should Not Contain  ${cert_file_content}  ${bmc_cert_content}
+
+
+Suite Setup Execution
+    [Documentation]  Do suite setup tasks.
+
+    # Create certificate sub-directory in current working directory.
+    Create Directory  certificate_dir
+    OperatingSystem.Directory Should Exist  ${EXECDIR}${/}certificate_dir
+
+
+Test Teardown Execution
+    [Documentation]  Do the post test teardown.
+
+    Empty Directory  ${EXECDIR}${/}certificate_dir
+    FFDC On Test Case Fail