From a6098136a8b58e32a5ba65d46c255e0e75b4a28f Mon Sep 17 00:00:00 2001 From: wangyan Date: Fri, 26 Jan 2018 02:37:56 -0800 Subject: [PATCH] Dump harbor version for CI --- tests/nightly-test/launch.py | 5 ++++ tests/nightly-test/utils/harbor_util.py | 32 ++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/nightly-test/launch.py b/tests/nightly-test/launch.py index 75f216be2..d1f36d166 100644 --- a/tests/nightly-test/launch.py +++ b/tests/nightly-test/launch.py @@ -89,6 +89,11 @@ if build_type == "ova" : logger.info("Harbor is not ready after 10 minutes.") sys.exit(-1) 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 ----- try: diff --git a/tests/nightly-test/utils/harbor_util.py b/tests/nightly-test/utils/harbor_util.py index 18707410d..7040c0f04 100644 --- a/tests/nightly-test/utils/harbor_util.py +++ b/tests/nightly-test/utils/harbor_util.py @@ -1,6 +1,33 @@ from urllib2 import urlopen import ssl 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. def wait_for_harbor_ready(harbor_endpoint, timeout=600): @@ -20,4 +47,7 @@ def wait_for_harbor_ready(harbor_endpoint, timeout=600): time.sleep(interval) continue timeout -= interval - time.sleep(interval) \ No newline at end of file + 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']