Commit 76cbcfcb authored by Danfeng Liu (c)'s avatar Danfeng Liu (c) Committed by danfengliu
Browse files

Refect upgrade script, population will be distinguished by harbor version.


Signed-off-by: default avatarDanfeng Liu (c) <danfengl@vmware.com>
parent 3f53aa94
......@@ -226,6 +226,11 @@ Select Rule And Replicate
Retry Element Click ${replication_exec_id}
Retry Double Keywords When Error Retry Element Click xpath=${dialog_replicate} Retry Wait Until Page Not Contains Element xpath=${dialog_replicate}
Select Rule And Click Edit Button
[Arguments] ${rule_name}
Retry Element Click //clr-dg-row[contains(.,'${rule_name}')]//clr-radio-wrapper/label
Retry Element Click ${edit_replication_rule_id}
Delete Replication Rule
[Arguments] ${name}
Retry Element Click ${endpoint_filter_search}
......
......@@ -26,7 +26,7 @@ Verify Project
Init Chrome Driver
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
:FOR ${project} IN @{project}
\ Page Should Contain ${project}
\ Retry Wait Until Page Contains ${project}
Verify Project Metadata ${json}
Close Browser
......@@ -56,10 +56,10 @@ Verify Project Metadata
\ 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}
\ Verify Checkbox ${json} $.projects[?(@.name=${project})].configuration.auto_scan ${project_config_scan_images_on_push_checkbox}
\ Verify Checkbox ${json} $.projects[?(@.name=${project})].configuration.prevent_vul ${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
\ @{severity}= Get Value From Json ${json} $.projects[?(@.name=${project})].configuration.severity
\ Should Contain ${ret} @{severity}[0]
\ Navigate To Projects
Close Browser
......@@ -145,12 +145,40 @@ Verify Endpoint
Verify Replicationrule
[Arguments] ${json}
@{replicationrule}= Get Value From Json ${json} $.replicationrule..name
Init Chrome Driver
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
Switch To Replication Manage
:For ${replicationrule} IN @{replicationrule}
\ Page Should Contain ${replicationrule}
@{replicationrules}= Get Value From Json ${json} $.replicationrule.[*].rulename
@{endpoints}= Get Value From Json ${json} $.endpoint.[*].name
: FOR ${replicationrule} IN @{replicationrules}
\ Init Chrome Driver
\ Log To Console -----replicationrule-----"${replicationrule}"------------
\ Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
\ Switch To Replication Manage
\ Select Rule And Click Edit Button ${replicationrule}
\ @{is_src_registry}= Get Value From Json ${json} $.replicationrule[?(@.rulename=${replicationrule})].is_src_registry
\ @{trigger_type}= Get Value From Json ${json} $.replicationrule[?(@.rulename=${replicationrule})].trigger_type
\ @{name_filters}= Get Value From Json ${json} $.replicationrule[?(@.rulename=${replicationrule})].name_filters
\ @{tag_filters}= Get Value From Json ${json} $.replicationrule[?(@.rulename=${replicationrule})].tag_filters
\ @{dest_namespace}= Get Value From Json ${json} $.replicationrule[?(@.rulename=${replicationrule})].dest_namespace
\ @{cron}= Get Value From Json ${json} $.replicationrule[?(@.rulename=${replicationrule})].cron
\ @{is_src_registry}= Get Value From Json ${json} $.replicationrule[?(@.rulename=${replicationrule})].is_src_registry
\ Log To Console -----is_src_registry-----@{is_src_registry}[0]------------
\ @{endpoint}= Get Value From Json ${json} $.replicationrule[?(@.rulename=${replicationrule})].endpoint
\ Log To Console -----endpoint-----@{endpoint}------------
\ ${endpoint0}= Set Variable @{endpoint}[0]
\ Log To Console -----endpoint0-----${endpoint0}------------
\ @{endpoint_type}= Get Value From Json ${json} $.endpoint[?(@.name=${endpoint0})].type
\ Retry Textfield Value Should Be ${source_project} @{name_filters}[0]
\ Retry Textfield Value Should Be ${filter_tag} @{tag_filters}[0]
\ Retry Textfield Value Should Be ${rule_name_input} ${replicationrule}
\ Retry Textfield Value Should Be ${dest_namespace_xpath} @{dest_namespace}[0]
\ Log To Console -----endpoint_type-----@{endpoint_type}[0]------------
\ ${registry}= Set Variable If "@{endpoint_type}[0]"=="harbor" ${endpoint0}-https://${IP} ${endpoint0}-https://hub.docker.com
\ Log To Console -------registry---${registry}------------
\ Run Keyword If '@{is_src_registry}[0]' == '${true}' Retry List Selection Should Be ${src_registry_dropdown_list} ${registry}
\ ... ELSE Retry List Selection Should Be ${dest_registry_dropdown_list} ${registry}
\ #\ Retry List Selection Should Be ${rule_resource_selector} ${resource_type}
\ Retry List Selection Should Be ${rule_trigger_select} @{trigger_type}[0]
\ Run Keyword If '@{trigger_type}[0]' == 'scheduled' Log To Console ----------@{trigger_type}[0]------------
\ Run Keyword If '@{trigger_type}[0]' == 'scheduled' Retry Textfield Value Should Be ${targetCron_id} @{cron}[0]
Close Browser
Verify Project Setting
......
......@@ -226,7 +226,7 @@ Command Should be Failed
Retry Keyword When Error
[Arguments] ${keyword} @{elements}
:For ${n} IN RANGE 1 6
\ Log To Console Trying ${keyword} ${n} times ...
\ Log To Console Trying ${keyword} elements @{elements} ${n} times ...
\ ${out} Run Keyword And Ignore Error ${keyword} @{elements}
\ Log To Console Return value is ${out[0]}
\ Exit For Loop If '${out[0]}'=='PASS'
......
......@@ -31,24 +31,53 @@
"url":"http://url",
"name":"endpoint1",
"user":"admin",
"pass":"Harbor12345"
}
"pass":"Harbor12345",
"insecure":true,
"type":"harbor"
},
{
"url":"https://hub.docker.com",
"name":"endpoint2",
"user":"",
"pass":"",
"insecure":false,
"type":"docker-hub"
}
],
"replicationrule":[
{
"project":"project1",
"endpoint":"endpoint1",
"trigger":"Manual",
"rulename":"rulename"
"rulename":"rulename",
"is_src_registry":false,
"dest_namespace":"rule1-namespace",
"trigger_type":"event_based",
"cron":"",
"deletion":true,
"enabled":true,
"override":true,
"name_filters":"namefilter1",
"tag_filters":"tagfilter1"
},
{
"project":"library",
"endpoint":"endpoint1",
"endpoint":"endpoint2",
"trigger":"Manual",
"rulename":"rulelibrary"
}
],
"configuration":{
"rulename":"rulelibrary",
"endpoint_type":"harbor",
"is_src_registry":true,
"dest_namespace":"rule2-namespace",
"trigger_type":"scheduled",
"cron":"6 7 8 * * *",
"deletion":false,
"enabled":true,
"override":true,
"name_filters":"namefilter2",
"tag_filters":"tagfilter2"
}
],
"configuration":{
"authmode":"Database",
"projectcreation":"everyone",
"selfreg":false,
......@@ -68,6 +97,25 @@
"daily":0
}
},
"deployment_security":{
"cve":[
{
"id":"CVE-2019-12904"
},
{
"id":"CVE-2011-3389"
},
{
"id":"CVE-2018-12886"
},
{
"id":"CVE-2019-3844"
}
],
"never_expires":false,
"expires_at":"2572969600"
},
"webhooks_enabled":true,
"syslabel":[
{
"name":"label1"
......@@ -121,6 +169,10 @@
"role":3
}
],
"count_limit":1234,
"storage_limit":53687091200,
"storage_limit_for_verify":50,
"storage_unit_for_verify":"GB",
"replications":{
"rulename":"ruleproject1",
"endpointname":"endpoint1",
......@@ -143,12 +195,50 @@
"operation":"create"
}
],
"robot_account":[
{
"name":"robot0",
"access": [
{
"action": "pull"
},
{
"action": "push"
}
]
}
],
"webhook":{
"address":"https://1.1.1.1",
"skip_cert_verify":true,
"auth_header":"aaa",
"enabled":true
},
"configuration":{
"public":"true",
"enable_content_trust":"true",
"automatically_scan_images_on_push":"true",
"prevent_vulnerable_images_from_running":"true",
"prevent_vlunerable_images_from_running_severity":"high"
"auto_scan":"true",
"prevent_vul":"true",
"severity":"high",
"reuse_sys_cve_whitelist":"false",
"deployment_security":{
"cve":[
{
"id":"CVE-2019-111"
},
{
"id":"CVE-2011-2222"
},
{
"id":"CVE-2018-33333"
},
{
"id":"CVE-2019-44444"
}
],
"never_expires":false,
"expires_at":"2572969600"
}
}
},
{
......@@ -182,6 +272,10 @@
"role":3
}
],
"count_limit":-1,
"storage_limit":32985348833280,
"storage_limit_for_verify":30,
"storage_unit_for_verify":"TB",
"replications":{
"rulename":"rulename1",
"endpointname":"endpoint1",
......@@ -204,12 +298,52 @@
"operation":"create"
}
],
"robot_account":[
{
"name":"robot1",
"access": [
{
"action": "pull"
},
{
"action": "push"
}
]
},
{
"name":"robot2",
"access": [
{
"action": "pull"
}
]
},
{
"name":"robot3",
"access": [
{
"action": "push"
}
]
}
],
"webhook":{
"address":"https://1.1.1.1",
"skip_cert_verify":true,
"auth_header":"aaa",
"enabled":true
},
"configuration":{
"public":"false",
"enable_content_trust":"false",
"automatically_scan_images_on_push":"false",
"prevent_vulnerable_images_from_running":"true",
"prevent_vlunerable_images_from_running_severity":"medium"
"auto_scan":"false",
"prevent_vul":"true",
"severity":"medium",
"reuse_sys_cve_whitelist":"true",
"deployment_security":{
"cve":[
]
}
}
}
]
......
{
"create_project":[
{
"branch":1,
"version":"1.4"
},
{
"branch":1,
"version":"1.6"
},
{
"branch":1,
"version":"1.7"
},
{
"branch":1,
"version":"1.8"
},
{
"branch":2,
"version":"1.9"
},
{
"branch":2,
"version":"1.10"
}
],
"add_member":[
{
"branch":1,
"version":"1.4"
},
{
"branch":2,
"version":"1.6"
},
{
"branch":2,
"version":"1.7"
},
{
"branch":2,
"version":"1.8"
},
{
"branch":2,
"version":"1.9"
},
{
"branch":2,
"version":"1.10"
}
],
"set_user_admin":[
{
"branch":1,
"version":"1.4"
},
{
"branch":2,
"version":"1.6"
},
{
"branch":2,
"version":"1.7"
},
{
"branch":2,
"version":"1.8"
},
{
"branch":2,
"version":"1.9"
},
{
"branch":2,
"version":"1.10"
}
],
"add_endpoint":[
{
"branch":1,
"version":"1.4"
},
{
"branch":1,
"version":"1.6"
},
{
"branch":1,
"version":"1.7"
},
{
"branch":2,
"version":"1.8"
},
{
"branch":2,
"version":"1.9"
},
{
"branch":2,
"version":"1.10"
}
],
"add_replication_rule":[
{
"branch":1,
"version":"1.4"
},
{
"branch":1,
"version":"1.6"
},
{
"branch":1,
"version":"1.7"
},
{
"branch":2,
"version":"1.8"
},
{
"branch":2,
"version":"1.9"
},
{
"branch":2,
"version":"1.10"
}
],
"add_sys_whitelist":[
{
"branch":1,
"version":"1.9"
},
{
"branch":1,
"version":"1.10"
}
],
"update_project_setting_whitelist":[
{
"branch":1,
"version":"1.9"
},
{
"branch":1,
"version":"1.10"
}
],
"add_project_robot_account":[
{
"branch":1,
"version":"1.8"
},
{
"branch":1,
"version":"1.9"
},
{
"branch":1,
"version":"1.10"
}
],
"add_tag_retention_rule":[
{
"branch":1,
"version":"1.9"
},
{
"branch":1,
"version":"1.10"
}
],
"add_tag_immutability_rule":[
{
"branch":1,
"version":"1.10"
}
],
"add_webhook":[
{
"branch":1,
"version":"1.9"
},
{
"branch":1,
"version":"1.10"
}
]
}
\ No newline at end of file
import os
import sys
import json
import argparse
import requests
from functools import wraps
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
......@@ -15,9 +16,43 @@ url = "https://"+args.endpoint+"/api/"
endpoint_url = "https://"+args.endpoint
print url
with open("feature_map.json") as f:
feature_map = json.load(f)
def get_branch(func_name, version):
has_feature = False
for node in feature_map[func_name]:
has_feature = True
if node["version"] == version:
return node["branch"]
if has_feature is False:
return "No Restriction"
else:
return "Not Supported"
def get_feature_branch(func):
@wraps(func)
def inner_func(*args,**kwargs):
branch=get_branch(inner_func.__name__, kwargs.get("version"))
if branch == "No Restriction":
func(*args,**kwargs)
elif branch == "Not Supported":
print("Feature {} is not supported in version {}".format(inner_func.__name__, kwargs.get("version")))
else:
kwargs["branch"] = branch
func(*args,**kwargs)
return
return inner_func
class HarborAPI:
def create_project(self, project_name):
body=dict(body={"project_name": ""+project_name+"", "metadata": {"public": "true"}})
@get_feature_branch
def create_project(self, project, **kwargs):
if kwargs["branch"] == 1:
body=dict(body={"project_name": ""+project["name"]+"", "metadata": {"public": "true"}})
elif kwargs["branch"] == 2:
body=dict(body={"project_name": ""+project["name"]+"", "metadata": {"public": "true"},"count_limit":project["count_limit"],"storage_limit":project["storage_limit"]})
else:
raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch))
request(url+"projects", 'post', **body)
def create_user(self, username):
......@@ -25,65 +60,135 @@ class HarborAPI:
body=dict(body=payload)
request(url+"users", 'post', **body)
def set_user_admin(self, user):
@get_feature_branch
def set_user_admin(self, user, **kwargs):
r = request(url+"users?username="+user+"", 'get')
userid = str(r.json()[0]['user_id'])
if args.version == "1.6":
body=dict(body={"sysadmin_flag": True})
if kwargs["branch"] == 1:
body=dict(body={"has_admin_role": 1})
elif kwargs["branch"] == 2:
body=dict(body={"has_admin_role": True})
else:
body=dict(body={"sysadmin_flag": 1})
raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch))
request(url+"users/"+userid+"/sysadmin", 'put', **body)
def add_member(self, project, user, role):
@get_feature_branch
def add_member(self, project, user, role, **kwargs):
r = request(url+"projects?name="+project+"", 'get')
projectid = str(r.json()[0]['project_id'])
if args.version == "1.6":
if kwargs["branch"] == 1:
payload = {"roles": [role], "username":""+user+""}
elif kwargs["branch"] == 2:
payload = {"member_user":{ "username": ""+user+""},"role_id": role}
else:
payload = {"roles": [role], "username":""+user+""}
raise Exception(r"Error: Feature {} has no branch {}.".format(sys._getframe().f_code.co_name, branch))
body=dict(body=payload)
request(url+"projects/"+projectid+"/members", 'post', **body)