Compare SHA1SUM Strings using Split String

Hi all,

i have made some “ugly” code any maybe you can help me to made it “nice”.
So my use case is that i have to download an image from a server to client-1 and then copy this file from my client-1 to another client-2.
The download from my server is done using “jfrog-cli” a tool which use checksums so i know that the download from server → client-1 is fine.
Now i use SSHLibrary to copy this file from client-1 to client-2 by “Put File…” and because my image is ~4GB i need to be sure the copying went fine.

For this i just do a sha1sum to the image on client-1 - then copy the file over to client-2 and use sha1sum via Execute Command on client-2. Then i just compare the sha1 sum’s using “Should be Equal as Strings”.

btw: sha1 is totaly sufficent for my needs - i could also use MD5 - i just want to know that during the 4GB copying nothing went bad.

This is my code:

${image_on_client-1}=    Run Process    sha1sum ${PATH_ON_HOST}${image_file}    
${image_on_client-2}=    Remote Execute Command    sha1sum 

${foo}=    Split String    ${image_on_client-1.stdout}
${bar}=    Split String    ${image_on_client-2}[0]

Should Be Equal As Strings    ${foo}[0]  ${bar}[0]

So this is working fine using the Split String. But is it possible to have the “Split String” somehow embedded to the “Should Be Equal as String” keyword?
E.g. like this

Should Be Equals As Strings (Split String ${image_on_client-1.stdout} Split String ${image_on_client-2}[0])

You should know that if you execute “sha1sum” the stdout will have the sha1sum (which i’m intrested in) and the full path of the image file seperated by a space. That’s why “Split String” will give me a list of 2 values (value [0] with the sha value i want, and value [1] with the full path i don’t care about)

Any help is welcome.


Do not wonder about “Remote Execute Command” i made this keyword as an extension to “Execute Command” and put it as a Resource - the code is here:

Remote Execute Command
Set Log Level    DEBUG
[Arguments]    ${command}    ${return_val}=${LIST_OF_RC}
${return_val} =    Create List    @{return_val}
${stdout}    ${stderr}    ${rc}=    Execute Command    ${command}    return_stdout=True    
return_stderr=True    return_rc=True
${rc_as_String}=    Convert To String    ${rc}
List Should Contain Value   ${return_val}   ${rc_as_String}
[Return]    ${stdout}    ${rc_as_String}


just found a solution without Split String.
I can just extend my sha1sum command by adding a pipe with a “cut” to only get the sha1 value i want to be in the stdout - so then i dont need to split it using rf :slight_smile:

So that’s how i do it

${image_client-1}=    Run Process    sha1sum ${PATH_ON_HOST}${image_file} | cut -d " " -f 1   shell=True
${image_client-2}=    Remote Execute Command    sha1sum ${PATH_ON_TARGET}${image_file} | cut -d " " -f 1
Log    ${client-1.stdout}
Log    ${client-2}[0]    
Should Be Equal As Strings    ${image_client-1.stdout}    ${image_client-2}[0]

This is a much better solution - linux will do the cut for me :wink:

and to even made it more readable i set the put command as variable so now it looks like this:

${cut_command}=    Set Variable    cut -d " " -f 1    # get only sha value from sha1sum command

${image_client-1}=    Run Process    sha1sum ${PATH_ON_HOST}${image_file} | ${cut_command}   shell=True
${image_client-2}=    Remote Execute Command    sha1sum ${PATH_ON_TARGET}${image_file} | ${cut_command}
Should Be Equal As Strings    ${image_client-1.stdout}    ${image_client-2}[0]

Hi Camil,

Great you found your solution, but you did say

maybe you can help me to made it “nice”

What I might suggest is to create a couple of keywords something like Sha1 Local File and Sha1 SSH Remote File

Have these keywords take the file path as in argument and have it return the sha1sum string, do the cut/split string nicely wrapped up inside the keywords then your test case could become:

${image_client-1}=    Sha1 Local File    ${PATH_ON_HOST}${image_file}
${image_client-2}=    Sha1 SSH Remote File   ${PATH_ON_TARGET}${image_file}
Should Be Equal As Strings    ${image_client-1}    ${image_client-2}

Nice and easy to read :+1:

Keywords would probably look something like this:

Sha1 Local File
    [Arguments]    ${localfilepath}
    ${sha}=    Run Process    sha1sum ${localfilepath} | cut -d " " -f 1   shell=True
    RETURN    ${sha.stdout}

Sha1 SSH Remote File
    [Arguments]    ${remotefilepath}
    ${sha}=    Remote Execute Command    sha1sum ${remotefilepath} | cut -d " " -f 1
    RETURN    ${sha}[0]

Then in the future if you need to do other files in other test cases, you can reuse these keywords

Hopefully that helps you make it “nice” and easy for others in your team to read the test case :crossed_fingers:


1 Like