Merge pull request #9239 from danfengliu/project-metadata-verification-in-upgrade-verify-script

Add project meta data verifcation In nightly migrate pipeline
This commit is contained in:
Wang Yan 2019-10-11 14:05:33 +08:00 committed by GitHub
commit 454a427806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 33 deletions

View File

@ -61,6 +61,10 @@ Switch To Replication
Retry Element Click xpath=${project_replication_xpath} Retry Element Click xpath=${project_replication_xpath}
Sleep 1 Sleep 1
Switch To Project Configuration
Retry Element Click ${project_config_tabsheet}
Sleep 1
Navigate To Projects Navigate To Projects
Retry Element Click xpath=${projects_xpath} Retry Element Click xpath=${projects_xpath}
Sleep 2 Sleep 2
@ -82,7 +86,7 @@ Search Private Projects
Make Project Private Make Project Private
[Arguments] ${projectname} [Arguments] ${projectname}
Go Into Project ${project name} Go Into Project ${project name}
Retry Element Click ${project_config_tabsheet} Switch To Project Configuration
Retry Checkbox Should Be Selected ${project_config_public_checkbox} Retry Checkbox Should Be Selected ${project_config_public_checkbox}
Retry Double Keywords When Error Retry Element Click ${project_config_public_checkbox_label} Retry Checkbox Should Not Be Selected ${project_config_public_checkbox} Retry Double Keywords When Error Retry Element Click ${project_config_public_checkbox_label} Retry Checkbox Should Not Be Selected ${project_config_public_checkbox}
Retry Element Click //button[contains(.,'SAVE')] Retry Element Click //button[contains(.,'SAVE')]
@ -91,7 +95,7 @@ Make Project Private
Make Project Public Make Project Public
[Arguments] ${projectname} [Arguments] ${projectname}
Go Into Project ${project name} Go Into Project ${project name}
Retry Element Click ${project_config_tabsheet} Switch To Project Configuration
Retry Checkbox Should Not Be Selected ${project_config_public_checkbox} Retry Checkbox Should Not Be Selected ${project_config_public_checkbox}
Retry Double Keywords When Error Retry Element Click ${project_config_public_checkbox_label} Retry Checkbox Should Be Selected ${project_config_public_checkbox} Retry Double Keywords When Error Retry Element Click ${project_config_public_checkbox_label} Retry Checkbox Should Be Selected ${project_config_public_checkbox}
Retry Element Click //button[contains(.,'SAVE')] Retry Element Click //button[contains(.,'SAVE')]

View File

@ -50,6 +50,10 @@ ${tag_images_btn} xpath=//hbr-repository//button[contains(.,'Images')]
${project_member_action_xpath} xpath=//*[@id='member-action'] ${project_member_action_xpath} xpath=//*[@id='member-action']
${project_member_set_role_xpath} xpath=//clr-dropdown-menu//label[contains(.,'SET ROLE')] ${project_member_set_role_xpath} xpath=//clr-dropdown-menu//label[contains(.,'SET ROLE')]
${project_config_public_checkbox} xpath=//input[@name='public'] ${project_config_public_checkbox} xpath=//input[@name='public']
${project_config_content_trust_checkbox} xpath=//input[@name='content-trust']
${project_config_scan_images_on_push_checkbox} xpath=//input[@name='scan-image-on-push']
${project_config_prevent_vulnerable_images_from_running_checkbox} xpath=//input[@name='prevent-vulenrability-image-input']
${project_config_severity_select} xpath=//select[@id='severity']
${project_config_public_checkbox_label} xpath=//*[@id="clr-wrapper-public"]/div/clr-checkbox-wrapper/label ${project_config_public_checkbox_label} xpath=//*[@id="clr-wrapper-public"]/div/clr-checkbox-wrapper/label
${project_config_prevent_vulenrability_checkbox_label} xpath=//*[@id='prevent-vulenrability-image']//clr-checkbox-wrapper//label ${project_config_prevent_vulenrability_checkbox_label} xpath=//*[@id='prevent-vulenrability-image']//clr-checkbox-wrapper//label
${project_config_system_wl_radio_input} xpath=//clr-radio-wrapper//label[contains(.,'System whitelist')] ${project_config_system_wl_radio_input} xpath=//clr-radio-wrapper//label[contains(.,'System whitelist')]

View File

@ -27,8 +27,7 @@ Verify Project
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
:FOR ${project} IN @{project} :FOR ${project} IN @{project}
\ Page Should Contain ${project} \ Page Should Contain ${project}
#TO_DO: Verify Project Metadata ${json}
#Verify project metadata.
Close Browser Close Browser
Verify Image Tag Verify Image Tag
@ -40,11 +39,38 @@ Verify Image Tag
\ @{out_has_image}= Get Value From Json ${json} $.projects[?(@.name=${project})].has_image \ @{out_has_image}= Get Value From Json ${json} $.projects[?(@.name=${project})].has_image
\ ${has_image} Set Variable If @{out_has_image}[0] == ${true} ${true} ${false} \ ${has_image} Set Variable If @{out_has_image}[0] == ${true} ${true} ${false}
\ Go Into Project ${project} has_image=${has_image} \ Go Into Project ${project} has_image=${has_image}
\ @{repo}= Get Value From Json ${json} $.projects[?(@name=${project})]..repo..name \ @{repo}= Get Value From Json ${json} $.projects[?(@.name=${project})]..repo..name
\ Loop Image Repo @{repo} \ Run Keyword If ${has_image} == ${true} Loop Image Repo @{repo}
\ Navigate To Projects \ Navigate To Projects
Close Browser Close Browser
Verify Project Metadata
[Arguments] ${json}
@{project}= Get Value From Json ${json} $.projects.[*].name
Init Chrome Driver
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
:FOR ${project} IN @{project}
\ @{out_has_image}= Get Value From Json ${json} $.projects[?(@.name=${project})].has_image
\ ${has_image} Set Variable If @{out_has_image}[0] == ${true} ${true} ${false}
\ Go Into Project ${project} has_image=${has_image}
\ Switch To Project Configuration
\ Verify Checkbox ${json} $.projects[?(@.name=${project})].configuration.public ${project_config_public_checkbox}
\ Verify Checkbox ${json} $.projects[?(@.name=${project})].configuration.enable_content_trust ${project_config_content_trust_checkbox}
\ Verify Checkbox ${json} $.projects[?(@.name=${project})].configuration.automatically_scan_images_on_push ${project_config_scan_images_on_push_checkbox}
\ Verify Checkbox ${json} $.projects[?(@.name=${project})].configuration.prevent_vulnerable_images_from_running ${project_config_prevent_vulnerable_images_from_running_checkbox}
\ ${ret} Get Selected List Value ${project_config_severity_select}
\ @{severity}= Get Value From Json ${json} $.projects[?(@.name=${project})].configuration.prevent_vlunerable_images_from_running_severity
\ Should Contain ${ret} @{severity}[0]
\ Navigate To Projects
Close Browser
Verify Checkbox
[Arguments] ${json} ${key} ${checkbox}
@{out}= Get Value From Json ${json} ${key}
Run Keyword If '@{out}[0]'=='true' Checkbox Should Be Selected ${checkbox}
... ELSE Checkbox Should Not Be Selected ${checkbox}
Loop Image Repo Loop Image Repo
[Arguments] @{repo} [Arguments] @{repo}
:For ${repo} In @{repo} :For ${repo} In @{repo}
@ -60,7 +86,7 @@ Verify Member Exist
\ ${has_image} Set Variable If @{out_has_image}[0] == ${true} ${true} ${false} \ ${has_image} Set Variable If @{out_has_image}[0] == ${true} ${true} ${false}
\ Go Into Project ${project} has_image=${has_image} \ Go Into Project ${project} has_image=${has_image}
\ Switch To Member \ Switch To Member
\ @{members}= Get Value From Json ${json} $.projects[?(@name=${project})].member..name \ @{members}= Get Value From Json ${json} $.projects[?(@.name=${project})].member..name
\ Loop Member @{members} \ Loop Member @{members}
\ Navigate To Projects \ Navigate To Projects
Close Browser Close Browser
@ -76,10 +102,10 @@ Verify User System Admin Role
Init Chrome Driver Init Chrome Driver
:FOR ${user} IN @{user} :FOR ${user} IN @{user}
\ Sign In Harbor ${HARBOR_URL} ${user} ${HARBOR_PASSWORD} \ Sign In Harbor ${HARBOR_URL} ${user} ${HARBOR_PASSWORD}
\ Page Should Contain Administration \ Page Should Contain Administration
\ Logout Harbor \ Logout Harbor
Close Browser Close Browser
Verify System Label Verify System Label
[Arguments] ${json} [Arguments] ${json}
@{label}= Get Value From Json ${json} $..syslabel..name @{label}= Get Value From Json ${json} $..syslabel..name
@ -106,7 +132,7 @@ Verify Project Label
\ \ Page Should Contain ${projectlabel} \ \ Page Should Contain ${projectlabel}
\ Navigate To Projects \ Navigate To Projects
Close Browser Close Browser
Verify Endpoint Verify Endpoint
[Arguments] ${json} [Arguments] ${json}
@{endpoint}= Get Value From Json ${json} $.endpoint..name @{endpoint}= Get Value From Json ${json} $.endpoint..name
@ -135,7 +161,7 @@ Verify Project Setting
\ ${contenttrust}= Get Value From Json ${json} $.projects[?(@.name=${project})]..enable_content_trust \ ${contenttrust}= Get Value From Json ${json} $.projects[?(@.name=${project})]..enable_content_trust
\ ${preventrunning}= Get Value From Json ${json} $.projects[?(@.name=${project})]..prevent_vulnerable_images_from_running \ ${preventrunning}= Get Value From Json ${json} $.projects[?(@.name=${project})]..prevent_vulnerable_images_from_running
\ ${scanonpush}= Get Value From Json ${json} $.projects[?(@.name=${project})]..automatically_scan_images_on_push \ ${scanonpush}= Get Value From Json ${json} $.projects[?(@.name=${project})]..automatically_scan_images_on_push
\ Init Chrome Driver \ Init Chrome Driver
\ Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} \ Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
\ @{out_has_image}= Get Value From Json ${json} $.projects[?(@.name=${project})].has_image \ @{out_has_image}= Get Value From Json ${json} $.projects[?(@.name=${project})].has_image
\ ${has_image} Set Variable If @{out_has_image}[0] == ${true} ${true} ${false} \ ${has_image} Set Variable If @{out_has_image}[0] == ${true} ${true} ${false}

View File

@ -99,12 +99,12 @@
{ {
"name":"busybox", "name":"busybox",
"tag":"latest", "tag":"latest",
"signed":"False" "signed":"false"
}, },
{ {
"name":"alpine", "name":"alpine",
"tag":"latest", "tag":"latest",
"signed":"True" "signed":"true"
} }
], ],
"member":[ "member":[
@ -144,10 +144,11 @@
} }
], ],
"configuration":{ "configuration":{
"public":"true",
"enable_content_trust":"true", "enable_content_trust":"true",
"automatically_scan_images_on_push":"true", "automatically_scan_images_on_push":"true",
"prevent_vulnerable_images_from_running":"true", "prevent_vulnerable_images_from_running":"true",
"prevent_vlunerable_images_from_running_severity":"High" "prevent_vlunerable_images_from_running_severity":"high"
} }
}, },
{ {
@ -159,12 +160,12 @@
{ {
"name":"busybox", "name":"busybox",
"tag":"latest", "tag":"latest",
"signed":"False" "signed":"false"
}, },
{ {
"name":"alpine", "name":"alpine",
"tag":"latest", "tag":"latest",
"signed":"True" "signed":"true"
} }
], ],
"member":[ "member":[
@ -204,10 +205,11 @@
} }
], ],
"configuration":{ "configuration":{
"enable_content_trust":"True", "public":"false",
"automatically_scan_images_on_push":"True", "enable_content_trust":"false",
"prevent_vulnerable_images_from_running":"True", "automatically_scan_images_on_push":"false",
"prevent_vlunerable_images_from_running_severity":"High" "prevent_vulnerable_images_from_running":"true",
"prevent_vlunerable_images_from_running_severity":"medium"
} }
} }
] ]

View File

@ -68,13 +68,13 @@ class HarborAPI:
body=dict(body=payload) body=dict(body=payload)
request(url+"replication/policies", 'post', **body) request(url+"replication/policies", 'post', **body)
def update_project_setting(self, project, contenttrust, preventrunning, preventseverity, scanonpush): def update_project_setting(self, project, public, contenttrust, preventrunning, preventseverity, scanonpush):
r = request(url+"projects?name="+project+"", 'get') r = request(url+"projects?name="+project+"", 'get')
projectid = str(r.json()[0]['project_id']) projectid = str(r.json()[0]['project_id'])
payload = { payload = {
"project_name": ""+project+"", "project_name": ""+project+"",
"metadata": { "metadata": {
"public": "True", "public": public,
"enable_content_trust": contenttrust, "enable_content_trust": contenttrust,
"prevent_vulnerable_images_from_running": preventrunning, "prevent_vulnerable_images_from_running": preventrunning,
"prevent_vulnerable_images_from_running_severity": preventseverity, "prevent_vulnerable_images_from_running_severity": preventseverity,
@ -188,6 +188,7 @@ def do_data_creation():
replicationrule["rulename"]) replicationrule["rulename"])
for project in data["projects"]: for project in data["projects"]:
harborAPI.update_project_setting(project["name"], harborAPI.update_project_setting(project["name"],
project["configuration"]["public"],
project["configuration"]["enable_content_trust"], project["configuration"]["enable_content_trust"],
project["configuration"]["prevent_vulnerable_images_from_running"], project["configuration"]["prevent_vulnerable_images_from_running"],
project["configuration"]["prevent_vlunerable_images_from_running_severity"], project["configuration"]["prevent_vlunerable_images_from_running_severity"],

View File

@ -58,19 +58,29 @@ class HarborAPI:
body=dict(body=payload) body=dict(body=payload)
request(url+"policies/replication", 'post', **body) request(url+"policies/replication", 'post', **body)
def update_project_setting(self, project, contenttrust, preventrunning, preventseverity, scanonpush): def update_project_setting(self, project, public, contenttrust, preventrunning, preventseverity, scanonpush):
r = request(url+"projects?name="+project+"", 'get') r = request(url+"projects?name="+project+"", 'get')
projectid = str(r.json()[0]['project_id']) projectid = str(r.json()[0]['project_id'])
payload = { if args.version == "1.6":
"project_name": ""+project+"", payload = {
"metadata": { "metadata": {
"public": "True", "public": public,
"enable_content_trust": contenttrust, "enable_content_trust": contenttrust,
"prevent_vulnerable_images_from_running": preventrunning, "prevent_vulnerable_images_from_running": preventrunning,
"prevent_vulnerable_images_from_running_severity": preventseverity, "prevent_vulnerable_images_from_running_severity": preventseverity,
"automatically_scan_images_on_push": scanonpush "automatically_scan_images_on_push": scanonpush
}
}
else:
payload = {
"metadata": {
"public": public,
"enable_content_trust": contenttrust,
"prevent_vul": preventrunning,
"severity": preventseverity,
"auto_scan": scanonpush
}
} }
}
body=dict(body=payload) body=dict(body=payload)
request(url+"projects/"+projectid+"", 'put', **body) request(url+"projects/"+projectid+"", 'put', **body)
@ -178,9 +188,10 @@ def do_data_creation():
replicationrule["rulename"]) replicationrule["rulename"])
for project in data["projects"]: for project in data["projects"]:
harborAPI.update_project_setting(project["name"], harborAPI.update_project_setting(project["name"],
project["configuration"]["public"],
project["configuration"]["enable_content_trust"], project["configuration"]["enable_content_trust"],
project["configuration"]["prevent_vulnerable_images_from_running"], project["configuration"]["prevent_vulnerable_images_from_running"],
project["configuration"]["prevent_vlunerable_images_from_running_severity"], project["configuration"]["prevent_vlunerable_images_from_running_severity"],
project["configuration"]["automatically_scan_images_on_push"]) project["configuration"]["automatically_scan_images_on_push"])
harborAPI.update_systemsetting(data["configuration"]["emailsetting"]["emailfrom"], harborAPI.update_systemsetting(data["configuration"]["emailsetting"]["emailfrom"],
data["configuration"]["emailsetting"]["emailserver"], data["configuration"]["emailsetting"]["emailserver"],