Added automation testcase to verify type of user initiated BMC dump

Changes:
    -  Added an automation test case to verify type of user initiated BMC dump.

Tested:
    -  Ran ‘Verify User Initiated BMC Dump Type’ from sandbox successfully.

Change-Id: I4df7ef604c2e7b5417c782b42c39b3b126c216ae
Signed-off-by: manashsarma <manashsarma@in.ibm.com>
diff --git a/redfish/managers/test_bmc_dumps.robot b/redfish/managers/test_bmc_dumps.robot
index e25e314..7d1989c 100644
--- a/redfish/managers/test_bmc_dumps.robot
+++ b/redfish/managers/test_bmc_dumps.robot
@@ -456,8 +456,74 @@
     Should Be Equal As Integers  ${length}  ${1}
 
 
+Verify User Initiated BMC Dump Type
+    [Documentation]  Download user initiate BMC dump and validates its type.
+    [Tags]  Verify_User_Initiated_BMC_Dump_Type
+
+    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
+
+    # Download BMC dump and verify its size.
+    ${resp}=  Redfish.Get  /redfish/v1/Managers/bmc/LogServices/Dump/Entries/${dump_id}
+    ${redfish_bmc_dump_size}=  Set Variable  ${resp.dict["AdditionalDataSizeBytes"]}
+    ${redfish_dump_creation_timestamp}=  Set Variable  ${resp.dict["Created"]}
+
+    Initialize OpenBMC
+    ${headers}=  Create Dictionary  Content-Type=application/octet-stream  X-Auth-Token=${XAUTH_TOKEN}
+
+    ${ret}=  Get Request  openbmc  /redfish/v1/Managers/bmc/LogServices/Dump/Entries/${dump_id}/attachment  headers=${headers}
+
+    Should Be Equal As Numbers  ${ret.status_code}  200
+
+    Create Binary File  BMC_dump.tar.gz  ${ret.content}
+    ${downloaded_dump_size}=  Get File Size  BMC_dump.tar.gz
+    Should Be Equal  ${downloaded_dump_size}  ${redfish_bmc_dump_size}
+
+    # Extract dump and verify type of dump from summary.log content:
+    # Wed Aug 30 17:23:29 UTC 2023 Name:          BMCDUMP.XXXXXXX.0001005.20230830172329
+    # Wed Aug 30 17:23:29 UTC 2023 Epochtime:     1693416209
+    # Wed Aug 30 17:23:29 UTC 2023 ID:            0001005
+    # Wed Aug 30 17:23:29 UTC 2023 Type:          user
+    ${extracted_dump_folder}=  Extract BMC Dump  BMC_dump.tar.gz  ${redfish_dump_creation_timestamp}
+    ${contents}=  OperatingSystem.Get File  ${extracted_dump_folder}/summary.log
+    Should Match Regexp  ${contents}  Type:[ ]*user
+
+    # Clean extracted dump files.
+    Remove Files  output  output.zst
+    Remove Directory  ${extracted_dump_folder}  True
+
+
 *** Keywords ***
 
+Extract BMC Dump
+    [Documentation]  Extract BMC dump from the tar file and returns the name of
+    ...  extracted folder like BMCDUMP.XXXXXXX.0000070.20230706063841.
+    [Arguments]  ${filename}   ${bmc_dump_timestamp}
+
+    # Description of argument(s):
+    # filename                name of BMC dump tar file.
+    # bmc_dump_timestamp      timestamp of generated BMC dump.
+
+    File Should Exist  ${filename}
+    ${rc}=  Run And Return RC  dd if=${filename} of=output.zst bs=1 skip=628
+    Should Be True  0 == ${rc}
+
+    ${rc}=  Run And Return RC  zstd -d output.zst
+    Should Be True  0 == ${rc}
+
+    ${rc}=  Run And Return RC  tar -xvf output
+    Should Be True  0 == ${rc}
+
+    # Find the extracted dump folder identified with BMCDUMP as prefix and
+    # timestamp of dump generation where timestamp format is : 2023-09-27T08:30:17.000000+00:00.
+    ${var}=  Fetch From Left  ${bmc_dump_timestamp}  .
+    ${var}=  Remove String  ${var}  -  T  :
+    ${bmc_extraction_folders}=  OperatingSystem.List Directories In Directory  .  BMCDUMP*${var}
+    ${cnt}=  Get length  ${bmc_extraction_folders}
+    should be equal as numbers  ${cnt}  1
+
+    [Return]  ${bmc_extraction_folders}[0]
+
+
 Get BMC Dump Entries
     [Documentation]  Return BMC dump ids list.