Jenkin job cd_daily_master failed due to sign image failure, but there're other failure for replicaiton NG, so API for replication NG need to be updated. (#7778)

Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
danfengliu 2019-05-30 15:59:09 +08:00 committed by GitHub
parent 592e40bacf
commit 496533296d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 12 deletions

View File

@ -41,7 +41,7 @@ Push image
Wait Unitl Command Success docker logout ${ip} Wait Unitl Command Success docker logout ${ip}
Push Image With Tag Push Image With Tag
#tag1 is tag of image on docker hub,default latest,use a version existing if you do not want to use latest #tag1 is tag of image on docker hub,default latest,use a version existing if you do not want to use latest
[Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag} ${tag1}=latest [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag} ${tag1}=latest
Log To Console \nRunning docker push ${image}... Log To Console \nRunning docker push ${image}...
Wait Unitl Command Success docker pull ${image}:${tag1} Wait Unitl Command Success docker pull ${image}:${tag1}

View File

@ -30,8 +30,8 @@
{ {
"url":"http://url", "url":"http://url",
"name":"endpoint1", "name":"endpoint1",
"user":"endpointuser", "user":"admin",
"pass":"endpointpass" "pass":"Harbor12345"
} }
], ],
"replicationrule":[ "replicationrule":[

View File

@ -12,6 +12,7 @@ parser.add_argument('--version', '-v', dest='version', required=False, help='The
args = parser.parse_args() args = parser.parse_args()
url = "https://"+args.endpoint+"/api/" url = "https://"+args.endpoint+"/api/"
endpoint_url = "https://"+args.endpoint
print url print url
class HarborAPI: class HarborAPI:
@ -45,18 +46,27 @@ class HarborAPI:
request(url+"projects/"+projectid+"/members", 'post', **body) request(url+"projects/"+projectid+"/members", 'post', **body)
def add_endpoint(self, endpointurl, endpointname, username, password, insecure): def add_endpoint(self, endpointurl, endpointname, username, password, insecure):
payload = {"endpoint": ""+endpointurl+"", "name": ""+endpointname+"", "username": ""+username+"", "password": ""+password+"", "insecure": insecure} payload = {
"credential":{
"access_key":""+username+"",
"access_secret":""+password+"",
"type":"basic"
},
"insecure":insecure,
"name":""+endpointname+"",
"type":"harbor",
"url":""+endpoint_url+""
}
body=dict(body=payload) body=dict(body=payload)
request(url+"targets", 'post', **body) print body
request(url+"/registries", 'post', **body)
def add_replication_rule(self, project, target, trigger, rulename): def add_replication_rule(self, project, target, trigger, rulename):
r = request(url+"projects?name="+project+"", 'get') r = request(url+"registries?name="+target+"", 'get')
projectid = r.json()[0]['project_id']
r = request(url+"targets?name="+target+"", 'get')
targetid = r.json()[0]['id'] targetid = r.json()[0]['id']
payload = {"name": ""+rulename+"", "description": "string", "projects": [{"project_id": projectid,}], "targets": [{"id": targetid,}], "trigger": {"kind": ""+trigger+"", "schedule_param": {"type": "weekly", "weekday": 1, "offtime": 0}}} payload = {"name": ""+rulename+"", "deletion": False, "enabled": True, "description": "string", "dest_registry": {"id": targetid},"trigger": {"type": "manual"}}
body=dict(body=payload) body=dict(body=payload)
request(url+"policies/replication", 'post', **body) request(url+"replication/policies", 'post', **body)
def update_project_setting(self, project, contenttrust, preventrunning, preventseverity, scanonpush): def update_project_setting(self, project, contenttrust, preventrunning, preventseverity, scanonpush):
r = request(url+"projects?name="+project+"", 'get') r = request(url+"projects?name="+project+"", 'get')
@ -171,7 +181,7 @@ def do_data_creation():
push_signed_image("alpine", data["projects"][0]["name"], "latest") push_signed_image("alpine", data["projects"][0]["name"], "latest")
for endpoint in data["endpoint"]: for endpoint in data["endpoint"]:
harborAPI.add_endpoint(endpoint["url"], endpoint["name"], endpoint["user"], endpoint["pass"], False) harborAPI.add_endpoint(endpoint["url"], endpoint["name"], endpoint["user"], endpoint["pass"], True)
for replicationrule in data["replicationrule"]: for replicationrule in data["replicationrule"]:
harborAPI.add_replication_rule(replicationrule["project"], harborAPI.add_replication_rule(replicationrule["project"],
replicationrule["endpoint"], replicationrule["trigger"], replicationrule["endpoint"], replicationrule["trigger"],
@ -180,7 +190,7 @@ def do_data_creation():
harborAPI.update_project_setting(project["name"], harborAPI.update_project_setting(project["name"],
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"],