Merge pull request #12688 from danfengliu/fix-upgrade-test-wrong-keyword-issue

Fix wrong keyword issue in upgrade test
This commit is contained in:
danfengliu 2020-08-14 10:11:37 +08:00 committed by GitHub
commit e1eac2b4d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 40 deletions

View File

@ -329,6 +329,7 @@ Delete Top Item In System CVE Allowlist
Retry Element Click ${configuration_system_wl_delete_a_cve_id_icon} Retry Element Click ${configuration_system_wl_delete_a_cve_id_icon}
END END
Retry Element Click ${config_system_save_button_xpath} Retry Element Click ${config_system_save_button_xpath}
Capture Page Screenshot
Get Project Count Quota Text From Project Quotas List Get Project Count Quota Text From Project Quotas List
[Arguments] ${project_name} [Arguments] ${project_name}

View File

@ -114,16 +114,16 @@ Verify Webhook
${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 Project Webhooks Switch To Project Webhooks
@{enabled}= Get Value From Json ${json} $.projects[?(@.name=${project})].webhook.enabled ${enabled}= Get Value From Json ${json} $.projects[?(@.name=${project})].webhook.enabled
${enable_count} Get Matching Xpath Count xpath=//span[contains(.,'Enabled')] ${enable_count} Get Element Count xpath=//span[contains(.,'Enabled')]
${disable_count} Get Matching Xpath Count xpath=//span[contains(.,'Disabled')] ${disable_count} Get Element Count xpath=//span[contains(.,'Disabled')]
Log To Console '@{enabled}[0]' Log To Console '${enabled}[0]'
Log To Console '${true}' Log To Console '${true}'
Run Keyword If '@{enabled}[0]' == '${true}' Page Should Contain Enabled Run Keyword If '${enabled}[0]' == '${true}' Page Should Contain Enabled
... ELSE Page Should Contain Disabled ... ELSE Page Should Contain Disabled
@{address}= Get Value From Json ${json} $.projects[?(@.name=${project})].webhook.address ${address}= Get Value From Json ${json} $.projects[?(@.name=${project})].webhook.address
Log To Console '@{address}[0]' Log To Console '${address}[0]'
Page Should Contain @{address}[0] Page Should Contain ${address}[0]
Page Should Contain policy Page Should Contain policy
Page Should Contain http Page Should Contain http
Navigate To Projects Navigate To Projects
@ -137,20 +137,20 @@ Verify Tag Retention Rule
Init Chrome Driver Init Chrome Driver
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}
@{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}
Switch To Tag Retention Switch To Tag Retention
${actions_count}= Set Variable 8 ${actions_count}= Set Variable 8
@{repository_patten}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.repository_patten ${repository_patten}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.repository_patten
@{tag_decoration}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.tag_decoration ${tag_decoration}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.tag_decoration
@{latestPushedK}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.latestPushedK ${latestPushedK}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.latestPushedK_verify
@{cron}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.cron ${cron}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.cron
Log To Console '@{repository_patten}[0]' Log To Console '${repository_patten}[0]'
Page Should Contain @{repository_patten}[0] Page Should Contain ${repository_patten}[0]
Page Should Contain @{tag_decoration}[0] Page Should Contain ${tag_decoration}[0]
Page Should Contain @{latestPushedK}[0] Page Should Contain ${latestPushedK}[0]
Page Should Contain @{cron}[0] Page Should Contain ${cron}[0]
Navigate To Projects Navigate To Projects
END END
Close Browser Close Browser

View File

@ -254,7 +254,7 @@ Body Of Verfiy System Level CVE Allowlist
# Add Items To System CVE Allowlist CVE-2019-18276 # Add Items To System CVE Allowlist CVE-2019-18276
Add Items To System CVE Allowlist ${single_cve} Add Items To System CVE Allowlist ${single_cve}
Pull Image ${ip} ${signin_user} ${signin_pwd} project${d} ${image} tag=${sha256} Pull Image ${ip} ${signin_user} ${signin_pwd} project${d} ${image} tag=${sha256}
Delete Top Item In System CVE Allowlist count=6 Delete Top Item In System CVE Allowlist count=16
Cannot Pull Image ${ip} ${signin_user} ${signin_pwd} project${d} ${image} tag=${sha256} err_msg=cannot be pulled due to configured policy Cannot Pull Image ${ip} ${signin_user} ${signin_pwd} project${d} ${image} tag=${sha256} err_msg=cannot be pulled due to configured policy
Close Browser Close Browser

View File

@ -216,6 +216,7 @@
"repository_patten":"*photon*", "repository_patten":"*photon*",
"tag_decoration":"*v1.*", "tag_decoration":"*v1.*",
"latestPushedK":666, "latestPushedK":666,
"latestPushedK_verify":"666",
"cron":"0 0 0 1 8 0" "cron":"0 0 0 1 8 0"
}, },
"tag_immutability_rule":{ "tag_immutability_rule":{
@ -347,6 +348,7 @@
"repository_patten":"*centos*", "repository_patten":"*centos*",
"tag_decoration":"*latest", "tag_decoration":"*latest",
"latestPushedK":999, "latestPushedK":999,
"latestPushedK_verify":"999",
"cron":"0 0 0 1 6 0" "cron":"0 0 0 1 6 0"
}, },
"tag_immutability_rule":{ "tag_immutability_rule":{

View File

@ -14,7 +14,7 @@ args = parser.parse_args()
url = "https://"+args.endpoint+"/api/" url = "https://"+args.endpoint+"/api/"
endpoint_url = "https://"+args.endpoint endpoint_url = "https://"+args.endpoint
print url print(url)
with open("feature_map.json") as f: with open("feature_map.json") as f:
feature_map = json.load(f) feature_map = json.load(f)
@ -108,7 +108,7 @@ class HarborAPI:
"url":""+endpointurl+"" "url":""+endpointurl+""
} }
body=dict(body=payload) body=dict(body=payload)
print body print(body)
request(url+"/registries", 'post', **body) request(url+"/registries", 'post', **body)
else: else:
raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch)) raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch))
@ -131,8 +131,8 @@ class HarborAPI:
else: else:
registry = r'"dest_registry": { "id": '+str(targetid)+r'},' registry = r'"dest_registry": { "id": '+str(targetid)+r'},'
body=dict(body=json.loads(r'{"name":"'+replicationrule["rulename"].encode('utf-8')+r'","dest_namespace":"'+replicationrule["dest_namespace"].encode('utf-8')+r'","deletion": '+str(replicationrule["deletion"]).lower()+r',"enabled": '+str(replicationrule["enabled"]).lower()+r',"override": '+str(replicationrule["override"]).lower()+r',"description": "string",'+ registry + r'"trigger":{"type": "'+replicationrule["trigger_type"]+r'", "trigger_settings":{"cron":"'+replicationrule["cron"]+r'"}},"filters":[ {"type":"name","value":"'+replicationrule["name_filters"]+r'"},{"type":"tag","value":"'+replicationrule["tag_filters"]+r'"}]}')) body=dict(body=json.loads(r'{"name":"'+replicationrule["rulename"]+r'","dest_namespace":"'+replicationrule["dest_namespace"]+r'","deletion": '+str(replicationrule["deletion"]).lower()+r',"enabled": '+str(replicationrule["enabled"]).lower()+r',"override": '+str(replicationrule["override"]).lower()+r',"description": "string",'+ registry + r'"trigger":{"type": "'+replicationrule["trigger_type"]+r'", "trigger_settings":{"cron":"'+replicationrule["cron"]+r'"}},"filters":[ {"type":"name","value":"'+replicationrule["name_filters"]+r'"},{"type":"tag","value":"'+replicationrule["tag_filters"]+r'"}]}'))
print body print(body)
request(url+"replication/policies", 'post', **body) request(url+"replication/policies", 'post', **body)
else: else:
raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch)) raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch))
@ -151,7 +151,7 @@ class HarborAPI:
} }
} }
body=dict(body=payload) body=dict(body=payload)
print body print(body)
request(url+"projects/"+projectid+"", 'put', **body) request(url+"projects/"+projectid+"", 'put', **body)
@get_feature_branch @get_feature_branch
@ -162,7 +162,7 @@ class HarborAPI:
cve_id_str = cve_id_str + '{"cve_id":"' +cve_id["id"] + '"}' cve_id_str = cve_id_str + '{"cve_id":"' +cve_id["id"] + '"}'
if index != len(cve_id_list["cve"]) - 1: if index != len(cve_id_list["cve"]) - 1:
cve_id_str = cve_id_str + "," cve_id_str = cve_id_str + ","
body=dict(body=json.loads(r'{"items":['+cve_id_str.encode('utf-8')+r'],"expires_at":'+cve_id_list["expires_at"]+'}')) body=dict(body=json.loads(r'{"items":['+cve_id_str+r'],"expires_at":'+cve_id_list["expires_at"]+'}'))
request(url+"system/CVEWhitelist", 'put', **body) request(url+"system/CVEWhitelist", 'put', **body)
else: else:
raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch)) raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch))
@ -177,12 +177,12 @@ class HarborAPI:
cve_id_str = cve_id_str + '{"cve_id":"' +cve_id["id"] + '"}' cve_id_str = cve_id_str + '{"cve_id":"' +cve_id["id"] + '"}'
if index != len(cve_id_list["cve"]) - 1: if index != len(cve_id_list["cve"]) - 1:
cve_id_str = cve_id_str + "," cve_id_str = cve_id_str + ","
print cve_id_str print(cve_id_str)
if reuse_sys_cve_whitelist == "true": if reuse_sys_cve_whitelist == "true":
payload = r'{"metadata":{"reuse_sys_cve_whitelist":"true"}}' payload = r'{"metadata":{"reuse_sys_cve_whitelist":"true"}}'
else: else:
payload = r'{"metadata":{"reuse_sys_cve_whitelist":"false"},"cve_whitelist":{"project_id":'+projectid+',"items":['+cve_id_str.encode('utf-8')+r'],"expires_at":'+cve_id_list["expires_at"]+'}}' payload = r'{"metadata":{"reuse_sys_cve_whitelist":"false"},"cve_whitelist":{"project_id":'+projectid+',"items":['+cve_id_str+r'],"expires_at":'+cve_id_list["expires_at"]+'}}'
print payload print(payload)
body=dict(body=json.loads(payload)) body=dict(body=json.loads(payload))
request(url+"projects/"+projectid+"", 'put', **body) request(url+"projects/"+projectid+"", 'put', **body)
else: else:
@ -191,7 +191,7 @@ class HarborAPI:
@get_feature_branch @get_feature_branch
def update_interrogation_services(self, cron, **kwargs): def update_interrogation_services(self, cron, **kwargs):
payload = {"schedule":{"type":"Custom","cron": cron}} payload = {"schedule":{"type":"Custom","cron": cron}}
print payload print(payload)
body=dict(body=payload) body=dict(body=payload)
request(url+"system/scanAll/schedule", 'post', **body) request(url+"system/scanAll/schedule", 'post', **body)
@ -217,7 +217,7 @@ class HarborAPI:
} }
} }
} }
print payload print(payload)
body=dict(body=payload) body=dict(body=payload)
request(url+"configurations", 'put', **body) request(url+"configurations", 'put', **body)
@ -256,7 +256,7 @@ class HarborAPI:
raise Exception(r"Error: Robot account count {} is not legal!".format(len(robot_account["access"]))) raise Exception(r"Error: Robot account count {} is not legal!".format(len(robot_account["access"])))
else: else:
raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch)) raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch))
print payload print(payload)
body=dict(body=payload) body=dict(body=payload)
request(url+"projects/"+projectid+"/robots", 'post', **body) request(url+"projects/"+projectid+"/robots", 'post', **body)
@ -306,7 +306,7 @@ class HarborAPI:
"ref":int(projectid) "ref":int(projectid)
} }
} }
print payload print(payload)
body=dict(body=payload) body=dict(body=payload)
request(url+"retentions", 'post', **body) request(url+"retentions", 'post', **body)
else: else:
@ -343,7 +343,7 @@ class HarborAPI:
"priority":0, "priority":0,
"template":"immutable_template" "template":"immutable_template"
} }
print payload print(payload)
body=dict(body=payload) body=dict(body=payload)
request(url+"projects/"+projectid+"/immutabletagrules", 'post', **body) request(url+"projects/"+projectid+"/immutabletagrules", 'post', **body)
else: else:
@ -375,7 +375,7 @@ class HarborAPI:
], ],
"enabled":webhook["enabled"] "enabled":webhook["enabled"]
} }
print payload print(payload)
body=dict(body=payload) body=dict(body=payload)
request(url+"projects/"+projectid+"/webhook/policies", 'post', **body) request(url+"projects/"+projectid+"/webhook/policies", 'post', **body)
else: else:
@ -383,7 +383,7 @@ class HarborAPI:
def update_repoinfo(self, reponame): def update_repoinfo(self, reponame):
payload = {"description": "testdescription"} payload = {"description": "testdescription"}
print payload print(payload)
body=dict(body=payload) body=dict(body=payload)
request(url+"repositories/"+reponame+"", 'put', **body) request(url+"repositories/"+reponame+"", 'put', **body)
@ -398,10 +398,10 @@ class HarborAPI:
if not os.path.exists(ca_path): if not os.path.exists(ca_path):
try: try:
os.makedirs(ca_path) os.makedirs(ca_path)
except Exception, e: except Exception as e:
print str(e) print(str(e))
pass pass
open(target, 'wb').write(ca_content) open(target, 'wb').write(ca_content.encode('utf-8'))
def request(url, method, user = None, userp = None, **kwargs): def request(url, method, user = None, userp = None, **kwargs):
@ -415,7 +415,7 @@ def request(url, method, user = None, userp = None, **kwargs):
kwargs['headers']['Content-Type'] = 'application/json' kwargs['headers']['Content-Type'] = 'application/json'
kwargs['data'] = json.dumps(kwargs['body']) kwargs['data'] = json.dumps(kwargs['body'])
del kwargs['body'] del kwargs['body']
print "url: ", url print("url: ", url)
resp = requests.request(method, url, verify=False, auth=(user, userp), **kwargs) resp = requests.request(method, url, verify=False, auth=(user, userp), **kwargs)
if resp.status_code >= 400: if resp.status_code >= 400:
raise Exception("[Exception Message] - {}".format(resp.text)) raise Exception("[Exception Message] - {}".format(resp.text))