From d10dfc816735fad2b20bd230b558e18df407d276 Mon Sep 17 00:00:00 2001 From: danfengliu Date: Thu, 30 Apr 2020 05:42:21 +0800 Subject: [PATCH] Fix issue of GC untag images case Signed-off-by: danfengliu --- .../Harbor-Pages/Configuration.robot | 7 -- tests/resources/Harbor-Pages/GC.robot | 21 +++++- .../Harbor-Pages/Project-Members.robot | 7 +- tests/resources/Util.robot | 8 +-- tests/robot-cases/Group1-Nightly/Common.robot | 72 +------------------ .../Group1-Nightly/Common_GC.robot | 58 +++++++++++++-- tests/robot-cases/Group1-Nightly/DB.robot | 19 +++++ 7 files changed, 98 insertions(+), 94 deletions(-) diff --git a/tests/resources/Harbor-Pages/Configuration.robot b/tests/resources/Harbor-Pages/Configuration.robot index 1a3266f4a..9f6c6e53a 100644 --- a/tests/resources/Harbor-Pages/Configuration.robot +++ b/tests/resources/Harbor-Pages/Configuration.robot @@ -304,13 +304,6 @@ Click GC Now Retry Element Click xpath=${gc_now_xpath} Sleep 2 -Click GC Now With Param Delete Untagged Artifacts - Sleep 1 - Retry Element Click xpath=${checkbox_delete_untagged_artifacts} - Sleep 1 - Retry Element Click xpath=${gc_now_xpath} - Sleep 5 - View GC Details Retry Element Click xpath=${gc_log_details_xpath} Sleep 2 diff --git a/tests/resources/Harbor-Pages/GC.robot b/tests/resources/Harbor-Pages/GC.robot index 37d54aea8..ea74beb2a 100644 --- a/tests/resources/Harbor-Pages/GC.robot +++ b/tests/resources/Harbor-Pages/GC.robot @@ -20,13 +20,28 @@ Resource ../../resources/Util.robot *** Keywords *** GC Now - [Arguments] ${harbor_url} ${login_user} ${login_pwd} + [Arguments] ${harbor_url} ${login_user} ${login_pwd} ${untag}=${false} Switch To Garbage Collection + Capture Page Screenshot + Run Keyword If '${untag}' == '${true}' Retry Element Click xpath=${checkbox_delete_untagged_artifacts} + Capture Page Screenshot Click GC Now Logout Harbor Sleep 2 Sign In Harbor ${harbor_url} ${login_user} ${login_pwd} Switch To Garbage Collection Sleep 1 - Switch To GC History - Retry Keyword N Times When Error 60 Retry Wait Until Page Contains Finished \ No newline at end of file + #Switch To GC History + #Retry Keyword N Times When Error 60 Retry Wait Until Page Contains Finished + +Retry GC Should Be Successful + [Arguments] ${history_id} ${expected_msg} + Retry Keyword When Error GC Should Be Successful ${history_id} ${expected_msg} + +GC Should Be Successful + [Arguments] ${history_id} ${expected_msg} + ${rc} ${output}= Run And Return Rc And Output curl -u ${HARBOR_ADMIN}:${HARBOR_PASSWORD} -i --insecure -H "Content-Type: application/json" -X GET "https://${ip}/api/v2.0/system/gc/${history_id}/log" + Log To Console ${output} + Should Be Equal As Integers ${rc} 0 + Run Keyword If '${expected_msg}' != '${null}' Should Contain ${output} ${expected_msg} + Should Contain ${output} success to run gc in job. \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/Project-Members.robot b/tests/resources/Harbor-Pages/Project-Members.robot index 2cbb4cc78..4f03131bc 100644 --- a/tests/resources/Harbor-Pages/Project-Members.robot +++ b/tests/resources/Harbor-Pages/Project-Members.robot @@ -21,11 +21,12 @@ Resource ../../resources/Util.robot *** Keywords *** Go Into Project [Arguments] ${project} ${has_image}=${true} + Sleep 2 + Retry Element Click xpath=//harbor-app/harbor-shell/clr-main-container/navigator/clr-header/div[1]/a/span + Sleep 2 + Retry Text Input ${search_input} ${project} :For ${n} IN RANGE 1 5 \ Sleep 2 - \ Retry Wait Element ${search_input} - \ Retry Clear Element Text ${search_input} - \ Input Text ${search_input} ${project} \ ${out} Run Keyword If ${has_image}==${false} Retry Double Keywords When Error Retry Element Click xpath=//*[@id='project-results']//clr-dg-cell[contains(.,'${project}')]/a Wait Until Element Is Visible And Enabled xpath=//clr-dg-placeholder[contains(.,\"We couldn\'t find any repositories!\")] DoAssert=${false} \ ... ELSE Retry Double Keywords When Error Retry Element Click xpath=//*[@id='project-results']//clr-dg-cell[contains(.,'${project}')]/a Wait Until Element Is Visible And Enabled xpath=//project-detail//hbr-repository-gridview//clr-dg-cell[contains(.,'${project}/')] DoAssert=${false} \ Log To Console ${out} diff --git a/tests/resources/Util.robot b/tests/resources/Util.robot index 9d27a42f8..cd64b37d6 100644 --- a/tests/resources/Util.robot +++ b/tests/resources/Util.robot @@ -228,13 +228,13 @@ Command Should be Failed Retry Keyword When Error [Arguments] ${keyword} @{elements} - :For ${n} IN RANGE 1 3 + :For ${n} IN RANGE 1 10 \ Log To Console Trying ${keyword} elements @{elements} ${n} times ... \ ${out} Run Keyword And Ignore Error ${keyword} @{elements} \ Log To Console Return value is ${out} and ${out[0]} \ Run Keyword If '${keyword}'=='Make Swagger Client' Exit For Loop If '${out[0]}'=='PASS' and '${out[1]}'=='0' \ ... ELSE Exit For Loop If '${out[0]}'=='PASS' - \ Sleep 2 + \ Sleep 10 Run Keyword If '${out[0]}'=='FAIL' Capture Page Screenshot Should Be Equal As Strings '${out[0]}' 'PASS' [Return] ${out[1]} @@ -265,8 +265,8 @@ Retry Keyword When Return Value Mismatch Should Be Equal As Strings ${status} 'PASS' Retry Double Keywords When Error - [Arguments] ${keyword1} ${element1} ${keyword2} ${element2} ${DoAssert}=${true} - :For ${n} IN RANGE 1 3 + [Arguments] ${keyword1} ${element1} ${keyword2} ${element2} ${DoAssert}=${true} ${times}=3 + :For ${n} IN RANGE 1 ${times} \ Log To Console Trying ${keyword1} and ${keyword2} ${n} times ... \ ${out1} Run Keyword And Ignore Error ${keyword1} ${element1} \ Capture Page Screenshot diff --git a/tests/robot-cases/Group1-Nightly/Common.robot b/tests/robot-cases/Group1-Nightly/Common.robot index 801b4ce42..f261f876f 100644 --- a/tests/robot-cases/Group1-Nightly/Common.robot +++ b/tests/robot-cases/Group1-Nightly/Common.robot @@ -444,26 +444,6 @@ Test Case - Create An New Project With Quotas Set Should Be Equal As Strings ${storage_quota_ret} 0Byte of ${storage_quota}${storage_quota_unit} Close Browser -# Make sure image logstash was pushed to harbor for the 1st time, so GC will delete it. -Test Case - Project Quotas Control Under GC - Init Chrome Driver - ${d}= Get Current Date result_format=%m%s - ${storage_quota}= Set Variable 200 - ${storage_quota_unit}= Set Variable MB - ${image_a}= Set Variable logstash - ${image_a_size}= Set Variable 321.03MB - ${image_a_ver}= Set Variable 6.8.3 - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Capture Page Screenshot - Create An New Project project${d} storage_quota=${storage_quota} storage_quota_unit=${storage_quota_unit} - Capture Page Screenshot - Cannot Push image ${ip} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} project${d} ${image_a}:${image_a_ver} err_msg=will exceed the configured upper limit of 200.0 MiB - Capture Page Screenshot - GC Now ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - @{param} Create List project${d} - Retry Keyword When Return Value Mismatch Get Project Storage Quota Text From Project Quotas List 0Byte of ${storage_quota}${storage_quota_unit} 60 @{param} - Close Browser - Test Case - Project Storage Quotas Dispaly And Control Init Chrome Driver ${d}= Get Current Date result_format=%m%s @@ -558,37 +538,6 @@ Test Case - Tag CRUD Should Not Contain Tag latest Close Browser -Test Case - GC Untagged Images - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - ${d}= Get Current Date result_format=%m%s - Create An New Project project${d} - Push Image With Tag ${ip} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} project${d} hello-world latest - # make hello-world untagged - Go Into Project project${d} - Go Into Repo hello-world - Go Into Artifact latest - Should Contain Tag latest - Delete A Tag latest - Should Not Contain Tag latest - # run gc without param delete untagged artifacts checked, should not delete hello-world:latest - Switch To Garbage Collection - Click GC Now - Go Into Project project${d} - Switch To Project Repo - Go Into Repo hello-world - Should Contain Artifact - # run gc with param delete untagged artifacts checked, should delete hello-world - Switch To Garbage Collection - Click GC Now With Param Delete Untagged Artifacts - Go Into Project project${d} - Switch To Project Repo - Go Into Repo hello-world - Should Not Contain Any Artifact - Close Browser - - - Test Case - Tag Retention Init Chrome Driver Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} @@ -627,7 +576,6 @@ Test Case - Tag Immutability Delete Success busybox Close Browser - Test Case - Robot Account Init Chrome Driver ${d}= Get Current Date result_format=%m%s @@ -756,22 +704,4 @@ Test Case - Read Only Mode Sleep 5 Push image ${ip} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} project${d} busybox:latest Close Browser -Test Case - Admin Add New Users - [Tags] non-uaa - Init Chrome Driver - ${d}= Get Current Date result_format=%m%s - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - # can add a new user when self-reg is enbled - Switch To Configure - Self Reg Should Be Enabled - Switch to User Tag - Add A New User username=tester${d} email=tester${d}@vmware.com realname=harbortest newPassword=Test1@34 comment=harbortest - # can add a new user when self-reg is disabled - Switch To Configure - Self Reg Should Be Enabled - Sleep 1 - Disable Self Reg - Self Reg Should Be Disabled - Switch to User Tag - Add A New User username=tester2${d} email=tester2${d}@vmware.com realname=harbortest2 newPassword=Test1@34 comment=harbortest2 - Close Browser + diff --git a/tests/robot-cases/Group1-Nightly/Common_GC.robot b/tests/robot-cases/Group1-Nightly/Common_GC.robot index ae9bd0607..abece76b8 100644 --- a/tests/robot-cases/Group1-Nightly/Common_GC.robot +++ b/tests/robot-cases/Group1-Nightly/Common_GC.robot @@ -34,12 +34,58 @@ Test Case - Garbage Collection Sleep 2 Go Into Project project${d} Delete Repo project${d} + Sleep 2 GC Now ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - ${rc} ${output}= Run And Return Rc And Output curl -u ${HARBOR_ADMIN}:${HARBOR_PASSWORD} -i --insecure -H "Content-Type: application/json" -X GET "https://${ip}/api/v2.0/system/gc/1/log" - Log To Console ${output} - Should Be Equal As Integers ${rc} 0 - #TODO: Need to find a reliable way to clear external storage, then this statistc will be accurate. - #Should Contain ${output} 0 blobs marked, 3 blobs and 0 manifests eligible for deletion - Should Contain ${output} success to run gc in job. + Retry GC Should Be Successful 1 0 blobs marked, 3 blobs and 0 manifests eligible for deletion + Close Browser +Test Case - GC Untagged Images + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + ${d}= Get Current Date result_format=%m%s + Create An New Project project${d} + Push Image With Tag ${ip} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} project${d} hello-world latest + # make hello-world untagged + Go Into Project project${d} + Go Into Repo hello-world + Go Into Artifact latest + Should Contain Tag latest + Delete A Tag latest + Should Not Contain Tag latest + # run gc without param delete untagged artifacts checked, should not delete hello-world:latest + GC Now ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Retry GC Should Be Successful 2 ${null} + Go Into Project project${d} + Switch To Project Repo + Go Into Repo hello-world + Should Contain Artifact + # run gc with param delete untagged artifacts checked, should delete hello-world + Switch To Garbage Collection + GC Now ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} untag=${true} + Retry GC Should Be Successful 3 ${null} + Go Into Project project${d} + Switch To Project Repo + Go Into Repo hello-world + Should Not Contain Any Artifact + Close Browser + +# Make sure image logstash was pushed to harbor for the 1st time, so GC will delete it. +Test Case - Project Quotas Control Under GC + Init Chrome Driver + ${d}= Get Current Date result_format=%m%s + ${storage_quota}= Set Variable 200 + ${storage_quota_unit}= Set Variable MB + ${image_a}= Set Variable logstash + ${image_a_size}= Set Variable 321.03MB + ${image_a_ver}= Set Variable 6.8.3 + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Capture Page Screenshot + Create An New Project project${d} storage_quota=${storage_quota} storage_quota_unit=${storage_quota_unit} + Capture Page Screenshot + Cannot Push image ${ip} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} project${d} ${image_a}:${image_a_ver} err_msg=will exceed the configured upper limit of 200.0 MiB + Capture Page Screenshot + GC Now ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Retry GC Should Be Successful 4 ${null} + @{param} Create List project${d} + Retry Keyword When Return Value Mismatch Get Project Storage Quota Text From Project Quotas List 0Byte of ${storage_quota}${storage_quota_unit} 60 @{param} Close Browser \ No newline at end of file diff --git a/tests/robot-cases/Group1-Nightly/DB.robot b/tests/robot-cases/Group1-Nightly/DB.robot index 0ce6d0d1e..b58b79017 100644 --- a/tests/robot-cases/Group1-Nightly/DB.robot +++ b/tests/robot-cases/Group1-Nightly/DB.robot @@ -86,3 +86,22 @@ Test Case - Edit Self-Registration # Restore setting Enable Self Reg Close Browser + +Test Case - Admin Add New Users + Init Chrome Driver + ${d}= Get Current Date result_format=%m%s + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + # can add a new user when self-reg is enbled + Switch To Configure + Self Reg Should Be Enabled + Switch to User Tag + Add A New User username=tester${d} email=tester${d}@vmware.com realname=harbortest newPassword=Test1@34 comment=harbortest + # can add a new user when self-reg is disabled + Switch To Configure + Self Reg Should Be Enabled + Sleep 1 + Disable Self Reg + Self Reg Should Be Disabled + Switch to User Tag + Add A New User username=tester2${d} email=tester2${d}@vmware.com realname=harbortest2 newPassword=Test1@34 comment=harbortest2 + Close Browser \ No newline at end of file