Update redfish rsp code for cert update/install
Changes:
- Updated redfish response code to expect either 200 or 204
while updating or installing certificate via redfish.
- Both client / server certificate response code updated.
Tested:
- Ran All The Scripts Successfully
Change-Id: Iae3c9c68b433e78c7c51a8891c0df1ac084b8595
Signed-off-by: ganesanb <ganesanb@ami.com>
diff --git a/redfish/dmtf_tools/test_redfishtool_certificate.robot b/redfish/dmtf_tools/test_redfishtool_certificate.robot
index 9c3a68b..f6bc373 100644
--- a/redfish/dmtf_tools/test_redfishtool_certificate.robot
+++ b/redfish/dmtf_tools/test_redfishtool_certificate.robot
@@ -148,6 +148,7 @@
${response}= Redfishtool Post
... ${payload} /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate
+ ... valid_status_codes=${HTTP_OK}, ${HTTP_NO_CONTENT}
Wait Until Keyword Succeeds 2 mins 15 secs Verify Certificate Visible Via OpenSSL ${cert_file_path}
@@ -223,7 +224,8 @@
Run Keyword If '${key_pair_algorithm}' == 'EC' Remove From Dictionary ${csr_dict} KeyBitLength
... ELSE IF '${key_pair_algorithm}' == 'RSA' Remove From Dictionary ${csr_dict} KeyCurveId
- ${expected_resp}= Set Variable If '${expected_status}' == 'ok' ${HTTP_OK}
+ ${expected_resp}= Set Variable If
+ ... '${expected_status}' == 'ok' ${HTTP_OK}, ${HTTP_NO_CONTENT}
... '${expected_status}' == 'error' ${HTTP_BAD_REQUEST}
${string}= Convert To String ${csr_dict}
@@ -243,6 +245,7 @@
Verify Redfishtool Install Certificate
[Documentation] Install and verify certificate using Redfishtool.
[Arguments] ${cert_type} ${cert_format} ${expected_status} ${delete_cert}=${True}
+ ... ${install_type}=install
# Description of argument(s):
# cert_type Certificate type (e.g. "Client" or "CA").
@@ -251,10 +254,12 @@
# request (i.e. "ok" or "error").
# delete_cert Certificate will be deleted before installing if this True.
- Run Keyword If '${cert_type}' == 'CA' and '${delete_cert}' == '${True}'
- ... Delete All CA Certificate Via Redfisthtool
- ... ELSE IF '${cert_type}' == 'Client' and '${delete_cert}' == '${True}'
- ... Redfishtool Delete Certificate Via BMC CLI ${cert_type}
+ Run Keyword If '${cert_type}' == 'CA'
+ ... Delete All CA Certificate Via Redfishtool ${delete_cert}
+ ... ELSE IF '${cert_type}' == 'Client'
+ ... Redfishtool Delete Certificate Via BMC CLI ${cert_type} ${delete_cert}
+
+ Return From Keyword If "${install_type}" != "install" and "${file_status}" != "Not Found"
${cert_file_path}= Generate Certificate File Via Openssl ${cert_format}
${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
@@ -278,15 +283,24 @@
Run Keyword If '${expected_status}' == 'ok' Should Contain ${cert_file_content} ${bmc_cert_content}
- [Return] ${cert_id}
-
-Delete All CA Certificate Via Redfisthtool
+Delete All CA Certificate Via Redfishtool
[Documentation] Delete all CA certificate via Redfish.
+ [Arguments] ${delete_cert}=${True}
${cmd_output}= Redfishtool Get /redfish/v1/Managers/${MANAGER_ID}/Truststore/Certificates
${cmd_output}= Convert String to JSON ${cmd_output}
${cert_list}= Set Variable ${cmd_output["Members"]}
+ ${uri_length}= Get Length ${cert_list}
+ ${file_status}= Set Variable If
+ ... "${uri_length}" == "0" Not Found
+ ... "${uri_length}" != "0" Found
+ ${cert_id}= Set Variable If
+ ... "${uri_length}" != "0" ${cert_list[-1]["@odata.id"].split("/")[-1].strip()}
+ ... "${uri_length}" == "0" None
+ Set Test Variable ${cert_id}
+ Set Test Variable ${file_status}
+ Return From Keyword If "${file_status}" != "Found" or "${delete_cert}" != "${True}"
FOR ${cert} IN @{cert_list}
Redfishtool Delete ${cert["@odata.id"]} ${root_cmd_args}
END
@@ -294,7 +308,7 @@
Redfishtool Delete Certificate Via BMC CLI
[Documentation] Delete certificate via BMC CLI.
- [Arguments] ${cert_type}
+ [Arguments] ${cert_type} ${delete_cert}=${True}
# Description of argument(s):
# cert_type Certificate type (e.g. "Client" or "CA").
@@ -310,7 +324,8 @@
${file_status} ${stderr} ${rc}= BMC Execute Command
... [ -f ${certificate_file_path} ] && echo "Found" || echo "Not Found"
- Return From Keyword If "${file_status}" != "Found"
+ Set Test Variable ${file_status}
+ Return From Keyword If "${file_status}" != "Found" or '${delete_cert}' != "${True}"
BMC Execute Command rm ${certificate_file_path}
BMC Execute Command systemctl restart ${certificate_service}
BMC Execute Command systemctl daemon-reload
@@ -335,10 +350,12 @@
Set To Dictionary ${kwargs} headers ${headers}
${resp}= POST On Session openbmc ${uri} &{kwargs} expected_status=any
- ${cert_id}= Set Variable If '${resp.status_code}' == '${HTTP_OK}' ${resp.json()["Id"]} -1
+ ${cert_id}= Set Variable If
+ ... '${resp.status_code}' == '${HTTP_OK}' ${resp.json()["Id"]}
+ ... '${resp.status_code}' == '${HTTP_NO_CONTENT}' ${resp.json()["Id"]} -1
Run Keyword If '${status}' == 'ok'
- ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
+ ... Should Contain Any "${resp.status_code}" ${HTTP_OK} ${HTTP_NO_CONTENT}
... ELSE IF '${status}' == 'error'
... Should Be Equal As Strings ${resp.status_code} ${HTTP_INTERNAL_SERVER_ERROR}
@@ -359,10 +376,12 @@
# request (i.e. "ok" or "error").
# Install certificate before replacing client or CA certificate.
- ${cert_id}= Run Keyword If '${cert_type}' == 'Client'
- ... Verify Redfishtool Install Certificate ${cert_type} Valid Certificate Valid Privatekey ok
+ Run Keyword If '${cert_type}' == 'Client'
+ ... Verify Redfishtool Install Certificate ${cert_type} ${cert_format} ${expected_status}
+ ... ${False} replace
... ELSE IF '${cert_type}' == 'CA'
- ... Verify Redfishtool Install Certificate ${cert_type} Valid Certificate ok
+ ... Verify Redfishtool Install Certificate ${cert_type} ${cert_format} ${expected_status}
+ ... ${False} replace
${cert_file_path}= Generate Certificate File Via Openssl ${cert_format}
${bytes}= OperatingSystem.Get Binary File ${cert_file_path}
@@ -380,8 +399,9 @@
${string}= Replace String ${string} ' "
${payload}= Set Variable '${string}'
- ${expected_resp}= Set Variable If '${expected_status}' == 'ok' ${HTTP_OK}
- ... '${expected_status}' == 'error' ${HTTP_NOT_FOUND},${HTTP_INTERNAL_SERVER_ERROR}
+ ${expected_resp}= Set Variable If
+ ... '${expected_status}' == 'ok' ${HTTP_OK}, ${HTTP_NO_CONTENT}
+ ... '${expected_status}' == 'error' ${HTTP_BAD_REQUEST}
${response}= Redfishtool Post
... ${payload} /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate