Merge pull request #4141 from wy65701436/dump-harbor-version

Dump harbor version for CI
This commit is contained in:
Daniel Jiang 2018-01-27 16:50:00 +08:00 committed by GitHub
commit 07a75ed266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -89,6 +89,11 @@ if build_type == "ova" :
logger.info("Harbor is not ready after 10 minutes.") logger.info("Harbor is not ready after 10 minutes.")
sys.exit(-1) sys.exit(-1)
logger.info("%s is ready for test now..." % item) logger.info("%s is ready for test now..." % item)
# ----- log harbor version -----
harbor_version = harbor_util.get_harbor_version(item, 'admin', 'Harbor12345')
logger.info("Harbor version: %s ..." % harbor_version)
with open(os.getcwd() + '/build.properties', 'w') as the_file:
the_file.write('harbor_version=%s' % harbor_version)
# ----- execute test cases ----- # ----- execute test cases -----
try: try:

View File

@ -1,6 +1,33 @@
from urllib2 import urlopen from urllib2 import urlopen
import ssl import ssl
import time import time
import os
try:
import json
except ImportError:
import simplejson as json
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def request(harbor_endpoint, url, method, user, pwd, **kwargs):
url = "https://" + harbor_endpoint + "/api" + url
kwargs.setdefault('headers', kwargs.get('headers', {}))
kwargs['headers']['Accept'] = 'application/json'
if 'body' in kwargs:
kwargs['headers']['Content-Type'] = 'application/json'
kwargs['data'] = json.dumps(kwargs['body'])
del kwargs['body']
resp = requests.request(method, url, verify=False, auth=(user, pwd), **kwargs)
if resp.status_code >= 400:
raise Exception("Error: %s" % resp.text)
try:
body = json.loads(resp.text)
except ValueError:
body = resp.text
return body
# wait for 10 minutes as OVA needs about 7 minutes to startup harbor. # wait for 10 minutes as OVA needs about 7 minutes to startup harbor.
def wait_for_harbor_ready(harbor_endpoint, timeout=600): def wait_for_harbor_ready(harbor_endpoint, timeout=600):
@ -21,3 +48,6 @@ def wait_for_harbor_ready(harbor_endpoint, timeout=600):
continue continue
timeout -= interval timeout -= interval
time.sleep(interval) time.sleep(interval)
def get_harbor_version(harbor_endpoint, harbor_user, harbor_pwd):
return request(harbor_endpoint, '/systeminfo', 'get', harbor_user, harbor_pwd)['harbor_version']