diff --git a/tests/apitests/python/library/artifact.py b/tests/apitests/python/library/artifact.py index 279f8dd86..97907d518 100644 --- a/tests/apitests/python/library/artifact.py +++ b/tests/apitests/python/library/artifact.py @@ -91,10 +91,6 @@ class Artifact(base.Base, object): if (timeout_count == 0): break artifact = self.get_reference_info(project_name, repo_name, reference, **kwargs) - print "artifact", artifact - print "artifact[0]", artifact[0] - print "artifact[0].scan_overview", artifact[0].scan_overview - print "artifact[0].scan_overview['application/vnd.scanner.adapter.vuln.report.harbor+json; version=1.0']", artifact[0].scan_overview['application/vnd.scanner.adapter.vuln.report.harbor+json; version=1.0'] scan_status = artifact[0].scan_overview['application/vnd.scanner.adapter.vuln.report.harbor+json; version=1.0']["scan_status"] if scan_status == expected_scan_status: return diff --git a/tests/apitests/python/library/base.py b/tests/apitests/python/library/base.py index 275656a3a..44a96e399 100644 --- a/tests/apitests/python/library/base.py +++ b/tests/apitests/python/library/base.py @@ -1,121 +1,121 @@ -# -*- coding: utf-8 -*- - -import sys -import time -import subprocess -import client -import swagger_client -import v2_swagger_client -try: - from urllib import getproxies -except ImportError: - from urllib.request import getproxies - -class Server: - def __init__(self, endpoint, verify_ssl): - self.endpoint = endpoint - self.verify_ssl = verify_ssl - -class Credential: - def __init__(self, type, username, password): - self.type = type - self.username = username - self.password = password - -def _create_client(server, credential, debug, api_type="products"): - cfg = None - if api_type in ('projectv2', 'artifact', 'repository', 'scan'): - cfg = v2_swagger_client.Configuration() - else: - cfg = swagger_client.Configuration() - - cfg.host = server.endpoint - cfg.verify_ssl = server.verify_ssl - # support basic auth only for now - cfg.username = credential.username - cfg.password = credential.password - cfg.debug = debug - - proxies = getproxies() - proxy = proxies.get('http', proxies.get('all', None)) - if proxy: - cfg.proxy = proxy - return { - "chart": client.ChartRepositoryApi(client.ApiClient(cfg)), - "products": swagger_client.ProductsApi(swagger_client.ApiClient(cfg)), - "projectv2": v2_swagger_client.ProjectApi(v2_swagger_client.ApiClient(cfg)), - "artifact": v2_swagger_client.ArtifactApi(v2_swagger_client.ApiClient(cfg)), - "repository": v2_swagger_client.RepositoryApi(v2_swagger_client.ApiClient(cfg)), - "scan": v2_swagger_client.ScanApi(v2_swagger_client.ApiClient(cfg)), - "scanner": swagger_client.ScannersApi(swagger_client.ApiClient(cfg)), - }.get(api_type,'Error: Wrong API type') - -def _assert_status_code(expect_code, return_code): - if str(return_code) != str(expect_code): - raise Exception(r"HTTPS status code s not as we expected. Expected {}, while actual HTTPS status code is {}.".format(expect_code, return_code)) - -def _assert_status_body(expect_status_body, returned_status_body): - if expect_status_body.strip() != returned_status_body.strip(): - raise Exception(r"HTTPS status body s not as we expected. Expected {}, while actual HTTPS status body is {}.".format(expect_status_body, returned_status_body)) - -def _random_name(prefix): - return "%s-%d" % (prefix, int(round(time.time() * 1000))) - -def _get_id_from_header(header): - try: - location = header["Location"] - return int(location.split("/")[-1]) - except Exception: - return None - -def _get_string_from_unicode(udata): - result='' - for u in udata: - tmp = u.encode('utf8') - result = result + tmp.strip('\n\r\t') - return result - -def run_command(command): - print "Command: ", subprocess.list2cmdline(command) - try: - output = subprocess.check_output(command, - stderr=subprocess.STDOUT, - universal_newlines=True) - except subprocess.CalledProcessError as e: - raise Exception('Error: Exited with error code: %s. Output:%s'% (e.returncode, e.output)) - return output - -class Base: - def __init__(self, - server = Server(endpoint="http://localhost:8080/api", verify_ssl=False), - credential = Credential(type="basic_auth", username="admin", password="Harbor12345"), - debug = True, api_type = "products"): - if not isinstance(server.verify_ssl, bool): - server.verify_ssl = server.verify_ssl == "True" - self.server = server - self.credential = credential - self.debug = debug - self.api_type = api_type - self.client = _create_client(server, credential, debug, api_type=api_type) - - def _get_client(self, **kwargs): - if len(kwargs) == 0: - return self.client - server = self.server - if "api_type" in kwargs: - server.api_type = kwargs.get("api_type") - if "endpoint" in kwargs: - server.endpoint = kwargs.get("endpoint") - if "verify_ssl" in kwargs: - if not isinstance(kwargs.get("verify_ssl"), bool): - server.verify_ssl = kwargs.get("verify_ssl") == "True" - else: - server.verify_ssl = kwargs.get("verify_ssl") - credential = self.credential - if "type" in kwargs: - credential.type = kwargs.get("type") - if "username" in kwargs: - credential.username = kwargs.get("username") - if "password" in kwargs: - credential.password = kwargs.get("password") +# -*- coding: utf-8 -*- + +import sys +import time +import subprocess +import client +import swagger_client +import v2_swagger_client +try: + from urllib import getproxies +except ImportError: + from urllib.request import getproxies + +class Server: + def __init__(self, endpoint, verify_ssl): + self.endpoint = endpoint + self.verify_ssl = verify_ssl + +class Credential: + def __init__(self, type, username, password): + self.type = type + self.username = username + self.password = password + +def _create_client(server, credential, debug, api_type="products"): + cfg = None + if api_type in ('projectv2', 'artifact', 'repository', 'scan'): + cfg = v2_swagger_client.Configuration() + else: + cfg = swagger_client.Configuration() + + cfg.host = server.endpoint + cfg.verify_ssl = server.verify_ssl + # support basic auth only for now + cfg.username = credential.username + cfg.password = credential.password + cfg.debug = debug + + proxies = getproxies() + proxy = proxies.get('http', proxies.get('all', None)) + if proxy: + cfg.proxy = proxy + return { + "chart": client.ChartRepositoryApi(client.ApiClient(cfg)), + "products": swagger_client.ProductsApi(swagger_client.ApiClient(cfg)), + "projectv2": v2_swagger_client.ProjectApi(v2_swagger_client.ApiClient(cfg)), + "artifact": v2_swagger_client.ArtifactApi(v2_swagger_client.ApiClient(cfg)), + "repository": v2_swagger_client.RepositoryApi(v2_swagger_client.ApiClient(cfg)), + "scan": v2_swagger_client.ScanApi(v2_swagger_client.ApiClient(cfg)), + "scanner": swagger_client.ScannersApi(swagger_client.ApiClient(cfg)), + }.get(api_type,'Error: Wrong API type') + +def _assert_status_code(expect_code, return_code): + if str(return_code) != str(expect_code): + raise Exception(r"HTTPS status code s not as we expected. Expected {}, while actual HTTPS status code is {}.".format(expect_code, return_code)) + +def _assert_status_body(expect_status_body, returned_status_body): + if expect_status_body.strip() != returned_status_body.strip(): + raise Exception(r"HTTPS status body s not as we expected. Expected {}, while actual HTTPS status body is {}.".format(expect_status_body, returned_status_body)) + +def _random_name(prefix): + return "%s-%d" % (prefix, int(round(time.time() * 1000))) + +def _get_id_from_header(header): + try: + location = header["Location"] + return int(location.split("/")[-1]) + except Exception: + return None + +def _get_string_from_unicode(udata): + result='' + for u in udata: + tmp = u.encode('utf8') + result = result + tmp.strip('\n\r\t') + return result + +def run_command(command): + print("Command: ", subprocess.list2cmdline(command)) + try: + output = subprocess.check_output(command, + stderr=subprocess.STDOUT, + universal_newlines=True) + except subprocess.CalledProcessError as e: + raise Exception('Error: Exited with error code: %s. Output:%s'% (e.returncode, e.output)) + return output + +class Base: + def __init__(self, + server = Server(endpoint="http://localhost:8080/api", verify_ssl=False), + credential = Credential(type="basic_auth", username="admin", password="Harbor12345"), + debug = True, api_type = "products"): + if not isinstance(server.verify_ssl, bool): + server.verify_ssl = server.verify_ssl == "True" + self.server = server + self.credential = credential + self.debug = debug + self.api_type = api_type + self.client = _create_client(server, credential, debug, api_type=api_type) + + def _get_client(self, **kwargs): + if len(kwargs) == 0: + return self.client + server = self.server + if "api_type" in kwargs: + server.api_type = kwargs.get("api_type") + if "endpoint" in kwargs: + server.endpoint = kwargs.get("endpoint") + if "verify_ssl" in kwargs: + if not isinstance(kwargs.get("verify_ssl"), bool): + server.verify_ssl = kwargs.get("verify_ssl") == "True" + else: + server.verify_ssl = kwargs.get("verify_ssl") + credential = self.credential + if "type" in kwargs: + credential.type = kwargs.get("type") + if "username" in kwargs: + credential.username = kwargs.get("username") + if "password" in kwargs: + credential.password = kwargs.get("password") return _create_client(server, credential, self.debug, self.api_type) \ No newline at end of file diff --git a/tests/apitests/python/library/chart.py b/tests/apitests/python/library/chart.py index 3d0fef853..d5bb6b64a 100644 --- a/tests/apitests/python/library/chart.py +++ b/tests/apitests/python/library/chart.py @@ -17,7 +17,6 @@ class Chart(base.Base, object): def chart_should_exist(self, repository, chart_name, **kwargs): charts_data = self.get_charts(repository, **kwargs) - print "charts_data:", charts_data for chart in charts_data: if chart.name == chart_name: return True diff --git a/tests/apitests/python/library/cnab.py b/tests/apitests/python/library/cnab.py index 835d002a8..f0b7231dc 100644 --- a/tests/apitests/python/library/cnab.py +++ b/tests/apitests/python/library/cnab.py @@ -9,12 +9,9 @@ def load_bundle(service_image, invocation_image): bundle_tmpl_file = "./tests/apitests/python/bundle_data/bundle.json.tmpl" with open(bundle_tmpl_file,'r') as load_f: load_dict = json.load(load_f) - print "load_dict:", load_dict - print "load_dict-invocationImages:", load_dict["invocationImages"][0]["contentDigest"] load_dict["images"]["hello"]["image"] = service_image load_dict["invocationImages"][0]["image"] = invocation_image bundle_str = json.dumps(load_dict) - print "bundle_str:", bundle_str with open(bundle_file,'w') as dump_f: dump_f.write(bundle_str) dump_f.close() @@ -26,16 +23,16 @@ def cnab_fixup_bundle(bundle_file, target, auto_update_bundle = True): if auto_update_bundle == True: command.append("--auto-update-bundle") #fixed_bundle_file = bundle_file - print "Command: ", command + print("Command: ", command) ret = base.run_command(command) - print "Command return: ", ret + print("Command return: ", ret) return fixed_bundle_file def cnab_push_bundle(bundle_file, target): command = ["cnab-to-oci", "push", bundle_file, "--target", target, "--auto-update-bundle"] - print "Command: ", command + print("Command: ", command) ret = base.run_command(command) - print "Command return: ", ret + print("Command return: ", ret) for line in ret.split("\n"): line = line.replace('\"', '') if line.find('sha256') >= 0: @@ -48,5 +45,4 @@ def push_cnab_bundle(harbor_server, user, password, service_image, invocation_im bundle_file = load_bundle(service_image, invocation_image) fixed_bundle_file = cnab_fixup_bundle(bundle_file, target, auto_update_bundle = auto_update_bundle) sha256 = cnab_push_bundle(fixed_bundle_file, target) - print "sha256:", sha256 return sha256 diff --git a/tests/apitests/python/library/containerd.py b/tests/apitests/python/library/containerd.py index 1517f169f..01ecc3cf7 100644 --- a/tests/apitests/python/library/containerd.py +++ b/tests/apitests/python/library/containerd.py @@ -6,15 +6,15 @@ import docker_api def ctr_images_pull(username, password, oci): command = ["sudo", "ctr", "images", "pull", "-u", username+":"+password, oci] - print "Command: ", command + print("Command: ", command) ret = base.run_command(command) - print "Command return: ", ret + print("Command return: ", ret) def ctr_images_list(oci_ref = None): command = ["sudo", "ctr", "images", "list", "--q"] - print "Command: ", command + print("Command: ", command) ret = base.run_command(command) - print "Command return: ", ret + print("Command return: ", ret) if oci_ref is not None and oci_ref not in ret.split("\n"): raise Exception(r" Get OCI ref failed, expected ref is [{}], but return ref list is [{}]".format (ret)) diff --git a/tests/apitests/python/library/docker_api.py b/tests/apitests/python/library/docker_api.py index 252791375..1041d1945 100644 --- a/tests/apitests/python/library/docker_api.py +++ b/tests/apitests/python/library/docker_api.py @@ -13,29 +13,29 @@ except ImportError: def docker_info_display(): command = ["docker", "info", "-f", "'{{.OSType}}/{{.Architecture}}'"] - print "Docker Info: ", command + print("Docker Info: ", command) ret = base.run_command(command) - print "Command return: ", ret + print("Command return: ", ret) def docker_login_cmd(harbor_host, user, password, enable_manifest = True): command = ["sudo", "docker", "login", harbor_host, "-u", user, "-p", password] - print "Docker Login Command: ", command + print( "Docker Login Command: ", command) base.run_command(command) if enable_manifest == True: try: ret = subprocess.check_output(["./tests/apitests/python/update_docker_cfg.sh"], shell=False) - except subprocess.CalledProcessError, exc: + except subprocess.CalledProcessError as exc: raise Exception("Failed to update docker config, error is {} {}.".format(exc.returncode, exc.output)) def docker_manifest_create(index, manifests): command = ["sudo", "docker","manifest","create",index] command.extend(manifests) - print "Docker Manifest Command: ", command + print( "Docker Manifest Command: ", command) base.run_command(command) def docker_manifest_push(index): command = ["sudo", "docker","manifest","push",index] - print "Docker Manifest Command: ", command + print( "Docker Manifest Command: ", command) ret = base.run_command(command) index_sha256="" manifest_list=[] @@ -58,7 +58,7 @@ def list_repositories(harbor_host, user, password, n = None, last = None): command = ["curl", "-s", "-u", user+":"+password, "https://"+harbor_host+"/v2/_catalog"+"?n=%d"%n, "--insecure"] else: command = ["curl", "-s", "-u", user+":"+password, "https://"+harbor_host+"/v2/_catalog", "--insecure"] - print "List Repositories Command: ", command + print( "List Repositories Command: ", command) ret = base.run_command(command) repos = json.loads(ret).get("repositories","") return repos @@ -70,7 +70,7 @@ def list_image_tags(harbor_host, repository, user, password, n = None, last = No command = ["curl", "-s", "-u", user+":"+password, "https://"+harbor_host+"/v2/"+repository+"/tags/list"+"?n=%d"%n, "--insecure"] else: command = ["curl", "-s", "-u", user+":"+password, "https://"+harbor_host+"/v2/"+repository+"/tags/list", "--insecure"] - print "List Image Tags Command: ", command + print( "List Image Tags Command: ", command) ret = base.run_command(command) tags = json.loads(ret).get("tags","") return tags @@ -85,9 +85,9 @@ class DockerAPI(object): expected_error_message = None try: self.DCLIENT.login(registry = registry, username=username, password=password) - except docker.errors.APIError, err: + except docker.errors.APIError as err: if expected_error_message is not None: - print "docker login error:", str(err) + print( "docker login error:", str(err)) if str(err).lower().find(expected_error_message.lower()) < 0: raise Exception(r"Docker login: Return message {} is not as expected {}".format(str(err), expected_error_message)) else: @@ -105,10 +105,10 @@ class DockerAPI(object): try: ret = base._get_string_from_unicode(self.DCLIENT.pull(r'{}:{}'.format(image, _tag))) return ret - except Exception, err: + except Exception as err: caught_err = True if expected_error_message is not None: - print "docker image pull error:", str(err) + print( "docker image pull error:", str(err)) if str(err).lower().find(expected_error_message.lower()) < 0: raise Exception(r"Pull image: Return message {} is not as expected {}".format(str(err), expected_error_message)) else: @@ -128,7 +128,7 @@ class DockerAPI(object): try: self.DCLIENT.tag(image, harbor_registry, _tag, force=True) return harbor_registry, _tag - except docker.errors.APIError, e: + except docker.errors.APIError as e: raise Exception(r" Docker tag image {} failed, error is [{}]".format (image, e.message)) def docker_image_push(self, harbor_registry, tag, expected_error_message = None): @@ -139,10 +139,10 @@ class DockerAPI(object): try: ret = base._get_string_from_unicode(self.DCLIENT.push(harbor_registry, tag, stream=True)) return ret - except Exception, err: + except Exception as err: caught_err = True if expected_error_message is not None: - print "docker image push error:", str(err) + print( "docker image push error:", str(err)) if str(err).lower().find(expected_error_message.lower()) < 0: raise Exception(r"Push image: Return message {} is not as expected {}".format(str(err), expected_error_message)) else: @@ -184,10 +184,10 @@ class DockerAPI(object): self.DCLIENT.pull(repo) image = self.DCLIENT2.images.get(repo) return repo, image.id - except Exception, err: + except Exception as err: caught_err = True if expected_error_message is not None: - print "docker image build error:", str(err) + print( "docker image build error:", str(err)) if str(err).lower().find(expected_error_message.lower()) < 0: raise Exception(r"Push image: Return message {} is not as expected {}".format(str(err), expected_error_message)) else: diff --git a/tests/apitests/python/library/helm.py b/tests/apitests/python/library/helm.py index 19002cfd7..5345ff10e 100644 --- a/tests/apitests/python/library/helm.py +++ b/tests/apitests/python/library/helm.py @@ -6,26 +6,26 @@ import base def get_chart_file(file_name): command = ["wget", file_name] ret = base.run_command(command) - print "Command Return: ", ret + print("Command return: ", ret) command = ["tar", "xvf", file_name.split('/')[-1]] ret = base.run_command(command) - print "Command Return: ", ret + print("Command return: ", ret) def helm_login(harbor_server, user, password): os.putenv("HELM_EXPERIMENTAL_OCI", "1") command = ["helm3", "registry", "login", harbor_server, "-u", user, "-p", password] - print "Command: ", command + print("Command: ", command) ret = base.run_command(command) - print "Command return: ", ret + print("Command return: ", ret) def helm_save(chart_archive, harbor_server, project, repo_name): command = ["helm3", "chart","save", chart_archive, harbor_server+"/"+project+"/"+repo_name] - print "Command: ", command + print("Command: ", command) base.run_command(command) def helm_push(harbor_server, project, repo_name, version): command = ["helm3", "chart","push", harbor_server+"/"+project+"/"+repo_name+":"+version] - print "Command: ", command + print("Command: ", command) ret = base.run_command(command) return ret @@ -37,11 +37,11 @@ def helm_chart_push_to_harbor(chart_file, archive, harbor_server, project, repo_ def helm2_add_repo(helm_repo_name, harbor_url, project, username, password): command = ["helm2", "repo", "add", "--username=" + username, "--password=" + password, helm_repo_name, harbor_url + "/chartrepo/" + project] - print "Command: ", command + print("Command: ", command) base.run_command(command) def helm2_push(helm_repo_name, chart_file, project, username, password): get_chart_file(chart_file) command = ["helm2", "push", "--username=" + username, "--password=" + password, chart_file.split('/')[-1], helm_repo_name] - print "Command: ", command + print("Command: ", command) base.run_command(command) \ No newline at end of file diff --git a/tests/apitests/python/library/oras.py b/tests/apitests/python/library/oras.py index 2e9751196..ce082984c 100644 --- a/tests/apitests/python/library/oras.py +++ b/tests/apitests/python/library/oras.py @@ -39,7 +39,6 @@ def oras_pull(harbor_server, user, password, project, repo, tag): os.rmdir(cwd) os.makedirs(cwd) os.chdir(cwd) - print "Tmp dir:", cwd except Exception as e: raise Exception('Error: Exited with error {}',format(e)) ret = base.run_command([oras_cmd, "pull", harbor_server + "/" + project + "/" + repo+":"+ tag, "-a"]) diff --git a/tests/apitests/python/library/replication.py b/tests/apitests/python/library/replication.py index 172889b02..055e53843 100644 --- a/tests/apitests/python/library/replication.py +++ b/tests/apitests/python/library/replication.py @@ -38,7 +38,7 @@ class Replication(base.Base): if str(rule_data.name) != str(expect_rule_name): raise Exception(r"Check replication rule failed, expect <{}> actual <{}>.".format(expect_rule_name, str(rule_data.name))) else: - print r"Check Replication rule passed, rule name <{}>.".format(str(rule_data.name)) + print(r"Check Replication rule passed, rule name <{}>.".format(str(rule_data.name))) #get_trigger = str(rule_data.trigger.kind) #if expect_trigger is not None and get_trigger == str(expect_trigger): # print r"Check Replication rule trigger passed, trigger name <{}>.".format(get_trigger) diff --git a/tests/apitests/python/library/repository.py b/tests/apitests/python/library/repository.py index 8955b8929..1b7d41e94 100644 --- a/tests/apitests/python/library/repository.py +++ b/tests/apitests/python/library/repository.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -import site -reload(site) import time import base import swagger_client @@ -121,7 +119,6 @@ class Repository(base.Base, object): def check_repository_exist(self, project_Name, repo_name, **kwargs): repositories = self.list_repositories(project_Name, **kwargs) for repo in repositories: - print project_Name+"/"+repo_name if repo.name == project_Name+"/"+repo_name: return True return False diff --git a/tests/apitests/python/library/sign.py b/tests/apitests/python/library/sign.py index 856b5bc58..7e7c417c5 100644 --- a/tests/apitests/python/library/sign.py +++ b/tests/apitests/python/library/sign.py @@ -5,7 +5,7 @@ from testutils import notary_url def sign_image(registry_ip, project_name, image, tag): try: ret = subprocess.check_output(["./tests/apitests/python/sign_image.sh", registry_ip, project_name, image, tag, notary_url], shell=False) - print "sign_image return: ", ret + print("sign_image return: ", ret) except subprocess.CalledProcessError, exc: raise Exception("Failed to sign image error is {} {}.".format(exc.returncode, exc.output)) diff --git a/tests/apitests/python/library/user.py b/tests/apitests/python/library/user.py index e577b4780..4983c87ac 100644 --- a/tests/apitests/python/library/user.py +++ b/tests/apitests/python/library/user.py @@ -45,7 +45,6 @@ class User(base.Base): client = self._get_client(**kwargs) data, status_code, _ = client.users_user_id_get_with_http_info(user_id) base._assert_status_code(200, status_code) - print "data in lib:", data return data @@ -80,7 +79,6 @@ class User(base.Base): def update_user_role_as_sysadmin(self, user_id, IsAdmin, **kwargs): client = self._get_client(**kwargs) sysadmin_flag = swagger_client.SysAdminFlag(IsAdmin) - print "sysadmin_flag:", sysadmin_flag _, status_code, _ = client.users_user_id_sysadmin_put_with_http_info(user_id, sysadmin_flag) base._assert_status_code(200, status_code) return user_id diff --git a/tests/apitests/python/populate.py b/tests/apitests/python/populate.py new file mode 100644 index 000000000..f4aa49ff9 --- /dev/null +++ b/tests/apitests/python/populate.py @@ -0,0 +1,77 @@ +from __future__ import absolute_import + + +import unittest +import numpy +import threading +from datetime import * +from time import sleep, ctime + +import library.repository +import library.docker_api +from library.base import _assert_status_code +from testutils import ADMIN_CLIENT +from testutils import harbor_server + +from testutils import TEARDOWN +from library.project import Project +from library.repository import Repository +from library.artifact import Artifact +from library.repository import push_image_to_project +from library.repository import pull_harbor_image +from library.repository import push_special_image_to_project +import argparse + +def do_populate(name_index, repo_count): + project= Project() + artifact = Artifact() + repo = Repository() + url = ADMIN_CLIENT["endpoint"] + ADMIN_CLIENT["password"] = "qA5ZgV" + + + #2. Create a new project(PA) by user(UA); + project_name = "project"+str(name_index) + if project.check_project_name_exist(name=project_name, **ADMIN_CLIENT) is not True: + project.create_project(name=project_name, metadata = {"public": "false"}, **ADMIN_CLIENT) + print("Create Project:", project_name) + + tag = 'latest' + for repo_index in range(int(repo_count)): + repo_name = "image"+ str(repo_index) + if artifact.check_reference_exist(project_name, repo_name, tag, ignore_not_found=True, **ADMIN_CLIENT) is not True: + push_special_image_to_project(project_name, harbor_server, ADMIN_CLIENT["username"], ADMIN_CLIENT["password"], repo_name, [tag], size=repo_index*30) + print("Push Image:", repo_name) + for tag_index in numpy.arange(1, 2, 0.1): + artifact.create_tag(project_name, repo_name, tag, str(tag_index), ignore_conflict = True, **ADMIN_CLIENT) + print("Add Tag:", str(tag_index)) + + +def get_parser(): + """ return a parser """ + parser = argparse.ArgumentParser("populate") + + parser.add_argument('--project-count','-p', dest='project_count', required=False, default=100) + parser.add_argument('--repo-count','-r', dest='repo_count', required=False, default=100) + args = parser.parse_args() + return (args.project_count, args.repo_count) + +def main(): + """ main entrance """ + project_count, repo_count = get_parser() + Threads = [] + for i in range(int(project_count)): + t = threading.Thread(target=do_populate, args=(str(i), repo_count), name='T'+str(i)) + t.setDaemon(True) + Threads.append(t) + sleep(3) + for t in Threads: + t.start() + for t in Threads: + t.join() + + print('Job Finished:', ctime()) + +if __name__ == '__main__': + main() + diff --git a/tests/apitests/python/test_add_replication_rule.py b/tests/apitests/python/test_add_replication_rule.py index 8ff14a8f3..eebe740cc 100644 --- a/tests/apitests/python/test_add_replication_rule.py +++ b/tests/apitests/python/test_add_replication_rule.py @@ -20,7 +20,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -69,7 +69,6 @@ class TestProjects(unittest.TestCase): #3. Create a new registry TestProjects.registry_id, _ = self.registry.create_registry("https://" + harbor_server,**ADMIN_CLIENT) - print "TestProjects.registry_id:", TestProjects.registry_id #4. Create a new rule for this registry; TestProjects.rule_id, rule_name = self.replication.create_replication_policy(dest_registry=swagger_client.Registry(id=int(TestProjects.registry_id)), **ADMIN_CLIENT) diff --git a/tests/apitests/python/test_add_sys_label_to_tag.py b/tests/apitests/python/test_add_sys_label_to_tag.py index f54a5804c..bc7e3e36b 100644 --- a/tests/apitests/python/test_add_sys_label_to_tag.py +++ b/tests/apitests/python/test_add_sys_label_to_tag.py @@ -23,7 +23,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_assign_sys_admin.py b/tests/apitests/python/test_assign_sys_admin.py index 431a66d63..7112ae20e 100644 --- a/tests/apitests/python/test_assign_sys_admin.py +++ b/tests/apitests/python/test_assign_sys_admin.py @@ -15,7 +15,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_copy_artifact_outside_project.py b/tests/apitests/python/test_copy_artifact_outside_project.py index 7b481527a..80c6acbfb 100644 --- a/tests/apitests/python/test_copy_artifact_outside_project.py +++ b/tests/apitests/python/test_copy_artifact_outside_project.py @@ -25,7 +25,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDownClass(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_create_delete_tag.py b/tests/apitests/python/test_create_delete_tag.py index ca7624a17..0732f70ad 100644 --- a/tests/apitests/python/test_create_delete_tag.py +++ b/tests/apitests/python/test_create_delete_tag.py @@ -30,7 +30,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDownClass(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_del_repo.py b/tests/apitests/python/test_del_repo.py index 6eed0af1a..b709ec12e 100644 --- a/tests/apitests/python/test_del_repo.py +++ b/tests/apitests/python/test_del_repo.py @@ -22,7 +22,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDownClass(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_edit_project_creation.py b/tests/apitests/python/test_edit_project_creation.py index d15cda6eb..e4dc4e7f5 100644 --- a/tests/apitests/python/test_edit_project_creation.py +++ b/tests/apitests/python/test_edit_project_creation.py @@ -16,11 +16,10 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): - print "Clear trace" #1. Delete project(PA); self.project.delete_project(TestProjects.project_edit_project_creation_id, **TestProjects.USER_edit_project_creation_CLIENT) diff --git a/tests/apitests/python/test_garbage_collection.py b/tests/apitests/python/test_garbage_collection.py index c23dd1747..77db71ee9 100644 --- a/tests/apitests/python/test_garbage_collection.py +++ b/tests/apitests/python/test_garbage_collection.py @@ -29,7 +29,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == True, "Test data won't be erased.") def test_ClearData(self): @@ -96,7 +96,6 @@ class TestProjects(unittest.TestCase): self.system.validate_deletion_success(gc_id, **ADMIN_CLIENT) artifacts = self.artifact.list_artifacts(TestProjects.project_gc_untag_name, self.repo_name_untag, **TestProjects.USER_GC_CLIENT) - print artifacts _assert_status_code(len(artifacts), 1) time.sleep(5) @@ -112,7 +111,6 @@ class TestProjects(unittest.TestCase): #11. Repository with untag image should be still there; repo_data_untag = self.repo.list_repositories(TestProjects.project_gc_untag_name, **TestProjects.USER_GC_CLIENT) - print "repo_data_untag:", repo_data_untag _assert_status_code(len(repo_data_untag), 1) self.assertEqual(TestProjects.project_gc_untag_name + "/" + self.repo_name_untag , repo_data_untag[0].name) diff --git a/tests/apitests/python/test_list_helm_charts.py b/tests/apitests/python/test_list_helm_charts.py index a8db08923..5b65226d5 100644 --- a/tests/apitests/python/test_list_helm_charts.py +++ b/tests/apitests/python/test_list_helm_charts.py @@ -17,7 +17,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_manage_project_member.py b/tests/apitests/python/test_manage_project_member.py index 27bd25f01..62924c346 100644 --- a/tests/apitests/python/test_manage_project_member.py +++ b/tests/apitests/python/test_manage_project_member.py @@ -19,7 +19,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_project_level_policy_content_trust.py b/tests/apitests/python/test_project_level_policy_content_trust.py index d54574a1e..f8179091a 100644 --- a/tests/apitests/python/test_project_level_policy_content_trust.py +++ b/tests/apitests/python/test_project_level_policy_content_trust.py @@ -23,7 +23,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_project_quota.py b/tests/apitests/python/test_project_quota.py index 508ba63cb..0cb4efea0 100644 --- a/tests/apitests/python/test_project_quota.py +++ b/tests/apitests/python/test_project_quota.py @@ -15,7 +15,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(cls): - print "Case completed" + print("Case completed") def testProjectQuota(self): """ diff --git a/tests/apitests/python/test_push_chart_by_helm2_helm3_with_robot_Account.py b/tests/apitests/python/test_push_chart_by_helm2_helm3_with_robot_Account.py index 0cb77f02b..5235607ca 100644 --- a/tests/apitests/python/test_push_chart_by_helm2_helm3_with_robot_Account.py +++ b/tests/apitests/python/test_push_chart_by_helm2_helm3_with_robot_Account.py @@ -31,7 +31,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDownClass(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -52,30 +52,27 @@ class TestProjects(unittest.TestCase): 1. Delete user(UA). """ - print "#1. Create user(UA);" + #1. Create user(UA); TestProjects.user_id, user_name = self.user.create_user(user_password = self.user_push_chart_password, **ADMIN_CLIENT) TestProjects.USER_CLIENT=dict(endpoint = self.url, username = user_name, password = self.user_push_chart_password) TestProjects.API_CHART_CLIENT=dict(endpoint = self.chart_api_url, username = user_name, password = self.user_push_chart_password) - print "#2. Create private project(PA) with user(UA);" + #2. Create private project(PA) with user(UA); TestProjects.project_id, TestProjects.project_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CLIENT) - print "#3. Create a new robot account(RA) with full priviliges in project(PA) with user(UA);" + #3. Create a new robot account(RA) with full priviliges in project(PA) with user(UA); robot_id, robot_account = self.project.add_project_robot_account(TestProjects.project_id, TestProjects.project_name, 2441000531 ,**TestProjects.USER_CLIENT) - print robot_account.name - print robot_account.token - - print "#4. Push chart to project(PA) by Helm2 CLI with robot account(RA);" + #4. Push chart to project(PA) by Helm2 CLI with robot account(RA);" library.helm.helm2_add_repo(self.chart_repo_name, "https://"+harbor_server, TestProjects.project_name, robot_account.name, robot_account.token) library.helm.helm2_push(self.chart_repo_name, self.chart_file, TestProjects.project_name, robot_account.name, robot_account.token) - print "#5. Get chart repositry from project(PA) successfully;" + #5. Get chart repositry from project(PA) successfully; self.chart.chart_should_exist(TestProjects.project_name, self.CHART_NAME, **TestProjects.API_CHART_CLIENT) - print "#6. Push chart to project(PA) by Helm3 CLI with robot account(RA);" + #6. Push chart to project(PA) by Helm3 CLI with robot account(RA); chart_cli_ret = library.helm.helm_chart_push_to_harbor(self.chart_file, self.archive, harbor_server, TestProjects.project_name, self.repo_name, self.verion, robot_account.name, robot_account.token) - print "chart_cli_ret:", chart_cli_ret + if __name__ == '__main__': unittest.main() diff --git a/tests/apitests/python/test_push_chart_by_helm3_chart_cli.py b/tests/apitests/python/test_push_chart_by_helm3_chart_cli.py index 2e7c653f8..efd56abda 100644 --- a/tests/apitests/python/test_push_chart_by_helm3_chart_cli.py +++ b/tests/apitests/python/test_push_chart_by_helm3_chart_cli.py @@ -30,7 +30,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDownClass(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -69,7 +69,6 @@ class TestProjects(unittest.TestCase): #3. Push an chart(CA) to Harbor by helm3 registry/chart CLI successfully; chart_cli_ret = library.helm.helm_chart_push_to_harbor(self.chart_file, self.archive, harbor_server, TestProjects.project_push_chart_name, self.repo_name, self.verion, user_name, self.user_push_chart_password) - print "chart_cli_ret:", chart_cli_ret #4. List artifacts successfully; artifacts = self.artifact.list_artifacts(TestProjects.project_push_chart_name, self.repo_name, **TestProjects.USER_CLIENT) diff --git a/tests/apitests/python/test_push_cnab_bundle.py b/tests/apitests/python/test_push_cnab_bundle.py index 3a28c006a..4c6a59fea 100644 --- a/tests/apitests/python/test_push_cnab_bundle.py +++ b/tests/apitests/python/test_push_cnab_bundle.py @@ -30,7 +30,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDownClass(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -80,7 +80,6 @@ class TestProjects(unittest.TestCase): #5. Get repository from Harbor successfully; index_data = self.repo.get_repository(TestProjects.project_push_bundle_name, self.cnab_repo_name, **TestProjects.USER_CLIENT) - print "index_data:", index_data #5.2 Cnab bundle can be pulled by ctr successfully; # This step might not successful since ctr does't support cnab fully, it might be uncomment sometime in future. diff --git a/tests/apitests/python/test_push_files_by_oras.py b/tests/apitests/python/test_push_files_by_oras.py index 3d974fc11..d04a9153b 100644 --- a/tests/apitests/python/test_push_files_by_oras.py +++ b/tests/apitests/python/test_push_files_by_oras.py @@ -25,7 +25,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -60,21 +60,17 @@ class TestProjects(unittest.TestCase): #3. ORAS CLI push artifacts; md5_list_push = library.oras.oras_push(harbor_server, user_name, user_001_password, TestProjects.project_name, self.repo_name, self.tag) - print "md5_list_push:",md5_list_push #4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by ORAS CLI; repo_data = self.repo.get_repository(TestProjects.project_name, self.repo_name, **TestProjects.USER_CLIENT) - print "repo_data:", repo_data self.assertEqual(repo_data.name, TestProjects.project_name + "/" + self.repo_name) #5. Get and verify artifacts by tag; artifact = self.artifact.get_reference_info(TestProjects.project_name, self.repo_name, self.tag, **TestProjects.USER_CLIENT) - print "artifact:", artifact self.assertEqual(artifact[0].tags[0].name, self.tag) #6. ORAS CLI pull artifacts index by tag; md5_list_pull = library.oras.oras_pull(harbor_server, user_name, user_001_password, TestProjects.project_name, self.repo_name, self.tag) - print "md5_list_pull:",md5_list_pull #7. Verfiy MD5 between artifacts pushed by ORAS and artifacts pulled by ORAS; if set(md5_list_push) != set(md5_list_pull): diff --git a/tests/apitests/python/test_push_image_with_special_name.py b/tests/apitests/python/test_push_image_with_special_name.py index 7077ed161..0211931d4 100644 --- a/tests/apitests/python/test_push_image_with_special_name.py +++ b/tests/apitests/python/test_push_image_with_special_name.py @@ -22,7 +22,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -80,7 +80,6 @@ class TestProjects(unittest.TestCase): full_name = urllib.quote(profix+"/"+image,'utf-8') artifact = self.artifact.get_reference_info(TestProjects.project_sign_image_name, (str(full_name)).encode(), tag, **TestProjects.USER_sign_image_CLIENT) - print artifact self.assertEqual(artifact[0].type, 'IMAGE') if __name__ == '__main__': diff --git a/tests/apitests/python/test_push_index_by_docker_manifest.py b/tests/apitests/python/test_push_index_by_docker_manifest.py index 8e371bb86..be30d2d5c 100644 --- a/tests/apitests/python/test_push_index_by_docker_manifest.py +++ b/tests/apitests/python/test_push_index_by_docker_manifest.py @@ -34,7 +34,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDownClass(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_push_sif_by_singularity.py b/tests/apitests/python/test_push_sif_by_singularity.py index ab67ebf61..ab91d3c0e 100644 --- a/tests/apitests/python/test_push_sif_by_singularity.py +++ b/tests/apitests/python/test_push_sif_by_singularity.py @@ -25,7 +25,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -63,12 +63,10 @@ class TestProjects(unittest.TestCase): #4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by singularity CLI; repo_data = self.repo.get_repository(TestProjects.project_name, self.repo_name, **TestProjects.USER_CLIENT) - print "repo_data:", repo_data self.assertEqual(repo_data.name, TestProjects.project_name + "/" + self.repo_name) #5. Get and verify artifacts by tag; artifact = self.artifact.get_reference_info(TestProjects.project_name, self.repo_name, self.tag, **TestProjects.USER_CLIENT) - print "artifact:", artifact self.assertEqual(artifact[0].tags[0].name, self.tag) #6. Pull sif file from harbor by singularity; diff --git a/tests/apitests/python/test_registry_api.py b/tests/apitests/python/test_registry_api.py index 40a8d9080..3a8af04d4 100644 --- a/tests/apitests/python/test_registry_api.py +++ b/tests/apitests/python/test_registry_api.py @@ -29,7 +29,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_replication_from_dockerhub.py b/tests/apitests/python/test_replication_from_dockerhub.py index ae41e6947..29fd6c2c5 100644 --- a/tests/apitests/python/test_replication_from_dockerhub.py +++ b/tests/apitests/python/test_replication_from_dockerhub.py @@ -25,7 +25,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -80,7 +80,6 @@ class TestProjects(unittest.TestCase): #3. Create a new registry; TestProjects.registry_id, _ = self.registry.create_registry("https://hub.docker.com", registry_type="docker-hub", access_key = "", access_secret = "", insecure=False, **ADMIN_CLIENT) - print "TestProjects.registry_id:", TestProjects.registry_id #4. Create a pull-based rule for this registry; TestProjects.rule_id, rule_name = self.replication.create_replication_policy(src_registry=swagger_client.Registry(id=int(TestProjects.registry_id)), @@ -99,8 +98,6 @@ class TestProjects(unittest.TestCase): #8. Check image is replicated into target project successfully. artifact = self.artifact.get_reference_info(TestProjects.project_name, self.image, self.tag, **ADMIN_CLIENT) - print artifact - if __name__ == '__main__': unittest.main() diff --git a/tests/apitests/python/test_retention.py b/tests/apitests/python/test_retention.py index 7aad5c87f..1c687515f 100644 --- a/tests/apitests/python/test_retention.py +++ b/tests/apitests/python/test_retention.py @@ -64,10 +64,8 @@ class TestProjects(unittest.TestCase): push_special_image_to_project(TestProjects.project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test4", ['1.0']) tag_data_artifact3_image1 = self.artifact.get_reference_info(TestProjects.project_src_repo_name, self.repo_name_1, "3.0", **TestProjects.USER_RA_CLIENT) - print tag_data_artifact3_image1[0].digest tag_data_artifact2_image2 = self.artifact.get_reference_info(TestProjects.project_src_repo_name, self.repo_name_2, "latest", **TestProjects.USER_RA_CLIENT) - print tag_data_artifact2_image2[0].digest tags = list_image_tags(harbor_server, TestProjects.project_src_repo_name+"/"+self.repo_name_1, user_ra_name, user_ra_password) #Delete all 2 tags of "artifact3" in repostory "image1"; @@ -114,19 +112,17 @@ class TestProjects(unittest.TestCase): #List artifacts successfully, and untagged artifact in test1 should be the only one retained; artifacts_1 = self.artifact.list_artifacts(TestProjects.project_src_repo_name, self.repo_name_1, **TestProjects.USER_RA_CLIENT) - print artifacts_1[0].digest self.assertTrue(len(artifacts_1)==1) self.assertEqual(artifacts_1[0].digest, tag_data_artifact3_image1[0].digest) #List artifacts successfully, and artifact with latest tag in test2 should be the only one retained; artifacts_2 = self.artifact.list_artifacts(TestProjects.project_src_repo_name, self.repo_name_2, **TestProjects.USER_RA_CLIENT) - print artifacts_2[0].digest self.assertTrue(len(artifacts_2)==1) self.assertEqual(artifacts_2[0].digest, tag_data_artifact2_image2[0].digest) @classmethod def tearDownClass(self): - print "Case completed" + print("Case completed") # TODO delete_repoitory will fail when no tags left anymore # @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") diff --git a/tests/apitests/python/test_robot_account.py b/tests/apitests/python/test_robot_account.py index 9c78abbbe..0be01048a 100644 --- a/tests/apitests/python/test_robot_account.py +++ b/tests/apitests/python/test_robot_account.py @@ -21,7 +21,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): @@ -74,58 +74,56 @@ class TestProjects(unittest.TestCase): image_robot_account = "alpine" tag = "latest" - print "#1. Create user(UA);" + #1. Create user(UA);" TestProjects.user_ra_id, user_ra_name = self.user.create_user(user_password = user_ra_password, **ADMIN_CLIENT) TestProjects.USER_RA_CLIENT=dict(endpoint = url, username = user_ra_name, password = user_ra_password) - print "#2. Create private project(PA), private project(PB) and public project(PC) by user(UA);" + #2. Create private project(PA), private project(PB) and public project(PC) by user(UA); TestProjects.project_ra_id_a, TestProjects.project_ra_name_a = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT) TestProjects.project_ra_id_b, TestProjects.project_ra_name_b = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT) TestProjects.project_ra_id_c, TestProjects.project_ra_name_c = self.project.create_project(metadata = {"public": "true"}, **TestProjects.USER_RA_CLIENT) - print "#3. Push image(ImagePA) to project(PA), image(ImagePB) to project(PB) and image(ImagePC) to project(PC) by user(UA);" + #3. Push image(ImagePA) to project(PA), image(ImagePB) to project(PB) and image(ImagePC) to project(PC) by user(UA); TestProjects.repo_name_in_project_a, tag_a = push_image_to_project(TestProjects.project_ra_name_a, harbor_server, user_ra_name, user_ra_password, image_project_a, tag) TestProjects.repo_name_in_project_b, tag_b = push_image_to_project(TestProjects.project_ra_name_b, harbor_server, user_ra_name, user_ra_password, image_project_b, tag) TestProjects.repo_name_in_project_c, tag_c = push_image_to_project(TestProjects.project_ra_name_c, harbor_server, user_ra_name, user_ra_password, image_project_c, tag) - print "#4. Create a new robot account(RA) with pull and push privilige in project(PA) by user(UA);" + #4. Create a new robot account(RA) with pull and push privilige in project(PA) by user(UA); robot_id, robot_account = self.project.add_project_robot_account(TestProjects.project_ra_id_a, TestProjects.project_ra_name_a, 2441000531 ,**TestProjects.USER_RA_CLIENT) - print robot_account.name - print robot_account.token - print "#5. Check robot account info, it should has both pull and push priviliges;" + #5. Check robot account info, it should has both pull and push priviliges; data = self.project.get_project_robot_account_by_id(TestProjects.project_ra_id_a, robot_id, **TestProjects.USER_RA_CLIENT) _assert_status_code(robot_account.name, data.name) - print "#6. Pull image(ImagePA) from project(PA) by robot account(RA), it must be successful;" + #6. Pull image(ImagePA) from project(PA) by robot account(RA), it must be successful; pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_a, tag_a) - print "#7. Push image(ImageRA) to project(PA) by robot account(RA), it must be successful;" + #7. Push image(ImageRA) to project(PA) by robot account(RA), it must be successful; TestProjects.repo_name_pa, _ = push_image_to_project(TestProjects.project_ra_name_a, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag) - print "#8. Push image(ImageRA) to project(PB) by robot account(RA), it must be not successful;" + #8. Push image(ImageRA) to project(PB) by robot account(RA), it must be not successful; push_image_to_project(TestProjects.project_ra_name_b, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_error_message = "unauthorized to access repository") - print "#9. Pull image(ImagePB) from project(PB) by robot account(RA), it must be not successful;" + #9. Pull image(ImagePB) from project(PB) by robot account(RA), it must be not successful; pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_b, tag_b, expected_error_message = "unauthorized to access repository") - print "#10. Pull image from project(PC), it must be successful;" + #10. Pull image from project(PC), it must be successful; pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_c, tag_c) - print "#11. Push image(ImageRA) to project(PC) by robot account(RA), it must be not successful;" + #11. Push image(ImageRA) to project(PC) by robot account(RA), it must be not successful; push_image_to_project(TestProjects.project_ra_name_c, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_error_message = "unauthorized to access repository") - print "#12. Update action property of robot account(RA);" + #12. Update action property of robot account(RA);" self.project.disable_project_robot_account(TestProjects.project_ra_id_a, robot_id, True, **TestProjects.USER_RA_CLIENT) - print "#13. Pull image(ImagePA) from project(PA) by robot account(RA), it must be not successful;" + #13. Pull image(ImagePA) from project(PA) by robot account(RA), it must be not successful; pull_harbor_image(harbor_server, robot_account.name, robot_account.token, TestProjects.repo_name_in_project_a, tag_a, expected_login_error_message = "unauthorized: authentication required") - print "#14. Push image(ImageRA) to project(PA) by robot account(RA), it must be not successful;" + #14. Push image(ImageRA) to project(PA) by robot account(RA), it must be not successful; push_image_to_project(TestProjects.project_ra_name_a, harbor_server, robot_account.name, robot_account.token, image_robot_account, tag, expected_login_error_message = "unauthorized: authentication required") - print "#15. Delete robot account(RA), it must be not successful." + #15. Delete robot account(RA), it must be not successful. self.project.delete_project_robot_account(TestProjects.project_ra_id_a, robot_id, **TestProjects.USER_RA_CLIENT) if __name__ == '__main__': diff --git a/tests/apitests/python/test_scan_image_artifact.py b/tests/apitests/python/test_scan_image_artifact.py index 93e04c76d..9ec4bedb4 100644 --- a/tests/apitests/python/test_scan_image_artifact.py +++ b/tests/apitests/python/test_scan_image_artifact.py @@ -23,7 +23,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == True, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_sign_image.py b/tests/apitests/python/test_sign_image.py index caa3482dd..4d5585594 100644 --- a/tests/apitests/python/test_sign_image.py +++ b/tests/apitests/python/test_sign_image.py @@ -23,7 +23,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_system_level_scan_all.py b/tests/apitests/python/test_system_level_scan_all.py index 20c15782b..030b30440 100644 --- a/tests/apitests/python/test_system_level_scan_all.py +++ b/tests/apitests/python/test_system_level_scan_all.py @@ -24,7 +24,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/test_user_view_logs.py b/tests/apitests/python/test_user_view_logs.py index 777b0c97b..d25bc5628 100644 --- a/tests/apitests/python/test_user_view_logs.py +++ b/tests/apitests/python/test_user_view_logs.py @@ -34,7 +34,7 @@ class TestProjects(unittest.TestCase): @classmethod def tearDown(self): self.test_result.get_final_result() - print "Case completed" + print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): diff --git a/tests/apitests/python/testutils.py b/tests/apitests/python/testutils.py index d991906c3..95067482c 100644 --- a/tests/apitests/python/testutils.py +++ b/tests/apitests/python/testutils.py @@ -53,7 +53,7 @@ class TestResult(object): def get_final_result(self): if self.num_errors > 0: for each_err_msg in self.error_message: - print "Error message:", each_err_msg + print("Error message:", each_err_msg) raise Exception(r"Test case failed with {} errors.".format(self.num_errors)) from contextlib import contextmanager diff --git a/tests/e2e-image/Dockerfile b/tests/e2e-image/Dockerfile index 820696b28..75a6bb8b6 100644 --- a/tests/e2e-image/Dockerfile +++ b/tests/e2e-image/Dockerfile @@ -48,6 +48,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ apt-get autoremove -y && \ rm -rf /var/lib/apt/lists/* +RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list && apt-get clean +RUN apt-get update -y && \ + apt-get install -y zbar-tools libzbar-dev python-zbar +RUN dpkg -L libzbar-dev; ls -l /usr/include/zbar.h +RUN apt-get update -y +RUN apt-get install -y python3.5 +RUN rm /usr/bin/python +RUN ln -s /usr/bin/python3.5 /usr/bin/python +RUN apt-get install -y python3-pip + RUN wget -N http://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip && \ unzip chromedriver_linux64.zip && \ chmod +x chromedriver && \ @@ -62,7 +72,7 @@ RUN apt-get update && apt install libnss3-tools && \ RUN wget https://bootstrap.pypa.io/get-pip.py && \ python ./get-pip.py && \ - pip install pyasn1 google-apitools==0.5.15 gsutil robotframework==3.0.4 robotframework-sshlibrary robotframework-httplibrary requests dbbot robotframework-selenium2library==4.4.0 robotframework-pabot robotframework-JSONLibrary --upgrade + pip install pyasn1 google-apitools==0.5.15 gsutil robotframework==3.2.1 robotframework-sshlibrary robotframework-httplibrary requests dbbot robotframework-seleniumlibrary==4.3.0 robotframework-pabot robotframework-JSONLibrary --upgrade # Install docker, docker compose RUN wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz && \ diff --git a/tests/resources/APITest-Util.robot b/tests/resources/APITest-Util.robot index a2b9a6857..e057de3a3 100644 --- a/tests/resources/APITest-Util.robot +++ b/tests/resources/APITest-Util.robot @@ -1,17 +1,17 @@ -*** Keywords *** -Make Swagger Client - ${rc} ${output}= Run And Return Rc And Output make swagger_client - Log ${output} - [Return] ${rc} - -Setup API Test - Retry Keyword N Times When Error 10 Make Swagger Client - -Harbor API Test - [Arguments] ${testcase_name} - ${current_dir}= Run pwd - Log To Console ${current_dir} - Log To Console ${ip} - ${rc} ${output}= Run And Return Rc And Output SWAGGER_CLIENT_PATH=${current_dir}/harborclient HARBOR_HOST=${ip} python ${testcase_name} - Log To Console ${output} +*** Keywords *** +Make Swagger Client + ${rc} ${output}= Run And Return Rc And Output make swagger_client + Log ${output} + [Return] ${rc} + +Setup API Test + Retry Keyword N Times When Error 10 Make Swagger Client + +Harbor API Test + [Arguments] ${testcase_name} + ${current_dir}= Run pwd + Log To Console ${current_dir} + Log To Console ${ip} + ${rc} ${output}= Run And Return Rc And Output SWAGGER_CLIENT_PATH=${current_dir}/harborclient HARBOR_HOST=${ip} python ${testcase_name} + Log To Console ${output} Should Be Equal As Integers ${rc} 0 \ No newline at end of file diff --git a/tests/resources/CNAB_Util.robot b/tests/resources/CNAB_Util.robot index f7f60410a..cb2735113 100644 --- a/tests/resources/CNAB_Util.robot +++ b/tests/resources/CNAB_Util.robot @@ -1,25 +1,25 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides helper functions for docker operations -Library OperatingSystem -Library Process - -*** Keywords *** -CNAB Push Bundle - [Arguments] ${ip} ${user} ${pwd} ${target} ${bundle_file} - ${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/cnab_push_bundle.sh ${ip} ${user} ${pwd} ${target} ${bundle_file} - Log ${output} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides helper functions for docker operations +Library OperatingSystem +Library Process + +*** Keywords *** +CNAB Push Bundle + [Arguments] ${ip} ${user} ${pwd} ${target} ${bundle_file} + ${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/cnab_push_bundle.sh ${ip} ${user} ${pwd} ${target} ${bundle_file} + Log ${output} Should Be Equal As Integers ${rc} 0 \ No newline at end of file diff --git a/tests/resources/Cert-Util.robot b/tests/resources/Cert-Util.robot index 3df5bd9fe..0263d7c52 100644 --- a/tests/resources/Cert-Util.robot +++ b/tests/resources/Cert-Util.robot @@ -1,116 +1,116 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource contains keywords related to creating and using certificates. Requires scripts in infra/integration-image/scripts be available in PATH - -*** Keywords *** -Generate Certificate Authority For Chrome - # add the ca to chrome trust list to enable https testing. - [Arguments] ${password}=%{HARBOR_PASSWORD} - ${rand}= Evaluate random.randint(0, 100000) modules=random - Log To Console Generate Certificate Authority For Chrome - ${rc} ${out}= Run And Return Rc And Output echo ${password} > password${rand}.ca - Log ${out} - Should Be Equal As Integers ${rc} 0 - ${rc} ${out}= Run And Return Rc And Output certutil -d sql:$HOME/.pki/nssdb -A -t TC -f password${rand}.ca -n "Harbor${rand}" -i ./harbor_ca.crt - Log ${out} - Should Be Equal As Integers ${rc} 0 - -Generate Certificate Authority - # Generates CA (private/ca.key.pem, certs/ca.cert.pem, certs/STARK_ENTERPRISES_ROOT_CA.crt) in OUT_DIR - [Arguments] ${CA_NAME}=STARK_ENTERPRISES_ROOT_CA ${OUT_DIR}=/root/ca - Log To Console Generating Certificate Authority - ${rc} ${out}= Run And Return Rc And Output generate-ca.sh -c ${CA_NAME} -d ${OUT_DIR} - Log ${out} - Should Be Equal As Integers ${rc} 0 - -Generate Wildcard Server Certificate - # Generates key and signs with CA for *.DOMAIN (csr/*.DOMAIN.csr.pem, - # private/*.DOMAIN.key.pem, certs/*.DOMAIN.cert.pem) in OUT_DIR - [Arguments] ${DOMAIN}=%{DOMAIN} ${OUT_DIR}=/root/ca ${CA_NAME}=STARK_ENTERPRISES_ROOT_CA - Log To Console Generating Wildcard Server Certificate - Run Keyword Generate Server Key And CSR *.${DOMAIN} ${OUT_DIR} - Run Keyword Sign Server CSR ${CA_NAME} *.${DOMAIN} ${OUT_DIR} - Run Keyword Create Certificate Bundle CA_NAME=${CA_NAME} SRC_DIR=${OUT_DIR} CN=*.${DOMAIN} - ${out}= Run ls -al ${OUT_DIR}/csr - Log ${out} - ${out}= Run ls -al ${OUT_DIR}/private - Log ${out} - ${out}= Run ls -al ${OUT_DIR}/certs - Log ${out} - - -Generate Server Key And CSR - # Generates key and CSR (private/DOMAIN.key.pem, csr/DOMAIN.csr.pem) in OUT_DIR - [Arguments] ${CN}=%{DOMAIN} ${OUT_DIR}=/root/ca - Log To Console Generating Server Key And CSR - ${out}= Run generate-server-key-csr.sh -d ${OUT_DIR} -n ${CN} - Log ${out} - - -Sign Server CSR - # Generates certificate signed by CA (certs/DOMAIN.cert.pem) in OUT_DIR - [Arguments] ${CA_NAME}=STARK_ENTERPRISES_ROOT_CA ${CN}=%{DOMAIN} ${OUT_DIR}=/root/ca - Log To Console Signing Server CSR - ${out}= Run sign-csr.sh -c ${CA_NAME} -d ${OUT_DIR} -n ${CN} - Log ${out} - - -Trust Certificate Authority - # Installs root certificate into trust store on Debian based distro - [Arguments] ${CRT_FILE}=/root/ca/certs/STARK_ENTERPRISES_ROOT_CA.crt - Log To Console Installing CA - ${rc} ${out}= Run And Return Rc And Output ubuntu-install-ca.sh -f ${CRT_FILE} - Should Be Equal As Integers ${rc} 0 - Log ${out} - - -Reload Default Certificate Authorities - # Reloads default certificates into trust store on Debian based distro - # Removes all user provided CAs - Log To Console Reloading Default CAs - ${rc} ${out}= Run And Return Rc And Output ubuntu-reload-cas.sh - Should Be Equal As Integers ${rc} 0 - Log ${out} - - -Create Certificate Bundle - [Arguments] ${CA_NAME}=STARK_ENTERPRISES_ROOT_CA ${SRC_DIR}=/root/ca ${OUT_FILE}=/root/ca/cert-bundle.tgz ${CN}=%{DOMAIN} ${TMP_DIR}=/root/ca/bundle - ${rc} ${out}= Run And Return Rc And Output bundle-certs.sh -c ${CA_NAME} -d ${SRC_DIR} -f ${OUT_FILE} -n ${CN} -o ${TMP_DIR} - Should Be Equal As Integers ${rc} 0 - Log ${out} - - -Get Certificate Authority CRT - # Return ascii armored certificate from file e.g. `-----BEGIN CERTIFICATE-----` - [Arguments] ${CA_CRT}=STARK_ENTERPRISES_ROOT_CA.crt ${DIR}=/root/ca/certs - ${out}= Run cat ${DIR}/${CA_CRT} - [Return] ${out} - - -Get Server Certificate - # Return ascii armored certificate from file e.g. `-----BEGIN CERTIFICATE-----` - # PEM must be provided if using a wildcard cert not specified by DOMAIN - [Arguments] ${PEM}=%{DOMAIN}.cert.pem ${DIR}=/root/ca/certs - ${out}= Run cat ${DIR}/${PEM} - [Return] ${out} - - -Get Server Key - # Return ascii armored key from file e.g. `-----BEGIN RSA PRIVATE KEY-----` - # PEM must be provided if using a wildcard cert not specified by DOMAIN - [Arguments] ${PEM}=%{DOMAIN}.key.pem ${DIR}=/root/ca/private - ${out}= Run cat ${DIR}/${PEM} - [Return] ${out} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource contains keywords related to creating and using certificates. Requires scripts in infra/integration-image/scripts be available in PATH + +*** Keywords *** +Generate Certificate Authority For Chrome + # add the ca to chrome trust list to enable https testing. + [Arguments] ${password}=%{HARBOR_PASSWORD} + ${rand}= Evaluate random.randint(0, 100000) modules=random + Log To Console Generate Certificate Authority For Chrome + ${rc} ${out}= Run And Return Rc And Output echo ${password} > password${rand}.ca + Log ${out} + Should Be Equal As Integers ${rc} 0 + ${rc} ${out}= Run And Return Rc And Output certutil -d sql:$HOME/.pki/nssdb -A -t TC -f password${rand}.ca -n "Harbor${rand}" -i ./harbor_ca.crt + Log ${out} + Should Be Equal As Integers ${rc} 0 + +Generate Certificate Authority + # Generates CA (private/ca.key.pem, certs/ca.cert.pem, certs/STARK_ENTERPRISES_ROOT_CA.crt) in OUT_DIR + [Arguments] ${CA_NAME}=STARK_ENTERPRISES_ROOT_CA ${OUT_DIR}=/root/ca + Log To Console Generating Certificate Authority + ${rc} ${out}= Run And Return Rc And Output generate-ca.sh -c ${CA_NAME} -d ${OUT_DIR} + Log ${out} + Should Be Equal As Integers ${rc} 0 + +Generate Wildcard Server Certificate + # Generates key and signs with CA for *.DOMAIN (csr/*.DOMAIN.csr.pem, + # private/*.DOMAIN.key.pem, certs/*.DOMAIN.cert.pem) in OUT_DIR + [Arguments] ${DOMAIN}=%{DOMAIN} ${OUT_DIR}=/root/ca ${CA_NAME}=STARK_ENTERPRISES_ROOT_CA + Log To Console Generating Wildcard Server Certificate + Run Keyword Generate Server Key And CSR *.${DOMAIN} ${OUT_DIR} + Run Keyword Sign Server CSR ${CA_NAME} *.${DOMAIN} ${OUT_DIR} + Run Keyword Create Certificate Bundle CA_NAME=${CA_NAME} SRC_DIR=${OUT_DIR} CN=*.${DOMAIN} + ${out}= Run ls -al ${OUT_DIR}/csr + Log ${out} + ${out}= Run ls -al ${OUT_DIR}/private + Log ${out} + ${out}= Run ls -al ${OUT_DIR}/certs + Log ${out} + + +Generate Server Key And CSR + # Generates key and CSR (private/DOMAIN.key.pem, csr/DOMAIN.csr.pem) in OUT_DIR + [Arguments] ${CN}=%{DOMAIN} ${OUT_DIR}=/root/ca + Log To Console Generating Server Key And CSR + ${out}= Run generate-server-key-csr.sh -d ${OUT_DIR} -n ${CN} + Log ${out} + + +Sign Server CSR + # Generates certificate signed by CA (certs/DOMAIN.cert.pem) in OUT_DIR + [Arguments] ${CA_NAME}=STARK_ENTERPRISES_ROOT_CA ${CN}=%{DOMAIN} ${OUT_DIR}=/root/ca + Log To Console Signing Server CSR + ${out}= Run sign-csr.sh -c ${CA_NAME} -d ${OUT_DIR} -n ${CN} + Log ${out} + + +Trust Certificate Authority + # Installs root certificate into trust store on Debian based distro + [Arguments] ${CRT_FILE}=/root/ca/certs/STARK_ENTERPRISES_ROOT_CA.crt + Log To Console Installing CA + ${rc} ${out}= Run And Return Rc And Output ubuntu-install-ca.sh -f ${CRT_FILE} + Should Be Equal As Integers ${rc} 0 + Log ${out} + + +Reload Default Certificate Authorities + # Reloads default certificates into trust store on Debian based distro + # Removes all user provided CAs + Log To Console Reloading Default CAs + ${rc} ${out}= Run And Return Rc And Output ubuntu-reload-cas.sh + Should Be Equal As Integers ${rc} 0 + Log ${out} + + +Create Certificate Bundle + [Arguments] ${CA_NAME}=STARK_ENTERPRISES_ROOT_CA ${SRC_DIR}=/root/ca ${OUT_FILE}=/root/ca/cert-bundle.tgz ${CN}=%{DOMAIN} ${TMP_DIR}=/root/ca/bundle + ${rc} ${out}= Run And Return Rc And Output bundle-certs.sh -c ${CA_NAME} -d ${SRC_DIR} -f ${OUT_FILE} -n ${CN} -o ${TMP_DIR} + Should Be Equal As Integers ${rc} 0 + Log ${out} + + +Get Certificate Authority CRT + # Return ascii armored certificate from file e.g. `-----BEGIN CERTIFICATE-----` + [Arguments] ${CA_CRT}=STARK_ENTERPRISES_ROOT_CA.crt ${DIR}=/root/ca/certs + ${out}= Run cat ${DIR}/${CA_CRT} + [Return] ${out} + + +Get Server Certificate + # Return ascii armored certificate from file e.g. `-----BEGIN CERTIFICATE-----` + # PEM must be provided if using a wildcard cert not specified by DOMAIN + [Arguments] ${PEM}=%{DOMAIN}.cert.pem ${DIR}=/root/ca/certs + ${out}= Run cat ${DIR}/${PEM} + [Return] ${out} + + +Get Server Key + # Return ascii armored key from file e.g. `-----BEGIN RSA PRIVATE KEY-----` + # PEM must be provided if using a wildcard cert not specified by DOMAIN + [Arguments] ${PEM}=%{DOMAIN}.key.pem ${DIR}=/root/ca/private + ${out}= Run cat ${DIR}/${PEM} + [Return] ${out} diff --git a/tests/resources/Docker-Util.robot b/tests/resources/Docker-Util.robot index 327707272..cc1d31856 100644 --- a/tests/resources/Docker-Util.robot +++ b/tests/resources/Docker-Util.robot @@ -1,200 +1,205 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides helper functions for docker operations -Library OperatingSystem -Library Process - -*** Keywords *** -Run Docker Info - [Arguments] ${docker-params} - Wait Unitl Command Success docker ${docker-params} info - -Pull image - [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag}=${null} ${is_robot}=${false} - Log To Console \nRunning docker pull ${image}... - ${image_with_tag}= Set Variable If '${tag}'=='${null}' ${image} ${image}:${tag} - Run Keyword If ${is_robot}==${false} Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} - ... ELSE Wait Unitl Command Success docker login -u robot\\\$${user} -p ${pwd} ${ip} - ${output}= Docker Pull ${ip}/${project}/${image_with_tag} - Log ${output} - Log To Console ${output} - Should Contain ${output} Digest: - Should Contain ${output} Status: - Should Not Contain ${output} No such image: - -Push image - # If no tag provided in $(image_with_or_without_tag}, latest will be the tag pulled from docker-hub or read from local - [Arguments] ${ip} ${user} ${pwd} ${project} ${image_with_or_without_tag} ${need_pull_first}=${true} ${sha256}=${null} ${is_robot}=${false} - ${d}= Get Current Date result_format=%m%s - ${image_in_use}= Set Variable If '${sha256}'=='${null}' ${image_with_or_without_tag} ${image_with_or_without_tag}@sha256:${sha256} - ${image_in_use_with_tag}= Set Variable If '${sha256}'=='${null}' ${image_with_or_without_tag} ${image_with_or_without_tag}:${sha256} - Sleep 3 - Log To Console \nRunning docker push ${image_with_or_without_tag}... - ${image_in_use}= Set Variable If ${need_pull_first}==${true} ${image_in_use} ${image_with_or_without_tag} - Run Keyword If ${need_pull_first}==${true} Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image_in_use} - Run Keyword If ${is_robot}==${false} Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} - ... ELSE Wait Unitl Command Success docker login -u robot\\\$${user} -p ${pwd} ${ip} - Run Keyword If ${need_pull_first}==${true} Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image_in_use} ${ip}/${project}/${image_in_use_with_tag} - ... ELSE Wait Unitl Command Success docker tag ${image_in_use} ${ip}/${project}/${image_in_use_with_tag} - Wait Unitl Command Success docker push ${ip}/${project}/${image_in_use_with_tag} - Wait Unitl Command Success docker logout ${ip} - Sleep 1 - -Push Image With Tag -#tag1 is tag of image on docker hub,default latest,use a existed version if you do not want to use latest - [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag} ${tag1}=latest - Log To Console \nRunning docker push ${image}... - Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image}:${tag1} - Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} - Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image}:${tag1} ${ip}/${project}/${image}:${tag} - Wait Unitl Command Success docker push ${ip}/${project}/${image}:${tag} - Wait Unitl Command Success docker logout ${ip} - -Cannot Docker Login Harbor - [Arguments] ${ip} ${user} ${pwd} - Command Should be Failed docker login -u ${user} -p ${pwd} ${ip} - -Cannot Pull Image - [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag}=${null} ${err_msg}=${null} - ${image_with_tag}= Set Variable If '${tag}'=='${null}' ${image} ${image}:${tag} - Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} - :FOR ${idx} IN RANGE 0 30 - \ ${out} Run Keyword And Ignore Error Command Should be Failed docker pull ${ip}/${project}/${image_with_tag} - \ Exit For Loop If '${out[0]}'=='PASS' - \ Sleep 3 - Log To Console Cannot Pull Image - Pull Log: ${out[1]} - Should Be Equal As Strings '${out[0]}' 'PASS' - Run Keyword If '${err_msg}' != '${null}' Should Contain ${out[1]} ${err_msg} - -Cannot Pull Unsigned Image - [Arguments] ${ip} ${user} ${pass} ${proj} ${imagewithtag} - Wait Unitl Command Success docker login -u ${user} -p ${pass} ${ip} - ${output}= Command Should be Failed docker pull ${ip}/${proj}/${imagewithtag} - Log To Console ${output} - Should Contain ${output} The image is not signed in Notary - -Cannot Push image - [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${err_msg}=${null} ${err_msg_2}=${null} - Log To Console \nRunning docker push ${image}... - Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image} - Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} - Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image} ${ip}/${project}/${image} - ${output}= Command Should be Failed docker push ${ip}/${project}/${image} - Run Keyword If '${err_msg}' != '${null}' Should Contain ${output} ${err_msg} - Run Keyword If '${err_msg_2}' != '${null}' Should Contain ${output} ${err_msg_2} - Wait Unitl Command Success docker logout ${ip} - -Wait Until Container Stops - [Arguments] ${container} - :FOR ${idx} IN RANGE 0 60 - \ ${out}= Run docker %{VCH-PARAMS} inspect ${container} | grep Status - \ ${status}= Run Keyword And Return Status Should Contain ${out} exited - \ Return From Keyword If ${status} - \ Sleep 1 - Fail Container did not stop within 60 seconds - -Hit Nginx Endpoint - [Arguments] ${vch-ip} ${port} - Wait Unitl Command Success wget ${vch-ip}:${port} - -Get Container IP - [Arguments] ${docker-params} ${id} ${network}=default ${dockercmd}=docker - ${ip}= Wait Unitl Command Success ${dockercmd} ${docker-params} network inspect ${network} | jq '.[0].Containers."${id}".IPv4Address' | cut -d \\" -f 2 | cut -d \\/ -f 1 - [Return] ${ip} - -# The local dind version is embedded in Dockerfile -# docker:1.13-dind -# If you are running this keyword in a container, make sure it is run with --privileged turned on -Start Docker Daemon Locally - ${pid}= Run pidof dockerd - #${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/docker_config.sh - #Log ${output} - #Should Be Equal As Integers ${rc} 0 - Return From Keyword If '${pid}' != '${EMPTY}' - OperatingSystem.File Should Exist /usr/local/bin/dockerd-entrypoint.sh - ${handle}= Start Process /usr/local/bin/dockerd-entrypoint.sh dockerd>./daemon-local.log 2>&1 shell=True - Process Should Be Running ${handle} - :FOR ${IDX} IN RANGE 5 - \ ${pid}= Run pidof dockerd - \ Exit For Loop If '${pid}' != '${EMPTY}' - \ Sleep 2s - Sleep 2s - [Return] ${handle} - -Prepare Docker Cert - [Arguments] ${ip} - Wait Unitl Command Success mkdir -p /etc/docker/certs.d/${ip} - Wait Unitl Command Success cp harbor_ca.crt /etc/docker/certs.d/${ip} - Wait Unitl Command Success cp harbor_ca.crt /usr/local/share/ca-certificates/ - Wait Unitl Command Success update-ca-certificates - -Kill Local Docker Daemon - [Arguments] ${handle} ${dockerd-pid} - Terminate Process ${handle} - Process Should Be Stopped ${handle} - Wait Unitl Command Success kill -9 ${dockerd-pid} - -Docker Login Fail - [Arguments] ${ip} ${user} ${pwd} - Log To Console \nRunning docker login ${ip} ... - ${output}= Command Should be Failed docker login -u ${user} -p ${pwd} ${ip} - Should Contain ${output} unauthorized - Should Not Contain ${output} 500 Internal Server Error - -Docker Login - [Arguments] ${server} ${username} ${password} - Wait Unitl Command Success docker login -u ${username} -p ${password} ${server} - -Docker Pull - [Arguments] ${image} - ${output}= Retry Keyword N Times When Error 10 Wait Unitl Command Success docker pull ${image} - Log ${output} - Log To Console Docker Pull: \n ${output} - [Return] ${output} - -Docker Tag - [Arguments] ${src_image} ${dst_image} - Wait Unitl Command Success docker tag ${src_image} ${dst_image} - -Docker Push - [Arguments] ${image} - Wait Unitl Command Success docker push ${image} - -Docker Push Index - [Arguments] ${ip} ${user} ${pwd} ${index} ${image1} ${image2} - ${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/docker_push_manifest_list.sh ${ip} ${user} ${pwd} ${index} ${image1} ${image2} - Log ${output} - Should Be Equal As Integers ${rc} 0 - -Docker Image Can Not Be Pulled - [Arguments] ${image} - :FOR ${idx} IN RANGE 0 30 - \ ${out}= Run Keyword And Ignore Error Command Should be Failed docker pull ${image} - \ Exit For Loop If '${out[0]}'=='PASS' - \ Sleep 3 - Log To Console Cannot Pull Image From Docker - Pull Log: ${out[1]} - Should Be Equal As Strings '${out[0]}' 'PASS' - -Docker Image Can Be Pulled - [Arguments] ${image} ${period}=60 ${times}=10 - :For ${n} IN RANGE 1 ${times} - \ Sleep ${period} - \ ${out}= Run Keyword And Ignore Error Docker Pull ${image} - \ Log To Console Return value is ${out[0]} - \ Exit For Loop If '${out[0]}'=='PASS' - \ Sleep 5 - Run Keyword If '${out[0]}'=='FAIL' Capture Page Screenshot +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides helper functions for docker operations +Library OperatingSystem +Library Process + +*** Keywords *** +Run Docker Info + [Arguments] ${docker-params} + Wait Unitl Command Success docker ${docker-params} info + +Pull image + [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag}=${null} ${is_robot}=${false} + Log To Console \nRunning docker pull ${image}... + ${image_with_tag}= Set Variable If '${tag}'=='${null}' ${image} ${image}:${tag} + Run Keyword If ${is_robot}==${false} Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} + ... ELSE Wait Unitl Command Success docker login -u robot\\\$${user} -p ${pwd} ${ip} + ${output}= Docker Pull ${ip}/${project}/${image_with_tag} + Log ${output} + Log To Console ${output} + Should Contain ${output} Digest: + Should Contain ${output} Status: + Should Not Contain ${output} No such image: + +Push image + # If no tag provided in $(image_with_or_without_tag}, latest will be the tag pulled from docker-hub or read from local + [Arguments] ${ip} ${user} ${pwd} ${project} ${image_with_or_without_tag} ${need_pull_first}=${true} ${sha256}=${null} ${is_robot}=${false} + ${d}= Get Current Date result_format=%m%s + ${image_in_use}= Set Variable If '${sha256}'=='${null}' ${image_with_or_without_tag} ${image_with_or_without_tag}@sha256:${sha256} + ${image_in_use_with_tag}= Set Variable If '${sha256}'=='${null}' ${image_with_or_without_tag} ${image_with_or_without_tag}:${sha256} + Sleep 3 + Log To Console \nRunning docker push ${image_with_or_without_tag}... + ${image_in_use}= Set Variable If ${need_pull_first}==${true} ${image_in_use} ${image_with_or_without_tag} + Run Keyword If ${need_pull_first}==${true} Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image_in_use} + Run Keyword If ${is_robot}==${false} Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} + ... ELSE Wait Unitl Command Success docker login -u robot\\\$${user} -p ${pwd} ${ip} + Run Keyword If ${need_pull_first}==${true} Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image_in_use} ${ip}/${project}/${image_in_use_with_tag} + ... ELSE Wait Unitl Command Success docker tag ${image_in_use} ${ip}/${project}/${image_in_use_with_tag} + Wait Unitl Command Success docker push ${ip}/${project}/${image_in_use_with_tag} + Wait Unitl Command Success docker logout ${ip} + Sleep 1 + +Push Image With Tag +#tag1 is tag of image on docker hub,default latest,use a existed version if you do not want to use latest + [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag} ${tag1}=latest + Log To Console \nRunning docker push ${image}... + Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image}:${tag1} + Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} + Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image}:${tag1} ${ip}/${project}/${image}:${tag} + Wait Unitl Command Success docker push ${ip}/${project}/${image}:${tag} + Wait Unitl Command Success docker logout ${ip} + +Cannot Docker Login Harbor + [Arguments] ${ip} ${user} ${pwd} + Command Should be Failed docker login -u ${user} -p ${pwd} ${ip} + +Cannot Pull Image + [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag}=${null} ${err_msg}=${null} + ${image_with_tag}= Set Variable If '${tag}'=='${null}' ${image} ${image}:${tag} + Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} + FOR ${idx} IN RANGE 0 30 + ${out} Run Keyword And Ignore Error Command Should be Failed docker pull ${ip}/${project}/${image_with_tag} + Exit For Loop If '${out[0]}'=='PASS' + Sleep 3 + END + Log To Console Cannot Pull Image - Pull Log: ${out[1]} + Should Be Equal As Strings '${out[0]}' 'PASS' + Run Keyword If '${err_msg}' != '${null}' Should Contain ${out[1]} ${err_msg} + +Cannot Pull Unsigned Image + [Arguments] ${ip} ${user} ${pass} ${proj} ${imagewithtag} + Wait Unitl Command Success docker login -u ${user} -p ${pass} ${ip} + ${output}= Command Should be Failed docker pull ${ip}/${proj}/${imagewithtag} + Log To Console ${output} + Should Contain ${output} The image is not signed in Notary + +Cannot Push image + [Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${err_msg}=${null} ${err_msg_2}=${null} + Log To Console \nRunning docker push ${image}... + Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image} + Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip} + Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image} ${ip}/${project}/${image} + ${output}= Command Should be Failed docker push ${ip}/${project}/${image} + Run Keyword If '${err_msg}' != '${null}' Should Contain ${output} ${err_msg} + Run Keyword If '${err_msg_2}' != '${null}' Should Contain ${output} ${err_msg_2} + Wait Unitl Command Success docker logout ${ip} + +Wait Until Container Stops + [Arguments] ${container} + FOR ${idx} IN RANGE 0 60 + ${out}= Run docker %{VCH-PARAMS} inspect ${container} | grep Status + ${status}= Run Keyword And Return Status Should Contain ${out} exited + Return From Keyword If ${status} + Sleep 1 + END + Fail Container did not stop within 60 seconds + +Hit Nginx Endpoint + [Arguments] ${vch-ip} ${port} + Wait Unitl Command Success wget ${vch-ip}:${port} + +Get Container IP + [Arguments] ${docker-params} ${id} ${network}=default ${dockercmd}=docker + ${ip}= Wait Unitl Command Success ${dockercmd} ${docker-params} network inspect ${network} | jq '.[0].Containers."${id}".IPv4Address' | cut -d \\" -f 2 | cut -d \\/ -f 1 + [Return] ${ip} + +# The local dind version is embedded in Dockerfile +# docker:1.13-dind +# If you are running this keyword in a container, make sure it is run with --privileged turned on +Start Docker Daemon Locally + ${pid}= Run pidof dockerd + #${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/docker_config.sh + #Log ${output} + #Should Be Equal As Integers ${rc} 0 + Return From Keyword If '${pid}' != '${EMPTY}' + OperatingSystem.File Should Exist /usr/local/bin/dockerd-entrypoint.sh + ${handle}= Start Process /usr/local/bin/dockerd-entrypoint.sh dockerd>./daemon-local.log 2>&1 shell=True + Process Should Be Running ${handle} + FOR ${IDX} IN RANGE 5 + ${pid}= Run pidof dockerd + Exit For Loop If '${pid}' != '${EMPTY}' + Sleep 2s + END + Sleep 2s + [Return] ${handle} + +Prepare Docker Cert + [Arguments] ${ip} + Wait Unitl Command Success mkdir -p /etc/docker/certs.d/${ip} + Wait Unitl Command Success cp harbor_ca.crt /etc/docker/certs.d/${ip} + Wait Unitl Command Success cp harbor_ca.crt /usr/local/share/ca-certificates/ + Wait Unitl Command Success update-ca-certificates + +Kill Local Docker Daemon + [Arguments] ${handle} ${dockerd-pid} + Terminate Process ${handle} + Process Should Be Stopped ${handle} + Wait Unitl Command Success kill -9 ${dockerd-pid} + +Docker Login Fail + [Arguments] ${ip} ${user} ${pwd} + Log To Console \nRunning docker login ${ip} ... + ${output}= Command Should be Failed docker login -u ${user} -p ${pwd} ${ip} + Should Contain ${output} unauthorized + Should Not Contain ${output} 500 Internal Server Error + +Docker Login + [Arguments] ${server} ${username} ${password} + Wait Unitl Command Success docker login -u ${username} -p ${password} ${server} + +Docker Pull + [Arguments] ${image} + ${output}= Retry Keyword N Times When Error 10 Wait Unitl Command Success docker pull ${image} + Log ${output} + Log To Console Docker Pull: \n ${output} + [Return] ${output} + +Docker Tag + [Arguments] ${src_image} ${dst_image} + Wait Unitl Command Success docker tag ${src_image} ${dst_image} + +Docker Push + [Arguments] ${image} + Wait Unitl Command Success docker push ${image} + +Docker Push Index + [Arguments] ${ip} ${user} ${pwd} ${index} ${image1} ${image2} + ${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/docker_push_manifest_list.sh ${ip} ${user} ${pwd} ${index} ${image1} ${image2} + Log ${output} + Should Be Equal As Integers ${rc} 0 + +Docker Image Can Not Be Pulled + [Arguments] ${image} + FOR ${idx} IN RANGE 0 30 + ${out}= Run Keyword And Ignore Error Command Should be Failed docker pull ${image} + Exit For Loop If '${out[0]}'=='PASS' + Sleep 3 + END + Log To Console Cannot Pull Image From Docker - Pull Log: ${out[1]} + Should Be Equal As Strings '${out[0]}' 'PASS' + +Docker Image Can Be Pulled + [Arguments] ${image} ${period}=60 ${times}=10 + FOR ${n} IN RANGE 1 ${times} + Sleep ${period} + ${out}= Run Keyword And Ignore Error Docker Pull ${image} + Log To Console Return value is ${out[0]} + Exit For Loop If '${out[0]}'=='PASS' + Sleep 5 + END + Run Keyword If '${out[0]}'=='FAIL' Capture Page Screenshot Should Be Equal As Strings '${out[0]}' 'PASS' \ No newline at end of file diff --git a/tests/resources/Drone-Util.robot b/tests/resources/Drone-Util.robot index d9befdd86..5954eee3c 100644 --- a/tests/resources/Drone-Util.robot +++ b/tests/resources/Drone-Util.robot @@ -1,31 +1,31 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource contains any keywords related to using the Drone CI Build System - -*** Keywords *** -Get State Of Drone Build - [Arguments] ${num} - Return From Keyword If '${num}' == '0' local - ${out}= Run drone build info vmware/vic ${num} - ${lines}= Split To Lines ${out} - [Return] @{lines}[2] - -Get Title of Drone Build - [Arguments] ${num} - Return From Keyword If '${num}' == '0' local - ${out}= Run drone build info vmware/vic ${num} - ${lines}= Split To Lines ${out} - [Return] @{lines}[-1] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource contains any keywords related to using the Drone CI Build System + +*** Keywords *** +Get State Of Drone Build + [Arguments] ${num} + Return From Keyword If '${num}' == '0' local + ${out}= Run drone build info vmware/vic ${num} + ${lines}= Split To Lines ${out} + [Return] @{lines}[2] + +Get Title of Drone Build + [Arguments] ${num} + Return From Keyword If '${num}' == '0' local + ${out}= Run drone build info vmware/vic ${num} + ${lines}= Split To Lines ${out} + [Return] @{lines}[-1] diff --git a/tests/resources/Github-Util.robot b/tests/resources/Github-Util.robot index 1ee6a7644..aa1685ebc 100644 --- a/tests/resources/Github-Util.robot +++ b/tests/resources/Github-Util.robot @@ -1,28 +1,29 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides keywords to interact with Github - -*** Keywords *** -Get State Of Github Issue - [Arguments] ${num} - [Tags] secret - :FOR ${idx} IN RANGE 0 5 - \ ${status} ${result}= Run Keyword And Ignore Error Get https://api.github.com/repos/vmware/vic/issues/${num}?access_token\=%{GITHUB_AUTOMATION_API_KEY} - \ Exit For Loop If '${status}' - \ Sleep 1 - Should Be Equal ${result.status_code} ${200} - ${status}= Get From Dictionary ${result.json()} state - [Return] ${status} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides keywords to interact with Github + +*** Keywords *** +Get State Of Github Issue + [Arguments] ${num} + [Tags] secret + FOR ${idx} IN RANGE 0 5 + ${status} ${result}= Run Keyword And Ignore Error Get https://api.github.com/repos/vmware/vic/issues/${num}?access_token\=%{GITHUB_AUTOMATION_API_KEY} + Exit For Loop If '${status}' + Sleep 1 + END + Should Be Equal ${result.status_code} ${200} + ${status}= Get From Dictionary ${result.json()} state + [Return] ${status} diff --git a/tests/resources/Harbor-Pages/Administration-Users.robot b/tests/resources/Harbor-Pages/Administration-Users.robot index 86ba32f51..f5a9b84d7 100644 --- a/tests/resources/Harbor-Pages/Administration-Users.robot +++ b/tests/resources/Harbor-Pages/Administration-Users.robot @@ -1,60 +1,60 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -Assign User Admin - [Arguments] ${user} - Retry Element Click xpath=//harbor-user//hbr-filter//clr-icon - Input Text xpath=//harbor-user//hbr-filter//input ${user} - Sleep 2 - #select checkbox - Retry Element Click //clr-dg-row[contains(.,'${user}')]//label - #click assign admin - Retry Element Click //*[@id='set-admin'] - Sleep 1 - -Switch to User Tag - Retry Element Click xpath=${administration_user_tag_xpath} - Sleep 1 - -Administration Tag Should Display - Retry Wait Until Page Contains Element xpath=${administration_tag_xpath} - -User Email Should Exist - [Arguments] ${email} - Sign In Harbor ${HARBOR_URL} %{HARBOR_ADMIN} %{HARBOR_PASSWORD} - Switch to User Tag - Retry Wait Until Page Contains Element xpath=//clr-dg-cell[contains(., '${email}')] - -Add User Button Should Be Disabled - Sleep 1 - Retry Wait Until Page Contains Element //button[contains(.,'New') and @disabled=''] - -Add A New User - [Arguments] ${username} ${email} ${realname} ${newPassword} ${comment} - Retry Element Click xpath=${add_new_user_button} - Retry Text Input xpath=${username_xpath} ${username} - Retry Text Input xpath=${email_xpath} ${email} - Retry Text Input xpath=${realname_xpath} ${realname} - Retry Text Input xpath=${newPassword_xpath} ${newPassword} - Retry Text Input xpath=${confirmPassword_xpath} ${newPassword} - Retry Text Input xpath=${comment_xpath} ${comment} - Retry Double Keywords When Error Retry Element Click xpath=${save_new_user_button} Retry Wait Until Page Not Contains Element xpath=${save_new_user_button} - Retry Wait Until Page Contains Element xpath=//harbor-user//clr-dg-row//clr-dg-cell[contains(., '${username}')] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +Assign User Admin + [Arguments] ${user} + Retry Element Click xpath=//harbor-user//hbr-filter//clr-icon + Input Text xpath=//harbor-user//hbr-filter//input ${user} + Sleep 2 + #select checkbox + Retry Element Click //clr-dg-row[contains(.,'${user}')]//label + #click assign admin + Retry Element Click //*[@id='set-admin'] + Sleep 1 + +Switch to User Tag + Retry Element Click xpath=${administration_user_tag_xpath} + Sleep 1 + +Administration Tag Should Display + Retry Wait Until Page Contains Element xpath=${administration_tag_xpath} + +User Email Should Exist + [Arguments] ${email} + Sign In Harbor ${HARBOR_URL} %{HARBOR_ADMIN} %{HARBOR_PASSWORD} + Switch to User Tag + Retry Wait Until Page Contains Element xpath=//clr-dg-cell[contains(., '${email}')] + +Add User Button Should Be Disabled + Sleep 1 + Retry Wait Until Page Contains Element //button[contains(.,'New') and @disabled=''] + +Add A New User + [Arguments] ${username} ${email} ${realname} ${newPassword} ${comment} + Retry Element Click xpath=${add_new_user_button} + Retry Text Input xpath=${username_xpath} ${username} + Retry Text Input xpath=${email_xpath} ${email} + Retry Text Input xpath=${realname_xpath} ${realname} + Retry Text Input xpath=${newPassword_xpath} ${newPassword} + Retry Text Input xpath=${confirmPassword_xpath} ${newPassword} + Retry Text Input xpath=${comment_xpath} ${comment} + Retry Double Keywords When Error Retry Element Click xpath=${save_new_user_button} Retry Wait Until Page Not Contains Element xpath=${save_new_user_button} + Retry Wait Until Page Contains Element xpath=//harbor-user//clr-dg-row//clr-dg-cell[contains(., '${username}')] diff --git a/tests/resources/Harbor-Pages/Administration-Users_Elements.robot b/tests/resources/Harbor-Pages/Administration-Users_Elements.robot index 9b950d179..3e780ef54 100644 --- a/tests/resources/Harbor-Pages/Administration-Users_Elements.robot +++ b/tests/resources/Harbor-Pages/Administration-Users_Elements.robot @@ -1,22 +1,22 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${administration_user_tag_xpath} //clr-vertical-nav-group-children/a[contains(.,'Users')] -${administration_tag_xpath} //clr-vertical-nav-group[contains(.,'Admin')] -${add_new_user_button} //*[@id='add-new-user'] -${save_new_user_button} //*[@id='save-button'] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${administration_user_tag_xpath} //clr-vertical-nav-group-children/a[contains(.,'Users')] +${administration_tag_xpath} //clr-vertical-nav-group[contains(.,'Admin')] +${add_new_user_button} //*[@id='add-new-user'] +${save_new_user_button} //*[@id='save-button'] diff --git a/tests/resources/Harbor-Pages/Configuration.robot b/tests/resources/Harbor-Pages/Configuration.robot index 2d9b603a3..34e32a147 100644 --- a/tests/resources/Harbor-Pages/Configuration.robot +++ b/tests/resources/Harbor-Pages/Configuration.robot @@ -1,354 +1,355 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -Init LDAP - ${rc} ${output}= Run And Return Rc And Output ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}' - Log ${output} - Sleep 2 - Input Text xpath=//*[@id='ldapUrl'] ldaps://${output} - Sleep 1 - Input Text xpath=//*[@id='ldapSearchDN'] cn=admin,dc=example,dc=com - Sleep 1 - Input Text xpath=//*[@id='ldapSearchPwd'] admin - Sleep 1 - Input Text xpath=//*[@id='ldapBaseDN'] dc=example,dc=com - Sleep 1 - Input Text xpath=//*[@id='ldapFilter'] (&(objectclass=inetorgperson)(memberof=cn=harbor_users,ou=groups,dc=example,dc=com)) - Sleep 1 - Input Text xpath=//*[@id='ldapUid'] cn - Sleep 1 - Capture Page Screenshot - Disable Ldap Verify Cert Checkbox - Retry Element Click xpath=${config_auth_save_button_xpath} - Sleep 2 - Retry Element Click xpath=/html/body/harbor-app/harbor-shell/clr-main-container/div/div/config/div/div/div/button[3] - Sleep 1 - Capture Page Screenshot - -Switch To Configure - Retry Element Click xpath=${configuration_xpath} - Sleep 2 - -Test Ldap Connection - ${rc} ${output}= Run And Return Rc And Output ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}' - Log ${output} - Sleep 2 - Input Text xpath=//*[@id='ldapUrl'] ldaps://${output} - Sleep 1 - Input Text xpath=//*[@id='ldapSearchDN'] cn=admin,dc=example,dc=com - Sleep 1 - Input Text xpath=//*[@id='ldapSearchPwd'] admin - Sleep 1 - Input Text xpath=//*[@id='ldapBaseDN'] dc=example,dc=com - Sleep 1 - Input Text xpath=//*[@id='ldapUid'] cn - Sleep 1 - - # default is checked, click test connection to verify fail as no cert. - Retry Element Click xpath=${test_ldap_xpath} - Sleep 1 - Wait Until Page Contains Failed to verify LDAP server with error - Sleep 5 - - Disable Ldap Verify Cert Checkbox - # ldap checkbox unchecked, click test connection to verify success. - Sleep 1 - Retry Element Click xpath=${test_ldap_xpath} - Capture Page Screenshot - Wait Until Page Contains Connection to LDAP server is verified timeout=15 - -Test LDAP Server Success - Retry Element Click xpath=${test_ldap_xpath} - Wait Until Page Contains Connection to LDAP server is verified timeout=15 - -Disable Ldap Verify Cert Checkbox - Mouse Down xpath=//*[@id='clr-checkbox-ldapVerifyCert'] - Mouse Up xpath=//*[@id='clr-checkbox-ldapVerifyCert'] - Sleep 2 - Capture Page Screenshot - Ldap Verify Cert Checkbox Should Be Disabled - -Ldap Verify Cert Checkbox Should Be Disabled - Checkbox Should Not Be Selected xpath=//*[@id='clr-checkbox-ldapVerifyCert'] - -Set Pro Create Admin Only - #set limit to admin only - Retry Element Click xpath=${configuration_xpath} - Sleep 2 - Retry Element Click xpath=${configuration_system_tabsheet_id} - Sleep 1 - Retry Element Click xpath=//select[@id='proCreation'] - Retry Element Click xpath=//select[@id='proCreation']//option[@value='adminonly'] - Sleep 1 - Retry Element Click xpath=${config_system_save_button_xpath} - Capture Page Screenshot AdminCreateOnly.png - -Set Pro Create Every One - Retry Element Click xpath=${configuration_xpath} - sleep 1 - #set limit to Every One - Retry Element Click xpath=${configuration_system_tabsheet_id} - Sleep 1 - Retry Element Click xpath=//select[@id='proCreation'] - Retry Element Click xpath=//select[@id='proCreation']//option[@value='everyone'] - Sleep 1 - Retry Element Click xpath=${config_system_save_button_xpath} - Sleep 2 - Capture Page Screenshot EveryoneCreate.png - -Disable Self Reg - Retry Element Click xpath=${configuration_xpath} - Mouse Down xpath=${self_reg_xpath} - Mouse Up xpath=${self_reg_xpath} - Sleep 1 - Self Reg Should Be Disabled - Retry Element Click xpath=${config_auth_save_button_xpath} - Capture Page Screenshot DisableSelfReg.png - Sleep 1 - -Enable Self Reg - Mouse Down xpath=${self_reg_xpath} - Mouse Up xpath=${self_reg_xpath} - Sleep 1 - Self Reg Should Be Enabled - Retry Element Click xpath=${config_auth_save_button_xpath} - Capture Page Screenshot EnableSelfReg.png - Sleep 1 - -Self Reg Should Be Disabled - Checkbox Should Not Be Selected xpath=${self_reg_xpath} - -Self Reg Should Be Enabled - Checkbox Should Be Selected xpath=${self_reg_xpath} - -Project Creation Should Display - Retry Wait Until Page Contains Element xpath=${project_create_xpath} - -Project Creation Should Not Display - Retry Wait Until Page Not Contains Element xpath=${project_create_xpath} - -## System settings -Switch To System Settings - Sleep 1 - Retry Element Click xpath=${configuration_xpath} - Retry Element Click xpath=${configuration_system_tabsheet_id} - Sleep 1 - -Switch To Project Quotas - Sleep 1 - Retry Element Click xpath=${configuration_xpath} - Sleep 1 - Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Project Quotas')] - Sleep 1 - -Modify Token Expiration - [Arguments] ${minutes} - Input Text xpath=//*[@id='tokenExpiration'] ${minutes} - Click Button xpath=${config_system_save_button_xpath} - Sleep 1 - -Token Must Be Match - [Arguments] ${minutes} - Textfield Value Should Be xpath=//*[@id='tokenExpiration'] ${minutes} - -Robot Account Token Must Be Match - [Arguments] ${days} - Textfield Value Should Be xpath=//*[@id='robotTokenExpiration'] ${days} - -## Replication -Check Verify Remote Cert - Mouse Down xpath=//*[@id='clr-checkbox-verifyRemoteCert'] - Mouse Up xpath=//*[@id='clr-checkbox-verifyRemoteCert'] - Retry Element Click xpath=${config_save_button_xpath} - Capture Page Screenshot RemoteCert.png - Sleep 1 - -Switch To System Replication - Sleep 1 - Switch To Configure - Retry Element Click xpath=//*[@id='config-replication'] - Sleep 1 - -Should Verify Remote Cert Be Enabled - Checkbox Should Not Be Selected xpath=//*[@id='clr-checkbox-verifyRemoteCert'] - -## Email -Switch To Email - Switch To Configure - Retry Element Click xpath=//*[@id='config-email'] - Sleep 1 - -Config Email - Input Text xpath=//*[@id='mailServer'] smtp.vmware.com - Input Text xpath=//*[@id='emailPort'] 25 - Input Text xpath=//*[@id='emailUsername'] example@vmware.com - Input Text xpath=//*[@id='emailPassword'] example - Input Text xpath=//*[@id='emailFrom'] example - Sleep 1 - Retry Element Click xpath=//*[@id='emailSSL-wrapper']/label - Sleep 1 - Retry Element Click xpath=//*[@id='emailInsecure-wrapper']/label - Sleep 1 - Retry Element Click xpath=${config_email_save_button_xpath} - Sleep 6 - -Verify Email - Textfield Value Should Be xpath=//*[@id='mailServer'] smtp.vmware.com - Textfield Value Should Be xpath=//*[@id='emailPort'] 25 - Textfield Value Should Be xpath=//*[@id='emailUsername'] example@vmware.com - Textfield Value Should Be xpath=//*[@id='emailFrom'] example - Checkbox Should Be Selected xpath=//*[@id='emailSSL'] - Checkbox Should Not Be Selected xpath=//*[@id='emailInsecure'] - -Set Scan All To None - Retry Element Click //vulnerability-config//select - Retry Element Click //vulnerability-config//select/option[@value='none'] - sleep 1 - Retry Element Click ${vulnerbility_save_button_xpath} - -Set Scan All To Daily - Retry Element Click //vulnerability-config//select - Retry Element Click //vulnerability-config//select/option[@value='daily'] - sleep 1 - Retry Element Click ${vulnerbility_save_button_xpath} - -Click Scan Now - Retry Element Click //vulnerability-config//button[contains(.,'SCAN')] - - -Enable Read Only - ${rc} ${output}= Run And Return Rc And Output curl -u admin:Harbor12345 -s --insecure -H "Content-Type: application/json" -X PUT -d '{"read_only":true}' "https://${ip}/api/v2.0/configurations" - Log To Console ${output} - Should Be Equal As Integers ${rc} 0 - -Disable Read Only - ${rc} ${output}= Run And Return Rc And Output curl -u admin:Harbor12345 -s --insecure -H "Content-Type: application/json" -X PUT -d '{"read_only":false}' "https://${ip}/api/v2.0/configurations" - Log To Console ${output} - Should Be Equal As Integers ${rc} 0 - -## System labels -Switch To System Labels - Sleep 1 - Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Labels')] - -## System labels -Switch To Configuration System Setting - Sleep 1 - Retry Element Click xpath=${configuration_xpath} - Retry Element Click xpath=${configuration_system_tabsheet_id} - -Switch To Configuration Project Quotas - Sleep 1 - Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Project Quotas')] - -Create New Labels - [Arguments] ${labelname} - Retry Element Click xpath=//button[contains(.,'New Label')] - Sleep 1 - Input Text xpath=//*[@id='name'] ${labelname} - Sleep 1 - Retry Element Click xpath=//hbr-create-edit-label//clr-dropdown/clr-icon - Sleep 1 - Retry Element Click xpath=//hbr-create-edit-label//clr-dropdown-menu/label[1] - Sleep 1 - Input Text xpath=//*[@id='description'] global - Retry Element Click xpath=//div/form/section/label[4]/button[2] - Capture Page Screenshot - Wait Until Page Contains ${labelname} - -Update A Label - [Arguments] ${labelname} - Retry Element Click xpath=//clr-dg-row[contains(.,'${labelname}')]//clr-checkbox-wrapper - Sleep 1 - Retry Element Click xpath=//button[contains(.,'Edit')] - Sleep 1 - Input Text xpath=//*[@id='name'] ${labelname}1 - Sleep 1 - Retry Element Click xpath=//hbr-create-edit-label//form/section//button[2] - Capture Page Screenshot - Wait Until Page Contains ${labelname}1 - -Delete A Label - [Arguments] ${labelname} - Retry Element Click xpath=//clr-dg-row[contains(.,'${labelname}')]//clr-checkbox-wrapper - Sleep 1 - Retry Element Click xpath=//button[contains(.,'Delete')] - Sleep 3 - Capture Page Screenshot - Retry Element Click xpath=//clr-modal//div//button[contains(.,'DELETE')] - Wait Until Page Contains Element //*[@id='contentAll']//div[contains(.,'${labelname}')]/../div/clr-icon[@shape='success-standard'] - -## Garbage Collection -Switch To Garbage Collection - Sleep 1 - Retry Element Click xpath=${gc_config_page} - Wait Until Page Contains Element ${garbage_collection_xpath} - Retry Element Click xpath=${garbage_collection_xpath} - -Click GC Now - Sleep 1 - Retry Element Click xpath=${gc_now_xpath} - Sleep 2 - -View GC Details - Retry Element Click xpath=${gc_log_details_xpath} - Sleep 2 - -Switch To GC History - Retry Element Click xpath=${gc_log_xpath} - Retry Wait Until Page Contains Job - -Add Items To System CVE Allowlist - [Arguments] ${cve_id} - Retry Element Click ${configuration_system_wl_add_btn} - Retry Text Input ${configuration_system_wl_textarea} ${cve_id} - Retry Element Click ${configuration_system_wl_add_confirm_btn} - Retry Element Click ${config_system_save_button_xpath} - -Delete Top Item In System CVE Allowlist - [Arguments] ${count}=1 - :FOR ${idx} IN RANGE 1 ${count} - \ Retry Element Click ${configuration_system_wl_delete_a_cve_id_icon} - Retry Element Click ${config_system_save_button_xpath} - -Get Project Count Quota Text From Project Quotas List - [Arguments] ${project_name} - Switch To Project Quotas - ${count_quota}= Get Text xpath=//project-quotas//clr-datagrid//clr-dg-row[contains(.,'${project_name}')]//clr-dg-cell[3]//label - [Return] ${count_quota} - -Get Project Storage Quota Text From Project Quotas List - [Arguments] ${project_name} - Switch To Configure - Switch To Project Quotas - ${storage_quota}= Get Text xpath=//project-quotas//clr-datagrid//clr-dg-row[contains(.,'${project_name}')]//clr-dg-cell[3]//label - [Return] ${storage_quota} - -Check Automatic Onboarding And Save - Retry Element Click ${cfg_auth_automatic_onboarding_checkbox} - Retry Element Click xpath=${config_auth_save_button_xpath} - Capture Page Screenshot - -Set User Name Claim And Save - [Arguments] ${type} - Retry Text Input ${cfg_auth_user_name_claim_input} ${type} - Retry Element Click xpath=${config_auth_save_button_xpath} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +Init LDAP + ${rc} ${output}= Run And Return Rc And Output ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}' + Log ${output} + Sleep 2 + Input Text xpath=//*[@id='ldapUrl'] ldaps://${output} + Sleep 1 + Input Text xpath=//*[@id='ldapSearchDN'] cn=admin,dc=example,dc=com + Sleep 1 + Input Text xpath=//*[@id='ldapSearchPwd'] admin + Sleep 1 + Input Text xpath=//*[@id='ldapBaseDN'] dc=example,dc=com + Sleep 1 + Input Text xpath=//*[@id='ldapFilter'] (&(objectclass=inetorgperson)(memberof=cn=harbor_users,ou=groups,dc=example,dc=com)) + Sleep 1 + Input Text xpath=//*[@id='ldapUid'] cn + Sleep 1 + Capture Page Screenshot + Disable Ldap Verify Cert Checkbox + Retry Element Click xpath=${config_auth_save_button_xpath} + Sleep 2 + Retry Element Click xpath=/html/body/harbor-app/harbor-shell/clr-main-container/div/div/config/div/div/div/button[3] + Sleep 1 + Capture Page Screenshot + +Switch To Configure + Retry Element Click xpath=${configuration_xpath} + Sleep 2 + +Test Ldap Connection + ${rc} ${output}= Run And Return Rc And Output ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}' + Log ${output} + Sleep 2 + Input Text xpath=//*[@id='ldapUrl'] ldaps://${output} + Sleep 1 + Input Text xpath=//*[@id='ldapSearchDN'] cn=admin,dc=example,dc=com + Sleep 1 + Input Text xpath=//*[@id='ldapSearchPwd'] admin + Sleep 1 + Input Text xpath=//*[@id='ldapBaseDN'] dc=example,dc=com + Sleep 1 + Input Text xpath=//*[@id='ldapUid'] cn + Sleep 1 + + # default is checked, click test connection to verify fail as no cert. + Retry Element Click xpath=${test_ldap_xpath} + Sleep 1 + Wait Until Page Contains Failed to verify LDAP server with error + Sleep 5 + + Disable Ldap Verify Cert Checkbox + # ldap checkbox unchecked, click test connection to verify success. + Sleep 1 + Retry Element Click xpath=${test_ldap_xpath} + Capture Page Screenshot + Wait Until Page Contains Connection to LDAP server is verified timeout=15 + +Test LDAP Server Success + Retry Element Click xpath=${test_ldap_xpath} + Wait Until Page Contains Connection to LDAP server is verified timeout=15 + +Disable Ldap Verify Cert Checkbox + Mouse Down xpath=//*[@id='clr-checkbox-ldapVerifyCert'] + Mouse Up xpath=//*[@id='clr-checkbox-ldapVerifyCert'] + Sleep 2 + Capture Page Screenshot + Ldap Verify Cert Checkbox Should Be Disabled + +Ldap Verify Cert Checkbox Should Be Disabled + Checkbox Should Not Be Selected xpath=//*[@id='clr-checkbox-ldapVerifyCert'] + +Set Pro Create Admin Only + #set limit to admin only + Retry Element Click xpath=${configuration_xpath} + Sleep 2 + Retry Element Click xpath=${configuration_system_tabsheet_id} + Sleep 1 + Retry Element Click xpath=//select[@id='proCreation'] + Retry Element Click xpath=//select[@id='proCreation']//option[@value='adminonly'] + Sleep 1 + Retry Element Click xpath=${config_system_save_button_xpath} + Capture Page Screenshot AdminCreateOnly.png + +Set Pro Create Every One + Retry Element Click xpath=${configuration_xpath} + sleep 1 + #set limit to Every One + Retry Element Click xpath=${configuration_system_tabsheet_id} + Sleep 1 + Retry Element Click xpath=//select[@id='proCreation'] + Retry Element Click xpath=//select[@id='proCreation']//option[@value='everyone'] + Sleep 1 + Retry Element Click xpath=${config_system_save_button_xpath} + Sleep 2 + Capture Page Screenshot EveryoneCreate.png + +Disable Self Reg + Retry Element Click xpath=${configuration_xpath} + Mouse Down xpath=${self_reg_xpath} + Mouse Up xpath=${self_reg_xpath} + Sleep 1 + Self Reg Should Be Disabled + Retry Element Click xpath=${config_auth_save_button_xpath} + Capture Page Screenshot DisableSelfReg.png + Sleep 1 + +Enable Self Reg + Mouse Down xpath=${self_reg_xpath} + Mouse Up xpath=${self_reg_xpath} + Sleep 1 + Self Reg Should Be Enabled + Retry Element Click xpath=${config_auth_save_button_xpath} + Capture Page Screenshot EnableSelfReg.png + Sleep 1 + +Self Reg Should Be Disabled + Checkbox Should Not Be Selected xpath=${self_reg_xpath} + +Self Reg Should Be Enabled + Checkbox Should Be Selected xpath=${self_reg_xpath} + +Project Creation Should Display + Retry Wait Until Page Contains Element xpath=${project_create_xpath} + +Project Creation Should Not Display + Retry Wait Until Page Not Contains Element xpath=${project_create_xpath} + +## System settings +Switch To System Settings + Sleep 1 + Retry Element Click xpath=${configuration_xpath} + Retry Element Click xpath=${configuration_system_tabsheet_id} + Sleep 1 + +Switch To Project Quotas + Sleep 1 + Retry Element Click xpath=${configuration_xpath} + Sleep 1 + Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Project Quotas')] + Sleep 1 + +Modify Token Expiration + [Arguments] ${minutes} + Input Text xpath=//*[@id='tokenExpiration'] ${minutes} + Click Button xpath=${config_system_save_button_xpath} + Sleep 1 + +Token Must Be Match + [Arguments] ${minutes} + Textfield Value Should Be xpath=//*[@id='tokenExpiration'] ${minutes} + +Robot Account Token Must Be Match + [Arguments] ${days} + Textfield Value Should Be xpath=//*[@id='robotTokenExpiration'] ${days} + +## Replication +Check Verify Remote Cert + Mouse Down xpath=//*[@id='clr-checkbox-verifyRemoteCert'] + Mouse Up xpath=//*[@id='clr-checkbox-verifyRemoteCert'] + Retry Element Click xpath=${config_save_button_xpath} + Capture Page Screenshot RemoteCert.png + Sleep 1 + +Switch To System Replication + Sleep 1 + Switch To Configure + Retry Element Click xpath=//*[@id='config-replication'] + Sleep 1 + +Should Verify Remote Cert Be Enabled + Checkbox Should Not Be Selected xpath=//*[@id='clr-checkbox-verifyRemoteCert'] + +## Email +Switch To Email + Switch To Configure + Retry Element Click xpath=//*[@id='config-email'] + Sleep 1 + +Config Email + Input Text xpath=//*[@id='mailServer'] smtp.vmware.com + Input Text xpath=//*[@id='emailPort'] 25 + Input Text xpath=//*[@id='emailUsername'] example@vmware.com + Input Text xpath=//*[@id='emailPassword'] example + Input Text xpath=//*[@id='emailFrom'] example + Sleep 1 + Retry Element Click xpath=//*[@id='emailSSL-wrapper']/label + Sleep 1 + Retry Element Click xpath=//*[@id='emailInsecure-wrapper']/label + Sleep 1 + Retry Element Click xpath=${config_email_save_button_xpath} + Sleep 6 + +Verify Email + Textfield Value Should Be xpath=//*[@id='mailServer'] smtp.vmware.com + Textfield Value Should Be xpath=//*[@id='emailPort'] 25 + Textfield Value Should Be xpath=//*[@id='emailUsername'] example@vmware.com + Textfield Value Should Be xpath=//*[@id='emailFrom'] example + Checkbox Should Be Selected xpath=//*[@id='emailSSL'] + Checkbox Should Not Be Selected xpath=//*[@id='emailInsecure'] + +Set Scan All To None + Retry Element Click //vulnerability-config//select + Retry Element Click //vulnerability-config//select/option[@value='none'] + sleep 1 + Retry Element Click ${vulnerbility_save_button_xpath} + +Set Scan All To Daily + Retry Element Click //vulnerability-config//select + Retry Element Click //vulnerability-config//select/option[@value='daily'] + sleep 1 + Retry Element Click ${vulnerbility_save_button_xpath} + +Click Scan Now + Retry Element Click //vulnerability-config//button[contains(.,'SCAN')] + + +Enable Read Only + ${rc} ${output}= Run And Return Rc And Output curl -u admin:Harbor12345 -s --insecure -H "Content-Type: application/json" -X PUT -d '{"read_only":true}' "https://${ip}/api/v2.0/configurations" + Log To Console ${output} + Should Be Equal As Integers ${rc} 0 + +Disable Read Only + ${rc} ${output}= Run And Return Rc And Output curl -u admin:Harbor12345 -s --insecure -H "Content-Type: application/json" -X PUT -d '{"read_only":false}' "https://${ip}/api/v2.0/configurations" + Log To Console ${output} + Should Be Equal As Integers ${rc} 0 + +## System labels +Switch To System Labels + Sleep 1 + Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Labels')] + +## System labels +Switch To Configuration System Setting + Sleep 1 + Retry Element Click xpath=${configuration_xpath} + Retry Element Click xpath=${configuration_system_tabsheet_id} + +Switch To Configuration Project Quotas + Sleep 1 + Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Project Quotas')] + +Create New Labels + [Arguments] ${labelname} + Retry Element Click xpath=//button[contains(.,'New Label')] + Sleep 1 + Input Text xpath=//*[@id='name'] ${labelname} + Sleep 1 + Retry Element Click xpath=//hbr-create-edit-label//clr-dropdown/clr-icon + Sleep 1 + Retry Element Click xpath=//hbr-create-edit-label//clr-dropdown-menu/label[1] + Sleep 1 + Input Text xpath=//*[@id='description'] global + Retry Element Click xpath=//div/form/section/label[4]/button[2] + Capture Page Screenshot + Wait Until Page Contains ${labelname} + +Update A Label + [Arguments] ${labelname} + Retry Element Click xpath=//clr-dg-row[contains(.,'${labelname}')]//clr-checkbox-wrapper + Sleep 1 + Retry Element Click xpath=//button[contains(.,'Edit')] + Sleep 1 + Input Text xpath=//*[@id='name'] ${labelname}1 + Sleep 1 + Retry Element Click xpath=//hbr-create-edit-label//form/section//button[2] + Capture Page Screenshot + Wait Until Page Contains ${labelname}1 + +Delete A Label + [Arguments] ${labelname} + Retry Element Click xpath=//clr-dg-row[contains(.,'${labelname}')]//clr-checkbox-wrapper + Sleep 1 + Retry Element Click xpath=//button[contains(.,'Delete')] + Sleep 3 + Capture Page Screenshot + Retry Element Click xpath=//clr-modal//div//button[contains(.,'DELETE')] + Wait Until Page Contains Element //*[@id='contentAll']//div[contains(.,'${labelname}')]/../div/clr-icon[@shape='success-standard'] + +## Garbage Collection +Switch To Garbage Collection + Sleep 1 + Retry Element Click xpath=${gc_config_page} + Wait Until Page Contains Element ${garbage_collection_xpath} + Retry Element Click xpath=${garbage_collection_xpath} + +Click GC Now + Sleep 1 + Retry Element Click xpath=${gc_now_xpath} + Sleep 2 + +View GC Details + Retry Element Click xpath=${gc_log_details_xpath} + Sleep 2 + +Switch To GC History + Retry Element Click xpath=${gc_log_xpath} + Retry Wait Until Page Contains Job + +Add Items To System CVE Allowlist + [Arguments] ${cve_id} + Retry Element Click ${configuration_system_wl_add_btn} + Retry Text Input ${configuration_system_wl_textarea} ${cve_id} + Retry Element Click ${configuration_system_wl_add_confirm_btn} + Retry Element Click ${config_system_save_button_xpath} + +Delete Top Item In System CVE Allowlist + [Arguments] ${count}=1 + FOR ${idx} IN RANGE 1 ${count} + Retry Element Click ${configuration_system_wl_delete_a_cve_id_icon} + END + Retry Element Click ${config_system_save_button_xpath} + +Get Project Count Quota Text From Project Quotas List + [Arguments] ${project_name} + Switch To Project Quotas + ${count_quota}= Get Text xpath=//project-quotas//clr-datagrid//clr-dg-row[contains(.,'${project_name}')]//clr-dg-cell[3]//label + [Return] ${count_quota} + +Get Project Storage Quota Text From Project Quotas List + [Arguments] ${project_name} + Switch To Configure + Switch To Project Quotas + ${storage_quota}= Get Text xpath=//project-quotas//clr-datagrid//clr-dg-row[contains(.,'${project_name}')]//clr-dg-cell[3]//label + [Return] ${storage_quota} + +Check Automatic Onboarding And Save + Retry Element Click ${cfg_auth_automatic_onboarding_checkbox} + Retry Element Click xpath=${config_auth_save_button_xpath} + Capture Page Screenshot + +Set User Name Claim And Save + [Arguments] ${type} + Retry Text Input ${cfg_auth_user_name_claim_input} ${type} + Retry Element Click xpath=${config_auth_save_button_xpath} Capture Page Screenshot \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/Configuration_Elements.robot b/tests/resources/Harbor-Pages/Configuration_Elements.robot index 5d56e41b1..b28a6f7e4 100644 --- a/tests/resources/Harbor-Pages/Configuration_Elements.robot +++ b/tests/resources/Harbor-Pages/Configuration_Elements.robot @@ -1,46 +1,46 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${project_create_xpath} //clr-dg-action-bar//button[contains(.,'New')] -${self_reg_xpath} //input[@id='selfReg'] -${test_ldap_xpath} //*[@id='authentication']/config-auth/div/button[3] -${config_save_button_xpath} //config//div/button[contains(.,'SAVE')] -${config_email_save_button_xpath} //*[@id='config_email_save'] -${config_auth_save_button_xpath} //*[@id='config_auth_save'] -${config_system_save_button_xpath} //*[@id='config_system_save'] -${vulnerbility_save_button_xpath} //*[@id='config-save'] -${configuration_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,' Configuration ')] -${garbage_collection_xpath} //*[@id='config-gc'] -${gc_log_xpath} //*[@id='gc-log'] -${gc_config_page} //clr-vertical-nav-group-children/a[contains(.,'Garbage')] -${gc_now_xpath} //*[@id='gc']/gc-config//button[contains(.,'GC')] -${gc_log_details_xpath} //*[@id='clr-dg-row26']/clr-dg-cell[6]/a -${configuration_system_tabsheet_id} //*[@id='config-system'] -${configuration_authentication_tabsheet_id} //*[@id="config-auth"] -${configuration_project_quotas_tabsheet_id} //*[@id='config-quotas'] -${configuration_system_wl_add_btn} //*[@id='show-add-modal-button'] -${configuration_system_wl_textarea} //*[@id='allowlist-textarea'] -${configuration_system_wl_add_confirm_btn} //*[@id='add-to-system'] -${configuration_system_wl_delete_a_cve_id_icon} //system-settings/form/section//ul/li[1]/a[2]/clr-icon -${configuration_sys_repo_readonly_chb_id} //*[@id='repo_read_only_lbl'] -${checkbox_delete_untagged_artifacts} //gc-config//clr-toggle-wrapper/label[contains(@for,'delete_untagged')] -${cfg_auth_automatic_onboarding_checkbox} //clr-checkbox-wrapper//label[contains(@for,'oidcAutoOnboard')] -${cfg_auth_user_name_claim_input} //*[@id='oidcUserClaim'] - - - +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${project_create_xpath} //clr-dg-action-bar//button[contains(.,'New')] +${self_reg_xpath} //input[@id='selfReg'] +${test_ldap_xpath} //*[@id='authentication']/config-auth/div/button[3] +${config_save_button_xpath} //config//div/button[contains(.,'SAVE')] +${config_email_save_button_xpath} //*[@id='config_email_save'] +${config_auth_save_button_xpath} //*[@id='config_auth_save'] +${config_system_save_button_xpath} //*[@id='config_system_save'] +${vulnerbility_save_button_xpath} //*[@id='config-save'] +${configuration_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,' Configuration ')] +${garbage_collection_xpath} //*[@id='config-gc'] +${gc_log_xpath} //*[@id='gc-log'] +${gc_config_page} //clr-vertical-nav-group-children/a[contains(.,'Garbage')] +${gc_now_xpath} //*[@id='gc']/gc-config//button[contains(.,'GC')] +${gc_log_details_xpath} //*[@id='clr-dg-row26']/clr-dg-cell[6]/a +${configuration_system_tabsheet_id} //*[@id='config-system'] +${configuration_authentication_tabsheet_id} //*[@id="config-auth"] +${configuration_project_quotas_tabsheet_id} //*[@id='config-quotas'] +${configuration_system_wl_add_btn} //*[@id='show-add-modal-button'] +${configuration_system_wl_textarea} //*[@id='allowlist-textarea'] +${configuration_system_wl_add_confirm_btn} //*[@id='add-to-system'] +${configuration_system_wl_delete_a_cve_id_icon} //system-settings/form/section//ul/li[1]/a[2]/clr-icon +${configuration_sys_repo_readonly_chb_id} //*[@id='repo_read_only_lbl'] +${checkbox_delete_untagged_artifacts} //gc-config//clr-toggle-wrapper/label[contains(@for,'delete_untagged')] +${cfg_auth_automatic_onboarding_checkbox} //clr-checkbox-wrapper//label[contains(@for,'oidcAutoOnboard')] +${cfg_auth_user_name_claim_input} //*[@id='oidcUserClaim'] + + + diff --git a/tests/resources/Harbor-Pages/GC.robot b/tests/resources/Harbor-Pages/GC.robot index fdb17b3da..0d111fb95 100644 --- a/tests/resources/Harbor-Pages/GC.robot +++ b/tests/resources/Harbor-Pages/GC.robot @@ -1,47 +1,47 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -GC Now - [Arguments] ${harbor_url} ${login_user} ${login_pwd} ${untag}=${false} - Switch To Garbage Collection - Capture Page Screenshot - Run Keyword If '${untag}' == '${true}' Retry Element Click xpath=${checkbox_delete_untagged_artifacts} - Capture Page Screenshot - Click GC Now - Logout Harbor - Sleep 2 - Sign In Harbor ${harbor_url} ${login_user} ${login_pwd} - Switch To Garbage Collection - Sleep 1 - #Switch To GC History - #Retry Keyword N Times When Error 60 Retry Wait Until Page Contains Finished - -Retry GC Should Be Successful - [Arguments] ${history_id} ${expected_msg} - Retry Keyword N Times When Error 15 GC Should Be Successful ${history_id} ${expected_msg} - -GC Should Be Successful - [Arguments] ${history_id} ${expected_msg} - ${rc} ${output}= Run And Return Rc And Output curl -u ${HARBOR_ADMIN}:${HARBOR_PASSWORD} -i --insecure -H "Content-Type: application/json" -X GET "https://${ip}/api/v2.0/system/gc/${history_id}/log" - Log To Console ${output} - Should Be Equal As Integers ${rc} 0 - Run Keyword If '${expected_msg}' != '${null}' Should Contain ${output} ${expected_msg} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +GC Now + [Arguments] ${harbor_url} ${login_user} ${login_pwd} ${untag}=${false} + Switch To Garbage Collection + Capture Page Screenshot + Run Keyword If '${untag}' == '${true}' Retry Element Click xpath=${checkbox_delete_untagged_artifacts} + Capture Page Screenshot + Click GC Now + Logout Harbor + Sleep 2 + Sign In Harbor ${harbor_url} ${login_user} ${login_pwd} + Switch To Garbage Collection + Sleep 1 + #Switch To GC History + #Retry Keyword N Times When Error 60 Retry Wait Until Page Contains Finished + +Retry GC Should Be Successful + [Arguments] ${history_id} ${expected_msg} + Retry Keyword N Times When Error 15 GC Should Be Successful ${history_id} ${expected_msg} + +GC Should Be Successful + [Arguments] ${history_id} ${expected_msg} + ${rc} ${output}= Run And Return Rc And Output curl -u ${HARBOR_ADMIN}:${HARBOR_PASSWORD} -i --insecure -H "Content-Type: application/json" -X GET "https://${ip}/api/v2.0/system/gc/${history_id}/log" + Log To Console ${output} + Should Be Equal As Integers ${rc} 0 + Run Keyword If '${expected_msg}' != '${null}' Should Contain ${output} ${expected_msg} Should Contain ${output} success to run gc in job. \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/HomePage.robot b/tests/resources/Harbor-Pages/HomePage.robot index 0486efdc1..136bd6a11 100644 --- a/tests/resources/Harbor-Pages/HomePage.robot +++ b/tests/resources/Harbor-Pages/HomePage.robot @@ -1,57 +1,57 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -Sign In Harbor - [Arguments] ${url} ${user} ${pw} - Go To ${url} - Retry Wait Element ${harbor_span_title} - Retry Wait Element ${login_name} - Retry Wait Element ${login_pwd} - Input Text ${login_name} ${user} - Input Text ${login_pwd} ${pw} - Retry Wait Element ${login_btn} - Retry Button Click ${login_btn} - Log To Console ${user} - Retry Wait Element xpath=//span[contains(., '${user}')] - -Capture Screenshot And Source - Capture Page Screenshot - Log Source - -Sign Up Should Not Display - Retry Wait Until Page Not Contains Element xpath=${sign_up_button_xpath} - -Create An New User - [Arguments] ${url} ${username} ${email} ${realname} ${newPassword} ${comment} - Go To ${url} - Retry Wait Element ${harbor_span_title} - Retry Element Click xpath=${sign_up_for_an_account_xpath} - Retry Text Input xpath=${username_xpath} ${username} - Retry Text Input xpath=${email_xpath} ${email} - Retry Text Input xpath=${realname_xpath} ${realname} - Retry Text Input xpath=${newPassword_xpath} ${newPassword} - Retry Text Input xpath=${confirmPassword_xpath} ${newPassword} - Retry Text Input xpath=${comment_xpath} ${comment} - Retry Double Keywords When Error Retry Element Click ${signup_xpath} Retry Wait Until Page Not Contains Element ${signup_xpath} - Retry Text Input ${login_name} ${username} - Retry Text Input ${login_pwd} ${newPassword} - Retry Double Keywords When Error Retry Element Click ${login_btn} Retry Wait Until Page Not Contains Element ${login_btn} - Retry Wait Element xpath=//span[contains(., '${username}')] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +Sign In Harbor + [Arguments] ${url} ${user} ${pw} + Go To ${url} + Retry Wait Element ${harbor_span_title} + Retry Wait Element ${login_name} + Retry Wait Element ${login_pwd} + Input Text ${login_name} ${user} + Input Text ${login_pwd} ${pw} + Retry Wait Element ${login_btn} + Retry Button Click ${login_btn} + Log To Console ${user} + Retry Wait Element xpath=//span[contains(., '${user}')] + +Capture Screenshot And Source + Capture Page Screenshot + Log Source + +Sign Up Should Not Display + Retry Wait Until Page Not Contains Element xpath=${sign_up_button_xpath} + +Create An New User + [Arguments] ${url} ${username} ${email} ${realname} ${newPassword} ${comment} + Go To ${url} + Retry Wait Element ${harbor_span_title} + Retry Element Click xpath=${sign_up_for_an_account_xpath} + Retry Text Input xpath=${username_xpath} ${username} + Retry Text Input xpath=${email_xpath} ${email} + Retry Text Input xpath=${realname_xpath} ${realname} + Retry Text Input xpath=${newPassword_xpath} ${newPassword} + Retry Text Input xpath=${confirmPassword_xpath} ${newPassword} + Retry Text Input xpath=${comment_xpath} ${comment} + Retry Double Keywords When Error Retry Element Click ${signup_xpath} Retry Wait Until Page Not Contains Element ${signup_xpath} + Retry Text Input ${login_name} ${username} + Retry Text Input ${login_pwd} ${newPassword} + Retry Double Keywords When Error Retry Element Click ${login_btn} Retry Wait Until Page Not Contains Element ${login_btn} + Retry Wait Element xpath=//span[contains(., '${username}')] diff --git a/tests/resources/Harbor-Pages/HomePage_Elements.robot b/tests/resources/Harbor-Pages/HomePage_Elements.robot index 15e54c186..42a387769 100644 --- a/tests/resources/Harbor-Pages/HomePage_Elements.robot +++ b/tests/resources/Harbor-Pages/HomePage_Elements.robot @@ -1,33 +1,33 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${sign_up_for_an_account_xpath} /html/body/harbor-app/sign-in/clr-main-container/div/form/div[1]/a -${sign_up_button_xpath} //a[@class='signup'] -${username_xpath} //*[@id='username'] -${email_xpath} //*[@id='email'] -${realname_xpath} //*[@id='realname'] -${newPassword_xpath} //*[@id='newPassword'] -${confirmPassword_xpath} //*[@id='confirmPassword'] -${comment_xpath} //*[@id='comment'] -${signup_xpath} //*[@id='sign-up'] -${search_input} //*[@id='search_input'] -${login_btn} //*[@id='log_in'] -${harbor_span_title} //span[contains(., 'Harbor')] -${login_name} //*[@id='login_username'] -${login_pwd} //*[@id='login_password'] - +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${sign_up_for_an_account_xpath} /html/body/harbor-app/sign-in/clr-main-container/div/form/div[1]/a +${sign_up_button_xpath} //a[@class='signup'] +${username_xpath} //*[@id='username'] +${email_xpath} //*[@id='email'] +${realname_xpath} //*[@id='realname'] +${newPassword_xpath} //*[@id='newPassword'] +${confirmPassword_xpath} //*[@id='confirmPassword'] +${comment_xpath} //*[@id='comment'] +${signup_xpath} //*[@id='sign-up'] +${search_input} //*[@id='search_input'] +${login_btn} //*[@id='log_in'] +${harbor_span_title} //span[contains(., 'Harbor')] +${login_name} //*[@id='login_username'] +${login_pwd} //*[@id='login_password'] + diff --git a/tests/resources/Harbor-Pages/LDAP-Mode.robot b/tests/resources/Harbor-Pages/LDAP-Mode.robot index fa0cf4c43..f75dfc24c 100644 --- a/tests/resources/Harbor-Pages/LDAP-Mode.robot +++ b/tests/resources/Harbor-Pages/LDAP-Mode.robot @@ -1,28 +1,28 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** - -Ldap User Should Not See Change Password - Retry Element Click //clr-header//clr-dropdown[2]//button - Sleep 2 - Page Should Not Contain Password - - +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** + +Ldap User Should Not See Change Password + Retry Element Click //clr-header//clr-dropdown[2]//button + Sleep 2 + Page Should Not Contain Password + + diff --git a/tests/resources/Harbor-Pages/OIDC_Auth.robot b/tests/resources/Harbor-Pages/OIDC_Auth.robot index 914abc0fe..cf748049b 100644 --- a/tests/resources/Harbor-Pages/OIDC_Auth.robot +++ b/tests/resources/Harbor-Pages/OIDC_Auth.robot @@ -1,64 +1,64 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** - -Sign In Harbor With OIDC User - [Arguments] ${url} ${username}=${OIDC_USERNAME} ${is_onboard}=${false} ${username_claim}=${null} - ${full_name}= Set Variable ${username}@example.com - ${head_username}= Set Variable If '${username_claim}' == 'email' xpath=//harbor-app/harbor-shell/clr-main-container/navigator/clr-header//clr-dropdown//button[contains(.,'${full_name}')] xpath=//harbor-app/harbor-shell/clr-main-container/navigator/clr-header//clr-dropdown//button[contains(.,'${username}')] - Init Chrome Driver - Go To ${url} - Retry Element Click ${log_oidc_provider_btn} - Retry Text Input ${dex_login_btn} ${full_name} - Retry Text Input ${dex_pwd_btn} password - Retry Element Click ${submit_login_btn} - Retry Element Click ${grant_btn} - - #If input box for harbor user name is visible, it means it's the 1st time login of this user, - # but if this user has been logged into harbor successfully, this input box will not show up, - # so there is condition branch for this stituation. - ${isVisible}= Run Keyword And Return Status Element Should Be Visible ${oidc_username_input} - Run Keyword If ${is_onboard} == ${true} Should Not Be True ${isVisible} - Run Keyword If '${isVisible}' == 'True' Run Keywords Retry Text Input ${oidc_username_input} ${username} AND Retry Element Click ${save_btn} - Retry Wait Element ${head_username} - ${name_display}= Get Text xpath=//harbor-app/harbor-shell/clr-main-container/navigator/clr-header//clr-dropdown[2]//button/span - Run Keyword If '${username_claim}' == 'email' Should Be Equal As Strings ${name_display} ${full_name} - ... ELSE Should Be Equal As Strings ${name_display} ${username} - -Get Secrete By API - [Arguments] ${url} ${username}=${OIDC_USERNAME} - ${json}= Run Curl And Return Json curl -s -k -X GET --header 'Accept: application/json' -u '${HARBOR_ADMIN}:${HARBOR_PASSWORD}' '${url}/api/v2.0/users/search?username=${username}' - ${user_info}= Set Variable ${json[0]} - ${user_id}= Set Variable ${user_info["user_id"]} - ${json}= Run Curl And Return Json curl -s -k -X GET --header 'Accept: application/json' -u '${HARBOR_ADMIN}:${HARBOR_PASSWORD}' '${url}/api/v2.0/users/${user_id}' - ${secret}= Set Variable ${json["oidc_user_meta"]["secret"]} - [Return] ${secret} - -Generate And Return Secret - [Arguments] ${url} - Retry Element Click ${head_admin_xpath} - Retry Element Click ${user_profile_xpath} - Retry Element Click ${more_btn} - Retry Element Click ${generate_secret_btn} - Retry Double Keywords When Error Retry Element Click ${confirm_btn} Retry Wait Until Page Not Contains Element ${confirm_btn} - Retry Wait Until Page Contains Cli secret setting is successful - ${secret}= Get Secrete By API ${url} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** + +Sign In Harbor With OIDC User + [Arguments] ${url} ${username}=${OIDC_USERNAME} ${is_onboard}=${false} ${username_claim}=${null} + ${full_name}= Set Variable ${username}@example.com + ${head_username}= Set Variable If '${username_claim}' == 'email' xpath=//harbor-app/harbor-shell/clr-main-container/navigator/clr-header//clr-dropdown//button[contains(.,'${full_name}')] xpath=//harbor-app/harbor-shell/clr-main-container/navigator/clr-header//clr-dropdown//button[contains(.,'${username}')] + Init Chrome Driver + Go To ${url} + Retry Element Click ${log_oidc_provider_btn} + Retry Text Input ${dex_login_btn} ${full_name} + Retry Text Input ${dex_pwd_btn} password + Retry Element Click ${submit_login_btn} + Retry Element Click ${grant_btn} + + #If input box for harbor user name is visible, it means it's the 1st time login of this user, + # but if this user has been logged into harbor successfully, this input box will not show up, + # so there is condition branch for this stituation. + ${isVisible}= Run Keyword And Return Status Element Should Be Visible ${oidc_username_input} + Run Keyword If ${is_onboard} == ${true} Should Not Be True ${isVisible} + Run Keyword If '${isVisible}' == 'True' Run Keywords Retry Text Input ${oidc_username_input} ${username} AND Retry Element Click ${save_btn} + Retry Wait Element ${head_username} + ${name_display}= Get Text xpath=//harbor-app/harbor-shell/clr-main-container/navigator/clr-header//clr-dropdown[2]//button/span + Run Keyword If '${username_claim}' == 'email' Should Be Equal As Strings ${name_display} ${full_name} + ... ELSE Should Be Equal As Strings ${name_display} ${username} + +Get Secrete By API + [Arguments] ${url} ${username}=${OIDC_USERNAME} + ${json}= Run Curl And Return Json curl -s -k -X GET --header 'Accept: application/json' -u '${HARBOR_ADMIN}:${HARBOR_PASSWORD}' '${url}/api/v2.0/users/search?username=${username}' + ${user_info}= Set Variable ${json[0]} + ${user_id}= Set Variable ${user_info["user_id"]} + ${json}= Run Curl And Return Json curl -s -k -X GET --header 'Accept: application/json' -u '${HARBOR_ADMIN}:${HARBOR_PASSWORD}' '${url}/api/v2.0/users/${user_id}' + ${secret}= Set Variable ${json["oidc_user_meta"]["secret"]} + [Return] ${secret} + +Generate And Return Secret + [Arguments] ${url} + Retry Element Click ${head_admin_xpath} + Retry Element Click ${user_profile_xpath} + Retry Element Click ${more_btn} + Retry Element Click ${generate_secret_btn} + Retry Double Keywords When Error Retry Element Click ${confirm_btn} Retry Wait Until Page Not Contains Element ${confirm_btn} + Retry Wait Until Page Contains Cli secret setting is successful + ${secret}= Get Secrete By API ${url} [Return] ${secret} \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/OIDC_Auth_Elements.robot b/tests/resources/Harbor-Pages/OIDC_Auth_Elements.robot index a73a78fc9..42389d0e6 100644 --- a/tests/resources/Harbor-Pages/OIDC_Auth_Elements.robot +++ b/tests/resources/Harbor-Pages/OIDC_Auth_Elements.robot @@ -1,28 +1,28 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${log_oidc_provider_btn} //*[@id='log_oidc'] -${dex_login_btn} //*[@id='login'] -${dex_pwd_btn} //*[@id='password'] -${submit_login_btn} //*[@id='submit-login'] -${grant_btn} xpath=/html/body/div[2]/div/div[2]/div[1]/form/button -${oidc_username_input} //*[@id='oidcUsername'] -${save_btn} //*[@id='saveButton'] -${OIDC_USERNAME} test1 -${generate_secret_btn} //*[@id='generate-cli-btn'] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${log_oidc_provider_btn} //*[@id='log_oidc'] +${dex_login_btn} //*[@id='login'] +${dex_pwd_btn} //*[@id='password'] +${submit_login_btn} //*[@id='submit-login'] +${grant_btn} xpath=/html/body/div[2]/div/div[2]/div[1]/form/button +${oidc_username_input} //*[@id='oidcUsername'] +${save_btn} //*[@id='saveButton'] +${OIDC_USERNAME} test1 +${generate_secret_btn} //*[@id='generate-cli-btn'] ${more_btn} //*[@id='hidden-generate-cli'] \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/Project-Artifact.robot b/tests/resources/Harbor-Pages/Project-Artifact.robot index ae60f65c0..bf5510397 100644 --- a/tests/resources/Harbor-Pages/Project-Artifact.robot +++ b/tests/resources/Harbor-Pages/Project-Artifact.robot @@ -1,49 +1,49 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Keywords *** -Go Into Artifact - [Arguments] ${tag} - Retry Wait Until Page Not Contains Element ${artifact_list_spinner} - Retry Element Click xpath=//clr-dg-row[contains(.,'${tag}')]//a[contains(.,'sha256')] - Retry Wait Until Page Contains Element ${artifact_tag_component} -Should Contain Tag - [Arguments] ${tag} - Retry Wait Until Page Contains Element xpath=//artifact-tag//clr-dg-row//clr-dg-cell[contains(.,'${tag}')] - -Should Not Contain Tag - [Arguments] ${tag} - Retry Wait Until Page Not Contains Element xpath=//artifact-tag//clr-dg-row//clr-dg-cell[contains(.,'${tag}')] - -Add A New Tag - [Arguments] ${tag} - Retry Double Keywords When Error Retry Element Click ${add_tag_button} Retry Wait Element ${tag_name_xpath} - Retry Text Input ${tag_name_xpath} ${tag} - Retry Double Keywords When Error Retry Element Click ${add_ok_button} Should Contain Tag ${tag} - -Delete A Tag - [Arguments] ${tag} - Retry Element Click xpath=//clr-dg-row[contains(.,'${tag}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] - Retry Double Keywords When Error Retry Element Click ${delete_tag_button} Retry Wait Until Page Contains Element ${dialog_delete_button} - Retry Double Keywords When Error Retry Element Click ${dialog_delete_button} Should Not Contain Tag ${tag} - -Should Contain Artifact - Retry Wait Until Page Contains Element xpath=//artifact-list-tab//clr-dg-row//a[contains(.,'sha256')] - -Should Not Contain Any Artifact +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Keywords *** +Go Into Artifact + [Arguments] ${tag} + Retry Wait Until Page Not Contains Element ${artifact_list_spinner} + Retry Element Click xpath=//clr-dg-row[contains(.,'${tag}')]//a[contains(.,'sha256')] + Retry Wait Until Page Contains Element ${artifact_tag_component} +Should Contain Tag + [Arguments] ${tag} + Retry Wait Until Page Contains Element xpath=//artifact-tag//clr-dg-row//clr-dg-cell[contains(.,'${tag}')] + +Should Not Contain Tag + [Arguments] ${tag} + Retry Wait Until Page Not Contains Element xpath=//artifact-tag//clr-dg-row//clr-dg-cell[contains(.,'${tag}')] + +Add A New Tag + [Arguments] ${tag} + Retry Double Keywords When Error Retry Element Click ${add_tag_button} Retry Wait Element ${tag_name_xpath} + Retry Text Input ${tag_name_xpath} ${tag} + Retry Double Keywords When Error Retry Element Click ${add_ok_button} Should Contain Tag ${tag} + +Delete A Tag + [Arguments] ${tag} + Retry Element Click xpath=//clr-dg-row[contains(.,'${tag}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] + Retry Double Keywords When Error Retry Element Click ${delete_tag_button} Retry Wait Until Page Contains Element ${dialog_delete_button} + Retry Double Keywords When Error Retry Element Click ${dialog_delete_button} Should Not Contain Tag ${tag} + +Should Contain Artifact + Retry Wait Until Page Contains Element xpath=//artifact-list-tab//clr-dg-row//a[contains(.,'sha256')] + +Should Not Contain Any Artifact Retry Wait Until Page Not Contains Element xpath=//artifact-list-tab//clr-dg-row \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/Project-Config-Elements.robot b/tests/resources/Harbor-Pages/Project-Config-Elements.robot index 12bb0e3bb..93b8195b9 100644 --- a/tests/resources/Harbor-Pages/Project-Config-Elements.robot +++ b/tests/resources/Harbor-Pages/Project-Config-Elements.robot @@ -1,6 +1,6 @@ -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${project_configuration_wl_delete_a_cve_id_icon} //hbr-project-policy-config/form/section//ul/li[1]/a[2]/clr-icon +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${project_configuration_wl_delete_a_cve_id_icon} //hbr-project-policy-config/form/section//ul/li[1]/a[2]/clr-icon ${project_configuration_wl_project_add_system_btn} //button[@id='add-system'] \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/Project-Config.robot b/tests/resources/Harbor-Pages/Project-Config.robot index 155a95a52..75b13059c 100644 --- a/tests/resources/Harbor-Pages/Project-Config.robot +++ b/tests/resources/Harbor-Pages/Project-Config.robot @@ -1,86 +1,86 @@ -*** Settings *** - -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** - -Goto Project Config - Sleep 3 - Retry Element Click //project-detail//ul/li[contains(.,'Configuration')] - Sleep 2 - -Click Project Public - Mouse Down //hbr-project-policy-config//input[@name='public'] - Mouse Up //hbr-project-policy-config//input[@name='public'] - -Click Content Trust - Mouse Down //hbr-project-policy-config//input[@name='content-trust'] - Mouse Up //hbr-project-policy-config//input[@name='content-trust'] - -Click Prevent Running - Mouse Down //hbr-project-policy-config//input[@name='prevent-vulnerability-image'] - Mouse Up //hbr-project-policy-config//input[@name='prevent-vulnerability-image'] - -Select Prevent Level -#value NEGLIGIBLE LOW MEDIUM HIGH - [Arguments] ${level} - Retry Element Click //hbr-project-policy-config//select - Retry Element Click //hbr-project-policy-config//select/option[contains(.,'${level}')] - -Click Auto Scan - Mouse Down //hbr-project-policy-config//input[@name='scan-image-on-push'] - Mouse Up //hbr-project-policy-config//input[@name='scan-image-on-push'] - -Save Project Config - Sleep 1 - Retry Element Click //hbr-project-policy-config//button[contains(.,'SAVE')] - -Public Should Be Selected - Checkbox Should Be Selected //hbr-project-policy-config//input[@name='public'] - -Project Should Be Public - [Arguments] ${projectName} - Retry Wait Until Page Contains Element //clr-dg-row[contains(.,'${projectName}')]//clr-dg-cell[contains(.,'Public')] - -Content Trust Should Be Selected - Checkbox Should Be Selected //hbr-project-policy-config//input[@name='content-trust'] - -Prevent Running Should Be Selected - Checkbox Should Be Selected //hbr-project-policy-config//input[@name='prevent-vulnerability-image'] - -Auto Scan Should Be Selected - Checkbox Should Be Selected //hbr-project-policy-config//input[@name='scan-image-on-push'] - -Select System CVE Allowlist - Retry Element Click ${project_config_system_wl_radio_input} - -Select Prject CVE Allowlist - Retry Element Click ${project_config_project_wl_radio_input} - -Add System CVE Allowlist to Project CVE Allowlist By Add System Button Click - Goto Project Config - Select Prject CVE Allowlist - Retry Element Click ${project_configuration_wl_project_add_system_btn} - Retry Element Click ${project_config_save_btn} - -Set Project To Project Level CVE Allowlist - Goto Project Config - Select Prject CVE Allowlist - Retry Element Click ${project_config_save_btn} - -Add Items to Project CVE Allowlist - [Arguments] ${cve_id} - Goto Project Config - Select Prject CVE Allowlist - Retry Element Click ${project_config_project_wl_add_btn} - Retry Text Input ${configuration_system_wl_textarea} ${cve_id} - Retry Element Click ${project_config_project_wl_add_confirm_btn} - Retry Element Click ${project_config_save_btn} - -Delete Top Item In Project CVE Allowlist - [Arguments] - Goto Project Config - Retry Element Click ${project_configuration_wl_delete_a_cve_id_icon} - Retry Element Click ${project_config_save_btn} +*** Settings *** + +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** + +Goto Project Config + Sleep 3 + Retry Element Click //project-detail//ul/li[contains(.,'Configuration')] + Sleep 2 + +Click Project Public + Mouse Down //hbr-project-policy-config//input[@name='public'] + Mouse Up //hbr-project-policy-config//input[@name='public'] + +Click Content Trust + Mouse Down //hbr-project-policy-config//input[@name='content-trust'] + Mouse Up //hbr-project-policy-config//input[@name='content-trust'] + +Click Prevent Running + Mouse Down //hbr-project-policy-config//input[@name='prevent-vulnerability-image'] + Mouse Up //hbr-project-policy-config//input[@name='prevent-vulnerability-image'] + +Select Prevent Level +#value NEGLIGIBLE LOW MEDIUM HIGH + [Arguments] ${level} + Retry Element Click //hbr-project-policy-config//select + Retry Element Click //hbr-project-policy-config//select/option[contains(.,'${level}')] + +Click Auto Scan + Mouse Down //hbr-project-policy-config//input[@name='scan-image-on-push'] + Mouse Up //hbr-project-policy-config//input[@name='scan-image-on-push'] + +Save Project Config + Sleep 1 + Retry Element Click //hbr-project-policy-config//button[contains(.,'SAVE')] + +Public Should Be Selected + Checkbox Should Be Selected //hbr-project-policy-config//input[@name='public'] + +Project Should Be Public + [Arguments] ${projectName} + Retry Wait Until Page Contains Element //clr-dg-row[contains(.,'${projectName}')]//clr-dg-cell[contains(.,'Public')] + +Content Trust Should Be Selected + Checkbox Should Be Selected //hbr-project-policy-config//input[@name='content-trust'] + +Prevent Running Should Be Selected + Checkbox Should Be Selected //hbr-project-policy-config//input[@name='prevent-vulnerability-image'] + +Auto Scan Should Be Selected + Checkbox Should Be Selected //hbr-project-policy-config//input[@name='scan-image-on-push'] + +Select System CVE Allowlist + Retry Element Click ${project_config_system_wl_radio_input} + +Select Prject CVE Allowlist + Retry Element Click ${project_config_project_wl_radio_input} + +Add System CVE Allowlist to Project CVE Allowlist By Add System Button Click + Goto Project Config + Select Prject CVE Allowlist + Retry Element Click ${project_configuration_wl_project_add_system_btn} + Retry Element Click ${project_config_save_btn} + +Set Project To Project Level CVE Allowlist + Goto Project Config + Select Prject CVE Allowlist + Retry Element Click ${project_config_save_btn} + +Add Items to Project CVE Allowlist + [Arguments] ${cve_id} + Goto Project Config + Select Prject CVE Allowlist + Retry Element Click ${project_config_project_wl_add_btn} + Retry Text Input ${configuration_system_wl_textarea} ${cve_id} + Retry Element Click ${project_config_project_wl_add_confirm_btn} + Retry Element Click ${project_config_save_btn} + +Delete Top Item In Project CVE Allowlist + [Arguments] + Goto Project Config + Retry Element Click ${project_configuration_wl_delete_a_cve_id_icon} + Retry Element Click ${project_config_save_btn} diff --git a/tests/resources/Harbor-Pages/Project-Copy-Elements.robot b/tests/resources/Harbor-Pages/Project-Copy-Elements.robot index d60eb60f3..bbc2bc333 100644 --- a/tests/resources/Harbor-Pages/Project-Copy-Elements.robot +++ b/tests/resources/Harbor-Pages/Project-Copy-Elements.robot @@ -1,14 +1,14 @@ -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** - -${retag_btn} //clr-dg-action-bar//button[contains(.,'Retag')] -${copy_project_name_xpath} //*[@id='project-name'] -${copy_repo_name_xpath} //*[@id='repo-name'] -${tag_name_xpath} //*[@id='tag-name'] -${confirm_btn} //button[contains(.,'CONFIRM')] -${target_image_name} target-alpine -${image_tag} 3.2.10-alpine -${tag_value_xpath} //clr-dg-row[contains(.,'${image_tag}')] +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** + +${retag_btn} //clr-dg-action-bar//button[contains(.,'Retag')] +${copy_project_name_xpath} //*[@id='project-name'] +${copy_repo_name_xpath} //*[@id='repo-name'] +${tag_name_xpath} //*[@id='tag-name'] +${confirm_btn} //button[contains(.,'CONFIRM')] +${target_image_name} target-alpine +${image_tag} 3.2.10-alpine +${tag_value_xpath} //clr-dg-row[contains(.,'${image_tag}')] ${modal-dialog} div.modal-dialog \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/Project-Copy.robot b/tests/resources/Harbor-Pages/Project-Copy.robot index 2f475c5e0..ea13db6f0 100644 --- a/tests/resources/Harbor-Pages/Project-Copy.robot +++ b/tests/resources/Harbor-Pages/Project-Copy.robot @@ -1,17 +1,17 @@ -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Keywords *** - -Copy Image - [Arguments] ${tag} ${projectname} ${reponame} - Retry Element Click xpath=//clr-dg-row[contains(.,'${tag}')]//label - Sleep 1 - Retry Element Click ${artifact_action_xpath} - Sleep 1 - Retry Element Click ${artifact_action_copy_xpath} - Sleep 1 - #input necessary info - Retry Text Input xpath=${copy_project_name_xpath} ${projectname} - Retry Text Input xpath=${copy_repo_name_xpath} ${reponame} - Retry Double Keywords When Error Retry Element Click ${confirm_btn} Retry Wait Until Page Not Contains Element ${confirm_btn} +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Keywords *** + +Copy Image + [Arguments] ${tag} ${projectname} ${reponame} + Retry Element Click xpath=//clr-dg-row[contains(.,'${tag}')]//label + Sleep 1 + Retry Element Click ${artifact_action_xpath} + Sleep 1 + Retry Element Click ${artifact_action_copy_xpath} + Sleep 1 + #input necessary info + Retry Text Input xpath=${copy_project_name_xpath} ${projectname} + Retry Text Input xpath=${copy_repo_name_xpath} ${reponame} + Retry Double Keywords When Error Retry Element Click ${confirm_btn} Retry Wait Until Page Not Contains Element ${confirm_btn} diff --git a/tests/resources/Harbor-Pages/Project-Helmcharts.robot b/tests/resources/Harbor-Pages/Project-Helmcharts.robot index 74ac151ae..a4bb2ac49 100644 --- a/tests/resources/Harbor-Pages/Project-Helmcharts.robot +++ b/tests/resources/Harbor-Pages/Project-Helmcharts.robot @@ -1,55 +1,56 @@ -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Keywords *** - -Switch To Project Charts - Retry Element Click ${project_chart_tabpage} - Retry Wait Until Page Contains Element ${project_chart_list} - -Upload Chart files - ${current_dir}= Run pwd - Run wget ${harbor_chart_file_url} - Run wget ${harbor_chart_prov_file_url} - Run wget ${prometheus_chart_file_url} - - Retry Double Keywords When Error Retry Element Click xpath=${upload_chart_button} Retry Wait Until Page Contains Element xpath=${upload_action_button} - ${prometheus_file_path} Set Variable ${current_dir}/${prometheus_chart_filename} - Choose File xpath=${chart_file_browse} ${prometheus_file_path} - Retry Double Keywords When Error Retry Element Click xpath=${upload_action_button} Retry Wait Until Page Not Contains Element xpath=${upload_action_button} - Retry Double Keywords When Error Retry Element Click xpath=${upload_chart_button} Retry Wait Until Page Contains Element xpath=${upload_action_button} - Retry Wait Until Page Contains ${prometheus_chart_name} - Capture Page Screenshot - ${harbor_file_path} Set Variable ${current_dir}/${harbor_chart_filename} - ${harbor_prov_file_path} Set Variable ${current_dir}/${harbor_chart_prov_filename} - Choose File xpath=${chart_file_browse} ${harbor_file_path} - Choose File xpath=${chart_prov_browse} ${harbor_prov_file_path} - Retry Double Keywords When Error Retry Element Click xpath=${upload_action_button} Retry Wait Until Page Not Contains Element xpath=${upload_action_button} - Retry Wait Until Page Contains ${harbor_chart_name} - Capture Page Screenshot - -Go Into Chart Version - [Arguments] ${chart_name} - Retry Element Click xpath=//hbr-helm-chart//a[contains(., '${chart_name}')] - Sleep 3 - Capture Page Screenshot viewchartversion.png - -Go Into Chart Detail - [Arguments] ${version_name} - Retry Element Click xpath=//hbr-helm-chart-version//a[contains(., '${version_name}')] - Retry Wait Until Page Contains Element ${chart_detail} - -Multi-delete Chart Files - [Arguments] @{obj} - Switch To Project Charts - :For ${obj} in @{obj} - \ Retry Element Click //clr-dg-row[contains(.,'${obj}')]//label - #Retry Element Click xpath=${version_checkbox} - Capture Page Screenshot - Retry Double Keywords When Error Retry Element Click xpath=${version_delete} Retry Wait Until Page Contains Element ${version_confirm_delete} - Capture Page Screenshot - Retry Double Keywords When Error Retry Element Click ${version_confirm_delete} Retry Wait Until Page Not Contains Element xpath=${version_confirm_delete} - Retry Wait Element xpath=//clr-dg-placeholder[contains(.,\"We couldn\'t find any charts!\")] - Capture Page Screenshot - +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Keywords *** + +Switch To Project Charts + Retry Element Click ${project_chart_tabpage} + Retry Wait Until Page Contains Element ${project_chart_list} + +Upload Chart files + ${current_dir}= Run pwd + Run wget ${harbor_chart_file_url} + Run wget ${harbor_chart_prov_file_url} + Run wget ${prometheus_chart_file_url} + + Retry Double Keywords When Error Retry Element Click xpath=${upload_chart_button} Retry Wait Until Page Contains Element xpath=${upload_action_button} + ${prometheus_file_path} Set Variable ${current_dir}/${prometheus_chart_filename} + Choose File xpath=${chart_file_browse} ${prometheus_file_path} + Retry Double Keywords When Error Retry Element Click xpath=${upload_action_button} Retry Wait Until Page Not Contains Element xpath=${upload_action_button} + Retry Double Keywords When Error Retry Element Click xpath=${upload_chart_button} Retry Wait Until Page Contains Element xpath=${upload_action_button} + Retry Wait Until Page Contains ${prometheus_chart_name} + Capture Page Screenshot + ${harbor_file_path} Set Variable ${current_dir}/${harbor_chart_filename} + ${harbor_prov_file_path} Set Variable ${current_dir}/${harbor_chart_prov_filename} + Choose File xpath=${chart_file_browse} ${harbor_file_path} + Choose File xpath=${chart_prov_browse} ${harbor_prov_file_path} + Retry Double Keywords When Error Retry Element Click xpath=${upload_action_button} Retry Wait Until Page Not Contains Element xpath=${upload_action_button} + Retry Wait Until Page Contains ${harbor_chart_name} + Capture Page Screenshot + +Go Into Chart Version + [Arguments] ${chart_name} + Retry Element Click xpath=//hbr-helm-chart//a[contains(., '${chart_name}')] + Sleep 3 + Capture Page Screenshot viewchartversion.png + +Go Into Chart Detail + [Arguments] ${version_name} + Retry Element Click xpath=//hbr-helm-chart-version//a[contains(., '${version_name}')] + Retry Wait Until Page Contains Element ${chart_detail} + +Multi-delete Chart Files + [Arguments] @{obj} + Switch To Project Charts + FOR ${obj} IN @{obj} + Retry Element Click //clr-dg-row[contains(.,'${obj}')]//label + END + #Retry Element Click xpath=${version_checkbox} + Capture Page Screenshot + Retry Double Keywords When Error Retry Element Click xpath=${version_delete} Retry Wait Until Page Contains Element ${version_confirm_delete} + Capture Page Screenshot + Retry Double Keywords When Error Retry Element Click ${version_confirm_delete} Retry Wait Until Page Not Contains Element xpath=${version_confirm_delete} + Retry Wait Element xpath=//clr-dg-placeholder[contains(.,\"We couldn\'t find any charts!\")] + Capture Page Screenshot + diff --git a/tests/resources/Harbor-Pages/Project-Helmcharts_Elements.robot b/tests/resources/Harbor-Pages/Project-Helmcharts_Elements.robot index 43cd02239..90ef8ca6e 100644 --- a/tests/resources/Harbor-Pages/Project-Helmcharts_Elements.robot +++ b/tests/resources/Harbor-Pages/Project-Helmcharts_Elements.robot @@ -1,38 +1,38 @@ -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${project_chart_tabpage} xpath=//project-detail//a[contains(.,'Charts')] -${project_chart_list} xpath=//hbr-helm-chart -${upload_chart_button} //*[@id='helm-chart-upload'] -${chart_file_browse} //*[@id='chart'] -${chart_prov_browse} //*[@id='prov'] -${upload_action_button} //*[@id='upload-chart'] - -${harbor_chart_name} harbor -${harbor_chart_filename} harbor-0.2.0.tgz -${harbor_chart_version} 0.2.0 -${harbor_chart_prov_filename} harbor-0.2.0.tgz.prov -${harbor_chart_file_url} https://storage.googleapis.com/harbor-builds/helm-chart-test-files/harbor-0.2.0.tgz -${harbor_chart_prov_file_url} https://storage.googleapis.com/harbor-builds/helm-chart-test-files/harbor-0.2.0.tgz.prov - -${prometheus_chart_name} prometheus -${prometheus_chart_filename} prometheus-7.0.2.tgz -${prometheus_chart_version} 7.0.2 -${prometheus_chart_file_url} https://storage.googleapis.com/harbor-builds/helm-chart-test-files/prometheus-7.0.2.tgz -${prometheus_version} //hbr-helm-chart//a[contains(.,'prometheus')] - -${chart_detail} //hbr-chart-detail -${summary_markdown} //*[@id='summary-content']//div[contains(@class,'md-div')] -${summary_container} //*[@id='summary-content']//div[contains(@class,'summary-container')] -${detail_dependency} //*[@id='depend-link'] -${dependency_content} //*[@id='depend-content']/hbr-chart-detail-dependency -${detail_value} //*[@id='value-link'] -${value_content} //*[@id='value-content']/hbr-chart-detail-value - -${version_bread_crumbs} //project-chart-detail//a[contains(.,'Versions')] -${version_checkbox} //clr-dg-row//clr-checkbox-wrapper/label -${version_delete} //clr-dg-action-bar/button[contains(.,'DELETE')] -${version_confirm_delete} //clr-modal//button[contains(.,'DELETE')] - +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${project_chart_tabpage} xpath=//project-detail//a[contains(.,'Charts')] +${project_chart_list} xpath=//hbr-helm-chart +${upload_chart_button} //*[@id='helm-chart-upload'] +${chart_file_browse} //*[@id='chart'] +${chart_prov_browse} //*[@id='prov'] +${upload_action_button} //*[@id='upload-chart'] + +${harbor_chart_name} harbor +${harbor_chart_filename} harbor-0.2.0.tgz +${harbor_chart_version} 0.2.0 +${harbor_chart_prov_filename} harbor-0.2.0.tgz.prov +${harbor_chart_file_url} https://storage.googleapis.com/harbor-builds/helm-chart-test-files/harbor-0.2.0.tgz +${harbor_chart_prov_file_url} https://storage.googleapis.com/harbor-builds/helm-chart-test-files/harbor-0.2.0.tgz.prov + +${prometheus_chart_name} prometheus +${prometheus_chart_filename} prometheus-7.0.2.tgz +${prometheus_chart_version} 7.0.2 +${prometheus_chart_file_url} https://storage.googleapis.com/harbor-builds/helm-chart-test-files/prometheus-7.0.2.tgz +${prometheus_version} //hbr-helm-chart//a[contains(.,'prometheus')] + +${chart_detail} //hbr-chart-detail +${summary_markdown} //*[@id='summary-content']//div[contains(@class,'md-div')] +${summary_container} //*[@id='summary-content']//div[contains(@class,'summary-container')] +${detail_dependency} //*[@id='depend-link'] +${dependency_content} //*[@id='depend-content']/hbr-chart-detail-dependency +${detail_value} //*[@id='value-link'] +${value_content} //*[@id='value-content']/hbr-chart-detail-value + +${version_bread_crumbs} //project-chart-detail//a[contains(.,'Versions')] +${version_checkbox} //clr-dg-row//clr-checkbox-wrapper/label +${version_delete} //clr-dg-action-bar/button[contains(.,'DELETE')] +${version_confirm_delete} //clr-modal//button[contains(.,'DELETE')] + ${helmchart_content} //project-detail/project-list-charts/hbr-helm-chart \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/Project-Members_Elements.robot b/tests/resources/Harbor-Pages/Project-Members_Elements.robot index e1b73850f..c14e71206 100644 --- a/tests/resources/Harbor-Pages/Project-Members_Elements.robot +++ b/tests/resources/Harbor-Pages/Project-Members_Elements.robot @@ -1,30 +1,30 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${project_member_tag_xpath} //clr-main-container//project-detail/clr-tabs//a[contains(.,'Members')] -${project_member_add_button_xpath} //project-detail//button[contains(.,'User')] -${project_member_add_username_xpath} //*[@id='member_name'] -${project_member_add_admin_xpath} /html/body/harbor-app/harbor-shell/clr-main-container/div/div/project-detail/ng-component/div/div[1]/div/div[1]/add-member/clr-modal/div/div[1]/div/div[1]/div/div[2]/form/section/div[2]/div[1]/label -${project_member_add_save_button_xpath} /html/body/harbor-app/harbor-shell/clr-main-container/div/div/project-detail/ng-component/div/div[1]/div/div[1]/add-member/clr-modal/div/div[1]/div/div[1]/div/div[3]/button[2] -${project_member_search_button_xpath} //project-detail//hbr-filter/span/clr-icon -${project_member_search_text_xpath} //project-detail//hbr-filter/span/input -${project_member_add_confirmation_ok_xpath} //project-detail//add-member//button[2] -${project_member_search_button_xpath2} //button[contains(.,'New')] -${project_member_add_button_xpath2} //project-detail//add-member//button[2] -${project_member_guest_radio_checkbox} //project-detail//form//input[@id='checkrads_guest'] -${project_member_delete_button_xpath} //button[contains(.,'REMOVE')] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${project_member_tag_xpath} //clr-main-container//project-detail/clr-tabs//a[contains(.,'Members')] +${project_member_add_button_xpath} //project-detail//button[contains(.,'User')] +${project_member_add_username_xpath} //*[@id='member_name'] +${project_member_add_admin_xpath} /html/body/harbor-app/harbor-shell/clr-main-container/div/div/project-detail/ng-component/div/div[1]/div/div[1]/add-member/clr-modal/div/div[1]/div/div[1]/div/div[2]/form/section/div[2]/div[1]/label +${project_member_add_save_button_xpath} /html/body/harbor-app/harbor-shell/clr-main-container/div/div/project-detail/ng-component/div/div[1]/div/div[1]/add-member/clr-modal/div/div[1]/div/div[1]/div/div[3]/button[2] +${project_member_search_button_xpath} //project-detail//hbr-filter/span/clr-icon +${project_member_search_text_xpath} //project-detail//hbr-filter/span/input +${project_member_add_confirmation_ok_xpath} //project-detail//add-member//button[2] +${project_member_search_button_xpath2} //button[contains(.,'New')] +${project_member_add_button_xpath2} //project-detail//add-member//button[2] +${project_member_guest_radio_checkbox} //project-detail//form//input[@id='checkrads_guest'] +${project_member_delete_button_xpath} //button[contains(.,'REMOVE')] diff --git a/tests/resources/Harbor-Pages/Project-Repository.robot b/tests/resources/Harbor-Pages/Project-Repository.robot index 51717d6a4..0f94df7f7 100644 --- a/tests/resources/Harbor-Pages/Project-Repository.robot +++ b/tests/resources/Harbor-Pages/Project-Repository.robot @@ -1,34 +1,35 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Keywords *** -View Repo Scan Details - [Arguments] @{vulnerabilities_level} - Retry Element Click xpath=${first_repo_xpath} - Capture Page Screenshot - :FOR ${item} IN @{vulnerabilities_level} - \ Retry Wait Until Page Contains Element //hbr-artifact-vulnerabilities//clr-dg-row[contains(.,'${item}')] - Retry Element Click xpath=${build_history_btn} - Retry Wait Until Page Contains Element xpath=${build_history_data} - -View Scan Error Log - Retry Wait Until Page Contains View Log - Retry Element Click xpath=${view_log_xpath} - Capture Page Screenshot viewlog.png - - +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Keywords *** +View Repo Scan Details + [Arguments] @{vulnerabilities_level} + Retry Element Click xpath=${first_repo_xpath} + Capture Page Screenshot + FOR ${item} IN @{vulnerabilities_level} + Retry Wait Until Page Contains Element //hbr-artifact-vulnerabilities//clr-dg-row[contains(.,'${item}')] + END + Retry Element Click xpath=${build_history_btn} + Retry Wait Until Page Contains Element xpath=${build_history_data} + +View Scan Error Log + Retry Wait Until Page Contains View Log + Retry Element Click xpath=${view_log_xpath} + Capture Page Screenshot viewlog.png + + diff --git a/tests/resources/Harbor-Pages/Project-Repository_Elements.robot b/tests/resources/Harbor-Pages/Project-Repository_Elements.robot index 5b4ec7b47..8a87dc82c 100644 --- a/tests/resources/Harbor-Pages/Project-Repository_Elements.robot +++ b/tests/resources/Harbor-Pages/Project-Repository_Elements.robot @@ -1,26 +1,26 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${first_repo_xpath} //clr-dg-row//clr-dg-cell[1]//a -${first_cve_xpath} //clr-dg-row[1]//clr-dg-cell//a -${view_log_xpath} //clr-dg-row//clr-dg-cell//a[contains(.,'View Log')] -${build_history_btn} //button[contains(.,'Build History')] -${build_history_data} //clr-dg-row -${push_image_command_btn} //hbr-push-image-button//button - - +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${first_repo_xpath} //clr-dg-row//clr-dg-cell[1]//a +${first_cve_xpath} //clr-dg-row[1]//clr-dg-cell//a +${view_log_xpath} //clr-dg-row//clr-dg-cell//a[contains(.,'View Log')] +${build_history_btn} //button[contains(.,'Build History')] +${build_history_data} //clr-dg-row +${push_image_command_btn} //hbr-push-image-button//button + + diff --git a/tests/resources/Harbor-Pages/Project-Tag-Retention.robot b/tests/resources/Harbor-Pages/Project-Tag-Retention.robot index 1bd2d6051..abd1996c7 100644 --- a/tests/resources/Harbor-Pages/Project-Tag-Retention.robot +++ b/tests/resources/Harbor-Pages/Project-Tag-Retention.robot @@ -1,107 +1,108 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** - -Add A Tag Retention Rule - Retry Element Click xpath=${project_tag_retention_add_rule_xpath} - Retry Element Click xpath=${project_tag_retention_template_xpath} - Retry Element Click xpath=${project_tag_retention_option_always_xpath} - Retry Element Click xpath=${project_tag_retention_save_add_button_xpath} - Retry Wait Until Page Contains Element xpath=${project_tag_retention_rule_name_xpath} - -Add A Tag Immutability Rule - [Arguments] ${scope} ${tag} - Retry Double Keywords When Error Retry Element Click xpath=${project_tag_retention_add_rule_xpath} Retry Wait Until Page Contains Element xpath=${project_tag_immutability_save_add_button_xpath} - Retry Clear Element Text ${project_tag_immutability_scope_input_xpath} - Retry Text Input ${project_tag_immutability_scope_input_xpath} ${scope} - Retry Clear Element Text ${project_tag_immutability_tag_input_xpath} - Retry Text Input ${project_tag_immutability_tag_input_xpath} ${tag} - Retry Double Keywords When Error Retry Element Click xpath=${project_tag_immutability_save_add_button_xpath} Retry Wait Until Page Contains Element xpath=${project_tag_retention_rule_name_xpath} - Retry Wait Until Page Contains ${scope} - Retry Wait Until Page Contains ${tag} - -Delete A Tag Retention Rule - Retry Element Click xpath=${project_tag_retention_action_button_xpath} - Retry Element Click xpath=${project_tag_retention_delete_button_xpath} - Retry Wait Until Page Not Contains Element xpath=${project_tag_retention_rule_name_xpath} - -Delete A Tag Immutability Rule - Retry Element Click xpath=${project_tag_retention_action_button_xpath} - Retry Element Click xpath=${project_tag_retention_delete_button_xpath} - Retry Wait Until Page Not Contains Element xpath=${project_tag_retention_rule_name_xpath} - -Edit A Tag Retention Rule - [Arguments] ${repos} ${tags} - Retry Element Click xpath=${project_tag_retention_action_button_xpath} - Retry Element Click xpath=${project_tag_retention_edit_button_xpath} - Retry Wait Until Page Contains Element xpath=${project_tag_retention_modal_title_edit_xpath} - Input Text ${project_tag_retention_repo_input_xpath} ${repos} - Input Text ${project_tag_retention_tags_input_xpath} ${tags} - Retry Element Click xpath=${project_tag_retention_save_add_button_xpath} - Retry Wait Until Page Contains Element xpath=//span[contains(@class, 'rule-name')]//span[contains(.,'${tags}')] - -Edit A Tag Immutability Rule - [Arguments] ${scope} ${tag} - Retry Element Click xpath=${project_tag_retention_action_button_xpath} - Retry Element Click xpath=${project_tag_retention_edit_button_xpath} - Retry Clear Element Text ${project_tag_immutability_scope_input_xpath} - Retry Text Input ${project_tag_immutability_scope_input_xpath} ${scope} - Retry Clear Element Text ${project_tag_immutability_tag_input_xpath} - Retry Text Input ${project_tag_immutability_tag_input_xpath} ${tag} - Retry Double Keywords When Error Retry Element Click xpath=${project_tag_immutability_save_add_button_xpath} Retry Wait Until Page Contains Element xpath=${project_tag_retention_rule_name_xpath} - Retry Wait Until Page Contains ${scope} - Retry Wait Until Page Contains ${tag} - -Set Daily Schedule - Retry Element Click xpath=${project_tag_retention_edit_schedule_xpath} - Retry Element Click xpath=${project_tag_retention_select_policy_xpath} - Retry Element Click xpath=${project_tag_retention_option_daily_xpath} - Retry Element Click xpath=${project_tag_retention_config_save_xpath} - Retry Wait Until Page Contains Element xpath=${project_tag_retention_schedule_ok_xpath} - Retry Element Click xpath=${project_tag_retention_schedule_ok_xpath} - Retry Wait Until Page Contains Element xpath=${project_tag_retention_span_daily_xpath} - -Execute Result Should Be - [Arguments] ${result} - :FOR ${idx} IN RANGE 0 20 - \ ${out} Run Keyword And Ignore Error Retry Wait Until Page Contains Element xpath=//clr-dg-cell[contains(., '${result}')] - \ Exit For Loop If '${out[0]}'=='PASS' - \ Sleep 6 - Should Be Equal As Strings '${out[0]}' 'PASS' - -Execute Dry Run - Retry Element Click xpath=${project_tag_retention_dry_run_xpath} - Retry Wait Until Page Contains Element xpath=${project_tag_retention_record_yes_xpath} - Sleep 5 - Retry Element Click xpath=${project_tag_retention_record_yes_xpath} - # memcached:123 should be deleted and hello-world:latest should be retained - Execute Result Should Be 0/1 - - -Execute Run - Retry Element Click xpath=${project_tag_retention_run_now_xpath} - Retry Element Click xpath=${project_tag_retention_execute_run_xpath} - Retry Wait Until Page Contains Element xpath=${project_tag_retention_record_no_xpath} - Sleep 5 - Retry Element Click xpath=${project_tag_retention_record_no_xpath} - # memcached:123 should be deleted and hello-world:latest should be retained - Execute Result Should Be 0/1 - +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** + +Add A Tag Retention Rule + Retry Element Click xpath=${project_tag_retention_add_rule_xpath} + Retry Element Click xpath=${project_tag_retention_template_xpath} + Retry Element Click xpath=${project_tag_retention_option_always_xpath} + Retry Element Click xpath=${project_tag_retention_save_add_button_xpath} + Retry Wait Until Page Contains Element xpath=${project_tag_retention_rule_name_xpath} + +Add A Tag Immutability Rule + [Arguments] ${scope} ${tag} + Retry Double Keywords When Error Retry Element Click xpath=${project_tag_retention_add_rule_xpath} Retry Wait Until Page Contains Element xpath=${project_tag_immutability_save_add_button_xpath} + Retry Clear Element Text ${project_tag_immutability_scope_input_xpath} + Retry Text Input ${project_tag_immutability_scope_input_xpath} ${scope} + Retry Clear Element Text ${project_tag_immutability_tag_input_xpath} + Retry Text Input ${project_tag_immutability_tag_input_xpath} ${tag} + Retry Double Keywords When Error Retry Element Click xpath=${project_tag_immutability_save_add_button_xpath} Retry Wait Until Page Contains Element xpath=${project_tag_retention_rule_name_xpath} + Retry Wait Until Page Contains ${scope} + Retry Wait Until Page Contains ${tag} + +Delete A Tag Retention Rule + Retry Element Click xpath=${project_tag_retention_action_button_xpath} + Retry Element Click xpath=${project_tag_retention_delete_button_xpath} + Retry Wait Until Page Not Contains Element xpath=${project_tag_retention_rule_name_xpath} + +Delete A Tag Immutability Rule + Retry Element Click xpath=${project_tag_retention_action_button_xpath} + Retry Element Click xpath=${project_tag_retention_delete_button_xpath} + Retry Wait Until Page Not Contains Element xpath=${project_tag_retention_rule_name_xpath} + +Edit A Tag Retention Rule + [Arguments] ${repos} ${tags} + Retry Element Click xpath=${project_tag_retention_action_button_xpath} + Retry Element Click xpath=${project_tag_retention_edit_button_xpath} + Retry Wait Until Page Contains Element xpath=${project_tag_retention_modal_title_edit_xpath} + Input Text ${project_tag_retention_repo_input_xpath} ${repos} + Input Text ${project_tag_retention_tags_input_xpath} ${tags} + Retry Element Click xpath=${project_tag_retention_save_add_button_xpath} + Retry Wait Until Page Contains Element xpath=//span[contains(@class, 'rule-name')]//span[contains(.,'${tags}')] + +Edit A Tag Immutability Rule + [Arguments] ${scope} ${tag} + Retry Element Click xpath=${project_tag_retention_action_button_xpath} + Retry Element Click xpath=${project_tag_retention_edit_button_xpath} + Retry Clear Element Text ${project_tag_immutability_scope_input_xpath} + Retry Text Input ${project_tag_immutability_scope_input_xpath} ${scope} + Retry Clear Element Text ${project_tag_immutability_tag_input_xpath} + Retry Text Input ${project_tag_immutability_tag_input_xpath} ${tag} + Retry Double Keywords When Error Retry Element Click xpath=${project_tag_immutability_save_add_button_xpath} Retry Wait Until Page Contains Element xpath=${project_tag_retention_rule_name_xpath} + Retry Wait Until Page Contains ${scope} + Retry Wait Until Page Contains ${tag} + +Set Daily Schedule + Retry Element Click xpath=${project_tag_retention_edit_schedule_xpath} + Retry Element Click xpath=${project_tag_retention_select_policy_xpath} + Retry Element Click xpath=${project_tag_retention_option_daily_xpath} + Retry Element Click xpath=${project_tag_retention_config_save_xpath} + Retry Wait Until Page Contains Element xpath=${project_tag_retention_schedule_ok_xpath} + Retry Element Click xpath=${project_tag_retention_schedule_ok_xpath} + Retry Wait Until Page Contains Element xpath=${project_tag_retention_span_daily_xpath} + +Execute Result Should Be + [Arguments] ${result} + FOR ${idx} IN RANGE 0 20 + ${out} Run Keyword And Ignore Error Retry Wait Until Page Contains Element xpath=//clr-dg-cell[contains(., '${result}')] + Exit For Loop If '${out[0]}'=='PASS' + Sleep 6 + END + Should Be Equal As Strings '${out[0]}' 'PASS' + +Execute Dry Run + Retry Element Click xpath=${project_tag_retention_dry_run_xpath} + Retry Wait Until Page Contains Element xpath=${project_tag_retention_record_yes_xpath} + Sleep 5 + Retry Element Click xpath=${project_tag_retention_record_yes_xpath} + # memcached:123 should be deleted and hello-world:latest should be retained + Execute Result Should Be 0/1 + + +Execute Run + Retry Element Click xpath=${project_tag_retention_run_now_xpath} + Retry Element Click xpath=${project_tag_retention_execute_run_xpath} + Retry Wait Until Page Contains Element xpath=${project_tag_retention_record_no_xpath} + Sleep 5 + Retry Element Click xpath=${project_tag_retention_record_no_xpath} + # memcached:123 should be deleted and hello-world:latest should be retained + Execute Result Should Be 0/1 + diff --git a/tests/resources/Harbor-Pages/Project-Tag-Retention_Elements.robot b/tests/resources/Harbor-Pages/Project-Tag-Retention_Elements.robot index dd72f138f..bcd351d12 100644 --- a/tests/resources/Harbor-Pages/Project-Tag-Retention_Elements.robot +++ b/tests/resources/Harbor-Pages/Project-Tag-Retention_Elements.robot @@ -1,45 +1,45 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${project_tag_retention_add_rule_xpath} //*[@id='add-rule'] -${project_tag_retention_repo_input_xpath} //*[@id='repos'] -${project_tag_retention_param_input_xpath} //*[@id='param'] -${project_tag_retention_tags_input_xpath} //*[@id='tags'] -${project_tag_retention_save_add_button_xpath} //*[@id='save-add'] -${project_tag_retention_template_xpath} //*[@id='template'] -${project_tag_retention_option_always_xpath} //option[@value='always'] -${project_tag_retention_rule_name_xpath} //ul//span[@class='rule-name ml-5'] -${project_tag_retention_edit_schedule_xpath} //*[@id='editSchedule'] -${project_tag_retention_select_policy_xpath} //*[@id='selectPolicy'] -${project_tag_retention_option_daily_xpath} //option[@value='Daily'] -${project_tag_retention_config_save_xpath} //*[@id='config-save'] -${project_tag_retention_schedule_ok_xpath} //*[@id='schedule-ok'] -${project_tag_retention_span_daily_xpath} //cron-selection//div//span[contains(.,'0 0 0 * * *')] -${project_tag_retention_dry_run_xpath} //*[@id='dry-run'] -${project_tag_retention_record_yes_xpath} //clr-datagrid[contains(.,'YES')] -${project_tag_retention_run_now_xpath} //*[@id='run-now'] -${project_tag_retention_execute_run_xpath} //*[@id='execute-run'] -${project_tag_retention_record_no_xpath} //clr-datagrid[contains(.,'NO')] -${project_tag_retention_action_button_xpath} //button[contains(.,'ACTION')] -${project_tag_retention_delete_button_xpath} //div[contains(@class,'dropdown-menu')]//button[contains(.,'Delete')] -${project_tag_retention_edit_button_xpath} //div[contains(@class,'dropdown-menu')]//button[contains(.,'Edit')] -${project_tag_retention_modal_title_edit_xpath} //h3[contains(.,'Edit Tag Retention Rule')] - -${project_tag_immutability_scope_input_xpath} //*[@id='scope-input'] -${project_tag_immutability_tag_input_xpath} //*[@id='tag-input'] -${project_tag_immutability_save_add_button_xpath} //*[@id='add-edit-btn'] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${project_tag_retention_add_rule_xpath} //*[@id='add-rule'] +${project_tag_retention_repo_input_xpath} //*[@id='repos'] +${project_tag_retention_param_input_xpath} //*[@id='param'] +${project_tag_retention_tags_input_xpath} //*[@id='tags'] +${project_tag_retention_save_add_button_xpath} //*[@id='save-add'] +${project_tag_retention_template_xpath} //*[@id='template'] +${project_tag_retention_option_always_xpath} //option[@value='always'] +${project_tag_retention_rule_name_xpath} //ul//span[@class='rule-name ml-5'] +${project_tag_retention_edit_schedule_xpath} //*[@id='editSchedule'] +${project_tag_retention_select_policy_xpath} //*[@id='selectPolicy'] +${project_tag_retention_option_daily_xpath} //option[@value='Daily'] +${project_tag_retention_config_save_xpath} //*[@id='config-save'] +${project_tag_retention_schedule_ok_xpath} //*[@id='schedule-ok'] +${project_tag_retention_span_daily_xpath} //cron-selection//div//span[contains(.,'0 0 0 * * *')] +${project_tag_retention_dry_run_xpath} //*[@id='dry-run'] +${project_tag_retention_record_yes_xpath} //clr-datagrid[contains(.,'YES')] +${project_tag_retention_run_now_xpath} //*[@id='run-now'] +${project_tag_retention_execute_run_xpath} //*[@id='execute-run'] +${project_tag_retention_record_no_xpath} //clr-datagrid[contains(.,'NO')] +${project_tag_retention_action_button_xpath} //button[contains(.,'ACTION')] +${project_tag_retention_delete_button_xpath} //div[contains(@class,'dropdown-menu')]//button[contains(.,'Delete')] +${project_tag_retention_edit_button_xpath} //div[contains(@class,'dropdown-menu')]//button[contains(.,'Edit')] +${project_tag_retention_modal_title_edit_xpath} //h3[contains(.,'Edit Tag Retention Rule')] + +${project_tag_immutability_scope_input_xpath} //*[@id='scope-input'] +${project_tag_immutability_tag_input_xpath} //*[@id='tag-input'] +${project_tag_immutability_save_add_button_xpath} //*[@id='add-edit-btn'] diff --git a/tests/resources/Harbor-Pages/Project-Webhooks.robot b/tests/resources/Harbor-Pages/Project-Webhooks.robot index 0a069403d..5f29ca403 100644 --- a/tests/resources/Harbor-Pages/Project-Webhooks.robot +++ b/tests/resources/Harbor-Pages/Project-Webhooks.robot @@ -1,65 +1,65 @@ -*** Settings *** -Documentation Harbor Webhooks -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -Switch To Project Webhooks - #Switch To Project Tab Overflow - Retry Element Click xpath=//project-detail//a[contains(.,'Webhooks')] - Sleep 1 - -Create A New Webhook - [Arguments] ${webhook_name} ${webhook_endpoint_url} - Retry Element Click ${new_webhook_button_xpath} - Retry Text Input ${webhook_name_xpath} ${webhook_name} - Retry Text Input ${webhook_endpoint_id_xpath} ${webhook_endpoint_url} - Retry Double Keywords When Error Retry Element Click ${create_webhooks_continue_button_xpath} Retry Wait Until Page Not Contains Element ${create_webhooks_continue_button_xpath} - Capture Page Screenshot - Retry Wait Until Page Contains ${webhook_name} - -Update A Webhook - [Arguments] ${old_webhook_name} ${new_webhook_name} ${new_webhook_enpoint} - # select one webhook - Retry Element Click xpath=//clr-dg-row[contains(.,'${old_webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] - Retry Element Click ${action_webhook_xpath} - Retry Element Click ${action_webhook_edit_button} - - #cancel1 - Retry Double Keywords When Error Retry Element Click ${edit_webhooks_cancel_button_xpath} Retry Wait Until Page Not Contains Element ${edit_webhooks_cancel_button_xpath} - #confirm - Retry Element Click ${action_webhook_xpath} - Retry Element Click ${action_webhook_edit_button} - Retry Text Input ${webhook_name_xpath} ${new_webhook_name} - Retry Text Input ${webhook_endpoint_id_xpath} ${new_webhook_enpoint} - Retry Double Keywords When Error Retry Element Click ${edit_webhooks_save_button_xpath} Retry Wait Until Page Not Contains Element ${edit_webhooks_save_button_xpath} - Retry Wait Until Page Contains ${new_webhook_name} - Capture Page Screenshot - -Enable/Disable State of Same Webhook - [Arguments] ${webhook_name} - Retry Element Click xpath=//clr-dg-row[contains(.,'${webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] - Retry Element Click ${action_webhook_xpath} - Retry Element Click ${action_webhook_disable_or_enable_button} - Retry Wait Until Page Contains Element ${dialog_disable_id_xpath} - Retry Element Click ${dialog_disable_id_xpath} - # contain disabled webhook - Retry Wait Until Page Contains Element xpath=//clr-dg-row[contains(.,'${webhook_name}')]//span[contains(.,'Disabled')] - - Retry Element Click xpath=//clr-dg-row[contains(.,'${webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] - Retry Element Click ${action_webhook_xpath} - Retry Element Click ${action_webhook_disable_or_enable_button} - Retry Wait Until Page Contains Element ${dialog_enable_id_xpath} - Retry Element Click ${dialog_enable_id_xpath} - # not contain disabled webhook - Retry Wait Until Page Not Contains Element xpath=//clr-dg-row[contains(.,'${webhook_name}')]//span[contains(.,'Disabled')] - -Delete A Webhook - [Arguments] ${webhook_name} - Retry Element Click xpath=//clr-dg-row[contains(.,'${webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] - Retry Element Click ${action_webhook_xpath} - Retry Element Click ${action_webhook_delete_button} - Retry Wait Until Page Contains Element ${dialog_delete_button} - Retry Element Click ${dialog_delete_button} +*** Settings *** +Documentation Harbor Webhooks +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +Switch To Project Webhooks + #Switch To Project Tab Overflow + Retry Element Click xpath=//project-detail//a[contains(.,'Webhooks')] + Sleep 1 + +Create A New Webhook + [Arguments] ${webhook_name} ${webhook_endpoint_url} + Retry Element Click ${new_webhook_button_xpath} + Retry Text Input ${webhook_name_xpath} ${webhook_name} + Retry Text Input ${webhook_endpoint_id_xpath} ${webhook_endpoint_url} + Retry Double Keywords When Error Retry Element Click ${create_webhooks_continue_button_xpath} Retry Wait Until Page Not Contains Element ${create_webhooks_continue_button_xpath} + Capture Page Screenshot + Retry Wait Until Page Contains ${webhook_name} + +Update A Webhook + [Arguments] ${old_webhook_name} ${new_webhook_name} ${new_webhook_enpoint} + # select one webhook + Retry Element Click xpath=//clr-dg-row[contains(.,'${old_webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] + Retry Element Click ${action_webhook_xpath} + Retry Element Click ${action_webhook_edit_button} + + #cancel1 + Retry Double Keywords When Error Retry Element Click ${edit_webhooks_cancel_button_xpath} Retry Wait Until Page Not Contains Element ${edit_webhooks_cancel_button_xpath} + #confirm + Retry Element Click ${action_webhook_xpath} + Retry Element Click ${action_webhook_edit_button} + Retry Text Input ${webhook_name_xpath} ${new_webhook_name} + Retry Text Input ${webhook_endpoint_id_xpath} ${new_webhook_enpoint} + Retry Double Keywords When Error Retry Element Click ${edit_webhooks_save_button_xpath} Retry Wait Until Page Not Contains Element ${edit_webhooks_save_button_xpath} + Retry Wait Until Page Contains ${new_webhook_name} + Capture Page Screenshot + +Enable/Disable State of Same Webhook + [Arguments] ${webhook_name} + Retry Element Click xpath=//clr-dg-row[contains(.,'${webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] + Retry Element Click ${action_webhook_xpath} + Retry Element Click ${action_webhook_disable_or_enable_button} + Retry Wait Until Page Contains Element ${dialog_disable_id_xpath} + Retry Element Click ${dialog_disable_id_xpath} + # contain disabled webhook + Retry Wait Until Page Contains Element xpath=//clr-dg-row[contains(.,'${webhook_name}')]//span[contains(.,'Disabled')] + + Retry Element Click xpath=//clr-dg-row[contains(.,'${webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] + Retry Element Click ${action_webhook_xpath} + Retry Element Click ${action_webhook_disable_or_enable_button} + Retry Wait Until Page Contains Element ${dialog_enable_id_xpath} + Retry Element Click ${dialog_enable_id_xpath} + # not contain disabled webhook + Retry Wait Until Page Not Contains Element xpath=//clr-dg-row[contains(.,'${webhook_name}')]//span[contains(.,'Disabled')] + +Delete A Webhook + [Arguments] ${webhook_name} + Retry Element Click xpath=//clr-dg-row[contains(.,'${webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] + Retry Element Click ${action_webhook_xpath} + Retry Element Click ${action_webhook_delete_button} + Retry Wait Until Page Contains Element ${dialog_delete_button} + Retry Element Click ${dialog_delete_button} Retry Wait Until Page Not Contains Element xpath=//clr-dg-row[contains(.,'${webhook_name}')]//clr-checkbox-wrapper//label[contains(@class,'clr-control-label')] \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/Project-Webhooks_Elements.robot b/tests/resources/Harbor-Pages/Project-Webhooks_Elements.robot index 9a61d7539..1c711a60d 100644 --- a/tests/resources/Harbor-Pages/Project-Webhooks_Elements.robot +++ b/tests/resources/Harbor-Pages/Project-Webhooks_Elements.robot @@ -1,24 +1,24 @@ -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${new_webhook_button_xpath} xpath=//*[@id='new-webhook'] -${webhook_name_xpath} xpath=//*[@id='name'] -${webhook_endpoint_id_xpath} xpath=//*[@id='edit_endpoint_url'] -${webhook_auth_header_xpath} xpath=//*[@id='auth_header'] -${action_webhook_xpath} xpath=//*[@id='action-webhook'] -${action_webhook_edit_button} xpath=//*[@id='edit-webhook'] -${action_webhook_disable_or_enable_button} xpath=//*[@id='toggle-webhook'] -${action_webhook_delete_button} xpath=//*[@id='delete-webhook'] -${dialog_delete_button} xpath=//clr-modal//button[contains(.,'DELETE')] - - -${create_webhooks_continue_button_xpath} xpath=//*[@id='new-webhook-continue'] -${edit_webhooks_cancel_button_xpath} xpath=//*[@id='edit-webhook-cancel'] -${edit_webhooks_save_button_xpath} xpath=//*[@id='edit-webhook-save'] -${edit_webhooks_verify_remote_cert_chkb_xpath} xpath=//input[@id='verify_remote_cert'] -${project_webhook_edit_id_xpath} xpath=//*[@id='edit-webhook'] -${project_webhook_enable_id_xpath} xpath=//*[@id='enable-webhook-action'] -${project_webhook_disable_id_xpath} xpath=//*[@id='disable-webhook-action'] -${dialog_disable_id_xpath} xpath=//*[@id='dialog-action-disable'] -${dialog_enable_id_xpath} xpath=//*[@id='dialog-action-enable'] +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${new_webhook_button_xpath} xpath=//*[@id='new-webhook'] +${webhook_name_xpath} xpath=//*[@id='name'] +${webhook_endpoint_id_xpath} xpath=//*[@id='edit_endpoint_url'] +${webhook_auth_header_xpath} xpath=//*[@id='auth_header'] +${action_webhook_xpath} xpath=//*[@id='action-webhook'] +${action_webhook_edit_button} xpath=//*[@id='edit-webhook'] +${action_webhook_disable_or_enable_button} xpath=//*[@id='toggle-webhook'] +${action_webhook_delete_button} xpath=//*[@id='delete-webhook'] +${dialog_delete_button} xpath=//clr-modal//button[contains(.,'DELETE')] + + +${create_webhooks_continue_button_xpath} xpath=//*[@id='new-webhook-continue'] +${edit_webhooks_cancel_button_xpath} xpath=//*[@id='edit-webhook-cancel'] +${edit_webhooks_save_button_xpath} xpath=//*[@id='edit-webhook-save'] +${edit_webhooks_verify_remote_cert_chkb_xpath} xpath=//input[@id='verify_remote_cert'] +${project_webhook_edit_id_xpath} xpath=//*[@id='edit-webhook'] +${project_webhook_enable_id_xpath} xpath=//*[@id='enable-webhook-action'] +${project_webhook_disable_id_xpath} xpath=//*[@id='disable-webhook-action'] +${dialog_disable_id_xpath} xpath=//*[@id='dialog-action-disable'] +${dialog_enable_id_xpath} xpath=//*[@id='dialog-action-enable'] diff --git a/tests/resources/Harbor-Pages/Project.robot b/tests/resources/Harbor-Pages/Project.robot index 784e482a7..82500cfea 100644 --- a/tests/resources/Harbor-Pages/Project.robot +++ b/tests/resources/Harbor-Pages/Project.robot @@ -198,14 +198,16 @@ Do Log Advanced Search Retry Click Repo Name [Arguments] ${repo_name_element} - :For ${n} IN RANGE 1 10 - \ ${out} Run Keyword And Ignore Error Retry Double Keywords When Error Retry Element Click ${repo_name_element} Retry Wait Element ${tag_table_column_vulnerabilities} - \ Exit For Loop If '${out[0]}'=='PASS' + FOR ${n} IN RANGE 1 10 + ${out} Run Keyword And Ignore Error Retry Double Keywords When Error Retry Element Click ${repo_name_element} Retry Wait Element ${tag_table_column_vulnerabilities} + Exit For Loop If '${out[0]}'=='PASS' + END Should Be Equal As Strings '${out[0]}' 'PASS' - :For ${n} IN RANGE 1 10 - \ ${out} Run Keyword And Ignore Error Retry Wait Until Page Not Contains Element ${repo_list_spinner} - \ Exit For Loop If '${out[0]}'=='PASS' + FOR ${n} IN RANGE 1 10 + ${out} Run Keyword And Ignore Error Retry Wait Until Page Not Contains Element ${repo_list_spinner} + Exit For Loop If '${out[0]}'=='PASS' + END Should Be Equal As Strings '${out[0]}' 'PASS' Go Into Repo @@ -214,15 +216,16 @@ Go Into Repo Retry Wait Until Page Not Contains Element ${repo_list_spinner} ${repo_name_element}= Set Variable xpath=//clr-dg-cell[contains(.,'${repoName}')]/a Retry Element Click ${repo_search_icon} - :For ${n} IN RANGE 1 10 - \ Retry Clear Element Text ${repo_search_input} - \ Retry Text Input ${repo_search_input} ${repoName} - \ ${out} Run Keyword And Ignore Error Retry Wait Until Page Contains Element ${repo_name_element} - \ Sleep 2 - \ Continue For Loop If '${out[0]}'=='FAIL' - \ ${out} Retry Click Repo Name ${repo_name_element} - \ Sleep 2 - \ Exit For Loop + FOR ${n} IN RANGE 1 10 + Retry Clear Element Text ${repo_search_input} + Retry Text Input ${repo_search_input} ${repoName} + ${out} Run Keyword And Ignore Error Retry Wait Until Page Contains Element ${repo_name_element} + Sleep 2 + Continue For Loop If '${out[0]}'=='FAIL' + ${out} Retry Click Repo Name ${repo_name_element} + Sleep 2 + Exit For Loop + END Click Index Achieve @@ -232,11 +235,12 @@ Click Index Achieve Go Into Index And Contain Artifacts [Arguments] ${tag_name} ${limit}=3 Retry Double Keywords When Error Click Index Achieve ${tag_name} Page Should Contain Element ${tag_table_column_os_arch} - :For ${n} IN RANGE 1 10 - \ ${out} Run Keyword And Ignore Error Page Should Contain Element ${artifact_rows} limit=${limit} - \ Exit For Loop If '${out[0]}'=='PASS' - \ Capture Page Screenshot gointo_${tag_name}.png - \ Sleep 3 + FOR ${n} IN RANGE 1 10 + ${out} Run Keyword And Ignore Error Page Should Contain Element ${artifact_rows} limit=${limit} + Exit For Loop If '${out[0]}'=='PASS' + Capture Page Screenshot gointo_${tag_name}.png + Sleep 3 + END Run Keyword If '${out[0]}'=='FAIL' Capture Page Screenshot Should Be Equal As Strings '${out[0]}' 'PASS' diff --git a/tests/resources/Harbor-Pages/Project_Elements.robot b/tests/resources/Harbor-Pages/Project_Elements.robot index 1e8cfbd10..1133f426b 100644 --- a/tests/resources/Harbor-Pages/Project_Elements.robot +++ b/tests/resources/Harbor-Pages/Project_Elements.robot @@ -1,77 +1,77 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${create_project_button_xpath} //clr-main-container//button[contains(., 'New Project')] -${project_name_xpath} //*[@id='create_project_name'] -${project_public_xpath} //input[@name='public']/..//label -${project_save_css} html body.no-scrolling harbor-app harbor-shell clr-main-container.main-container div.content-container div.content-area.content-area-override project div.row div.col-lg-12.col-md-12.col-sm-12.col-xs-12 div.row.flex-items-xs-between div.option-left create-project clr-modal div.modal div.modal-dialog div.modal-content div.modal-footer button.btn.btn-primary -${log_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,'Logs')] -${projects_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,'Projects')] -${project_replication_xpath} //project-detail//a[contains(.,'Replication')] -${project_log_xpath} //project-detail//a[contains(.,'Logs')] -${project_member_xpath} //project-detail//a[contains(.,'Members')] -${project_config_tabsheet} xpath=//project-detail//a[contains(.,'Configuration')] -${project_tag_strategy_xpath} //clr-tabs//a[contains(.,'Policy')] -${project_tab_overflow_btn} //clr-tabs//li//button[contains(@class,"dropdown-toggle")] - -${project_tag_immutability_switch} //project-detail/app-tag-feature-integration//label/a[contains(.,'Tag Immutability')] - -${create_project_CANCEL_button_xpath} xpath=//button[contains(.,'CANCEL')] -${create_project_OK_button_xpath} xpath=//button[contains(.,'OK')] -${delete_confirm_btn} xpath=//confirmation-dialog//button[contains(.,'DELETE')] -${project_statistics_private_repository_icon} xpath=//project/div/div/div[1]/div/statistics-panel/div/div[2]/div[1]/div[2]/div[2]/statistics/div/span[1] -${repo_delete_confirm_btn} xpath=//clr-modal//button[2] -${repo_retag_confirm_dlg} css=${modal-dialog} -${repo_delete_on_card_view_btn} //clr-modal//button[contains(.,'DELETE')] -${delete_btn} //button[contains(.,'Delete')] -${repo_delete_btn} xpath=//hbr-repository-gridview//button[contains(.,'Delete')] -${project_delete_btn} xpath=//button[@id='delete-project'] -${tag_delete_btn} xpath=//tag-repository//clr-datagrid//button[contains(.,'Delete')] -${user_delete_btn} xpath=/clr-dropdown-menu//button[contains(.,'Delete')] -${repo_search_icon} xpath=//hbr-filter//clr-icon -${repo_search_input} xpath=//hbr-filter//input -${repo_list_spinner} xpath=//clr-datagrid//clr-spinner -#${repo_search_icon} xpath=//hbr-repository-gridview//clr-datagrid//clr-dg-column[contains(.,'Name')]//clr-dg-string-filter//button//clr-icon -#${repo_search_input} xpath=//div[@class[contains(.,'datagrid-filter')]]//input -${repo_tag_1st_checkbox} xpath=//clr-datagrid//clr-dg-row//clr-checkbox-wrapper -${tag_table_column_pull_command} xpath=//clr-dg-column//span[contains(.,'Pull Command')] -${tag_table_column_vulnerabilities} xpath=//clr-dg-column//span[contains(.,'Vulnerabilities')] -${tag_table_column_os_arch} xpath=//clr-dg-column//span[contains(.,'OS/ARCH')] -${tag_table_column_tag} xpath=//clr-dg-column//span[contains(.,'Tag')] -${tag_table_column_size} xpath=//clr-dg-column//span[contains(.,'Size')] -${tag_table_column_vulnerability} xpath=//clr-dg-column//span[contains(.,'Vulnerability')] -${tag_images_btn} xpath=//hbr-repository//button[contains(.,'Images')] -${project_member_action_xpath} xpath=//*[@id='member-action'] -${project_member_set_role_xpath} xpath=//clr-dropdown-menu//label[contains(.,'Set Role')] -${project_config_public_checkbox} xpath=//input[@name='public'] -${project_config_content_trust_checkbox} xpath=//input[@name='content-trust'] -${project_config_scan_images_on_push_checkbox} xpath=//input[@name='scan-image-on-push'] -${project_config_prevent_vulnerable_images_from_running_checkbox} xpath=//input[@name='prevent-vulenrability-image-input'] -${project_config_severity_select} xpath=//select[@id='severity'] -${project_config_public_checkbox_label} xpath=//*[@id="clr-wrapper-public"]/div/clr-checkbox-wrapper/label -${project_config_prevent_vulenrability_checkbox_label} xpath=//*[@id='prevent-vulenrability-image']//clr-checkbox-wrapper//label -${project_config_system_wl_radio_input} xpath=//clr-radio-wrapper//label[contains(.,'System allowlist')] -${project_config_project_wl_radio_input} xpath=//clr-radio-wrapper//label[contains(.,'Project allowlist')] -${project_config_system_wl_radio_input_id} systemAllowlistOrProjectAllowlist -${project_config_project_wl_radio_input_id} systemAllowlistOrProjectAllowlist -${project_config_project_wl_add_btn} xpath=//*[@id='show-add-modal'] -${project_config_project_wl_add_confirm_btn} xpath=//*[@id='add-to-allowlist'] -${project_config_save_btn} xpath=//hbr-project-policy-config//button[contains(.,'SAVE')] -${project_add_count_quota_input_text_id} xpath=//*[@id='create_project_count_limit'] -${project_add_storage_quota_input_text_id} xpath=//*[@id='create_project_storage_limit'] -${project_add_storage_quota_unit_id} xpath=//*[@id='create_project_storage_limit_unit'] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${create_project_button_xpath} //clr-main-container//button[contains(., 'New Project')] +${project_name_xpath} //*[@id='create_project_name'] +${project_public_xpath} //input[@name='public']/..//label +${project_save_css} html body.no-scrolling harbor-app harbor-shell clr-main-container.main-container div.content-container div.content-area.content-area-override project div.row div.col-lg-12.col-md-12.col-sm-12.col-xs-12 div.row.flex-items-xs-between div.option-left create-project clr-modal div.modal div.modal-dialog div.modal-content div.modal-footer button.btn.btn-primary +${log_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,'Logs')] +${projects_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,'Projects')] +${project_replication_xpath} //project-detail//a[contains(.,'Replication')] +${project_log_xpath} //project-detail//a[contains(.,'Logs')] +${project_member_xpath} //project-detail//a[contains(.,'Members')] +${project_config_tabsheet} xpath=//project-detail//a[contains(.,'Configuration')] +${project_tag_strategy_xpath} //clr-tabs//a[contains(.,'Policy')] +${project_tab_overflow_btn} //clr-tabs//li//button[contains(@class,"dropdown-toggle")] + +${project_tag_immutability_switch} //project-detail/app-tag-feature-integration//label/a[contains(.,'Tag Immutability')] + +${create_project_CANCEL_button_xpath} xpath=//button[contains(.,'CANCEL')] +${create_project_OK_button_xpath} xpath=//button[contains(.,'OK')] +${delete_confirm_btn} xpath=//confirmation-dialog//button[contains(.,'DELETE')] +${project_statistics_private_repository_icon} xpath=//project/div/div/div[1]/div/statistics-panel/div/div[2]/div[1]/div[2]/div[2]/statistics/div/span[1] +${repo_delete_confirm_btn} xpath=//clr-modal//button[2] +${repo_retag_confirm_dlg} css=${modal-dialog} +${repo_delete_on_card_view_btn} //clr-modal//button[contains(.,'DELETE')] +${delete_btn} //button[contains(.,'Delete')] +${repo_delete_btn} xpath=//hbr-repository-gridview//button[contains(.,'Delete')] +${project_delete_btn} xpath=//button[@id='delete-project'] +${tag_delete_btn} xpath=//tag-repository//clr-datagrid//button[contains(.,'Delete')] +${user_delete_btn} xpath=/clr-dropdown-menu//button[contains(.,'Delete')] +${repo_search_icon} xpath=//hbr-filter//clr-icon +${repo_search_input} xpath=//hbr-filter//input +${repo_list_spinner} xpath=//clr-datagrid//clr-spinner +#${repo_search_icon} xpath=//hbr-repository-gridview//clr-datagrid//clr-dg-column[contains(.,'Name')]//clr-dg-string-filter//button//clr-icon +#${repo_search_input} xpath=//div[@class[contains(.,'datagrid-filter')]]//input +${repo_tag_1st_checkbox} xpath=//clr-datagrid//clr-dg-row//clr-checkbox-wrapper +${tag_table_column_pull_command} xpath=//clr-dg-column//span[contains(.,'Pull Command')] +${tag_table_column_vulnerabilities} xpath=//clr-dg-column//span[contains(.,'Vulnerabilities')] +${tag_table_column_os_arch} xpath=//clr-dg-column//span[contains(.,'OS/ARCH')] +${tag_table_column_tag} xpath=//clr-dg-column//span[contains(.,'Tag')] +${tag_table_column_size} xpath=//clr-dg-column//span[contains(.,'Size')] +${tag_table_column_vulnerability} xpath=//clr-dg-column//span[contains(.,'Vulnerability')] +${tag_images_btn} xpath=//hbr-repository//button[contains(.,'Images')] +${project_member_action_xpath} xpath=//*[@id='member-action'] +${project_member_set_role_xpath} xpath=//clr-dropdown-menu//label[contains(.,'Set Role')] +${project_config_public_checkbox} xpath=//input[@name='public'] +${project_config_content_trust_checkbox} xpath=//input[@name='content-trust'] +${project_config_scan_images_on_push_checkbox} xpath=//input[@name='scan-image-on-push'] +${project_config_prevent_vulnerable_images_from_running_checkbox} xpath=//input[@name='prevent-vulenrability-image-input'] +${project_config_severity_select} xpath=//select[@id='severity'] +${project_config_public_checkbox_label} xpath=//*[@id="clr-wrapper-public"]/div/clr-checkbox-wrapper/label +${project_config_prevent_vulenrability_checkbox_label} xpath=//*[@id='prevent-vulenrability-image']//clr-checkbox-wrapper//label +${project_config_system_wl_radio_input} xpath=//clr-radio-wrapper//label[contains(.,'System allowlist')] +${project_config_project_wl_radio_input} xpath=//clr-radio-wrapper//label[contains(.,'Project allowlist')] +${project_config_system_wl_radio_input_id} systemAllowlistOrProjectAllowlist +${project_config_project_wl_radio_input_id} systemAllowlistOrProjectAllowlist +${project_config_project_wl_add_btn} xpath=//*[@id='show-add-modal'] +${project_config_project_wl_add_confirm_btn} xpath=//*[@id='add-to-allowlist'] +${project_config_save_btn} xpath=//hbr-project-policy-config//button[contains(.,'SAVE')] +${project_add_count_quota_input_text_id} xpath=//*[@id='create_project_count_limit'] +${project_add_storage_quota_input_text_id} xpath=//*[@id='create_project_storage_limit'] +${project_add_storage_quota_unit_id} xpath=//*[@id='create_project_storage_limit_unit'] diff --git a/tests/resources/Harbor-Pages/Project_Robot_Account.robot b/tests/resources/Harbor-Pages/Project_Robot_Account.robot index 7c3f471cb..6b28c5722 100644 --- a/tests/resources/Harbor-Pages/Project_Robot_Account.robot +++ b/tests/resources/Harbor-Pages/Project_Robot_Account.robot @@ -1,24 +1,24 @@ -*** Settings *** - -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -Switch To Project Robot Account - #Switch To Project Tab Overflow - Retry Element Click ${project_robot_account_tabpage} - Retry Wait Until Page Contains Element ${project_robot_account_create_btn} - -Create A Robot Account And Return Token - [Arguments] ${projectname} ${robot_account_name} ${project_has_image}=${false} - Go Into Project ${projectname} has_image=${project_has_image} - Switch To Project Robot Account - Retry Element Click ${project_robot_account_create_btn} - Retry Text Input ${project_robot_account_create_name_input} ${robot_account_name} - Retry Element Click ${project_robot_account_never_expired_chkbox} - Retry Double Keywords When Error Retry Element Click ${project_robot_account_create_save_btn} Retry Wait Until Page Not Contains Element ${project_robot_account_create_save_btn} - ${token}= Get Value ${project_robot_account_token_input} - [Return] ${token} - - +*** Settings *** + +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +Switch To Project Robot Account + #Switch To Project Tab Overflow + Retry Element Click ${project_robot_account_tabpage} + Retry Wait Until Page Contains Element ${project_robot_account_create_btn} + +Create A Robot Account And Return Token + [Arguments] ${projectname} ${robot_account_name} ${project_has_image}=${false} + Go Into Project ${projectname} has_image=${project_has_image} + Switch To Project Robot Account + Retry Element Click ${project_robot_account_create_btn} + Retry Text Input ${project_robot_account_create_name_input} ${robot_account_name} + Retry Element Click ${project_robot_account_never_expired_chkbox} + Retry Double Keywords When Error Retry Element Click ${project_robot_account_create_save_btn} Retry Wait Until Page Not Contains Element ${project_robot_account_create_save_btn} + ${token}= Get Value ${project_robot_account_token_input} + [Return] ${token} + + diff --git a/tests/resources/Harbor-Pages/Project_Robot_Account_Elements.robot b/tests/resources/Harbor-Pages/Project_Robot_Account_Elements.robot index 9278f6eb3..f50389ae4 100644 --- a/tests/resources/Harbor-Pages/Project_Robot_Account_Elements.robot +++ b/tests/resources/Harbor-Pages/Project_Robot_Account_Elements.robot @@ -1,10 +1,10 @@ -*** Settings *** -Documentation This resource provides any keywords related to the Harbor robot-account feature - -*** Variables *** -${project_robot_account_tabpage} xpath=//project-detail//a[contains(.,'Robot Accounts')] -${project_robot_account_create_btn} xpath=//project-detail/app-robot-account//button -${project_robot_account_token_input} xpath=//app-robot-account//hbr-copy-input//input -${project_robot_account_never_expired_chkbox} xpath=//add-robot//clr-checkbox-wrapper/label[contains(.,'Never Expired')] -${project_robot_account_create_name_input} //input[@id='robot_name'] -${project_robot_account_create_save_btn} //add-robot//button[contains(.,'SAVE')] +*** Settings *** +Documentation This resource provides any keywords related to the Harbor robot-account feature + +*** Variables *** +${project_robot_account_tabpage} xpath=//project-detail//a[contains(.,'Robot Accounts')] +${project_robot_account_create_btn} xpath=//project-detail/app-robot-account//button +${project_robot_account_token_input} xpath=//app-robot-account//hbr-copy-input//input +${project_robot_account_never_expired_chkbox} xpath=//add-robot//clr-checkbox-wrapper/label[contains(.,'Never Expired')] +${project_robot_account_create_name_input} //input[@id='robot_name'] +${project_robot_account_create_save_btn} //add-robot//button[contains(.,'SAVE')] diff --git a/tests/resources/Harbor-Pages/Replication.robot b/tests/resources/Harbor-Pages/Replication.robot index 5e8e49aef..0d77c1e4c 100644 --- a/tests/resources/Harbor-Pages/Replication.robot +++ b/tests/resources/Harbor-Pages/Replication.robot @@ -30,10 +30,12 @@ Filter Replication Rule Filter Registry [Arguments] ${registry_name} ${registry_name_element}= Set Variable xpath=//clr-dg-cell[contains(.,'${registry_name}')] + Switch To Replication Manage + Switch To Registries Retry Element Click ${filter_registry_btn} - Retry Text Input ${filter_registry_input} ${ruleName} + Retry Text Input ${filter_registry_input} ${registry_name} Retry Wait Until Page Contains Element ${registry_name_element} - Capture Page Screenshot filter_repistry_${ruleName}.png + Capture Page Screenshot filter_repistry_${registry_name}.png Select Dest Registry [Arguments] ${endpoint} @@ -249,15 +251,16 @@ Delete Replication Rule Image Should Be Replicated To Project [Arguments] ${project} ${image} ${period}=60 ${times}=3 - :For ${n} IN RANGE 0 ${times} - \ Sleep ${period} - \ Go Into Project ${project} - \ Switch To Project Repo - \ #In AWS-ECR, under repository a, there're only several images: httpd,alpine,hello-world. - \ ${out} Run Keyword And Ignore Error Retry Wait Until Page Contains ${project}/${image} - \ Log To Console Return value is ${out[0]} - \ Exit For Loop If '${out[0]}'=='PASS' - \ Sleep 5 + FOR ${n} IN RANGE 0 ${times} + Sleep ${period} + Go Into Project ${project} + Switch To Project Repo + #In AWS-ECR, under repository a, there're only several images: httpd,alpine,hello-world. + ${out} Run Keyword And Ignore Error Retry Wait Until Page Contains ${project}/${image} + Log To Console Return value is ${out[0]} + Exit For Loop If '${out[0]}'=='PASS' + Sleep 5 + END Run Keyword If '${out[0]}'=='FAIL' Capture Page Screenshot Should Be Equal As Strings '${out[0]}' 'PASS' diff --git a/tests/resources/Harbor-Pages/ToolKit.robot b/tests/resources/Harbor-Pages/ToolKit.robot index 15e319f93..2cfc0b5c3 100644 --- a/tests/resources/Harbor-Pages/ToolKit.robot +++ b/tests/resources/Harbor-Pages/ToolKit.robot @@ -1,117 +1,124 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -Delete Success - [Arguments] @{obj} - :For ${obj} in @{obj} - \ Retry Wait Until Page Contains Element //*[@id='contentAll']//div[contains(.,'${obj}')]/../div/clr-icon[@shape='success-standard'] - Sleep 1 - Capture Page Screenshot - -Delete Fail - [Arguments] @{obj} - :For ${obj} in @{obj} - \ Retry Wait Until Page Contains Element //*[@id='contentAll']//div[contains(.,'${obj}')]/../div/clr-icon[@shape='error-standard'] - Sleep 1 - Capture Page Screenshot - -Filter Object -#Filter project repo user tag. - [Arguments] ${kw} - Retry Element Click xpath=//hbr-filter//clr-icon - ${element}= Set Variable xpath=//hbr-filter//input - Wait Until Element Is Visible And Enabled ${element} - Retry Clear Element Text ${element} - Retry Text Input ${element} ${kw} - Sleep 3 - -Filter Project -#Filter project repo user tag. - [Arguments] ${kw} - Retry Element Click ${log_xpath} - Retry Element Click ${projects_xpath} - Filter Object ${kw} - -Select Object -#select single element such as user project repo tag - [Arguments] ${obj} - Retry Element Click xpath=//clr-dg-row[contains(.,'${obj}')]//label - -Multi-delete Object - [Arguments] ${delete_btn} @{obj} - :For ${obj} in @{obj} - \ ${element}= Set Variable xpath=//clr-dg-row[contains(.,'${obj}')]//label - \ Retry Element Click ${element} - Sleep 1 - Capture Page Screenshot - Retry Element Click ${delete_btn} - Sleep 1 - Capture Page Screenshot - Retry Element Click ${repo_delete_on_card_view_btn} - Sleep 1 - Capture Page Screenshot - Sleep 1 - -# This func cannot support as the delete user flow changed. -Multi-delete Artifact - [Arguments] ${delete_btn} @{obj} - :For ${obj} in @{obj} - \ ${element}= Set Variable xpath=//clr-dg-row[contains(.,'${obj}')]//label - \ Retry Element Click ${element} - Sleep 1 - Capture Page Screenshot - Retry Element Click ${artifact_action_xpath} - Sleep 1 - Retry Element Click ${artifact_action_delete_xpath} - Sleep 1 - Capture Page Screenshot - Retry Element Click ${repo_delete_on_card_view_btn} - Sleep 1 - Capture Page Screenshot - Sleep 1 - -Multi-delete User - [Arguments] @{obj} - :For ${obj} in @{obj} - \ Retry Element Click //clr-dg-row[contains(.,'${obj}')]//label - Retry Element Click ${member_action_xpath} - Retry Element Click //*[@id='deleteUser'] - Retry Double Keywords When Error Retry Element Click ${delete_btn} Retry Wait Until Page Not Contains Element ${delete_btn} - - -Multi-delete Member - [Arguments] @{obj} - :For ${obj} in @{obj} - \ Retry Element Click //clr-dg-row[contains(.,'${obj}')]//clr-checkbox-wrapper/label - Retry Double Keywords When Error Retry Element Click ${member_action_xpath} Retry Wait Until Page Contains Element ${delete_action_xpath} - Retry Double Keywords When Error Retry Element Click ${delete_action_xpath} Retry Wait Until Page Contains Element ${delete_btn} - Retry Double Keywords When Error Retry Element Click ${delete_btn} Retry Wait Until Page Not Contains Element ${delete_btn} - - -Multi-delete Object Without Confirmation - [Arguments] @{obj} - :For ${obj} in @{obj} - \ Retry Element Click //clr-dg-row[contains(.,'${obj}')]//label - Retry Double Keywords When Error Retry Element Click ${delete_btn_2} Retry Wait Until Page Not Contains Element ${delete_btn_2} - - -Select All On Current Page Object - Retry Element Click //div[@class='datagrid-head']//label +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +Delete Success + [Arguments] @{obj} + FOR ${obj} IN @{obj} + Retry Wait Until Page Contains Element //*[@id='contentAll']//div[contains(.,'${obj}')]/../div/clr-icon[@shape='success-standard'] + END + Sleep 1 + Capture Page Screenshot + +Delete Fail + [Arguments] @{obj} + FOR ${obj} IN @{obj} + Retry Wait Until Page Contains Element //*[@id='contentAll']//div[contains(.,'${obj}')]/../div/clr-icon[@shape='error-standard'] + END + Sleep 1 + Capture Page Screenshot + +Filter Object +#Filter project repo user tag. + [Arguments] ${kw} + Retry Element Click xpath=//hbr-filter//clr-icon + ${element}= Set Variable xpath=//hbr-filter//input + Wait Until Element Is Visible And Enabled ${element} + Retry Clear Element Text ${element} + Retry Text Input ${element} ${kw} + Sleep 3 + +Filter Project +#Filter project repo user tag. + [Arguments] ${kw} + Retry Element Click ${log_xpath} + Retry Element Click ${projects_xpath} + Filter Object ${kw} + +Select Object +#select single element such as user project repo tag + [Arguments] ${obj} + Retry Element Click xpath=//clr-dg-row[contains(.,'${obj}')]//label + +Multi-delete Object + [Arguments] ${delete_btn} @{obj} + FOR ${obj} IN @{obj} + ${element}= Set Variable xpath=//clr-dg-row[contains(.,'${obj}')]//label + Retry Element Click ${element} + END + Sleep 1 + Capture Page Screenshot + Retry Element Click ${delete_btn} + Sleep 1 + Capture Page Screenshot + Retry Element Click ${repo_delete_on_card_view_btn} + Sleep 1 + Capture Page Screenshot + Sleep 1 + +# This func cannot support as the delete user flow changed. +Multi-delete Artifact + [Arguments] ${delete_btn} @{obj} + FOR ${obj} IN @{obj} + ${element}= Set Variable xpath=//clr-dg-row[contains(.,'${obj}')]//label + Retry Element Click ${element} + END + Sleep 1 + Capture Page Screenshot + Retry Element Click ${artifact_action_xpath} + Sleep 1 + Retry Element Click ${artifact_action_delete_xpath} + Sleep 1 + Capture Page Screenshot + Retry Element Click ${repo_delete_on_card_view_btn} + Sleep 1 + Capture Page Screenshot + Sleep 1 + +Multi-delete User + [Arguments] @{obj} + FOR ${obj} IN @{obj} + Retry Element Click //clr-dg-row[contains(.,'${obj}')]//label + END + Retry Element Click ${member_action_xpath} + Retry Element Click //*[@id='deleteUser'] + Retry Double Keywords When Error Retry Element Click ${delete_btn} Retry Wait Until Page Not Contains Element ${delete_btn} + + +Multi-delete Member + [Arguments] @{obj} + FOR ${obj} IN @{obj} + Retry Element Click //clr-dg-row[contains(.,'${obj}')]//clr-checkbox-wrapper/label + END + Retry Double Keywords When Error Retry Element Click ${member_action_xpath} Retry Wait Until Page Contains Element ${delete_action_xpath} + Retry Double Keywords When Error Retry Element Click ${delete_action_xpath} Retry Wait Until Page Contains Element ${delete_btn} + Retry Double Keywords When Error Retry Element Click ${delete_btn} Retry Wait Until Page Not Contains Element ${delete_btn} + + +Multi-delete Object Without Confirmation + [Arguments] @{obj} + FOR ${obj} IN @{obj} + Retry Element Click //clr-dg-row[contains(.,'${obj}')]//label + END + Retry Double Keywords When Error Retry Element Click ${delete_btn_2} Retry Wait Until Page Not Contains Element ${delete_btn_2} + + +Select All On Current Page Object + Retry Element Click //div[@class='datagrid-head']//label diff --git a/tests/resources/Harbor-Pages/ToolKit_Elements.robot b/tests/resources/Harbor-Pages/ToolKit_Elements.robot index f569010e1..c6909b08f 100644 --- a/tests/resources/Harbor-Pages/ToolKit_Elements.robot +++ b/tests/resources/Harbor-Pages/ToolKit_Elements.robot @@ -1,20 +1,20 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${member_action_xpath} //*[@id="member-action"] -${delete_action_xpath} //clr-dropdown/clr-dropdown-menu/button[contains(.,'Remove')] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${member_action_xpath} //*[@id="member-action"] +${delete_action_xpath} //clr-dropdown/clr-dropdown-menu/button[contains(.,'Remove')] diff --git a/tests/resources/Harbor-Pages/UserProfile.robot b/tests/resources/Harbor-Pages/UserProfile.robot index 8525fcca7..8d58d999e 100644 --- a/tests/resources/Harbor-Pages/UserProfile.robot +++ b/tests/resources/Harbor-Pages/UserProfile.robot @@ -1,46 +1,46 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -Change Password - [Arguments] ${cur_pw} ${new_pw} - Retry Element Click ${head_admin_xpath} - Retry Element Click ${change_password_xpath} - Retry Text Input ${old_password_xpath} ${cur_pw} - Retry Text Input ${new_password_xpath} ${new_pw} - Retry Text Input ${renew_password_xpath} ${new_pw} - Retry Element Click ${change_password_confirm_btn_xpath} - Retry Element Click xpath=${log_xpath} - Sleep 1 - -Update User Comment - [Arguments] ${new_comment} - Retry Element Click ${head_admin_xpath} - Retry Element Click ${user_profile_xpath} - Retry Text Input ${account_settings_comments_xpath} ${new_comment} - Retry Element Click ${user_profile_confirm_btn_xpath} - Sleep 2 - -Logout Harbor - Retry Element Click ${head_admin_xpath} - Retry Link Click Log Out - Capture Page Screenshot Logout.png - Sleep 2 +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +Change Password + [Arguments] ${cur_pw} ${new_pw} + Retry Element Click ${head_admin_xpath} + Retry Element Click ${change_password_xpath} + Retry Text Input ${old_password_xpath} ${cur_pw} + Retry Text Input ${new_password_xpath} ${new_pw} + Retry Text Input ${renew_password_xpath} ${new_pw} + Retry Element Click ${change_password_confirm_btn_xpath} + Retry Element Click xpath=${log_xpath} + Sleep 1 + +Update User Comment + [Arguments] ${new_comment} + Retry Element Click ${head_admin_xpath} + Retry Element Click ${user_profile_xpath} + Retry Text Input ${account_settings_comments_xpath} ${new_comment} + Retry Element Click ${user_profile_confirm_btn_xpath} + Sleep 2 + +Logout Harbor + Retry Element Click ${head_admin_xpath} + Retry Link Click Log Out + Capture Page Screenshot Logout.png + Sleep 2 Wait Until Keyword Succeeds 5x 1 Retry Wait Until Page Contains Element ${sign_in_title_xpath} \ No newline at end of file diff --git a/tests/resources/Harbor-Pages/UserProfile_Elements.robot b/tests/resources/Harbor-Pages/UserProfile_Elements.robot index 50b3dc0d2..efb7b7c38 100644 --- a/tests/resources/Harbor-Pages/UserProfile_Elements.robot +++ b/tests/resources/Harbor-Pages/UserProfile_Elements.robot @@ -1,28 +1,28 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${head_admin_xpath} xpath=/html/body/harbor-app/harbor-shell/clr-main-container/navigator/clr-header/div[3]/clr-dropdown[2]/button/span -${change_password_xpath} xpath=//clr-main-container//clr-dropdown//a[2] -${user_profile_xpath} xpath=//clr-main-container//clr-dropdown//a[1] -${old_password_xpath} xpath=//*[@id='oldPassword'] -${new_password_xpath} xpath=//*[@id='newPassword'] -${renew_password_xpath} xpath=//*[@id='reNewPassword'] -${change_password_confirm_btn_xpath} xpath=//password-setting/clr-modal//button[2] -${user_profile_confirm_btn_xpath} xpath=//account-settings-modal/clr-modal//button[2] -${sign_in_title_xpath} xpath=//sign-in//form//*[@class='title'] -${account_settings_comments_xpath} xpath=//*[@id='account_settings_comments'] +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${head_admin_xpath} xpath=/html/body/harbor-app/harbor-shell/clr-main-container/navigator/clr-header/div[3]/clr-dropdown[2]/button/span +${change_password_xpath} xpath=//clr-main-container//clr-dropdown//a[2] +${user_profile_xpath} xpath=//clr-main-container//clr-dropdown//a[1] +${old_password_xpath} xpath=//*[@id='oldPassword'] +${new_password_xpath} xpath=//*[@id='newPassword'] +${renew_password_xpath} xpath=//*[@id='reNewPassword'] +${change_password_confirm_btn_xpath} xpath=//password-setting/clr-modal//button[2] +${user_profile_confirm_btn_xpath} xpath=//account-settings-modal/clr-modal//button[2] +${sign_in_title_xpath} xpath=//sign-in//form//*[@class='title'] +${account_settings_comments_xpath} xpath=//*[@id='account_settings_comments'] diff --git a/tests/resources/Harbor-Pages/Verify.robot b/tests/resources/Harbor-Pages/Verify.robot index 811f227b7..c0c3c43cb 100644 --- a/tests/resources/Harbor-Pages/Verify.robot +++ b/tests/resources/Harbor-Pages/Verify.robot @@ -1,403 +1,425 @@ -*** settings *** -Resource ../../resources/Util.robot - -*** Keywords *** -#for jsonpath refer to http://goessner.net/articles/JsonPath/ or https://nottyo.github.io/robotframework-jsonlibrary/JSONLibrary.html - -Verify User - [Arguments] ${json} - Log To Console "Verify User..." - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Switch To User Tag - @{user}= Get Value From Json ${json} $.users..name - :FOR ${user} IN @{user} - \ Page Should Contain ${user} - Logout Harbor - #verify user can login - @{user}= Get Value From Json ${json} $.users..name - :FOR ${user} IN @{user} - \ Sign In Harbor ${HARBOR_URL} ${user} ${HARBOR_PASSWORD} - \ Logout Harbor - Close Browser - -Verify Project - [Arguments] ${json} - Log To Console "Verify Project..." - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :FOR ${project} IN @{project} - \ Retry Wait Until Page Contains ${project} - Verify Project Metadata ${json} - Close Browser - -Verify Image Tag - [Arguments] ${json} - Log To Console "Verify Image Tag..." - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :FOR ${project} IN @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ @{repo}= Get Value From Json ${json} $.projects[?(@.name=${project})]..repo..name - \ Run Keyword If ${has_image} == ${true} Loop Image Repo @{repo} - \ Navigate To Projects - Close Browser - -Verify Project Metadata - [Arguments] ${json} - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :FOR ${project} IN @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ 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.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.severity - \ Should Contain ${ret} @{severity}[0] - \ Navigate To Projects - Close Browser - -Verify Checkbox - [Arguments] ${json} ${key} ${checkbox} ${is_opposite}=${false} - @{out}= Get Value From Json ${json} ${key} - ${value}= Set Variable If '${is_opposite}'=='${true}' 'false' 'true' - Run Keyword If '@{out}[0]'==${value} Checkbox Should Be Selected ${checkbox} - ... ELSE Checkbox Should Not Be Selected ${checkbox} - - -Loop Image Repo - [Arguments] @{repo} - :For ${repo} In @{repo} - \ Page Should Contain ${repo} - -Verify Member Exist - [Arguments] ${json} - Log To Console "Verify Member Exist..." - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :For ${project} In @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ Switch To Member - \ @{members}= Get Value From Json ${json} $.projects[?(@.name=${project})].member..name - \ Loop Member @{members} - \ Navigate To Projects - Close Browser - -Verify Webhook - [Arguments] ${json} - Log To Console "Verify Webhook..." - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :For ${project} In @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ Switch To Project Webhooks - \ @{enabled}= Get Value From Json ${json} $.projects[?(@.name=${project})].webhook.enabled - \ ${enable_count} Get Matching Xpath Count xpath=//span[contains(.,'Enabled')] - \ ${disable_count} Get Matching Xpath Count xpath=//span[contains(.,'Disabled')] - \ Log To Console '@{enabled}[0]' - \ Log To Console '${true}' - \ Run Keyword If '@{enabled}[0]' == '${true}' Page Should Contain Enabled - \ ... ELSE Page Should Contain Disabled - \ @{address}= Get Value From Json ${json} $.projects[?(@.name=${project})].webhook.address - \ Log To Console '@{address}[0]' - \ Page Should Contain @{address}[0] - \ Page Should Contain policy - \ Page Should Contain http - \ Navigate To Projects - Close Browser - -Verify Tag Retention Rule - [Arguments] ${json} - Log To Console "Verify Tag Retention Rule..." - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :For ${project} In @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ Switch To Tag Retention - \ ${actions_count}= Set Variable 8 - \ @{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 - \ @{latestPushedK}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.latestPushedK - \ @{cron}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.cron - \ Log To Console '@{repository_patten}[0]' - \ Page Should Contain @{repository_patten}[0] - \ Page Should Contain @{tag_decoration}[0] - \ Page Should Contain @{latestPushedK}[0] - \ Page Should Contain @{cron}[0] - \ Navigate To Projects - Close Browser - -Verify Tag Immutability Rule - [Arguments] ${json} - Log To Console "Verify Tag Immutability Rule..." - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :For ${project} In @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ Switch To Tag Immutability - \ @{repo_decoration}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_immutability_rule.repo_decoration - \ @{tag_decoration}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_immutability_rule.tag_decoration - \ @{repo_pattern}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_immutability_rule.repo_pattern - \ @{tag_pattern}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_immutability_rule.tag_pattern - \ Log To Console '@{repo_decoration}[0]' - #\ Page Should Contain @{repo_decoration}[0] - #\ Page Should Contain @{tag_decoration}[0] - \ Page Should Contain @{repo_pattern}[0] - \ Page Should Contain @{tag_pattern}[0] - \ Navigate To Projects - Close Browser - -Loop Member - [Arguments] @{members} - :For ${member} In @{members} - \ Page Should Contain ${member} - -Verify Robot Account Exist - [Arguments] ${json} - Log To Console "Verify Robot Account Exist..." - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :For ${project} In @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ Switch To Project Robot Account - \ @{robot_accounts}= Get Value From Json ${json} $.projects[?(@.name=${project})].robot_account..name - \ Loop Verify Robot Account @{robot_accounts} - \ Navigate To Projects - Close Browser - -Loop Verify Robot Account - [Arguments] @{robot_accounts} - :For ${robot_account} In @{robot_accounts} - \ Page Should Contain ${robot_account} - -Verify User System Admin Role - [Arguments] ${json} - Log To Console "Verify User System Admin Role..." - @{user}= Get Value From Json ${json} $.admin..name - Init Chrome Driver - :FOR ${user} IN @{user} - \ Sign In Harbor ${HARBOR_URL} ${user} ${HARBOR_PASSWORD} - \ Page Should Contain Administration - \ Logout Harbor - Close Browser - -Verify System Label - [Arguments] ${json} - Log To Console "Verify System Label..." - @{label}= Get Value From Json ${json} $..syslabel..name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Switch To Configure - Switch To System Labels - :For ${label} In @{label} - \ Page Should Contain ${label} - Close Browser - -Verify Project Label - [Arguments] ${json} - Log To Console "Verify Project Label..." - @{project}= Get Value From Json ${json} $.peoject.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :For ${project} In @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ Switch To Project Label - \ @{projectlabel}= Get Value From Json ${json} $.projects[?(@.name=${project})]..labels..name - \ :For ${label} In @{label} - \ \ Page Should Contain ${projectlabel} - \ Navigate To Projects - Close Browser - -Verify Endpoint - [Arguments] ${json} - Log To Console "Verify Endpoint..." - @{endpoint}= Get Value From Json ${json} $.endpoint..name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Switch To Registries - :For ${endpoint} In @{endpoint} - \ Page Should Contain ${endpoint} - Close Browser - -Verify Replicationrule - [Arguments] ${json} - Log To Console "Verify 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 ${filter_name_id} @{name_filters}[0] - \ Retry Textfield Value Should Be ${filter_tag_id} @{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 - [Arguments] ${json} - Log To Console "Verify Project Setting..." - @{projects}= Get Value From Json ${json} $.projects.[*].name - :For ${project} In @{Projects} - \ ${public}= Get Value From Json ${json} $.projects[?(@.name=${project})].accesslevel - \ ${contenttrust}= Get Value From Json ${json} $.projects[?(@.name=${project})]..enable_content_trust - \ ${preventrunning}= Get Value From Json ${json} $.projects[?(@.name=${project})]..prevent_vulnerable_images_from_running - \ ${scanonpush}= Get Value From Json ${json} $.projects[?(@.name=${project})]..automatically_scan_images_on_push - \ Init Chrome Driver - \ Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ Goto Project Config - \ Run Keyword If ${public} == "public" Checkbox Should Be Checked //clr-checkbox-wrapper[@name='public']//label - \ Run Keyword If ${contenttrust} == "true" Checkbox Should Be Checked //clr-checkbox-wrapper[@name='content-trust']//label - \ Run Keyword If ${contenttrust} == "false" Checkbox Should Not Be Checked //clr-checkbox-wrapper[@name='content-trust']//label - \ Run Keyword If ${preventrunning} == "true" Checkbox Should Be Checked //*[@id='prevent-vulenrability-image']//clr-checkbox-wrapper//label - \ Run Keyword If ${preventrunning} == "false" Checkbox Should Not Be Checked //*[@id='prevent-vulenrability-image']//clr-checkbox-wrapper//label - \ Run Keyword If ${scanonpush} == "true" Checkbox Should Be Checked //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input - \ Run Keyword If ${scanonpush} == "true" Checkbox Should Not Be Checked //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input - \ Close Browser - -Verify Interrogation Services - [Arguments] ${json} - Log To Console "Verify Interrogation Services..." - @{cron}= Get Value From Json ${json} $.interrogation_services..cron - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Switch To Vulnerability Page - Page Should Contain Custom - Page Should Contain @{cron}[0] - Close Browser - -Verify System Setting - [Arguments] ${json} - Log To Console "Verify System Setting..." - @{authtype}= Get Value From Json ${json} $.configuration.authmode - @{creation}= Get Value From Json ${json} $.configuration..projectcreation - @{selfreg}= Get Value From Json ${json} $.configuration..selfreg - @{emailserver}= Get Value From Json ${json} $.configuration..emailserver - @{emailport}= Get Value From Json ${json} $.configuration..emailport - @{emailuser}= Get Value From Json ${json} $.configuration..emailuser - @{emailfrom}= Get Value From Json ${json} $.configuration..emailfrom - @{token}= Get Value From Json ${json} $.configuration..token - @{robot_token}= Get Value From Json ${json} $.configuration..robot_token - @{scanschedule}= Get Value From Json ${json} $.configuration..scanall - @{cve_ids}= Get Value From Json ${json} $.configuration..cve - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Switch To Configure - Page Should Contain @{authtype}[0] - Run Keyword If @{selfreg}[0] == 'True' Checkbox Should Be Checked //clr-checkbox-wrapper[@id='selfReg']//label - Run Keyword If @{selfreg}[0] == 'False' Checkbox Should Not Be Checked //clr-checkbox-wrapper[@id='selfReg']//label - Switch To Email - Textfield Value Should Be xpath=//*[@id='mailServer'] @{emailserver}[0] - Textfield Value Should Be xpath=//*[@id='emailPort'] @{emailport}[0] - Textfield Value Should Be xpath=//*[@id='emailUsername'] @{emailuser}[0] - Textfield Value Should Be xpath=//*[@id='emailFrom'] @{emailfrom}[0] - Switch To System Settings - ${ret} Get Selected List Value xpath=//select[@id='proCreation'] - Should Be Equal As Strings ${ret} @{creation}[0] - Token Must Be Match @{token}[0] - Robot Account Token Must Be Match @{robot_token}[0] - Close Browser - -Verify Project-level Allowlist - [Arguments] ${json} - Log To Console "Verify Project-level Allowlist..." - @{project}= Get Value From Json ${json} $.projects.[*].name - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - :FOR ${project} IN @{project} - \ @{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} - \ Go Into Project ${project} has_image=${has_image} - \ Switch To Project Configuration - \ @{is_reuse_sys_cve_allowlist}= Get Value From Json ${json} $.projects[?(@.name=${project})].configuration.reuse_sys_cve_allowlist - \ Run Keyword If "@{is_reuse_sys_cve_allowlist}[0]" == "true" Retry Wait Element Should Be Disabled ${project_config_project_wl_add_btn} - \ ... ELSE Retry Wait Element ${project_config_project_wl_add_btn} - \ @{cve_ids}= Get Value From Json ${json} $.projects[?(@.name=${project})].configuration.cve - \ Loop Verifiy CVE_IDs @{cve_ids} - \ Navigate To Projects - Close Browser - -Loop Verifiy CVE_IDs - [Arguments] @{cve_ids} - :For ${cve_id} In @{cve_ids} - \ Page Should Contain ${cve_id} - -Verify System Setting Allowlist - [Arguments] ${json} - Log To Console "Verify Verify System Setting Allowlist..." - @{cve_ids}= Get Value From Json ${json} $.configuration..cve..id - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Switch To Configure - Switch To System Settings - Log To Console "@{cve_ids}" - Loop Verifiy CVE_IDs @{cve_ids} - Close Browser - -Verify Clair Is Default Scanner - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Switch To Scanners Page - Should Display The Default Clair Scanner - Close Browser - -Verify Trivy Is Default Scanner - Init Chrome Driver - Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} - Switch To Scanners Page - Should Display The Default Trivy Scanner - Close Browser +*** settings *** +Resource ../../resources/Util.robot + +*** Keywords *** +#for jsonpath refer to http://goessner.net/articles/JsonPath/ or https://nottyo.github.io/robotframework-jsonlibrary/JSONLibrary.html + +Verify User + [Arguments] ${json} + Log To Console "Verify User..." + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Switch To User Tag + @{user}= Get Value From Json ${json} $.users..name + FOR ${user} IN @{user} + Page Should Contain ${user} + END + Logout Harbor + #verify user can login + @{user}= Get Value From Json ${json} $.users..name + FOR ${user} IN @{user} + Sign In Harbor ${HARBOR_URL} ${user} ${HARBOR_PASSWORD} + Logout Harbor + END + Close Browser + +Verify Project + [Arguments] ${json} + Log To Console "Verify Project..." + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + Retry Wait Until Page Contains ${project} + END + Verify Project Metadata ${json} + Close Browser + +Verify Image Tag + [Arguments] ${json} + Log To Console "Verify Image Tag..." + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + @{repo}= Get Value From Json ${json} $.projects[?(@.name=${project})]..repo..name + Run Keyword If ${has_image} == ${true} Loop Image Repo @{repo} + Navigate To Projects + END + Close Browser + +Verify Project Metadata + [Arguments] ${json} + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + 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.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.severity + Should Contain ${ret} @{severity}[0] + Navigate To Projects + END + Close Browser + +Verify Checkbox + [Arguments] ${json} ${key} ${checkbox} ${is_opposite}=${false} + @{out}= Get Value From Json ${json} ${key} + ${value}= Set Variable If '${is_opposite}'=='${true}' 'false' 'true' + Run Keyword If '@{out}[0]'==${value} Checkbox Should Be Selected ${checkbox} + ... ELSE Checkbox Should Not Be Selected ${checkbox} + + +Loop Image Repo + [Arguments] @{repo} + FOR ${repo} IN @{repo} + Page Should Contain ${repo} + END + +Verify Member Exist + [Arguments] ${json} + Log To Console "Verify Member Exist..." + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + Switch To Member + @{members}= Get Value From Json ${json} $.projects[?(@.name=${project})].member..name + Loop Member @{members} + Navigate To Projects + END + Close Browser + +Verify Webhook + [Arguments] ${json} + Log To Console "Verify Webhook..." + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + Switch To Project Webhooks + @{enabled}= Get Value From Json ${json} $.projects[?(@.name=${project})].webhook.enabled + ${enable_count} Get Matching Xpath Count xpath=//span[contains(.,'Enabled')] + ${disable_count} Get Matching Xpath Count xpath=//span[contains(.,'Disabled')] + Log To Console '@{enabled}[0]' + Log To Console '${true}' + Run Keyword If '@{enabled}[0]' == '${true}' Page Should Contain Enabled + ... ELSE Page Should Contain Disabled + @{address}= Get Value From Json ${json} $.projects[?(@.name=${project})].webhook.address + Log To Console '@{address}[0]' + Page Should Contain @{address}[0] + Page Should Contain policy + Page Should Contain http + Navigate To Projects + END + Close Browser + +Verify Tag Retention Rule + [Arguments] ${json} + Log To Console "Verify Tag Retention Rule..." + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + Switch To Tag Retention + ${actions_count}= Set Variable 8 + @{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 + @{latestPushedK}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.latestPushedK + @{cron}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_retention_rule.cron + Log To Console '@{repository_patten}[0]' + Page Should Contain @{repository_patten}[0] + Page Should Contain @{tag_decoration}[0] + Page Should Contain @{latestPushedK}[0] + Page Should Contain @{cron}[0] + Navigate To Projects + END + Close Browser + +Verify Tag Immutability Rule + [Arguments] ${json} + Log To Console "Verify Tag Immutability Rule..." + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + Switch To Tag Immutability + @{repo_decoration}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_immutability_rule.repo_decoration + @{tag_decoration}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_immutability_rule.tag_decoration + @{repo_pattern}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_immutability_rule.repo_pattern + @{tag_pattern}= Get Value From Json ${json} $.projects[?(@.name=${project})].tag_immutability_rule.tag_pattern + Log To Console '@{repo_decoration}[0]' + #Page Should Contain @{repo_decoration}[0] + #Page Should Contain @{tag_decoration}[0] + Page Should Contain @{repo_pattern}[0] + Page Should Contain @{tag_pattern}[0] + Navigate To Projects + END + Close Browser + +Loop Member + [Arguments] @{members} + FOR ${member} IN @{members} + Page Should Contain ${member} + END + +Verify Robot Account Exist + [Arguments] ${json} + Log To Console "Verify Robot Account Exist..." + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + Switch To Project Robot Account + @{robot_accounts}= Get Value From Json ${json} $.projects[?(@.name=${project})].robot_account..name + Loop Verify Robot Account @{robot_accounts} + Navigate To Projects + END + Close Browser + +Loop Verify Robot Account + [Arguments] @{robot_accounts} + FOR ${robot_account} IN @{robot_accounts} + Page Should Contain ${robot_account} + END + +Verify User System Admin Role + [Arguments] ${json} + Log To Console "Verify User System Admin Role..." + @{user}= Get Value From Json ${json} $.admin..name + Init Chrome Driver + FOR ${user} IN @{user} + Sign In Harbor ${HARBOR_URL} ${user} ${HARBOR_PASSWORD} + Page Should Contain Administration + Logout Harbor + END + Close Browser + +Verify System Label + [Arguments] ${json} + Log To Console "Verify System Label..." + @{label}= Get Value From Json ${json} $..syslabel..name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Switch To Configure + Switch To System Labels + FOR ${label} IN @{label} + Page Should Contain ${label} + END + Close Browser + +Verify Project Label + [Arguments] ${json} + Log To Console "Verify Project Label..." + @{project}= Get Value From Json ${json} $.peoject.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + Switch To Project Label + @{projectlabel}= Get Value From Json ${json} $.projects[?(@.name=${project})]..labels..name + FOR ${label} IN @{label} + Page Should Contain ${projectlabel} + END + Navigate To Projects + END + Close Browser + +Verify Endpoint + [Arguments] ${json} + Log To Console "Verify Endpoint..." + @{endpoint}= Get Value From Json ${json} $.endpoint..name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Switch To Registries + FOR ${endpoint} IN @{endpoint} + Page Should Contain ${endpoint} + END + Close Browser + +Verify Replicationrule + [Arguments] ${json} + Log To Console "Verify 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 ${filter_name_id} @{name_filters}[0] + Retry Textfield Value Should Be ${filter_tag_id} @{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] + END + Close Browser + +Verify Project Setting + [Arguments] ${json} + Log To Console "Verify Project Setting..." + @{projects}= Get Value From Json ${json} $.projects.[*].name + FOR ${project} IN @{Projects} + ${public}= Get Value From Json ${json} $.projects[?(@.name=${project})].accesslevel + ${contenttrust}= Get Value From Json ${json} $.projects[?(@.name=${project})]..enable_content_trust + ${preventrunning}= Get Value From Json ${json} $.projects[?(@.name=${project})]..prevent_vulnerable_images_from_running + ${scanonpush}= Get Value From Json ${json} $.projects[?(@.name=${project})]..automatically_scan_images_on_push + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + @{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} + Go Into Project ${project} has_image=${has_image} + Goto Project Config + Run Keyword If ${public} == "public" Checkbox Should Be Checked //clr-checkbox-wrapper[@name='public']//label + Run Keyword If ${contenttrust} == "true" Checkbox Should Be Checked //clr-checkbox-wrapper[@name='content-trust']//label + Run Keyword If ${contenttrust} == "false" Checkbox Should Not Be Checked //clr-checkbox-wrapper[@name='content-trust']//label + Run Keyword If ${preventrunning} == "true" Checkbox Should Be Checked //*[@id='prevent-vulenrability-image']//clr-checkbox-wrapper//label + Run Keyword If ${preventrunning} == "false" Checkbox Should Not Be Checked //*[@id='prevent-vulenrability-image']//clr-checkbox-wrapper//label + Run Keyword If ${scanonpush} == "true" Checkbox Should Be Checked //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input + Run Keyword If ${scanonpush} == "true" Checkbox Should Not Be Checked //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input + Close Browser + END + +Verify Interrogation Services + [Arguments] ${json} + Log To Console "Verify Interrogation Services..." + @{cron}= Get Value From Json ${json} $.interrogation_services..cron + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Switch To Vulnerability Page + Page Should Contain Custom + Page Should Contain @{cron}[0] + Close Browser + +Verify System Setting + [Arguments] ${json} + Log To Console "Verify System Setting..." + @{authtype}= Get Value From Json ${json} $.configuration.authmode + @{creation}= Get Value From Json ${json} $.configuration..projectcreation + @{selfreg}= Get Value From Json ${json} $.configuration..selfreg + @{emailserver}= Get Value From Json ${json} $.configuration..emailserver + @{emailport}= Get Value From Json ${json} $.configuration..emailport + @{emailuser}= Get Value From Json ${json} $.configuration..emailuser + @{emailfrom}= Get Value From Json ${json} $.configuration..emailfrom + @{token}= Get Value From Json ${json} $.configuration..token + @{robot_token}= Get Value From Json ${json} $.configuration..robot_token + @{scanschedule}= Get Value From Json ${json} $.configuration..scanall + @{cve_ids}= Get Value From Json ${json} $.configuration..cve + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Switch To Configure + Page Should Contain @{authtype}[0] + Run Keyword If @{selfreg}[0] == 'True' Checkbox Should Be Checked //clr-checkbox-wrapper[@id='selfReg']//label + Run Keyword If @{selfreg}[0] == 'False' Checkbox Should Not Be Checked //clr-checkbox-wrapper[@id='selfReg']//label + Switch To Email + Textfield Value Should Be xpath=//*[@id='mailServer'] @{emailserver}[0] + Textfield Value Should Be xpath=//*[@id='emailPort'] @{emailport}[0] + Textfield Value Should Be xpath=//*[@id='emailUsername'] @{emailuser}[0] + Textfield Value Should Be xpath=//*[@id='emailFrom'] @{emailfrom}[0] + Switch To System Settings + ${ret} Get Selected List Value xpath=//select[@id='proCreation'] + Should Be Equal As Strings ${ret} @{creation}[0] + Token Must Be Match @{token}[0] + Robot Account Token Must Be Match @{robot_token}[0] + Close Browser + +Verify Project-level Allowlist + [Arguments] ${json} + Log To Console "Verify Project-level Allowlist..." + @{project}= Get Value From Json ${json} $.projects.[*].name + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + FOR ${project} IN @{project} + @{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} + Go Into Project ${project} has_image=${has_image} + Switch To Project Configuration + @{is_reuse_sys_cve_allowlist}= Get Value From Json ${json} $.projects[?(@.name=${project})].configuration.reuse_sys_cve_allowlist + Run Keyword If "@{is_reuse_sys_cve_allowlist}[0]" == "true" Retry Wait Element Should Be Disabled ${project_config_project_wl_add_btn} + ... ELSE Retry Wait Element ${project_config_project_wl_add_btn} + @{cve_ids}= Get Value From Json ${json} $.projects[?(@.name=${project})].configuration.cve + Loop Verifiy CVE_IDs @{cve_ids} + Navigate To Projects + END + Close Browser + +Loop Verifiy CVE_IDs + [Arguments] @{cve_ids} + FOR ${cve_id} IN @{cve_ids} + Page Should Contain ${cve_id} + END + +Verify System Setting Allowlist + [Arguments] ${json} + Log To Console "Verify Verify System Setting Allowlist..." + @{cve_ids}= Get Value From Json ${json} $.configuration..cve..id + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Switch To Configure + Switch To System Settings + Log To Console "@{cve_ids}" + Loop Verifiy CVE_IDs @{cve_ids} + Close Browser + +Verify Clair Is Default Scanner + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Switch To Scanners Page + Should Display The Default Clair Scanner + Close Browser + +Verify Trivy Is Default Scanner + Init Chrome Driver + Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD} + Switch To Scanners Page + Should Display The Default Trivy Scanner + Close Browser diff --git a/tests/resources/Harbor-Pages/Vulnerability.robot b/tests/resources/Harbor-Pages/Vulnerability.robot index 3f99a45a8..c99aa224b 100644 --- a/tests/resources/Harbor-Pages/Vulnerability.robot +++ b/tests/resources/Harbor-Pages/Vulnerability.robot @@ -1,105 +1,105 @@ -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource ../../resources/Util.robot - -*** Variables *** - -*** Keywords *** -Disable Scan Schedule - Retry Double Keywords When Error Retry Element Click ${vulnerability_edit_btn} Retry Wait Until Page Not Contains Element ${vulnerability_edit_btn} - Retry Element Click ${vulnerability_dropdown_list} - Retry Element Click ${vulnerability_dropdown_list_item_none} - Retry Double Keywords When Error Retry Element Click ${vulnerability_save_btn} Retry Wait Until Page Not Contains Element ${vulnerability_save_btn} - -Set Scan Schedule - [Arguments] ${type} ${value}=${null} - Retry Double Keywords When Error Retry Element Click ${vulnerability_edit_btn} Retry Wait Until Page Not Contains Element ${vulnerability_edit_btn} - Retry Element Click ${vulnerability_dropdown_list} - Run Keyword If '${type}'=='custom' Run Keywords Retry Element Click ${vulnerability_dropdown_list_item_custom} AND Retry Text Input ${targetCron_id} ${value} - Retry Double Keywords When Error Retry Element Click ${vulnerability_save_btn} Retry Wait Until Page Not Contains Element ${vulnerability_save_btn} - -Trigger Scan Now And Wait Until The Result Appears - Retry Element Click xpath=${scan_now_button} - Sleep 60 - Retry Wait Until Page Contains Element ${scan_now_result} - -Switch To Vulnerability Page - Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Interrogation')] - Retry Element Click xpath=//app-interrogation-services//a[contains(.,'Vulnerability')] - Retry Wait Element ${scan_now_button} - - -Set Vulnerabilty Serverity -#0 is critical, 1 is high, 2 is medium, 3 is low, 4 is negligible. - [Arguments] ${level} - Goto Project Config - #enable first - Retry Element Click ${project_config_prevent_vulenrability_checkbox_label} - Checkbox Should Be Selected //project-detail//clr-checkbox-wrapper//input[@name='prevent-vulenrability-image-input'] - Retry Element Click //project-detail//select - #wait for dropdown popup - Sleep 1 - Select From List By Index //project-detail//select ${level} - Retry Element Click ${project_config_save_btn} - -Scan Is Disabled - Retry Wait Until Page Contains Element //button[contains(.,'Scan') and @disabled=''] - -Move To Summary Chart - Sleep 2 - Wait Until Element Is Visible //hbr-vulnerability-bar//hbr-result-tip-histogram - Mouse Over //hbr-result-tip-histogram - Sleep 1 - -Scan Repo -#use fail for image clair can not scan, otherwise use success - [Arguments] ${tagname} ${status} - #select one tag - Retry Element Click //clr-dg-row[contains(.,'${tagname}')]//label - Retry Element Click //button[contains(.,'Scan')] - Run Keyword If '${status}' == 'Succeed' Wait Until Element Is Visible //hbr-vulnerability-bar//hbr-result-tip-histogram 300 - Run Keyword If '${status}' == 'Fail' Wait Until Element Is Visible //hbr-vulnerability-bar//a 300 - -Scan Result Should Display In List Row - [Arguments] ${tagname} ${is_no_vulerabilty}=${false} - Run Keyword If ${is_no_vulerabilty}==${true} Retry Wait Until Page Contains Element //artifact-list-tab//clr-dg-row[contains(.,'No vulnerability') and contains(.,'${tagname}')]//clr-dg-cell//clr-tooltip - ... ELSE Retry Wait Until Page Contains Element //artifact-list-tab//clr-dg-row[contains(.,'Total') and contains(.,'Fixable') and contains(.,'${tagname}')]//clr-dg-cell//clr-tooltip - -Enable Scan On Push - Checkbox Should Not Be Selected //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input - Retry Element Click //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//label - Checkbox Should Be Selected //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input - Retry Element Click ${project_config_save_btn} - Sleep 10 - -Vulnerability Not Ready Project Hint - Sleep 2 - ${element}= Set Variable xpath=//span[contains(@class, 'db-status-warning')] - Wait Until Element Is Visible And Enabled ${element} - -Switch To Scanners Page - Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Interrogation')] - Retry Wait Until Page Contains Element ${set_default_scanner} - -Should Display The Default Clair Scanner - Retry Wait Until Page Contains Element //clr-datagrid//clr-dg-row//clr-dg-cell[contains(.,'Clair')]//span[contains(.,'Default')] - -Should Display The Default Trivy Scanner - Retry Wait Until Page Contains Element //clr-datagrid//clr-dg-row//clr-dg-cell[contains(.,'Trivy')]//span[contains(.,'Default')] - -Clair Is Immutable Scanner - Retry Element Click //clr-dg-row[contains(.,'Clair')]//clr-radio-wrapper/label - Retry Double Keywords When Error Retry Element Click ${scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_action_xpath} - Retry Double Keywords When Error Retry Element Click ${delete_scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_confirm_btn} - Retry Double Keywords When Error Retry Element Click ${delete_scanner_confirm_btn} Retry Wait Until Page Contains Element ${immutable_msg_xpath} - -Trivy Is Immutable Scanner - Retry Element Click //clr-dg-row[contains(.,'Trivy')]//clr-radio-wrapper/label - Retry Double Keywords When Error Retry Element Click ${scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_action_xpath} - Retry Double Keywords When Error Retry Element Click ${delete_scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_confirm_btn} - Retry Double Keywords When Error Retry Element Click ${delete_scanner_confirm_btn} Retry Wait Until Page Contains Element ${immutable_trivy_msg_xpath} - -Set Default Scanner - [Arguments] ${scanner_name} - Retry Element Click //clr-dg-row[contains(.,'${scanner_name}')]//clr-radio-wrapper/label - Retry Double Keywords When Error Retry Element Click ${scanner_set_default} Retry Wait Until Page Contains Element ${scanner_set_default_success_xpath} +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource ../../resources/Util.robot + +*** Variables *** + +*** Keywords *** +Disable Scan Schedule + Retry Double Keywords When Error Retry Element Click ${vulnerability_edit_btn} Retry Wait Until Page Not Contains Element ${vulnerability_edit_btn} + Retry Element Click ${vulnerability_dropdown_list} + Retry Element Click ${vulnerability_dropdown_list_item_none} + Retry Double Keywords When Error Retry Element Click ${vulnerability_save_btn} Retry Wait Until Page Not Contains Element ${vulnerability_save_btn} + +Set Scan Schedule + [Arguments] ${type} ${value}=${null} + Retry Double Keywords When Error Retry Element Click ${vulnerability_edit_btn} Retry Wait Until Page Not Contains Element ${vulnerability_edit_btn} + Retry Element Click ${vulnerability_dropdown_list} + Run Keyword If '${type}'=='custom' Run Keywords Retry Element Click ${vulnerability_dropdown_list_item_custom} AND Retry Text Input ${targetCron_id} ${value} + Retry Double Keywords When Error Retry Element Click ${vulnerability_save_btn} Retry Wait Until Page Not Contains Element ${vulnerability_save_btn} + +Trigger Scan Now And Wait Until The Result Appears + Retry Element Click xpath=${scan_now_button} + Sleep 60 + Retry Wait Until Page Contains Element ${scan_now_result} + +Switch To Vulnerability Page + Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Interrogation')] + Retry Element Click xpath=//app-interrogation-services//a[contains(.,'Vulnerability')] + Retry Wait Element ${scan_now_button} + + +Set Vulnerabilty Serverity +#0 is critical, 1 is high, 2 is medium, 3 is low, 4 is negligible. + [Arguments] ${level} + Goto Project Config + #enable first + Retry Element Click ${project_config_prevent_vulenrability_checkbox_label} + Checkbox Should Be Selected //project-detail//clr-checkbox-wrapper//input[@name='prevent-vulenrability-image-input'] + Retry Element Click //project-detail//select + #wait for dropdown popup + Sleep 1 + Select From List By Index //project-detail//select ${level} + Retry Element Click ${project_config_save_btn} + +Scan Is Disabled + Retry Wait Until Page Contains Element //button[contains(.,'Scan') and @disabled=''] + +Move To Summary Chart + Sleep 2 + Wait Until Element Is Visible //hbr-vulnerability-bar//hbr-result-tip-histogram + Mouse Over //hbr-result-tip-histogram + Sleep 1 + +Scan Repo +#use fail for image clair can not scan, otherwise use success + [Arguments] ${tagname} ${status} + #select one tag + Retry Element Click //clr-dg-row[contains(.,'${tagname}')]//label + Retry Element Click //button[contains(.,'Scan')] + Run Keyword If '${status}' == 'Succeed' Wait Until Element Is Visible //hbr-vulnerability-bar//hbr-result-tip-histogram 300 + Run Keyword If '${status}' == 'Fail' Wait Until Element Is Visible //hbr-vulnerability-bar//a 300 + +Scan Result Should Display In List Row + [Arguments] ${tagname} ${is_no_vulerabilty}=${false} + Run Keyword If ${is_no_vulerabilty}==${true} Retry Wait Until Page Contains Element //artifact-list-tab//clr-dg-row[contains(.,'No vulnerability') and contains(.,'${tagname}')]//clr-dg-cell//clr-tooltip + ... ELSE Retry Wait Until Page Contains Element //artifact-list-tab//clr-dg-row[contains(.,'Total') and contains(.,'Fixable') and contains(.,'${tagname}')]//clr-dg-cell//clr-tooltip + +Enable Scan On Push + Checkbox Should Not Be Selected //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input + Retry Element Click //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//label + Checkbox Should Be Selected //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input + Retry Element Click ${project_config_save_btn} + Sleep 10 + +Vulnerability Not Ready Project Hint + Sleep 2 + ${element}= Set Variable xpath=//span[contains(@class, 'db-status-warning')] + Wait Until Element Is Visible And Enabled ${element} + +Switch To Scanners Page + Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Interrogation')] + Retry Wait Until Page Contains Element ${set_default_scanner} + +Should Display The Default Clair Scanner + Retry Wait Until Page Contains Element //clr-datagrid//clr-dg-row//clr-dg-cell[contains(.,'Clair')]//span[contains(.,'Default')] + +Should Display The Default Trivy Scanner + Retry Wait Until Page Contains Element //clr-datagrid//clr-dg-row//clr-dg-cell[contains(.,'Trivy')]//span[contains(.,'Default')] + +Clair Is Immutable Scanner + Retry Element Click //clr-dg-row[contains(.,'Clair')]//clr-radio-wrapper/label + Retry Double Keywords When Error Retry Element Click ${scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_action_xpath} + Retry Double Keywords When Error Retry Element Click ${delete_scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_confirm_btn} + Retry Double Keywords When Error Retry Element Click ${delete_scanner_confirm_btn} Retry Wait Until Page Contains Element ${immutable_msg_xpath} + +Trivy Is Immutable Scanner + Retry Element Click //clr-dg-row[contains(.,'Trivy')]//clr-radio-wrapper/label + Retry Double Keywords When Error Retry Element Click ${scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_action_xpath} + Retry Double Keywords When Error Retry Element Click ${delete_scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_confirm_btn} + Retry Double Keywords When Error Retry Element Click ${delete_scanner_confirm_btn} Retry Wait Until Page Contains Element ${immutable_trivy_msg_xpath} + +Set Default Scanner + [Arguments] ${scanner_name} + Retry Element Click //clr-dg-row[contains(.,'${scanner_name}')]//clr-radio-wrapper/label + Retry Double Keywords When Error Retry Element Click ${scanner_set_default} Retry Wait Until Page Contains Element ${scanner_set_default_success_xpath} diff --git a/tests/resources/Harbor-Pages/Vulnerability_Elements.robot b/tests/resources/Harbor-Pages/Vulnerability_Elements.robot index 815ddb616..597b630b0 100644 --- a/tests/resources/Harbor-Pages/Vulnerability_Elements.robot +++ b/tests/resources/Harbor-Pages/Vulnerability_Elements.robot @@ -1,37 +1,37 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance - -*** Variables *** -${vulnerability_edit_btn} xpath=//vulnerability-config//cron-selection//button[contains(.,'EDIT')] -${vulnerability_dropdown_list} xpath=//vulnerability-config//cron-selection//select[@id='selectPolicy'] -${vulnerability_dropdown_list_item_none} xpath=//vulnerability-config//cron-selection//select[@id='selectPolicy']//option[contains(.,'None')] -${vulnerability_dropdown_list_item_custom} xpath=//vulnerability-config//cron-selection//select[@id='selectPolicy']//option[contains(.,'Custom')] -${vulnerability_save_btn} xpath=//cron-selection//button[contains(.,'SAVE')] -${scan_now_button} //vulnerability-config//button[contains(.,'NOW')] -${vulnerability_page} //clr-vertical-nav-group-children/a[contains(.,'Vulnerability')] -${set_default_scanner} //button[@id='set-default'] -${scanner_action_xpath} //span[@id='action-scanner'] -${delete_scanner_action_xpath} //span[@id='delete-scanner-action'] -${immutable_msg_xpath} //span[contains(.,'registration Clair is not allowed to delete as it is immutable: scanner API: delete')] -${immutable_trivy_msg_xpath} //span[contains(.,'registration Trivy is not allowed to delete as it is immutable: scanner API: delete')] -${delete_scanner_confirm_btn} xpath=//clr-modal//button[contains(.,'DELETE')] -${scan_now_result} xpath=//div[@id="scan-result-container"] -${scanner_set_default} xpath=//button[@id="set-default"] -${scanner_set_default_success_xpath} //span[contains(.,'Successfully updated')] -${not_scanned_icon} xpath=//span[@class[contains(.,'not-scan')]] - - +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance + +*** Variables *** +${vulnerability_edit_btn} xpath=//vulnerability-config//cron-selection//button[contains(.,'EDIT')] +${vulnerability_dropdown_list} xpath=//vulnerability-config//cron-selection//select[@id='selectPolicy'] +${vulnerability_dropdown_list_item_none} xpath=//vulnerability-config//cron-selection//select[@id='selectPolicy']//option[contains(.,'None')] +${vulnerability_dropdown_list_item_custom} xpath=//vulnerability-config//cron-selection//select[@id='selectPolicy']//option[contains(.,'Custom')] +${vulnerability_save_btn} xpath=//cron-selection//button[contains(.,'SAVE')] +${scan_now_button} //vulnerability-config//button[contains(.,'NOW')] +${vulnerability_page} //clr-vertical-nav-group-children/a[contains(.,'Vulnerability')] +${set_default_scanner} //button[@id='set-default'] +${scanner_action_xpath} //span[@id='action-scanner'] +${delete_scanner_action_xpath} //span[@id='delete-scanner-action'] +${immutable_msg_xpath} //span[contains(.,'registration Clair is not allowed to delete as it is immutable: scanner API: delete')] +${immutable_trivy_msg_xpath} //span[contains(.,'registration Trivy is not allowed to delete as it is immutable: scanner API: delete')] +${delete_scanner_confirm_btn} xpath=//clr-modal//button[contains(.,'DELETE')] +${scan_now_result} xpath=//div[@id="scan-result-container"] +${scanner_set_default} xpath=//button[@id="set-default"] +${scanner_set_default_success_xpath} //span[contains(.,'Successfully updated')] +${not_scanned_icon} xpath=//span[@class[contains(.,'not-scan')]] + + diff --git a/tests/resources/Harbor-Util.robot b/tests/resources/Harbor-Util.robot index bff05c28a..51fe5853f 100644 --- a/tests/resources/Harbor-Util.robot +++ b/tests/resources/Harbor-Util.robot @@ -1,163 +1,164 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Library Selenium2Library -Library OperatingSystem - -*** Variables *** - -*** Keywords *** -Install Harbor to Test Server - Log To Console \nStart Docker Daemon - Start Docker Daemon Locally - Sleep 5s - ${rc} ${output}= Run And Return Rc And Output docker ps - Should Be Equal As Integers ${rc} 0 - Log To Console \n${output} - Log To Console \nconfig harbor cfg - Config Harbor cfg http_proxy=https - Prepare Cert - Log To Console \ncomplile and up harbor now - Compile and Up Harbor With Source Code - ${rc} ${output}= Run And Return Rc And Output docker ps - Should Be Equal As Integers ${rc} 0 - Log To Console \n${output} - Generate Certificate Authority For Chrome - -Up Harbor - [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true - ${rc} ${output}= Run And Return Rc And Output make start -e NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} - Log ${rc} - Log ${output} - Should Be Equal As Integers ${rc} 0 - -Down Harbor - [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true - ${rc} ${output}= Run And Return Rc And Output echo "Y" | make down -e NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} - Log ${rc} - Log ${output} - Should Be Equal As Integers ${rc} 0 - -Package Harbor Offline - [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true ${with_trivy}=true - Log To Console \nStart Docker Daemon - Start Docker Daemon Locally - Log To Console \n\nmake package_offline GOBUILDTAGS="include_oss include_gcs" BASEIMAGETAG=%{Harbor_Build_Base_Tag} NPM_REGISTRY=%{NPM_REGISTRY} VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} TRIVYFLAG=${with_trivy} HTTPPROXY= - ${rc} ${output}= Run And Return Rc And Output make package_offline GOBUILDTAGS="include_oss include_gcs" BASEIMAGETAG=%{Harbor_Build_Base_Tag} NPM_REGISTRY=%{NPM_REGISTRY} VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} TRIVYFLAG=${with_trivy} HTTPPROXY= - Log To Console ${rc} - Log To Console ${output} - Should Be Equal As Integers ${rc} 0 - -Package Harbor Online - [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true ${with_trivy}=true - Log To Console \nStart Docker Daemon - Start Docker Daemon Locally - Log To Console \nmake package_online GOBUILDTAGS="include_oss include_gcs" VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} TRIVYFLAG=${with_trivy} HTTPPROXY= - ${rc} ${output}= Run And Return Rc And Output make package_online GOBUILDTAGS="include_oss include_gcs" VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} TRIVYFLAG=${with_trivy} HTTPPROXY= - Log ${rc} - Log ${output} - Should Be Equal As Integers ${rc} 0 - -Switch To LDAP - Down Harbor - ${rc} ${output}= Run And Return Rc And Output rm -rf /data - Log ${rc} - Should Be Equal As Integers ${rc} 0 - Prepare Cert - Config Harbor cfg auth=ldap_auth http_proxy=https - Prepare - Up Harbor - Docker Pull osixia/openldap:1.1.7 - ${rc} ${output}= Run And Return Rc And Output cd tests && ./ldapprepare.sh - Log ${rc} - Log ${output} - Should Be Equal As Integers ${rc} 0 - ${rc} ${output}= Run And Return Rc And Output docker ps - Log ${output} - Should Be Equal As Integers ${rc} 0 - Generate Certificate Authority For Chrome - -Enable Notary Client - ${rc} ${output}= Run And Return Rc And Output rm -rf ~/.docker/ - Log ${rc} - ${rc} ${output}= Run And Return Rc and Output curl -o /notary_ca.crt -s -k -X GET --header 'Accept: application/json' -u 'admin:Harbor12345' 'https://${ip}/api/v2.0/systeminfo/getcert' - Log ${output} - Should Be Equal As Integers ${rc} 0 - -Remove Notary Signature - [Arguments] ${ip} ${image} - ${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/notary-remove-image-signature.expect ${ip} library ${image} ${notaryServerEndpoint} - Log To Console ${output} - Log ${output} - Should Be Equal As Integers ${rc} 0 - -Prepare - [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true - ${rc} ${output}= Run And Return Rc And Output make prepare -e NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} - Log ${rc} - Log ${output} - Should Be Equal As Integers ${rc} 0 - -Config Harbor cfg - # Will change the IP and Protocol in the harbor.cfg - [Arguments] ${http_proxy}=http ${auth}=db_auth - ${rc} ${output}= Run And Return Rc And Output ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}' - ${rc}= Run And Return Rc sed "s/^hostname = .*/hostname = ${output}/g" -i ./make/harbor.cfg - Log ${rc} - Should Be Equal As Integers ${rc} 0 - ${rc}= Run And Return Rc sed "s/^ui_url_protocol = .*/ui_url_protocol = ${http_proxy}/g" -i ./make/harbor.cfg - Log ${rc} - Should Be Equal As Integers ${rc} 0 - ${rc}= Run And Return Rc sed "s/^auth_mode = .*/auth_mode = ${auth}/g" -i ./make/harbor.cfg - Log ${rc} - Should Be Equal As Integers ${rc} 0 - ${out}= Run cat ./make/harbor.cfg - Log ${out} - -Prepare Cert - # Will change the IP and Protocol in the harbor.cfg - ${rc} ${ip}= Run And Return Rc And Output ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}' - Log ${ip} - ${rc}= Run And Return Rc sed "s/^IP=.*/IP=${ip}/g" -i ./tests/generateCerts.sh - Log ${rc} - ${out}= Run cat ./tests/generateCerts.sh - Log ${out} - ${rc} ${output}= Run And Return Rc And Output ./tests/generateCerts.sh - Should Be Equal As Integers ${rc} 0 - -Compile and Up Harbor With Source Code - [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true - ${rc} ${output}= Run And Return Rc And Output make install swagger_client NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} HTTPPROXY= - Log ${output} - Should Be Equal As Integers ${rc} 0 - Sleep 20 - -Wait for Harbor Ready - [Arguments] ${protocol} ${HARBOR_IP} - Log To Console Waiting for Harbor to Come Up... - :FOR ${i} IN RANGE 20 - \ ${out}= Run curl -k ${protocol}://${HARBOR_IP} - \ Log ${out} - \ ${status}= Run Keyword And Return Status Should Not Contain ${out} 502 Bad Gateway - \ ${status}= Run Keyword If ${status} Run Keyword And Return Status Should Not Contain ${out} Connection refused - \ ${status}= Run Keyword If ${status} Run Keyword And Return Status Should Contain ${out} Harbor - \ Return From Keyword If ${status} ${HARBOR_IP} - \ Sleep 30s - Fail Harbor failed to come up properly! - -Get Harbor Version - ${rc} ${output}= Run And Return Rc And Output curl -k -X GET --header 'Accept: application/json' 'https://${ip}/api/v2.0/systeminfo'|grep -i harbor_version - Log To Console ${output} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Library SeleniumLibrary +Library OperatingSystem + +*** Variables *** + +*** Keywords *** +Install Harbor to Test Server + Log To Console \nStart Docker Daemon + Start Docker Daemon Locally + Sleep 5s + ${rc} ${output}= Run And Return Rc And Output docker ps + Should Be Equal As Integers ${rc} 0 + Log To Console \n${output} + Log To Console \nconfig harbor cfg + Config Harbor cfg http_proxy=https + Prepare Cert + Log To Console \ncomplile and up harbor now + Compile and Up Harbor With Source Code + ${rc} ${output}= Run And Return Rc And Output docker ps + Should Be Equal As Integers ${rc} 0 + Log To Console \n${output} + Generate Certificate Authority For Chrome + +Up Harbor + [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true + ${rc} ${output}= Run And Return Rc And Output make start -e NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} + Log ${rc} + Log ${output} + Should Be Equal As Integers ${rc} 0 + +Down Harbor + [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true + ${rc} ${output}= Run And Return Rc And Output echo "Y" | make down -e NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} + Log ${rc} + Log ${output} + Should Be Equal As Integers ${rc} 0 + +Package Harbor Offline + [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true ${with_trivy}=true + Log To Console \nStart Docker Daemon + Start Docker Daemon Locally + Log To Console \n\nmake package_offline GOBUILDTAGS="include_oss include_gcs" BASEIMAGETAG=%{Harbor_Build_Base_Tag} NPM_REGISTRY=%{NPM_REGISTRY} VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} TRIVYFLAG=${with_trivy} HTTPPROXY= + ${rc} ${output}= Run And Return Rc And Output make package_offline GOBUILDTAGS="include_oss include_gcs" BASEIMAGETAG=%{Harbor_Build_Base_Tag} NPM_REGISTRY=%{NPM_REGISTRY} VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} TRIVYFLAG=${with_trivy} HTTPPROXY= + Log To Console ${rc} + Log To Console ${output} + Should Be Equal As Integers ${rc} 0 + +Package Harbor Online + [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true ${with_trivy}=true + Log To Console \nStart Docker Daemon + Start Docker Daemon Locally + Log To Console \nmake package_online GOBUILDTAGS="include_oss include_gcs" VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} TRIVYFLAG=${with_trivy} HTTPPROXY= + ${rc} ${output}= Run And Return Rc And Output make package_online GOBUILDTAGS="include_oss include_gcs" VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} TRIVYFLAG=${with_trivy} HTTPPROXY= + Log ${rc} + Log ${output} + Should Be Equal As Integers ${rc} 0 + +Switch To LDAP + Down Harbor + ${rc} ${output}= Run And Return Rc And Output rm -rf /data + Log ${rc} + Should Be Equal As Integers ${rc} 0 + Prepare Cert + Config Harbor cfg auth=ldap_auth http_proxy=https + Prepare + Up Harbor + Docker Pull osixia/openldap:1.1.7 + ${rc} ${output}= Run And Return Rc And Output cd tests && ./ldapprepare.sh + Log ${rc} + Log ${output} + Should Be Equal As Integers ${rc} 0 + ${rc} ${output}= Run And Return Rc And Output docker ps + Log ${output} + Should Be Equal As Integers ${rc} 0 + Generate Certificate Authority For Chrome + +Enable Notary Client + ${rc} ${output}= Run And Return Rc And Output rm -rf ~/.docker/ + Log ${rc} + ${rc} ${output}= Run And Return Rc and Output curl -o /notary_ca.crt -s -k -X GET --header 'Accept: application/json' -u 'admin:Harbor12345' 'https://${ip}/api/v2.0/systeminfo/getcert' + Log ${output} + Should Be Equal As Integers ${rc} 0 + +Remove Notary Signature + [Arguments] ${ip} ${image} + ${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/notary-remove-image-signature.expect ${ip} library ${image} ${notaryServerEndpoint} + Log To Console ${output} + Log ${output} + Should Be Equal As Integers ${rc} 0 + +Prepare + [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true + ${rc} ${output}= Run And Return Rc And Output make prepare -e NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} + Log ${rc} + Log ${output} + Should Be Equal As Integers ${rc} 0 + +Config Harbor cfg + # Will change the IP and Protocol in the harbor.cfg + [Arguments] ${http_proxy}=http ${auth}=db_auth + ${rc} ${output}= Run And Return Rc And Output ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}' + ${rc}= Run And Return Rc sed "s/^hostname = .*/hostname = ${output}/g" -i ./make/harbor.cfg + Log ${rc} + Should Be Equal As Integers ${rc} 0 + ${rc}= Run And Return Rc sed "s/^ui_url_protocol = .*/ui_url_protocol = ${http_proxy}/g" -i ./make/harbor.cfg + Log ${rc} + Should Be Equal As Integers ${rc} 0 + ${rc}= Run And Return Rc sed "s/^auth_mode = .*/auth_mode = ${auth}/g" -i ./make/harbor.cfg + Log ${rc} + Should Be Equal As Integers ${rc} 0 + ${out}= Run cat ./make/harbor.cfg + Log ${out} + +Prepare Cert + # Will change the IP and Protocol in the harbor.cfg + ${rc} ${ip}= Run And Return Rc And Output ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}' + Log ${ip} + ${rc}= Run And Return Rc sed "s/^IP=.*/IP=${ip}/g" -i ./tests/generateCerts.sh + Log ${rc} + ${out}= Run cat ./tests/generateCerts.sh + Log ${out} + ${rc} ${output}= Run And Return Rc And Output ./tests/generateCerts.sh + Should Be Equal As Integers ${rc} 0 + +Compile and Up Harbor With Source Code + [Arguments] ${with_notary}=true ${with_clair}=true ${with_chartmuseum}=true + ${rc} ${output}= Run And Return Rc And Output make install swagger_client NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} CHARTFLAG=${with_chartmuseum} HTTPPROXY= + Log ${output} + Should Be Equal As Integers ${rc} 0 + Sleep 20 + +Wait for Harbor Ready + [Arguments] ${protocol} ${HARBOR_IP} + Log To Console Waiting for Harbor to Come Up... + FOR ${i} IN RANGE 20 + ${out}= Run curl -k ${protocol}://${HARBOR_IP} + Log ${out} + ${status}= Run Keyword And Return Status Should Not Contain ${out} 502 Bad Gateway + ${status}= Run Keyword If ${status} Run Keyword And Return Status Should Not Contain ${out} Connection refused + ${status}= Run Keyword If ${status} Run Keyword And Return Status Should Contain ${out} Harbor + Return From Keyword If ${status} ${HARBOR_IP} + Sleep 30s + END + Fail Harbor failed to come up properly! + +Get Harbor Version + ${rc} ${output}= Run And Return Rc And Output curl -k -X GET --header 'Accept: application/json' 'https://${ip}/api/v2.0/systeminfo'|grep -i harbor_version + Log To Console ${output} diff --git a/tests/resources/Helm-Util.robot b/tests/resources/Helm-Util.robot index ccc281b79..6ca70de42 100644 --- a/tests/resources/Helm-Util.robot +++ b/tests/resources/Helm-Util.robot @@ -1,41 +1,41 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides helper functions for docker operations -Library OperatingSystem -Library Process - -*** Keywords *** -Prepare Helm Cert - Wait Unitl Command Success cp harbor_ca.crt /ca/server.crt - -Helm Repo Add - [Arguments] ${harbor_url} ${user} ${pwd} ${project_name}=library ${helm_repo_name}=myrepo - ${rc} ${output}= Run And Return Rc And Output helm repo remove ${project_name} - Log To Console ${output} - Wait Unitl Command Success helm repo add --ca-file /ca/server.crt --username=${user} --password=${pwd} ${helm_repo_name} ${harbor_url}/chartrepo/${project_name} - -Helm Repo Push - [Arguments] ${user} ${pwd} ${chart_filename} ${helm_repo_name}=myrepo ${helm_cmd}=helm - ${current_dir}= Run pwd - Run cd ${current_dir} - Run wget ${harbor_chart_file_url} - Wait Unitl Command Success ${helm_cmd} push --ca-file=/ca/server.crt --username=${user} --password=${pwd} ${chart_filename} ${helm_repo_name} - -Helm Chart Push - [Arguments] ${ip} ${user} ${pwd} ${chart_file} ${archive} ${project} ${repo_name} ${verion} - ${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/helm_push_chart.sh ${ip} ${user} ${pwd} ${chart_file} ${archive} ${project} ${repo_name} ${verion} - Log ${output} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides helper functions for docker operations +Library OperatingSystem +Library Process + +*** Keywords *** +Prepare Helm Cert + Wait Unitl Command Success cp harbor_ca.crt /ca/server.crt + +Helm Repo Add + [Arguments] ${harbor_url} ${user} ${pwd} ${project_name}=library ${helm_repo_name}=myrepo + ${rc} ${output}= Run And Return Rc And Output helm repo remove ${project_name} + Log To Console ${output} + Wait Unitl Command Success helm repo add --ca-file /ca/server.crt --username=${user} --password=${pwd} ${helm_repo_name} ${harbor_url}/chartrepo/${project_name} + +Helm Repo Push + [Arguments] ${user} ${pwd} ${chart_filename} ${helm_repo_name}=myrepo ${helm_cmd}=helm + ${current_dir}= Run pwd + Run cd ${current_dir} + Run wget ${harbor_chart_file_url} + Wait Unitl Command Success ${helm_cmd} push --ca-file=/ca/server.crt --username=${user} --password=${pwd} ${chart_filename} ${helm_repo_name} + +Helm Chart Push + [Arguments] ${ip} ${user} ${pwd} ${chart_file} ${archive} ${project} ${repo_name} ${verion} + ${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/helm_push_chart.sh ${ip} ${user} ${pwd} ${chart_file} ${archive} ${project} ${repo_name} ${verion} + Log ${output} Should Be Equal As Integers ${rc} 0 \ No newline at end of file diff --git a/tests/resources/Nightly-Util.robot b/tests/resources/Nightly-Util.robot index 8a07d829b..dcc80023e 100644 --- a/tests/resources/Nightly-Util.robot +++ b/tests/resources/Nightly-Util.robot @@ -1,58 +1,58 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to the Harbor private registry appliance -Resource Util.robot - -*** Variables *** -${SSH_USER} root - -*** Keywords *** -Nightly Test Setup - [Arguments] ${ip} ${HARBOR_PASSWORD} ${ip1}==${EMPTY} - Run Keyword If '${ip1}' != '${EMPTY}' CA setup ${ip1} ${HARBOR_PASSWORD} /ca/ca1.crt - Run Keyword If '${ip1}' != '${EMPTY}' Run rm -rf ./harbor_ca.crt - Run Keyword CA setup ${ip} ${HARBOR_PASSWORD} - Run Keyword Start Docker Daemon Locally - -CA Setup - [Arguments] ${ip} ${HARBOR_PASSWORD} ${cert}=/ca/ca.crt - Run cp ${cert} harbor_ca.crt - Generate Certificate Authority For Chrome ${HARBOR_PASSWORD} - Prepare Docker Cert ${ip} - Prepare Helm Cert - -Collect Nightly Logs - [Arguments] ${ip} ${SSH_PWD} ${ip1}==${EMPTY} - Run Keyword Collect Logs ${ip} ${SSH_PWD} - Run Keyword If '${ip1}' != '${EMPTY}' Collect Logs ${ip1} ${SSH_PWD} - -Collect Logs - [Arguments] ${ip} ${SSH_PWD} - Open Connection ${ip} - Login ${SSH_USER} ${SSH_PWD} - SSHLibrary.Get File /var/log/harbor/ui.log - SSHLibrary.Get File /var/log/harbor/registry.log - SSHLibrary.Get File /var/log/harbor/proxy.log - SSHLibrary.Get File /var/log/harbor/adminserver.log - SSHLibrary.Get File /var/log/harbor/clair.log - SSHLibrary.Get File /var/log/harbor/jobservice.log - SSHLibrary.Get File /var/log/harbor/postgresql.log - SSHLibrary.Get File /var/log/harbor/notary-server.log - SSHLibrary.Get File /var/log/harbor/notary-signer.log - SSHLibrary.Get File /var/log/harbor/chartmuseum.log - SSHLibrary.Get File /var/log/harbor/registryctl.log - Run rename 's/^/${ip}/' *.log +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to the Harbor private registry appliance +Resource Util.robot + +*** Variables *** +${SSH_USER} root + +*** Keywords *** +Nightly Test Setup + [Arguments] ${ip} ${HARBOR_PASSWORD} ${ip1}==${EMPTY} + Run Keyword If '${ip1}' != '${EMPTY}' CA setup ${ip1} ${HARBOR_PASSWORD} /ca/ca1.crt + Run Keyword If '${ip1}' != '${EMPTY}' Run rm -rf ./harbor_ca.crt + Run Keyword CA setup ${ip} ${HARBOR_PASSWORD} + Run Keyword Start Docker Daemon Locally + +CA Setup + [Arguments] ${ip} ${HARBOR_PASSWORD} ${cert}=/ca/ca.crt + Run cp ${cert} harbor_ca.crt + Generate Certificate Authority For Chrome ${HARBOR_PASSWORD} + Prepare Docker Cert ${ip} + Prepare Helm Cert + +Collect Nightly Logs + [Arguments] ${ip} ${SSH_PWD} ${ip1}==${EMPTY} + Run Keyword Collect Logs ${ip} ${SSH_PWD} + Run Keyword If '${ip1}' != '${EMPTY}' Collect Logs ${ip1} ${SSH_PWD} + +Collect Logs + [Arguments] ${ip} ${SSH_PWD} + Open Connection ${ip} + Login ${SSH_USER} ${SSH_PWD} + SSHLibrary.Get File /var/log/harbor/ui.log + SSHLibrary.Get File /var/log/harbor/registry.log + SSHLibrary.Get File /var/log/harbor/proxy.log + SSHLibrary.Get File /var/log/harbor/adminserver.log + SSHLibrary.Get File /var/log/harbor/clair.log + SSHLibrary.Get File /var/log/harbor/jobservice.log + SSHLibrary.Get File /var/log/harbor/postgresql.log + SSHLibrary.Get File /var/log/harbor/notary-server.log + SSHLibrary.Get File /var/log/harbor/notary-signer.log + SSHLibrary.Get File /var/log/harbor/chartmuseum.log + SSHLibrary.Get File /var/log/harbor/registryctl.log + Run rename 's/^/${ip}/' *.log Close All Connections \ No newline at end of file diff --git a/tests/resources/Nimbus-Util.robot b/tests/resources/Nimbus-Util.robot index 34f3da266..41eb1a791 100644 --- a/tests/resources/Nimbus-Util.robot +++ b/tests/resources/Nimbus-Util.robot @@ -1,407 +1,407 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource contains any keywords related to using the Nimbus cluster - -*** Variables *** -${ESX_VERSION} 4564106 #6.5 RTM -${VC_VERSION} 4602587 #6.5 RTM -${NIMBUS_ESX_PASSWORD} e2eFunctionalTest - -*** Keywords *** -Deploy Nimbus ESXi Server - [Arguments] ${user} ${password} ${version}=${ESX_VERSION} ${tls_disabled}=True - ${name}= Evaluate 'ESX-' + str(random.randint(1000,9999)) modules=random - Log To Console \nDeploying Nimbus ESXi server: ${name} - Open Connection %{NIMBUS_GW} - Wait Until Keyword Succeeds 2 min 30 sec Login ${user} ${password} - - :FOR ${IDX} IN RANGE 1 5 - \ ${out}= Execute Command nimbus-esxdeploy ${name} --disk=48000000 --ssd=24000000 --memory=8192 --nics 2 ob-${version} - \ # Make sure the deploy actually worked - \ ${status}= Run Keyword And Return Status Should Contain ${out} To manage this VM use - \ Exit For Loop If ${status} - \ Log To Console ${out} - \ Log To Console Nimbus deployment ${IDX} failed, trying again in 5 minutes - \ Sleep 5 minutes - - # Now grab the IP address and return the name and ip for later use - @{out}= Split To Lines ${out} - :FOR ${item} IN @{out} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} IP is - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} - @{gotIP}= Split String ${line} ${SPACE} - ${ip}= Remove String @{gotIP}[5] , - - # Let's set a password so govc doesn't complain - Remove Environment Variable GOVC_PASSWORD - Remove Environment Variable GOVC_USERNAME - Set Environment Variable GOVC_INSECURE 1 - Set Environment Variable GOVC_URL root:@${ip} - ${out}= Run govc host.account.update -id root -password ${NIMBUS_ESX_PASSWORD} - Should Be Empty ${out} - Run Keyword If ${tls_disabled} Disable TLS On ESX Host - Log To Console Successfully deployed new ESXi server - ${user}-${name} - Close connection - [Return] ${user}-${name} ${ip} - -Deploy Multiple Nimbus ESXi Servers in Parallel - [Arguments] ${user} ${password} ${version}=${ESX_VERSION} - ${name1}= Evaluate 'ESX-' + str(random.randint(1000,9999)) modules=random - ${name2}= Evaluate 'ESX-' + str(random.randint(1000,9999)) modules=random - ${name3}= Evaluate 'ESX-' + str(random.randint(1000,9999)) modules=random - - Open Connection %{NIMBUS_GW} - Login ${user} ${password} - - ${out1}= Deploy Nimbus ESXi Server Async ${name1} - ${out2}= Deploy Nimbus ESXi Server Async ${name2} - ${out3}= Deploy Nimbus ESXi Server Async ${name3} - - Wait For Process ${out1} - Wait For Process ${out2} - Wait For Process ${out3} - - ${out}= Execute Command nimbus-ctl ip ${user}-${name1} - - @{out}= Split To Lines ${out} - :FOR ${item} IN @{out} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} ${user}-${name1} - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} - @{gotIP}= Split String ${line} ${SPACE} - ${ip1}= Remove String @{gotIP}[2] - - ${out}= Execute Command nimbus-ctl ip ${user}-${name2} - - @{out}= Split To Lines ${out} - :FOR ${item} IN @{out} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} ${user}-${name2} - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} - @{gotIP}= Split String ${line} ${SPACE} - ${ip2}= Remove String @{gotIP}[2] - - ${out}= Execute Command nimbus-ctl ip ${user}-${name3} - - @{out}= Split To Lines ${out} - :FOR ${item} IN @{out} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} ${user}-${name3} - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} - @{gotIP}= Split String ${line} ${SPACE} - ${ip3}= Remove String @{gotIP}[2] - - Log To Console \nDeploying Nimbus ESXi server: ${gotIP} - - # Let's set a password so govc doesn't complain - Remove Environment Variable GOVC_PASSWORD - Remove Environment Variable GOVC_USERNAME - Set Environment Variable GOVC_INSECURE 1 - Set Environment Variable GOVC_URL root:@${ip1} - ${out}= Run govc host.account.update -id root -password ${NIMBUS_ESX_PASSWORD} - Should Be Empty ${out} - Disable TLS On ESX Host - Log To Console Successfully deployed new ESXi server - ${user}-${name1} - Log To Console \nNimbus ESXi server IP: ${ip1} - - Remove Environment Variable GOVC_PASSWORD - Remove Environment Variable GOVC_USERNAME - Set Environment Variable GOVC_INSECURE 1 - Set Environment Variable GOVC_URL root:@${ip2} - ${out}= Run govc host.account.update -id root -password ${NIMBUS_ESX_PASSWORD} - Should Be Empty ${out} - Disable TLS On ESX Host - Log To Console Successfully deployed new ESXi server - ${user}-${name2} - Log To Console \nNimbus ESXi server IP: ${ip2} - - Remove Environment Variable GOVC_PASSWORD - Remove Environment Variable GOVC_USERNAME - Set Environment Variable GOVC_INSECURE 1 - Set Environment Variable GOVC_URL root:@${ip3} - ${out}= Run govc host.account.update -id root -password ${NIMBUS_ESX_PASSWORD} - Should Be Empty ${out} - Disable TLS On ESX Host - Log To Console Successfully deployed new ESXi server - ${user}-${name3} - Log To Console \nNimbus ESXi server IP: ${ip3} - - Close connection - [Return] ${user}-${name1} ${ip1} ${user}-${name2} ${ip2} ${user}-${name3} ${ip3} - -Deploy Nimbus vCenter Server - [Arguments] ${user} ${password} ${version}=${VC_VERSION} - ${name}= Evaluate 'VC-' + str(random.randint(1000,9999)) modules=random - Log To Console \nDeploying Nimbus vCenter server: ${name} - Open Connection %{NIMBUS_GW} - Login ${user} ${password} - - :FOR ${IDX} IN RANGE 1 5 - \ ${out}= Execute Command nimbus-vcvadeploy --vcvaBuild ${version} ${name} - \ # Make sure the deploy actually worked - \ ${status}= Run Keyword And Return Status Should Contain ${out} Overall Status: Succeeded - \ Exit For Loop If ${status} - \ Log To Console Nimbus deployment ${IDX} failed, trying again in 5 minutes - \ Sleep 5 minutes - - # Now grab the IP address and return the name and ip for later use - @{out}= Split To Lines ${out} - :FOR ${item} IN @{out} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} Cloudvm is running on IP - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} - ${ip}= Fetch From Right ${line} ${SPACE} - - Set Environment Variable GOVC_INSECURE 1 - Set Environment Variable GOVC_USERNAME Administrator@vsphere.local - Set Environment Variable GOVC_PASSWORD Admin!23 - Set Environment Variable GOVC_URL ${ip} - Log To Console Successfully deployed new vCenter server - ${user}-${name} - Close connection - [Return] ${user}-${name} ${ip} - -Deploy Nimbus ESXi Server Async - [Tags] secret - [Arguments] ${name} ${version}=${ESX_VERSION} - Log To Console \nDeploying Nimbus ESXi server: ${name} - - ${out}= Run Secret SSHPASS command %{NIMBUS_USER} %{NIMBUS_PASSWORD} 'nimbus-esxdeploy ${name} --disk\=48000000 --ssd\=24000000 --memory\=8192 --nics 2 ${version}' - [Return] ${out} - -Run Secret SSHPASS command - [Tags] secret - [Arguments] ${user} ${password} ${cmd} - - ${out}= Start Process sshpass -p ${password} ssh -o StrictHostKeyChecking\=no ${user}@%{NIMBUS_GW} ${cmd} shell=True - [Return] ${out} - -Deploy Nimbus vCenter Server Async - [Tags] secret - [Arguments] ${name} ${version}=${VC_VERSION} - Log To Console \nDeploying Nimbus VC server: ${name} - - ${out}= Run Secret SSHPASS command %{NIMBUS_USER} %{NIMBUS_PASSWORD} 'nimbus-vcvadeploy --vcvaBuild ${version} ${name}' - [Return] ${out} - -Deploy Nimbus Testbed - [Arguments] ${user} ${password} ${testbed} - Open Connection %{NIMBUS_GW} - Login ${user} ${password} - - :FOR ${IDX} IN RANGE 1 5 - \ ${out}= Execute Command nimbus-testbeddeploy ${testbed} - \ # Make sure the deploy actually worked - \ ${status}= Run Keyword And Return Status Should Contain ${out} is up. IP: - \ Exit For Loop If ${status} - \ Log To Console Nimbus deployment ${IDX} failed, trying again in 5 minutes - \ Sleep 5 minutes - [Return] ${out} - -Kill Nimbus Server - [Arguments] ${user} ${password} ${name} - Open Connection %{NIMBUS_GW} - Login ${user} ${password} - ${out}= Execute Command nimbus-ctl kill '${name}' - Close connection - -Cleanup Nimbus PXE folder - [Arguments] ${user} ${password} - Open Connection %{NIMBUS_GW} - Login ${user} ${password} - ${out}= Execute Command rm -rf public_html/pxe/* - Close connection - -Nimbus Cleanup - [Arguments] ${vm_list} ${collect_log}=True ${dontDelete}=${false} - Run Keyword If ${collect_log} Run Keyword And Continue On Failure Gather Logs From Test Server - Run Keyword And Ignore Error Cleanup Nimbus PXE folder %{NIMBUS_USER} %{NIMBUS_PASSWORD} - Return From Keyword If ${dontDelete} - :FOR ${item} IN @{vm_list} - \ Run Keyword And Ignore Error Kill Nimbus Server %{NIMBUS_USER} %{NIMBUS_PASSWORD} ${item} - -Gather Host IPs - ${out}= Run govc ls host/cls - ${out}= Split To Lines ${out} - ${idx}= Set Variable 1 - :FOR ${line} IN @{out} - \ Continue For Loop If '${line}' == '/vcqaDC/host/cls/Resources' - \ ${ip}= Fetch From Right ${line} / - \ Set Suite Variable ${esx${idx}-ip} ${ip} - \ ${idx}= Evaluate ${idx}+1 - -Create a VSAN Cluster - Log To Console \nStarting basic VSAN cluster deploy... - ${out}= Deploy Nimbus Testbed %{NIMBUS_USER} %{NIMBUS_PASSWORD} --noSupportBundles --vcvaBuild ${VC_VERSION} --esxPxeDir ${ESX_VERSION} --esxBuild ${ESX_VERSION} --testbedName vcqa-vsan-simple-pxeBoot-vcva --runName vic-vmotion - ${out}= Split To Lines ${out} - :FOR ${line} IN @{out} - \ ${status}= Run Keyword And Return Status Should Contain ${line} .vcva-${VC_VERSION}' is up. IP: - \ ${ip}= Run Keyword If ${status} Fetch From Right ${line} ${SPACE} - \ Run Keyword If ${status} Set Suite Variable ${vc-ip} ${ip} - \ Exit For Loop If ${status} - - Log To Console Set environment variables up for GOVC - Set Environment Variable GOVC_URL ${vc-ip} - Set Environment Variable GOVC_USERNAME Administrator@vsphere.local - Set Environment Variable GOVC_PASSWORD Admin\!23 - - Log To Console Create a distributed switch - ${out}= Run govc dvs.create -dc=vcqaDC test-ds - Should Contain ${out} OK - - Log To Console Create three new distributed switch port groups for management and vm network traffic - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=vcqaDC -dvs=test-ds management - Should Contain ${out} OK - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=vcqaDC -dvs=test-ds vm-network - Should Contain ${out} OK - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=vcqaDC -dvs=test-ds bridge - Should Contain ${out} OK - - Log To Console Add all the hosts to the distributed switch - ${out}= Run govc dvs.add -dvs=test-ds -pnic=vmnic1 /vcqaDC/host/cls - Should Contain ${out} OK - - Log To Console Enable DRS and VSAN on the cluster - ${out}= Run govc cluster.change -drs-enabled /vcqaDC/host/cls - Should Be Empty ${out} - - Log To Console Deploy VIC to the VC cluster - Set Environment Variable TEST_URL_ARRAY ${vc-ip} - Set Environment Variable TEST_USERNAME Administrator@vsphere.local - Set Environment Variable TEST_PASSWORD Admin\!23 - Set Environment Variable BRIDGE_NETWORK bridge - Set Environment Variable PUBLIC_NETWORK vm-network - Set Environment Variable TEST_DATASTORE vsanDatastore - Set Environment Variable TEST_RESOURCE cls - Set Environment Variable TEST_TIMEOUT 30m - - Gather Host IPs - -Create a Simple VC Cluster - [Arguments] ${datacenter}=ha-datacenter ${cluster}=cls ${esx_number}=3 ${network}=True - Log To Console \nStarting simple VC cluster deploy... - ${esx_names}= Create List - ${esx_ips}= Create List - :FOR ${IDX} IN RANGE ${esx_number} - \ ${esx} ${esx_ip}= Deploy Nimbus ESXi Server %{NIMBUS_USER} %{NIMBUS_PASSWORD} ${ESX_VERSION} False - \ Append To List ${esx_names} ${esx} - \ Append To List ${esx_ips} ${esx_ip} - - ${vc} ${vc_ip}= Deploy Nimbus vCenter Server %{NIMBUS_USER} %{NIMBUS_PASSWORD} - - Log To Console Create a datacenter on the VC - ${out}= Run govc datacenter.create ${datacenter} - Should Be Empty ${out} - - Log To Console Create a cluster on the VC - ${out}= Run govc cluster.create ${cluster} - Should Be Empty ${out} - - Log To Console Add ESX host to the VC - :FOR ${IDX} IN RANGE ${esx_number} - \ ${out}= Run govc cluster.add -hostname=@{esx_ips}[${IDX}] -username=root -dc=${datacenter} -password=${NIMBUS_ESX_PASSWORD} -noverify=true - \ Should Contain ${out} OK - - Run Keyword If ${network} Setup Network For Simple VC Cluster ${esx_number} ${datacenter} ${cluster} - - Log To Console Enable DRS on the cluster - ${out}= Run govc cluster.change -drs-enabled /${datacenter}/host/${cluster} - Should Be Empty ${out} - - Set Environment Variable TEST_URL_ARRAY ${vc_ip} - Set Environment Variable TEST_URL ${vc_ip} - Set Environment Variable TEST_USERNAME Administrator@vsphere.local - Set Environment Variable TEST_PASSWORD Admin\!23 - Set Environment Variable TEST_DATASTORE datastore1 - Set Environment Variable TEST_DATACENTER /${datacenter} - Set Environment Variable TEST_RESOURCE ${cluster} - Set Environment Variable TEST_TIMEOUT 30m - [Return] @{esx_names} ${vc} @{esx_ips} ${vc_ip} - -Setup Network For Simple VC Cluster - [Arguments] ${esx_number} ${datacenter} ${cluster} - Log To Console Create a distributed switch - ${out}= Run govc dvs.create -dc=${datacenter} test-ds - Should Contain ${out} OK - - Log To Console Create three new distributed switch port groups for management and vm network traffic - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=test-ds management - Should Contain ${out} OK - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=test-ds vm-network - Should Contain ${out} OK - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=test-ds bridge - Should Contain ${out} OK - - Log To Console Add all the hosts to the distributed switch - ${out}= Run govc dvs.add -dvs=test-ds -pnic=vmnic1 /${datacenter}/host/${cluster} - Should Contain ${out} OK - - Log To Console Enable DRS on the cluster - ${out}= Run govc cluster.change -drs-enabled /${datacenter}/host/${cluster} - Should Be Empty ${out} - - Set Environment Variable BRIDGE_NETWORK bridge - Set Environment Variable PUBLIC_NETWORK vm-network - -Create A Distributed Switch - [Arguments] ${datacenter} ${dvs}=test-ds - Log To Console \nCreate a distributed switch - ${out}= Run govc dvs.create -product-version 5.5.0 -dc=${datacenter} ${dvs} - Should Contain ${out} OK - -Create Three Distributed Port Groups - [Arguments] ${datacenter} ${dvs}=test-ds - Log To Console \nCreate three new distributed switch port groups for management and vm network traffic - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=${dvs} management - Should Contain ${out} OK - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=${dvs} vm-network - Should Contain ${out} OK - ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=${dvs} bridge - Should Contain ${out} OK - -Add Host To Distributed Switch - [Arguments] ${host} ${dvs}=test-ds - Log To Console \nAdd host(s) to the distributed switch - ${out}= Run govc dvs.add -dvs=${dvs} -pnic=vmnic1 ${host} - Should Contain ${out} OK - -Disable TLS On ESX Host - Log To Console \nDisable TLS on the host - ${ver}= Get Vsphere Version - ${out}= Run Keyword If '${ver}' != '5.5.0' Run govc host.option.set UserVars.ESXiVPsDisabledProtocols sslv3,tlsv1,tlsv1.1 - Run Keyword If '${ver}' != '5.5.0' Should Be Empty ${out} - -Get Vsphere Version - ${out}= Run govc about - ${out}= Split To Lines ${out} - :FOR ${line} IN @{out} - \ ${status}= Run Keyword And Return Status Should Contain ${line} Version: - \ Run Keyword And Return If ${status} Fetch From Right ${line} ${SPACE} - -Deploy Nimbus NFS Datastore - [Arguments] ${user} ${password} - ${name}= Evaluate 'NFS-' + str(random.randint(1000,9999)) modules=random - Log To Console \nDeploying Nimbus NFS server: ${name} - Open Connection %{NIMBUS_GW} - Login ${user} ${password} - - ${out}= Execute Command nimbus-nfsdeploy ${name} - # Make sure the deploy actually worked - Should Contain ${out} To manage this VM use - # Now grab the IP address and return the name and ip for later use - @{out}= Split To Lines ${out} - :FOR ${item} IN @{out} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} IP is - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} - @{gotIP}= Split String ${line} ${SPACE} - ${ip}= Remove String @{gotIP}[5] , - - Log To Console Successfully deployed new NFS server - ${user}-${name} - Close connection - [Return] ${user}-${name} ${ip} +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource contains any keywords related to using the Nimbus cluster + +*** Variables *** +${ESX_VERSION} 4564106 #6.5 RTM +${VC_VERSION} 4602587 #6.5 RTM +${NIMBUS_ESX_PASSWORD} e2eFunctionalTest + +*** Keywords *** +Deploy Nimbus ESXi Server + [Arguments] ${user} ${password} ${version}=${ESX_VERSION} ${tls_disabled}=True + ${name}= Evaluate 'ESX-' + str(random.randint(1000,9999)) modules=random + Log To Console \nDeploying Nimbus ESXi server: ${name} + Open Connection %{NIMBUS_GW} + Wait Until Keyword Succeeds 2 min 30 sec Login ${user} ${password} + + :FOR ${IDX} IN RANGE 1 5 + \ ${out}= Execute Command nimbus-esxdeploy ${name} --disk=48000000 --ssd=24000000 --memory=8192 --nics 2 ob-${version} + \ # Make sure the deploy actually worked + \ ${status}= Run Keyword And Return Status Should Contain ${out} To manage this VM use + \ Exit For Loop If ${status} + \ Log To Console ${out} + \ Log To Console Nimbus deployment ${IDX} failed, trying again in 5 minutes + \ Sleep 5 minutes + + # Now grab the IP address and return the name and ip for later use + @{out}= Split To Lines ${out} + :FOR ${item} IN @{out} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} IP is + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} + @{gotIP}= Split String ${line} ${SPACE} + ${ip}= Remove String @{gotIP}[5] , + + # Let's set a password so govc doesn't complain + Remove Environment Variable GOVC_PASSWORD + Remove Environment Variable GOVC_USERNAME + Set Environment Variable GOVC_INSECURE 1 + Set Environment Variable GOVC_URL root:@${ip} + ${out}= Run govc host.account.update -id root -password ${NIMBUS_ESX_PASSWORD} + Should Be Empty ${out} + Run Keyword If ${tls_disabled} Disable TLS On ESX Host + Log To Console Successfully deployed new ESXi server - ${user}-${name} + Close connection + [Return] ${user}-${name} ${ip} + +Deploy Multiple Nimbus ESXi Servers in Parallel + [Arguments] ${user} ${password} ${version}=${ESX_VERSION} + ${name1}= Evaluate 'ESX-' + str(random.randint(1000,9999)) modules=random + ${name2}= Evaluate 'ESX-' + str(random.randint(1000,9999)) modules=random + ${name3}= Evaluate 'ESX-' + str(random.randint(1000,9999)) modules=random + + Open Connection %{NIMBUS_GW} + Login ${user} ${password} + + ${out1}= Deploy Nimbus ESXi Server Async ${name1} + ${out2}= Deploy Nimbus ESXi Server Async ${name2} + ${out3}= Deploy Nimbus ESXi Server Async ${name3} + + Wait For Process ${out1} + Wait For Process ${out2} + Wait For Process ${out3} + + ${out}= Execute Command nimbus-ctl ip ${user}-${name1} + + @{out}= Split To Lines ${out} + :FOR ${item} IN @{out} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} ${user}-${name1} + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} + @{gotIP}= Split String ${line} ${SPACE} + ${ip1}= Remove String @{gotIP}[2] + + ${out}= Execute Command nimbus-ctl ip ${user}-${name2} + + @{out}= Split To Lines ${out} + :FOR ${item} IN @{out} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} ${user}-${name2} + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} + @{gotIP}= Split String ${line} ${SPACE} + ${ip2}= Remove String @{gotIP}[2] + + ${out}= Execute Command nimbus-ctl ip ${user}-${name3} + + @{out}= Split To Lines ${out} + :FOR ${item} IN @{out} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} ${user}-${name3} + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} + @{gotIP}= Split String ${line} ${SPACE} + ${ip3}= Remove String @{gotIP}[2] + + Log To Console \nDeploying Nimbus ESXi server: ${gotIP} + + # Let's set a password so govc doesn't complain + Remove Environment Variable GOVC_PASSWORD + Remove Environment Variable GOVC_USERNAME + Set Environment Variable GOVC_INSECURE 1 + Set Environment Variable GOVC_URL root:@${ip1} + ${out}= Run govc host.account.update -id root -password ${NIMBUS_ESX_PASSWORD} + Should Be Empty ${out} + Disable TLS On ESX Host + Log To Console Successfully deployed new ESXi server - ${user}-${name1} + Log To Console \nNimbus ESXi server IP: ${ip1} + + Remove Environment Variable GOVC_PASSWORD + Remove Environment Variable GOVC_USERNAME + Set Environment Variable GOVC_INSECURE 1 + Set Environment Variable GOVC_URL root:@${ip2} + ${out}= Run govc host.account.update -id root -password ${NIMBUS_ESX_PASSWORD} + Should Be Empty ${out} + Disable TLS On ESX Host + Log To Console Successfully deployed new ESXi server - ${user}-${name2} + Log To Console \nNimbus ESXi server IP: ${ip2} + + Remove Environment Variable GOVC_PASSWORD + Remove Environment Variable GOVC_USERNAME + Set Environment Variable GOVC_INSECURE 1 + Set Environment Variable GOVC_URL root:@${ip3} + ${out}= Run govc host.account.update -id root -password ${NIMBUS_ESX_PASSWORD} + Should Be Empty ${out} + Disable TLS On ESX Host + Log To Console Successfully deployed new ESXi server - ${user}-${name3} + Log To Console \nNimbus ESXi server IP: ${ip3} + + Close connection + [Return] ${user}-${name1} ${ip1} ${user}-${name2} ${ip2} ${user}-${name3} ${ip3} + +Deploy Nimbus vCenter Server + [Arguments] ${user} ${password} ${version}=${VC_VERSION} + ${name}= Evaluate 'VC-' + str(random.randint(1000,9999)) modules=random + Log To Console \nDeploying Nimbus vCenter server: ${name} + Open Connection %{NIMBUS_GW} + Login ${user} ${password} + + :FOR ${IDX} IN RANGE 1 5 + \ ${out}= Execute Command nimbus-vcvadeploy --vcvaBuild ${version} ${name} + \ # Make sure the deploy actually worked + \ ${status}= Run Keyword And Return Status Should Contain ${out} Overall Status: Succeeded + \ Exit For Loop If ${status} + \ Log To Console Nimbus deployment ${IDX} failed, trying again in 5 minutes + \ Sleep 5 minutes + + # Now grab the IP address and return the name and ip for later use + @{out}= Split To Lines ${out} + :FOR ${item} IN @{out} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} Cloudvm is running on IP + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} + ${ip}= Fetch From Right ${line} ${SPACE} + + Set Environment Variable GOVC_INSECURE 1 + Set Environment Variable GOVC_USERNAME Administrator@vsphere.local + Set Environment Variable GOVC_PASSWORD Admin!23 + Set Environment Variable GOVC_URL ${ip} + Log To Console Successfully deployed new vCenter server - ${user}-${name} + Close connection + [Return] ${user}-${name} ${ip} + +Deploy Nimbus ESXi Server Async + [Tags] secret + [Arguments] ${name} ${version}=${ESX_VERSION} + Log To Console \nDeploying Nimbus ESXi server: ${name} + + ${out}= Run Secret SSHPASS command %{NIMBUS_USER} %{NIMBUS_PASSWORD} 'nimbus-esxdeploy ${name} --disk\=48000000 --ssd\=24000000 --memory\=8192 --nics 2 ${version}' + [Return] ${out} + +Run Secret SSHPASS command + [Tags] secret + [Arguments] ${user} ${password} ${cmd} + + ${out}= Start Process sshpass -p ${password} ssh -o StrictHostKeyChecking\=no ${user}@%{NIMBUS_GW} ${cmd} shell=True + [Return] ${out} + +Deploy Nimbus vCenter Server Async + [Tags] secret + [Arguments] ${name} ${version}=${VC_VERSION} + Log To Console \nDeploying Nimbus VC server: ${name} + + ${out}= Run Secret SSHPASS command %{NIMBUS_USER} %{NIMBUS_PASSWORD} 'nimbus-vcvadeploy --vcvaBuild ${version} ${name}' + [Return] ${out} + +Deploy Nimbus Testbed + [Arguments] ${user} ${password} ${testbed} + Open Connection %{NIMBUS_GW} + Login ${user} ${password} + + :FOR ${IDX} IN RANGE 1 5 + \ ${out}= Execute Command nimbus-testbeddeploy ${testbed} + \ # Make sure the deploy actually worked + \ ${status}= Run Keyword And Return Status Should Contain ${out} is up. IP: + \ Exit For Loop If ${status} + \ Log To Console Nimbus deployment ${IDX} failed, trying again in 5 minutes + \ Sleep 5 minutes + [Return] ${out} + +Kill Nimbus Server + [Arguments] ${user} ${password} ${name} + Open Connection %{NIMBUS_GW} + Login ${user} ${password} + ${out}= Execute Command nimbus-ctl kill '${name}' + Close connection + +Cleanup Nimbus PXE folder + [Arguments] ${user} ${password} + Open Connection %{NIMBUS_GW} + Login ${user} ${password} + ${out}= Execute Command rm -rf public_html/pxe/* + Close connection + +Nimbus Cleanup + [Arguments] ${vm_list} ${collect_log}=True ${dontDelete}=${false} + Run Keyword If ${collect_log} Run Keyword And Continue On Failure Gather Logs From Test Server + Run Keyword And Ignore Error Cleanup Nimbus PXE folder %{NIMBUS_USER} %{NIMBUS_PASSWORD} + Return From Keyword If ${dontDelete} + :FOR ${item} IN @{vm_list} + \ Run Keyword And Ignore Error Kill Nimbus Server %{NIMBUS_USER} %{NIMBUS_PASSWORD} ${item} + +Gather Host IPs + ${out}= Run govc ls host/cls + ${out}= Split To Lines ${out} + ${idx}= Set Variable 1 + :FOR ${line} IN @{out} + \ Continue For Loop If '${line}' == '/vcqaDC/host/cls/Resources' + \ ${ip}= Fetch From Right ${line} / + \ Set Suite Variable ${esx${idx}-ip} ${ip} + \ ${idx}= Evaluate ${idx}+1 + +Create a VSAN Cluster + Log To Console \nStarting basic VSAN cluster deploy... + ${out}= Deploy Nimbus Testbed %{NIMBUS_USER} %{NIMBUS_PASSWORD} --noSupportBundles --vcvaBuild ${VC_VERSION} --esxPxeDir ${ESX_VERSION} --esxBuild ${ESX_VERSION} --testbedName vcqa-vsan-simple-pxeBoot-vcva --runName vic-vmotion + ${out}= Split To Lines ${out} + :FOR ${line} IN @{out} + \ ${status}= Run Keyword And Return Status Should Contain ${line} .vcva-${VC_VERSION}' is up. IP: + \ ${ip}= Run Keyword If ${status} Fetch From Right ${line} ${SPACE} + \ Run Keyword If ${status} Set Suite Variable ${vc-ip} ${ip} + \ Exit For Loop If ${status} + + Log To Console Set environment variables up for GOVC + Set Environment Variable GOVC_URL ${vc-ip} + Set Environment Variable GOVC_USERNAME Administrator@vsphere.local + Set Environment Variable GOVC_PASSWORD Admin\!23 + + Log To Console Create a distributed switch + ${out}= Run govc dvs.create -dc=vcqaDC test-ds + Should Contain ${out} OK + + Log To Console Create three new distributed switch port groups for management and vm network traffic + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=vcqaDC -dvs=test-ds management + Should Contain ${out} OK + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=vcqaDC -dvs=test-ds vm-network + Should Contain ${out} OK + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=vcqaDC -dvs=test-ds bridge + Should Contain ${out} OK + + Log To Console Add all the hosts to the distributed switch + ${out}= Run govc dvs.add -dvs=test-ds -pnic=vmnic1 /vcqaDC/host/cls + Should Contain ${out} OK + + Log To Console Enable DRS and VSAN on the cluster + ${out}= Run govc cluster.change -drs-enabled /vcqaDC/host/cls + Should Be Empty ${out} + + Log To Console Deploy VIC to the VC cluster + Set Environment Variable TEST_URL_ARRAY ${vc-ip} + Set Environment Variable TEST_USERNAME Administrator@vsphere.local + Set Environment Variable TEST_PASSWORD Admin\!23 + Set Environment Variable BRIDGE_NETWORK bridge + Set Environment Variable PUBLIC_NETWORK vm-network + Set Environment Variable TEST_DATASTORE vsanDatastore + Set Environment Variable TEST_RESOURCE cls + Set Environment Variable TEST_TIMEOUT 30m + + Gather Host IPs + +Create a Simple VC Cluster + [Arguments] ${datacenter}=ha-datacenter ${cluster}=cls ${esx_number}=3 ${network}=True + Log To Console \nStarting simple VC cluster deploy... + ${esx_names}= Create List + ${esx_ips}= Create List + :FOR ${IDX} IN RANGE ${esx_number} + \ ${esx} ${esx_ip}= Deploy Nimbus ESXi Server %{NIMBUS_USER} %{NIMBUS_PASSWORD} ${ESX_VERSION} False + \ Append To List ${esx_names} ${esx} + \ Append To List ${esx_ips} ${esx_ip} + + ${vc} ${vc_ip}= Deploy Nimbus vCenter Server %{NIMBUS_USER} %{NIMBUS_PASSWORD} + + Log To Console Create a datacenter on the VC + ${out}= Run govc datacenter.create ${datacenter} + Should Be Empty ${out} + + Log To Console Create a cluster on the VC + ${out}= Run govc cluster.create ${cluster} + Should Be Empty ${out} + + Log To Console Add ESX host to the VC + :FOR ${IDX} IN RANGE ${esx_number} + \ ${out}= Run govc cluster.add -hostname=@{esx_ips}[${IDX}] -username=root -dc=${datacenter} -password=${NIMBUS_ESX_PASSWORD} -noverify=true + \ Should Contain ${out} OK + + Run Keyword If ${network} Setup Network For Simple VC Cluster ${esx_number} ${datacenter} ${cluster} + + Log To Console Enable DRS on the cluster + ${out}= Run govc cluster.change -drs-enabled /${datacenter}/host/${cluster} + Should Be Empty ${out} + + Set Environment Variable TEST_URL_ARRAY ${vc_ip} + Set Environment Variable TEST_URL ${vc_ip} + Set Environment Variable TEST_USERNAME Administrator@vsphere.local + Set Environment Variable TEST_PASSWORD Admin\!23 + Set Environment Variable TEST_DATASTORE datastore1 + Set Environment Variable TEST_DATACENTER /${datacenter} + Set Environment Variable TEST_RESOURCE ${cluster} + Set Environment Variable TEST_TIMEOUT 30m + [Return] @{esx_names} ${vc} @{esx_ips} ${vc_ip} + +Setup Network For Simple VC Cluster + [Arguments] ${esx_number} ${datacenter} ${cluster} + Log To Console Create a distributed switch + ${out}= Run govc dvs.create -dc=${datacenter} test-ds + Should Contain ${out} OK + + Log To Console Create three new distributed switch port groups for management and vm network traffic + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=test-ds management + Should Contain ${out} OK + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=test-ds vm-network + Should Contain ${out} OK + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=test-ds bridge + Should Contain ${out} OK + + Log To Console Add all the hosts to the distributed switch + ${out}= Run govc dvs.add -dvs=test-ds -pnic=vmnic1 /${datacenter}/host/${cluster} + Should Contain ${out} OK + + Log To Console Enable DRS on the cluster + ${out}= Run govc cluster.change -drs-enabled /${datacenter}/host/${cluster} + Should Be Empty ${out} + + Set Environment Variable BRIDGE_NETWORK bridge + Set Environment Variable PUBLIC_NETWORK vm-network + +Create A Distributed Switch + [Arguments] ${datacenter} ${dvs}=test-ds + Log To Console \nCreate a distributed switch + ${out}= Run govc dvs.create -product-version 5.5.0 -dc=${datacenter} ${dvs} + Should Contain ${out} OK + +Create Three Distributed Port Groups + [Arguments] ${datacenter} ${dvs}=test-ds + Log To Console \nCreate three new distributed switch port groups for management and vm network traffic + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=${dvs} management + Should Contain ${out} OK + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=${dvs} vm-network + Should Contain ${out} OK + ${out}= Run govc dvs.portgroup.add -nports 12 -dc=${datacenter} -dvs=${dvs} bridge + Should Contain ${out} OK + +Add Host To Distributed Switch + [Arguments] ${host} ${dvs}=test-ds + Log To Console \nAdd host(s) to the distributed switch + ${out}= Run govc dvs.add -dvs=${dvs} -pnic=vmnic1 ${host} + Should Contain ${out} OK + +Disable TLS On ESX Host + Log To Console \nDisable TLS on the host + ${ver}= Get Vsphere Version + ${out}= Run Keyword If '${ver}' != '5.5.0' Run govc host.option.set UserVars.ESXiVPsDisabledProtocols sslv3,tlsv1,tlsv1.1 + Run Keyword If '${ver}' != '5.5.0' Should Be Empty ${out} + +Get Vsphere Version + ${out}= Run govc about + ${out}= Split To Lines ${out} + :FOR ${line} IN @{out} + \ ${status}= Run Keyword And Return Status Should Contain ${line} Version: + \ Run Keyword And Return If ${status} Fetch From Right ${line} ${SPACE} + +Deploy Nimbus NFS Datastore + [Arguments] ${user} ${password} + ${name}= Evaluate 'NFS-' + str(random.randint(1000,9999)) modules=random + Log To Console \nDeploying Nimbus NFS server: ${name} + Open Connection %{NIMBUS_GW} + Login ${user} ${password} + + ${out}= Execute Command nimbus-nfsdeploy ${name} + # Make sure the deploy actually worked + Should Contain ${out} To manage this VM use + # Now grab the IP address and return the name and ip for later use + @{out}= Split To Lines ${out} + :FOR ${item} IN @{out} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} IP is + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} + @{gotIP}= Split String ${line} ${SPACE} + ${ip}= Remove String @{gotIP}[5] , + + Log To Console Successfully deployed new NFS server - ${user}-${name} + Close connection + [Return] ${user}-${name} ${ip} diff --git a/tests/resources/OVA-Util.robot b/tests/resources/OVA-Util.robot index 0e5fb1888..5638512c2 100644 --- a/tests/resources/OVA-Util.robot +++ b/tests/resources/OVA-Util.robot @@ -1,97 +1,97 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides any keywords related to Unified OVA - -*** Variables *** -${ova_root_pwd} ova-test-root-pwd -${ova_appliance_options} --prop:root_pwd=${ova_root_pwd} --prop:permit_root_login=true - -${ova_target_vm_name} harbor-unified-ova-integration-test -${ovftool_options} --noSSLVerify --acceptAllEulas --name=${ova_target_vm_name} --diskMode=thin --powerOn --X:waitForIp --X:injectOvfEnv --X:enableHiddenProperties - -${ova_network_ip0} 10.17.109.207 -${ova_network_netmask0} 255.255.255.0 -${ova_network_gateway} 10.17.109.253 -${ova_network_dns} 10.118.81.1 -${ova_network_searchpath} eng.vmware.com -${ova_network_domain} mrburns -${ova_network_options} --prop:network.ip0=${ova_network_ip0} --prop:network.netmask0=${ova_network_netmask0} --prop:network.gateway=${ova_network_gateway} --prop:network.DNS=${ova_network_dns} --prop:network.searchpath=${ova_network_searchpath} --prop:network.domain=${ova_network_domain} - -${ova_harbor_admin_password} harbor-admin-passwd -${ova_harbor_db_password} harbor-db-passwd -#${ova_service_options} --prop:auth_mode="%{AUTH_MODE}" --prop:clair_db_password="%{CLAIR_DB_PASSWORD}" --prop:max_job_workers="%{MAX_JOB_WORKERS}" --prop:harbor_admin_password="%{HARBOR_ADMIN_PASSWORD}" --prop:db_password="%{DB_PASSWORD}" - -#${ova_options} ${ovftool_options} ${ova_appliance_options} ${ova_service_options} -#${ova_options_with_network} ${ova_options} ${ova_network_options} - -${tls_not_disabled} False - -*** Keywords *** -# Requires vc credential for govc -Deploy Harbor-OVA To Test Server - [Arguments] ${dhcp} ${protocol} ${build} ${user} ${password} ${ova_path} ${host} ${datastore} ${cluster} ${datacenter} - - Log To Console \nCleanup environment... - Run Keyword And Ignore Error Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc vm.destroy ${ova_target_vm_name} - Run Keyword And Ignore Error Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc object.destroy /${datacenter}/vm/${ova_target_vm_name} - - Log To Console \nStarting to deploy unified-ova to test server... - Run Keyword If ${dhcp} Log To Console ovftool --datastore=${datastore} ${ova_options} ${ova_path} 'vi://${user}:${password}@${host}/${datacenter}/host/${cluster}' - ... ELSE Log To Console ovftool --datastore=${datastore} ${ova_options_with_network} ${ova_path} 'vi://${user}:${password}@${host}/${datacenter}/host/${cluster}' - ${out}= Run Keyword If ${dhcp} Run ovftool --datastore=${datastore} ${ova_options} ${ova_path} 'vi://${user}:${password}@${host}/${datacenter}/host/${cluster}' - ... ELSE Run ovftool --datastore=${datastore} ${ova_options_with_network} ${ova_path} 'vi://${user}:${password}@${host}/${datacenter}/host/${cluster}' - - Should Contain ${out} Received IP address: - Should Not Contain ${out} None - - ${out}= Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc ls /ha-datacenter/host/cls/ - ${out}= Split To Lines ${out} - ${idx}= Set Variable 1 - :FOR ${line} IN @{out} - \ Continue For Loop If '${line}' == '/ha-datacenter/host/cls/Resources' - \ ${ip}= Fetch From Right ${line} / - \ Set Suite Variable ${esx${idx}-ip} ${ip} - \ ${idx}= Evaluate ${idx}+1 - - Run Keyword And Ignore Error Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc host.esxcli -host.ip=${esx1-ip} system settings advanced set -o /Net/GuestIPHack -i 1 - ${ip}= Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc vm.ip -esxcli harbor-unified-ova-integration-test - - Set Environment Variable HARBOR_IP ${ip} - - Log To Console \nHarbor IP: %{HARBOR_IP} - - Wait for Harbor Ready ${protocol} %{HARBOR_IP} - [Return] %{HARBOR_IP} - -# Requires vc credential for govc -Cleanup Harbor-OVA On Test Server - [Arguments] ${url}=%{GOVC_URL} ${username}=%{GOVC_USERNAME} ${password}=%{GOVC_PASSWORD} - ${rc} ${output}= Run And Return Rc And Output GOVC_URL=${url} GOVC_USERNAME=${username} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc vm.destroy ${ova_target_vm_name} - Log ${output} - Should Be Equal As Integers ${rc} 0 - Run Keyword And Ignore Error Run GOVC_URL=${url} GOVC_USERNAME=${username} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc object.destroy /%{TEST_DATACENTER}/vm/${ova_target_vm_name} - Log To Console \nUnified-OVA deployment is cleaned up on test server - -Build Unified OVA - [Arguments] ${user}=%{TEST_USERNAME} ${password}=%{TEST_PASSWORD} ${host}=%{TEST_URL} - Log To Console \nStarting to build Unified OVA... - Log To Console \nRemove stale local OVA artifacts - Run Remove OVA Artifacts Locally - ${out}= Run PACKER_ESX_HOST=${host} PACKER_USER=${user} PACKER_PASSWORD=${password} make ova-release - Log ${out} - @{out}= Split To Lines ${out} - Should Not Contain @{out}[-1] Error +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides any keywords related to Unified OVA + +*** Variables *** +${ova_root_pwd} ova-test-root-pwd +${ova_appliance_options} --prop:root_pwd=${ova_root_pwd} --prop:permit_root_login=true + +${ova_target_vm_name} harbor-unified-ova-integration-test +${ovftool_options} --noSSLVerify --acceptAllEulas --name=${ova_target_vm_name} --diskMode=thin --powerOn --X:waitForIp --X:injectOvfEnv --X:enableHiddenProperties + +${ova_network_ip0} 10.17.109.207 +${ova_network_netmask0} 255.255.255.0 +${ova_network_gateway} 10.17.109.253 +${ova_network_dns} 10.118.81.1 +${ova_network_searchpath} eng.vmware.com +${ova_network_domain} mrburns +${ova_network_options} --prop:network.ip0=${ova_network_ip0} --prop:network.netmask0=${ova_network_netmask0} --prop:network.gateway=${ova_network_gateway} --prop:network.DNS=${ova_network_dns} --prop:network.searchpath=${ova_network_searchpath} --prop:network.domain=${ova_network_domain} + +${ova_harbor_admin_password} harbor-admin-passwd +${ova_harbor_db_password} harbor-db-passwd +#${ova_service_options} --prop:auth_mode="%{AUTH_MODE}" --prop:clair_db_password="%{CLAIR_DB_PASSWORD}" --prop:max_job_workers="%{MAX_JOB_WORKERS}" --prop:harbor_admin_password="%{HARBOR_ADMIN_PASSWORD}" --prop:db_password="%{DB_PASSWORD}" + +#${ova_options} ${ovftool_options} ${ova_appliance_options} ${ova_service_options} +#${ova_options_with_network} ${ova_options} ${ova_network_options} + +${tls_not_disabled} False + +*** Keywords *** +# Requires vc credential for govc +Deploy Harbor-OVA To Test Server + [Arguments] ${dhcp} ${protocol} ${build} ${user} ${password} ${ova_path} ${host} ${datastore} ${cluster} ${datacenter} + + Log To Console \nCleanup environment... + Run Keyword And Ignore Error Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc vm.destroy ${ova_target_vm_name} + Run Keyword And Ignore Error Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc object.destroy /${datacenter}/vm/${ova_target_vm_name} + + Log To Console \nStarting to deploy unified-ova to test server... + Run Keyword If ${dhcp} Log To Console ovftool --datastore=${datastore} ${ova_options} ${ova_path} 'vi://${user}:${password}@${host}/${datacenter}/host/${cluster}' + ... ELSE Log To Console ovftool --datastore=${datastore} ${ova_options_with_network} ${ova_path} 'vi://${user}:${password}@${host}/${datacenter}/host/${cluster}' + ${out}= Run Keyword If ${dhcp} Run ovftool --datastore=${datastore} ${ova_options} ${ova_path} 'vi://${user}:${password}@${host}/${datacenter}/host/${cluster}' + ... ELSE Run ovftool --datastore=${datastore} ${ova_options_with_network} ${ova_path} 'vi://${user}:${password}@${host}/${datacenter}/host/${cluster}' + + Should Contain ${out} Received IP address: + Should Not Contain ${out} None + + ${out}= Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc ls /ha-datacenter/host/cls/ + ${out}= Split To Lines ${out} + ${idx}= Set Variable 1 + :FOR ${line} IN @{out} + \ Continue For Loop If '${line}' == '/ha-datacenter/host/cls/Resources' + \ ${ip}= Fetch From Right ${line} / + \ Set Suite Variable ${esx${idx}-ip} ${ip} + \ ${idx}= Evaluate ${idx}+1 + + Run Keyword And Ignore Error Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc host.esxcli -host.ip=${esx1-ip} system settings advanced set -o /Net/GuestIPHack -i 1 + ${ip}= Run GOVC_URL=${host} GOVC_USERNAME=${user} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc vm.ip -esxcli harbor-unified-ova-integration-test + + Set Environment Variable HARBOR_IP ${ip} + + Log To Console \nHarbor IP: %{HARBOR_IP} + + Wait for Harbor Ready ${protocol} %{HARBOR_IP} + [Return] %{HARBOR_IP} + +# Requires vc credential for govc +Cleanup Harbor-OVA On Test Server + [Arguments] ${url}=%{GOVC_URL} ${username}=%{GOVC_USERNAME} ${password}=%{GOVC_PASSWORD} + ${rc} ${output}= Run And Return Rc And Output GOVC_URL=${url} GOVC_USERNAME=${username} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc vm.destroy ${ova_target_vm_name} + Log ${output} + Should Be Equal As Integers ${rc} 0 + Run Keyword And Ignore Error Run GOVC_URL=${url} GOVC_USERNAME=${username} GOVC_PASSWORD=${password} GOVC_INSECURE=1 govc object.destroy /%{TEST_DATACENTER}/vm/${ova_target_vm_name} + Log To Console \nUnified-OVA deployment is cleaned up on test server + +Build Unified OVA + [Arguments] ${user}=%{TEST_USERNAME} ${password}=%{TEST_PASSWORD} ${host}=%{TEST_URL} + Log To Console \nStarting to build Unified OVA... + Log To Console \nRemove stale local OVA artifacts + Run Remove OVA Artifacts Locally + ${out}= Run PACKER_ESX_HOST=${host} PACKER_USER=${user} PACKER_PASSWORD=${password} make ova-release + Log ${out} + @{out}= Split To Lines ${out} + Should Not Contain @{out}[-1] Error Log To Console \nUnified OVA is built successfully \ No newline at end of file diff --git a/tests/resources/SeleniumUtil.robot b/tests/resources/SeleniumUtil.robot index 420e8a7c2..0ab7f7a9c 100644 --- a/tests/resources/SeleniumUtil.robot +++ b/tests/resources/SeleniumUtil.robot @@ -1,48 +1,49 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource provides helper functions for docker operations -Resource Util.robot - -*** Keywords *** -Start Selenium Standalone Server Locally - OperatingSystem.File Should Exist /go/selenium-server-standalone-3.4.0.jar - ${handle}= Start Process java -jar /go/selenium-server-standalone-3.4.0.jar >./selenium-local.log 2>&1 shell=True - Process Should Be Running ${handle} - Sleep 10s - [Return] ${handle} - -Init Chrome Driver - Run pkill chromedriver - Run pkill chrome - ${chrome options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys - ${capabilities}= Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.CHROME sys - Set To Dictionary ${capabilities} acceptInsecureCerts ${True} - Call Method ${chrome options} add_argument --headless - Call Method ${chrome options} add_argument --disable-gpu - Call Method ${chrome options} add_argument --start-maximized - Call Method ${chrome options} add_argument --no-sandbox - Call Method ${chrome options} add_argument --window-size\=1600,900 - ${chrome options.binary_location} Set Variable /usr/bin/google-chrome - #Create Webdriver Chrome Chrome_headless chrome_options=${chrome options} desired_capabilities=${capabilities} - :For ${n} IN RANGE 1 6 - \ Log To Console Trying Create Webdriver ${n} times ... - \ ${out} Run Keyword And Ignore Error Create Webdriver Chrome Chrome_headless chrome_options=${chrome options} desired_capabilities=${capabilities} - \ Log To Console Return value is ${out[0]} - \ Exit For Loop If '${out[0]}'=='PASS' - \ Sleep 2 - Run Keyword If '${out[0]}'=='FAIL' Capture Page Screenshot - Should Be Equal As Strings '${out[0]}' 'PASS' - Sleep 5 +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource provides helper functions for docker operations +Resource Util.robot + +*** Keywords *** +Start Selenium Standalone Server Locally + OperatingSystem.File Should Exist /go/selenium-server-standalone-3.4.0.jar + ${handle}= Start Process java -jar /go/selenium-server-standalone-3.4.0.jar >./selenium-local.log 2>&1 shell=True + Process Should Be Running ${handle} + Sleep 10s + [Return] ${handle} + +Init Chrome Driver + Run pkill chromedriver + Run pkill chrome + ${chrome options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys + ${capabilities}= Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.CHROME sys + Set To Dictionary ${capabilities} acceptInsecureCerts ${True} + Call Method ${chrome options} add_argument --headless + Call Method ${chrome options} add_argument --disable-gpu + Call Method ${chrome options} add_argument --start-maximized + Call Method ${chrome options} add_argument --no-sandbox + Call Method ${chrome options} add_argument --window-size\=1600,900 + ${chrome options.binary_location} Set Variable /usr/bin/google-chrome + #Create Webdriver Chrome Chrome_headless chrome_options=${chrome options} desired_capabilities=${capabilities} + FOR ${n} IN RANGE 1 6 + Log To Console Trying Create Webdriver ${n} times ... + ${out} Run Keyword And Ignore Error Create Webdriver Chrome Chrome_headless chrome_options=${chrome options} desired_capabilities=${capabilities} + Log To Console Return value is ${out[0]} + Exit For Loop If '${out[0]}'=='PASS' + Sleep 2 + END + Run Keyword If '${out[0]}'=='FAIL' Capture Page Screenshot + Should Be Equal As Strings '${out[0]}' 'PASS' + Sleep 5 diff --git a/tests/resources/Test-Example/Test.robot b/tests/resources/Test-Example/Test.robot index df5d1af91..152191d72 100644 --- a/tests/resources/Test-Example/Test.robot +++ b/tests/resources/Test-Example/Test.robot @@ -1,28 +1,28 @@ - -*** Settings *** -Documentation Harbor BATs -Resource ../Util.robot - -*** Variables *** -${HARBOR_URL} https://${ip} -${HARBOR_ADMIN} admin -${HARBOR_PASSWORD} Harbor12345 - -*** Test Cases *** -# For Windows -Test Case - Example For Windows - Open Browser https://localhost:4200 Chrome - Retry Element Click xpath=//clr-dropdown/button - Retry Element Click xpath=//clr-dropdown/clr-dropdown-menu/a[contains(., 'English')] - # your case starts ===================================== - - # your case ends ====================================== - Close Browser - -# For Linux -Test Case - Example For Linux - init chrome driver - # your case starts ===================================== - - # your case ends ====================================== + +*** Settings *** +Documentation Harbor BATs +Resource ../Util.robot + +*** Variables *** +${HARBOR_URL} https://${ip} +${HARBOR_ADMIN} admin +${HARBOR_PASSWORD} Harbor12345 + +*** Test Cases *** +# For Windows +Test Case - Example For Windows + Open Browser https://localhost:4200 Chrome + Retry Element Click xpath=//clr-dropdown/button + Retry Element Click xpath=//clr-dropdown/clr-dropdown-menu/a[contains(., 'English')] + # your case starts ===================================== + + # your case ends ====================================== + Close Browser + +# For Linux +Test Case - Example For Linux + init chrome driver + # your case starts ===================================== + + # your case ends ====================================== Close Browser \ No newline at end of file diff --git a/tests/resources/Util.robot b/tests/resources/Util.robot index 8f58741f8..6097717cd 100644 --- a/tests/resources/Util.robot +++ b/tests/resources/Util.robot @@ -20,7 +20,7 @@ Library requests Library Process Library SSHLibrary 1 minute Library DateTime -Library Selenium2Library 60 10 +Library SeleniumLibrary 60 10 Library JSONLibrary Resource Nimbus-Util.robot Resource Vsphere-Util.robot @@ -206,16 +206,18 @@ Text Input Clear Field Of Characters [Arguments] ${field} ${character count} [Documentation] This keyword pushes the delete key (ascii: \8) a specified number of times in a specified field. - : FOR ${index} IN RANGE ${character count} - \ Press Keys ${field} \\8 + FOR ${index} IN RANGE ${character count} + Press Keys ${field} \\8 + END Wait Unitl Command Success [Arguments] ${cmd} ${times}=8 - :FOR ${n} IN RANGE 1 ${times} - \ Log Trying ${cmd}: ${n} ... console=True - \ ${rc} ${output}= Run And Return Rc And Output ${cmd} - \ Exit For Loop If '${rc}'=='0' - \ Sleep 2 + FOR ${n} IN RANGE 1 ${times} + Log Trying ${cmd}: ${n} ... console=True + ${rc} ${output}= Run And Return Rc And Output ${cmd} + Exit For Loop If '${rc}'=='0' + Sleep 2 + END Log Command Result is ${output} Should Be Equal As Strings '${rc}' '0' [Return] ${output} @@ -229,42 +231,45 @@ Command Should be Failed Retry Keyword N Times When Error [Arguments] ${times} ${keyword} @{elements} - :For ${n} IN RANGE 1 ${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} and ${out[0]} - \ Capture Page Screenshot record.png - \ Run Keyword If '${keyword}'=='Make Swagger Client' Exit For Loop If '${out[0]}'=='PASS' and '${out[1]}'=='0' - \ ... ELSE Exit For Loop If '${out[0]}'=='PASS' - \ Sleep 10 + FOR ${n} IN RANGE 1 ${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} and ${out[0]} + Capture Page Screenshot record.png + Run Keyword If '${keyword}'=='Make Swagger Client' Exit For Loop If '${out[0]}'=='PASS' and '${out[1]}'=='0' + ... ELSE Exit For Loop If '${out[0]}'=='PASS' + Sleep 10 + END Run Keyword If '${out[0]}'=='FAIL' Capture Page Screenshot Should Be Equal As Strings '${out[0]}' 'PASS' [Return] ${out[1]} Retry Keyword When Return Value Mismatch [Arguments] ${keyword} ${expected_value} ${count} @{elements} - :For ${n} IN RANGE 1 ${count} - \ Log To Console Trying ${keyword} ${n} times ... - \ ${out} Run Keyword And Ignore Error ${keyword} @{elements} - \ Log To Console Return value is ${out[1]} - \ ${status}= Set Variable If '${out[1]}'=='${expected_value}' 'PASS' 'FAIL' - \ Exit For Loop If '${out[1]}'=='${expected_value}' - \ Sleep 2 + FOR ${n} IN RANGE 1 ${count} + Log To Console Trying ${keyword} ${n} times ... + ${out} Run Keyword And Ignore Error ${keyword} @{elements} + Log To Console Return value is ${out[1]} + ${status}= Set Variable If '${out[1]}'=='${expected_value}' 'PASS' 'FAIL' + Exit For Loop If '${out[1]}'=='${expected_value}' + Sleep 2 + END Run Keyword If ${status}=='FAIL' Capture Page Screenshot Should Be Equal As Strings ${status} 'PASS' Retry Double Keywords When Error [Arguments] ${keyword1} ${element1} ${keyword2} ${element2} ${DoAssert}=${true} ${times}=3 - :For ${n} IN RANGE 1 ${times} - \ Log To Console Trying ${keyword1} and ${keyword2} ${n} times ... - \ ${out1} Run Keyword And Ignore Error ${keyword1} ${element1} - \ Capture Page Screenshot - \ Sleep 1 - \ ${out2} Run Keyword And Ignore Error ${keyword2} ${element2} - \ Capture Page Screenshot - \ Log To Console Return value is ${out1[0]} ${out2[0]} - \ Exit For Loop If '${out2[0]}'=='PASS' - \ Sleep 1 + FOR ${n} IN RANGE 1 ${times} + Log To Console Trying ${keyword1} and ${keyword2} ${n} times ... + ${out1} Run Keyword And Ignore Error ${keyword1} ${element1} + Capture Page Screenshot + Sleep 1 + ${out2} Run Keyword And Ignore Error ${keyword2} ${element2} + Capture Page Screenshot + Log To Console Return value is ${out1[0]} ${out2[0]} + Exit For Loop If '${out2[0]}'=='PASS' + Sleep 1 + END Return From Keyword If ${DoAssert} == ${false} '${out2[0]}' Should Be Equal As Strings '${out2[0]}' 'PASS' diff --git a/tests/resources/VCH-Util.robot b/tests/resources/VCH-Util.robot index 81bb92b21..52b02d2dc 100644 --- a/tests/resources/VCH-Util.robot +++ b/tests/resources/VCH-Util.robot @@ -1,404 +1,404 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource contains all keywords related to creating, deleting, maintaining VCHs - -*** Keywords *** -Set Test Environment Variables - # Finish setting up environment variables - ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set DRONE_BUILD_NUMBER - Run Keyword If '${status}' == 'FAIL' Set Environment Variable DRONE_BUILD_NUMBER 0 - ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set BRIDGE_NETWORK - Run Keyword If '${status}' == 'FAIL' Set Environment Variable BRIDGE_NETWORK network - ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set PUBLIC_NETWORK - Run Keyword If '${status}' == 'FAIL' Set Environment Variable PUBLIC_NETWORK 'VM Network' - ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set TEST_DATACENTER - Run Keyword If '${status}' == 'FAIL' Set Environment Variable TEST_DATACENTER ${SPACE} - - @{URLs}= Split String %{TEST_URL_ARRAY} - ${len}= Get Length ${URLs} - ${IDX}= Evaluate %{DRONE_BUILD_NUMBER} \% ${len} - - Set Environment Variable TEST_URL @{URLs}[${IDX}] - Set Environment Variable GOVC_URL %{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL} - # TODO: need an integration/vic-test image update to include the about.cert command - #${rc} ${thumbprint}= Run And Return Rc And Output govc about.cert -k | jq -r .ThumbprintSHA1 - ${rc} ${thumbprint}= Run And Return Rc And Output openssl s_client -connect $(govc env -x GOVC_URL_HOST):443 /dev/null | openssl x509 -fingerprint -noout | cut -d= -f2 - Should Be Equal As Integers ${rc} 0 - Set Environment Variable TEST_THUMBPRINT ${thumbprint} - Log To Console \nTEST_URL=%{TEST_URL} - - ${host}= Run govc ls host - ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set TEST_RESOURCE - Run Keyword If '${status}' == 'FAIL' Set Environment Variable TEST_RESOURCE ${host}/Resources - Set Environment Variable GOVC_RESOURCE_POOL %{TEST_RESOURCE} - ${noQuotes}= Strip String %{TEST_DATASTORE} characters=" - Set Environment Variable GOVC_DATASTORE ${noQuotes} - - ${about}= Run govc about - ${status}= Run Keyword And Return Status Should Contain ${about} VMware ESXi - Run Keyword If ${status} Set Environment Variable HOST_TYPE ESXi - Run Keyword Unless ${status} Set Environment Variable HOST_TYPE VC - - ${about}= Run govc datastore.info %{TEST_DATASTORE} | grep 'Type' - ${status}= Run Keyword And Return Status Should Contain ${about} vsan - Run Keyword If ${status} Set Environment Variable DATASTORE_TYPE VSAN - Run Keyword Unless ${status} Set Environment Variable DATASTORE_TYPE Non_VSAN - - # set the TLS config options suitable for vic-machine in this env - ${domain}= Get Environment Variable DOMAIN '' - Run Keyword If $domain == '' Set Suite Variable ${vicmachinetls} --no-tlsverify - Run Keyword If $domain != '' Set Suite Variable ${vicmachinetls} --tls-cname=*.${domain} - - Set Test VCH Name - # Set a unique bridge network for each VCH that has a random VLAN ID - ${vlan}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Evaluate str(random.randint(1, 4093)) modules=random - ${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.add -vlan=${vlan} -vswitch vSwitchLAN %{VCH-NAME}-bridge - Run Keyword If '%{HOST_TYPE}' == 'ESXi' Set Environment Variable BRIDGE_NETWORK %{VCH-NAME}-bridge - -Set Test VCH Name - ${name}= Evaluate 'VCH-%{DRONE_BUILD_NUMBER}-' + str(random.randint(1000,9999)) modules=random - Set Environment Variable VCH-NAME ${name} - -Set List Of Env Variables - [Arguments] ${vars} - @{vars}= Split String ${vars} - :FOR ${var} IN @{vars} - \ ${varname} ${varval}= Split String ${var} = - \ Set Environment Variable ${varname} ${varval} - -Parse Environment Variables - [Arguments] ${line} - # If using the old logging format - ${status}= Run Keyword And Return Status Should Contain ${line} mINFO - ${logdeco} ${vars}= Run Keyword If ${status} Split String ${line} ${SPACE} 1 - Run Keyword If ${status} Set List Of Env Variables ${vars} - Return From Keyword If ${status} - - # Split the log log into pieces, discarding the initial log decoration, and assign to env vars - ${logmon} ${logday} ${logyear} ${logtime} ${loglevel} ${vars}= Split String ${line} max_split=5 - Set List Of Env Variables ${vars} - -Get Docker Params - # Get VCH docker params e.g. "-H 192.168.218.181:2376 --tls" - [Arguments] ${output} ${certs} - @{output}= Split To Lines ${output} - :FOR ${item} IN @{output} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} DOCKER_HOST= - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} - - # Ensure we start from a clean slate with docker env vars - Remove Environment Variable DOCKER_HOST DOCKER_TLS_VERIFY DOCKER_CERT_PATH CURL_CA_BUNDLE COMPOSE_PARAMS COMPOSE_TLS_VERSION - - Parse Environment Variables ${line} - - ${dockerHost}= Get Environment Variable DOCKER_HOST - - @{hostParts}= Split String ${dockerHost} : - ${ip}= Strip String @{hostParts}[0] - ${port}= Strip String @{hostParts}[1] - Set Environment Variable VCH-IP ${ip} - Set Environment Variable VCH-PORT ${port} - - :FOR ${index} ${item} IN ENUMERATE @{output} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} http - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} - \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} Published ports can be reached at - \ ${idx} = Evaluate ${index} + 1 - \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${ext-ip} @{output}[${idx}] - - ${rest} ${ext-ip} = Split String From Right ${ext-ip} ${SPACE} 1 - ${ext-ip} = Strip String ${ext-ip} - Set Environment Variable EXT-IP ${ext-ip} - - ${rest} ${vic-admin}= Split String From Right ${line} ${SPACE} 1 - Set Environment Variable VIC-ADMIN ${vic-admin} - - Run Keyword If ${port} == 2376 Set Environment Variable VCH-PARAMS -H ${dockerHost} --tls - Run Keyword If ${port} == 2375 Set Environment Variable VCH-PARAMS -H ${dockerHost} - - ### Add environment variables for Compose and TLS - - # Check if tls is enable from vic-machine's output and not trust ${certs} which some tests bypasses - ${tls_enabled}= Get Environment Variable DOCKER_TLS_VERIFY ${false} - - ### Compose case for no-tlsverify - - # Set environment variables if certs not used to create the VCH. This is NOT the recommended - # approach to running compose. There will be security warnings in the logs and some compose - # operations may not work properly because certs == false currently means we install with - # --no-tlsverify. Add CURL_CA_BUNDLE for a workaround in compose tests. If we change - # certs == false to install with --no-tls, then we need to change this again. - Run Keyword If ${tls_enabled} == ${false} Set Environment Variable CURL_CA_BUNDLE ${EMPTY} - - # Get around quirk in compose if no-tlsverify, then CURL_CA_BUNDLE must exist and compose called with --tls - Run Keyword If ${tls_enabled} == ${false} Set Environment Variable COMPOSE-PARAMS -H ${dockerHost} --tls - - ### Compose case for tlsverify (assumes DOCKER_TLS_VERIFY also set) - - Run Keyword If ${tls_enabled} == ${true} Set Environment Variable COMPOSE_TLS_VERSION TLSv1_2 - Run Keyword If ${tls_enabled} == ${true} Set Environment Variable COMPOSE-PARAMS -H ${dockerHost} - -Install VIC Appliance To Test Server - [Arguments] ${vic-machine}=bin/vic-machine-linux ${appliance-iso}=bin/appliance.iso ${bootstrap-iso}=bin/bootstrap.iso ${certs}=${true} ${vol}=default ${cleanup}=${true} - Set Test Environment Variables - # disable firewall - Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.esxcli network firewall set -e false - # Attempt to cleanup old/canceled tests - Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Dangling VMs On Test Server - Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Datastore On Test Server - Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Dangling Networks On Test Server - Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Dangling vSwitches On Test Server - Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Dangling Containers On Test Server - - # Install the VCH now - Log To Console \nInstalling VCH to test server... - ${output}= Run VIC Machine Command ${vic-machine} ${appliance-iso} ${bootstrap-iso} ${certs} ${vol} - Log ${output} - Should Contain ${output} Installer completed successfully - Get Docker Params ${output} ${certs} - Log To Console Installer completed successfully: %{VCH-NAME}... - -Run VIC Machine Command - [Tags] secret - [Arguments] ${vic-machine} ${appliance-iso} ${bootstrap-iso} ${certs} ${vol} - ${output}= Run Keyword If ${certs} Run ${vic-machine} create --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --volume-store=%{TEST_DATASTORE}/test:${vol} ${vicmachinetls} - Run Keyword If ${certs} Should Contain ${output} Installer completed successfully - Return From Keyword If ${certs} ${output} - - ${output}= Run Keyword Unless ${certs} Run ${vic-machine} create --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --volume-store=%{TEST_DATASTORE}/test:${vol} --no-tlsverify - Run Keyword Unless ${certs} Should Contain ${output} Installer completed successfully - [Return] ${output} - -Run Secret VIC Machine Delete Command - [Tags] secret - [Arguments] ${vch-name} - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux delete --name=${vch-name} --target=%{TEST_URL}%{TEST_DATACENTER} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} - [Return] ${rc} ${output} - -Run Secret VIC Machine Inspect Command - [Tags] secret - [Arguments] ${name} - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux inspect --name=${name} --target=%{TEST_URL}%{TEST_DATACENTER} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --thumbprint=%{TEST_THUMBPRINT} - [Return] ${rc} ${output} - -Run VIC Machine Delete Command - ${rc} ${output}= Run Secret VIC Machine Delete Command %{VCH-NAME} - Wait Until Keyword Succeeds 6x 5s Check Delete Success %{VCH-NAME} - Should Be Equal As Integers ${rc} 0 - Should Contain ${output} Completed successfully - ${output}= Run rm -rf %{VCH-NAME} - [Return] ${output} - -Run VIC Machine Inspect Command - ${rc} ${output}= Run Secret VIC Machine Inspect Command %{VCH-NAME} - Get Docker Params ${output} ${true} - -Gather Logs From Test Server - [Tags] secret - Run Keyword And Continue On Failure Run zip %{VCH-NAME}-certs -r %{VCH-NAME} - ${out}= Run curl -k -D vic-admin-cookies -Fusername=%{TEST_USERNAME} -Fpassword=%{TEST_PASSWORD} %{VIC-ADMIN}/authentication - Log ${out} - ${out}= Run curl -k -b vic-admin-cookies %{VIC-ADMIN}/container-logs.zip -o ${SUITE NAME}-%{VCH-NAME}-container-logs.zip - Log ${out} - Remove File vic-admin-cookies - ${out}= Run govc datastore.download %{VCH-NAME}/vmware.log %{VCH-NAME}-vmware.log - Should Contain ${out} OK - Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc logs -log=vmkernel -n=10000 > vmkernel.log - -Check For The Proper Log Files - [Arguments] ${container} - # Ensure container logs are correctly being gathered for debugging purposes - ${rc} ${output}= Run And Return Rc and Output curl -sk %{VIC-ADMIN}/authentication -XPOST -F username=%{TEST_USERNAME} -F password=%{TEST_PASSWORD} -D /tmp/cookies-%{VCH-NAME} - Should Be Equal As Integers ${rc} 0 - ${rc} ${output}= Run And Return Rc and Output curl -sk %{VIC-ADMIN}/container-logs.tar.gz -b /tmp/cookies-%{VCH-NAME} | tar tvzf - - Should Be Equal As Integers ${rc} 0 - Log ${output} - Should Contain ${output} ${container}/output.log - Should Contain ${output} ${container}/vmware.log - Should Contain ${output} ${container}/tether.debug - -Scrape Logs For the Password - [Tags] secret - ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/authentication -XPOST -F username=%{TEST_USERNAME} -F password=%{TEST_PASSWORD} -D /tmp/cookies-%{VCH-NAME} - Should Be Equal As Integers ${rc} 0 - - ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/logs/port-layer.log -b /tmp/cookies-%{VCH-NAME} | grep -q "%{TEST_PASSWORD}" - Should Be Equal As Integers ${rc} 1 - ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/logs/init.log -b /tmp/cookies-%{VCH-NAME} | grep -q "%{TEST_PASSWORD}" - Should Be Equal As Integers ${rc} 1 - ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/logs/docker-personality.log -b /tmp/cookies-%{VCH-NAME} | grep -q "%{TEST_PASSWORD}" - Should Be Equal As Integers ${rc} 1 - ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/logs/vicadmin.log -b /tmp/cookies-%{VCH-NAME} | grep -q "%{TEST_PASSWORD}" - Should Be Equal As Integers ${rc} 1 - - Remove File /tmp/cookies-%{VCH-NAME} - -Cleanup VIC Appliance On Test Server - Log To Console Gathering logs from the test server %{VCH-NAME} - Gather Logs From Test Server - Log To Console Deleting the VCH appliance %{VCH-NAME} - ${output}= Run VIC Machine Delete Command - Run Keyword And Ignore Error Cleanup VCH Bridge Network %{VCH-NAME} - [Return] ${output} - -Cleanup VCH Bridge Network - [Arguments] ${name} - Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.remove ${name}-bridge - ${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.info - Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Not Contain ${out} ${name}-bridge - -Cleanup Datastore On Test Server - ${out}= Run govc datastore.ls - ${items}= Split To Lines ${out} - :FOR ${item} IN @{items} - \ ${build}= Split String ${item} - - \ # Skip any item that is not associated with integration tests - \ Continue For Loop If '@{build}[0]' != 'VCH' - \ # Skip any item that is still running - \ ${state}= Get State Of Drone Build @{build}[1] - \ Continue For Loop If '${state}' == 'running' - \ Log To Console Removing the following item from datastore: ${item} - \ ${out}= Run govc datastore.rm ${item} - \ Wait Until Keyword Succeeds 6x 5s Check Delete Success ${item} - -Cleanup Dangling VMs On Test Server - ${out}= Run govc ls vm - ${vms}= Split To Lines ${out} - :FOR ${vm} IN @{vms} - \ ${vm}= Fetch From Right ${vm} / - \ ${build}= Split String ${vm} - - \ # Skip any VM that is not associated with integration tests - \ Continue For Loop If '@{build}[0]' != 'VCH' - \ # Skip any VM that is still running - \ ${state}= Get State Of Drone Build @{build}[1] - \ Continue For Loop If '${state}' == 'running' - \ ${uuid}= Run govc vm.info -json\=true ${vm} | jq -r '.VirtualMachines[0].Config.Uuid' - \ Log To Console Destroying dangling VCH: ${vm} - \ ${rc} ${output}= Run Secret VIC Machine Delete Command ${vm} - \ Wait Until Keyword Succeeds 6x 5s Check Delete Success ${vm} - -Cleanup Dangling Networks On Test Server - ${out}= Run govc ls network - ${nets}= Split To Lines ${out} - :FOR ${net} IN @{nets} - \ ${net}= Fetch From Right ${net} / - \ ${build}= Split String ${net} - - \ # Skip any Network that is not associated with integration tests - \ Continue For Loop If '@{build}[0]' != 'VCH' - \ # Skip any Network that is still running - \ ${state}= Get State Of Drone Build @{build}[1] - \ Continue For Loop If '${state}' == 'running' - \ ${uuid}= Run govc host.portgroup.remove ${net} - -Cleanup Dangling vSwitches On Test Server - ${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.vswitch.info | grep VCH - ${nets}= Split To Lines ${out} - :FOR ${net} IN @{nets} - \ ${net}= Fetch From Right ${net} ${SPACE} - \ ${build}= Split String ${net} - - \ # Skip any vSwitch that is not associated with integration tests - \ Continue For Loop If '@{build}[0]' != 'VCH' - \ # Skip any vSwitch that is still running - \ ${state}= Get State Of Drone Build @{build}[1] - \ Continue For Loop If '${state}' == 'running' - \ ${uuid}= Run govc host.vswitch.remove ${net} - -Get Scratch Disk From VM Info - [Arguments] ${vm} - ${disks}= Run govc vm.info -json ${vm} | jq -r '.VirtualMachines[].Layout.Disk[].DiskFile[]' - ${disks}= Split To Lines ${disks} - :FOR ${disk} IN @{disks} - \ ${disk}= Fetch From Right ${disk} ${SPACE} - \ ${status}= Run Keyword And Return Status Should Contain ${disk} scratch.vmdk - \ Return From Keyword If ${status} ${disk} - -Cleanup Dangling Containers On Test Server - ${vms}= Run govc ls vm - ${vms}= Split To Lines ${vms} - :FOR ${vm} IN @{vms} - \ # Ignore VCH's, we only care about containers at this point - \ ${status}= Run Keyword And Return Status Should Contain ${vm} VCH - \ Continue For Loop If ${status} - \ ${disk}= Get Scratch Disk From VM Info ${vm} - \ ${vch}= Fetch From Left ${disk} / - \ ${vch}= Split String ${vch} - - \ # Skip any VM that is not associated with integration tests - \ Continue For Loop If '@{vch}[0]' != 'VCH' - \ ${state}= Get State Of Drone Build @{vch}[1] - \ # Skip any VM that is still running - \ Continue For Loop If '${state}' == 'running' - \ # Destroy the VM and remove it from datastore because it is a dangling container - \ Log To Console Cleaning up dangling container: ${vm} - \ ${out}= Run govc vm.destroy ${vm} - \ ${name}= Fetch From Right ${vm} / - \ ${out}= Run govc datastore.rm ${name} - \ Wait Until Keyword Succeeds 6x 5s Check Delete Success ${name} - -# VCH upgrade helpers -Install VIC with version to Test Server - [Arguments] ${version}=7315 ${insecureregistry}= - Log To Console \nDownloading vic ${version} from bintray... - ${rc} ${output}= Run And Return Rc And Output wget https://bintray.com/vmware/vic-repo/download_file?file_path=vic_${version}.tar.gz -O vic.tar.gz - ${rc} ${output}= Run And Return Rc And Output tar zxvf vic.tar.gz - Set Environment Variable TEST_TIMEOUT 20m0s - Install VIC Appliance To Test Server vic-machine=./vic/vic-machine-linux appliance-iso=./vic/appliance.iso bootstrap-iso=./vic/bootstrap.iso certs=${false} vol=default ${insecureregistry} - Set Environment Variable VIC-ADMIN %{VCH-IP}:2378 - Set Environment Variable INITIAL-VERSION ${version} - -Clean up VIC Appliance And Local Binary - Cleanup VIC Appliance On Test Server - Run rm -rf vic.tar.gz vic - -Upgrade - Log To Console \nUpgrading VCH... - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux upgrade --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} - Should Contain ${output} Completed successfully - Should Not Contain ${output} Rolling back upgrade - Should Be Equal As Integers ${rc} 0 - -Check Upgraded Version - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux version - @{vers}= Split String ${output} - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux inspect --name=%{VCH-NAME} --target=%{TEST_URL} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --compute-resource=%{TEST_RESOURCE} - Should Contain ${output} Completed successfully - Should Contain ${output} @{vers}[2] - Should Not Contain ${output} %{INITIAL-VERSION} - Should Be Equal As Integers ${rc} 0 - Log ${output} - Get Docker Params ${output} ${true} - -Check Original Version - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux version - @{vers}= Split String ${output} - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux inspect --name=%{VCH-NAME} --target=%{TEST_URL} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --compute-resource=%{TEST_RESOURCE} - Should Contain ${output} Completed successfully - Should Contain ${output} @{vers}[2] - Should Be Equal As Integers ${rc} 0 - Log ${output} - Get Docker Params ${output} ${true} - -Rollback - Log To Console \nTesting rollback... - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux upgrade --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --rollback - Should Contain ${output} Completed successfully - Should Be Equal As Integers ${rc} 0 - -Enable VCH SSH - [Arguments] ${vic-machine}=bin/vic-machine-linux ${rootpw}=%{TEST_PASSWORD} ${target}=%{TEST_URL} ${password}=%{TEST_PASSWORD} ${thumbprint}=%{TEST_THUMBPRINT} ${name}=%{VCH-NAME} ${user}=%{TEST_USERNAME} ${resource}=%{TEST_RESOURCE} - Log To Console \nEnable SSH on vch... - ${rc} ${output}= Run And Return Rc And Output ${vic-machine} debug --rootpw ${rootpw} --target ${target} --password ${password} --thumbprint ${thumbprint} --name ${name} --user ${user} --compute-resource ${resource} --enable-ssh - Should Be Equal As Integers ${rc} 0 - Should Contain ${output} Completed successfully +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource contains all keywords related to creating, deleting, maintaining VCHs + +*** Keywords *** +Set Test Environment Variables + # Finish setting up environment variables + ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set DRONE_BUILD_NUMBER + Run Keyword If '${status}' == 'FAIL' Set Environment Variable DRONE_BUILD_NUMBER 0 + ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set BRIDGE_NETWORK + Run Keyword If '${status}' == 'FAIL' Set Environment Variable BRIDGE_NETWORK network + ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set PUBLIC_NETWORK + Run Keyword If '${status}' == 'FAIL' Set Environment Variable PUBLIC_NETWORK 'VM Network' + ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set TEST_DATACENTER + Run Keyword If '${status}' == 'FAIL' Set Environment Variable TEST_DATACENTER ${SPACE} + + @{URLs}= Split String %{TEST_URL_ARRAY} + ${len}= Get Length ${URLs} + ${IDX}= Evaluate %{DRONE_BUILD_NUMBER} \% ${len} + + Set Environment Variable TEST_URL @{URLs}[${IDX}] + Set Environment Variable GOVC_URL %{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL} + # TODO: need an integration/vic-test image update to include the about.cert command + #${rc} ${thumbprint}= Run And Return Rc And Output govc about.cert -k | jq -r .ThumbprintSHA1 + ${rc} ${thumbprint}= Run And Return Rc And Output openssl s_client -connect $(govc env -x GOVC_URL_HOST):443 /dev/null | openssl x509 -fingerprint -noout | cut -d= -f2 + Should Be Equal As Integers ${rc} 0 + Set Environment Variable TEST_THUMBPRINT ${thumbprint} + Log To Console \nTEST_URL=%{TEST_URL} + + ${host}= Run govc ls host + ${status} ${message}= Run Keyword And Ignore Error Environment Variable Should Be Set TEST_RESOURCE + Run Keyword If '${status}' == 'FAIL' Set Environment Variable TEST_RESOURCE ${host}/Resources + Set Environment Variable GOVC_RESOURCE_POOL %{TEST_RESOURCE} + ${noQuotes}= Strip String %{TEST_DATASTORE} characters=" + Set Environment Variable GOVC_DATASTORE ${noQuotes} + + ${about}= Run govc about + ${status}= Run Keyword And Return Status Should Contain ${about} VMware ESXi + Run Keyword If ${status} Set Environment Variable HOST_TYPE ESXi + Run Keyword Unless ${status} Set Environment Variable HOST_TYPE VC + + ${about}= Run govc datastore.info %{TEST_DATASTORE} | grep 'Type' + ${status}= Run Keyword And Return Status Should Contain ${about} vsan + Run Keyword If ${status} Set Environment Variable DATASTORE_TYPE VSAN + Run Keyword Unless ${status} Set Environment Variable DATASTORE_TYPE Non_VSAN + + # set the TLS config options suitable for vic-machine in this env + ${domain}= Get Environment Variable DOMAIN '' + Run Keyword If $domain == '' Set Suite Variable ${vicmachinetls} --no-tlsverify + Run Keyword If $domain != '' Set Suite Variable ${vicmachinetls} --tls-cname=*.${domain} + + Set Test VCH Name + # Set a unique bridge network for each VCH that has a random VLAN ID + ${vlan}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Evaluate str(random.randint(1, 4093)) modules=random + ${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.add -vlan=${vlan} -vswitch vSwitchLAN %{VCH-NAME}-bridge + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Set Environment Variable BRIDGE_NETWORK %{VCH-NAME}-bridge + +Set Test VCH Name + ${name}= Evaluate 'VCH-%{DRONE_BUILD_NUMBER}-' + str(random.randint(1000,9999)) modules=random + Set Environment Variable VCH-NAME ${name} + +Set List Of Env Variables + [Arguments] ${vars} + @{vars}= Split String ${vars} + :FOR ${var} IN @{vars} + \ ${varname} ${varval}= Split String ${var} = + \ Set Environment Variable ${varname} ${varval} + +Parse Environment Variables + [Arguments] ${line} + # If using the old logging format + ${status}= Run Keyword And Return Status Should Contain ${line} mINFO + ${logdeco} ${vars}= Run Keyword If ${status} Split String ${line} ${SPACE} 1 + Run Keyword If ${status} Set List Of Env Variables ${vars} + Return From Keyword If ${status} + + # Split the log log into pieces, discarding the initial log decoration, and assign to env vars + ${logmon} ${logday} ${logyear} ${logtime} ${loglevel} ${vars}= Split String ${line} max_split=5 + Set List Of Env Variables ${vars} + +Get Docker Params + # Get VCH docker params e.g. "-H 192.168.218.181:2376 --tls" + [Arguments] ${output} ${certs} + @{output}= Split To Lines ${output} + :FOR ${item} IN @{output} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} DOCKER_HOST= + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} + + # Ensure we start from a clean slate with docker env vars + Remove Environment Variable DOCKER_HOST DOCKER_TLS_VERIFY DOCKER_CERT_PATH CURL_CA_BUNDLE COMPOSE_PARAMS COMPOSE_TLS_VERSION + + Parse Environment Variables ${line} + + ${dockerHost}= Get Environment Variable DOCKER_HOST + + @{hostParts}= Split String ${dockerHost} : + ${ip}= Strip String @{hostParts}[0] + ${port}= Strip String @{hostParts}[1] + Set Environment Variable VCH-IP ${ip} + Set Environment Variable VCH-PORT ${port} + + :FOR ${index} ${item} IN ENUMERATE @{output} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} http + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${line} ${item} + \ ${status} ${message}= Run Keyword And Ignore Error Should Contain ${item} Published ports can be reached at + \ ${idx} = Evaluate ${index} + 1 + \ Run Keyword If '${status}' == 'PASS' Set Suite Variable ${ext-ip} @{output}[${idx}] + + ${rest} ${ext-ip} = Split String From Right ${ext-ip} ${SPACE} 1 + ${ext-ip} = Strip String ${ext-ip} + Set Environment Variable EXT-IP ${ext-ip} + + ${rest} ${vic-admin}= Split String From Right ${line} ${SPACE} 1 + Set Environment Variable VIC-ADMIN ${vic-admin} + + Run Keyword If ${port} == 2376 Set Environment Variable VCH-PARAMS -H ${dockerHost} --tls + Run Keyword If ${port} == 2375 Set Environment Variable VCH-PARAMS -H ${dockerHost} + + ### Add environment variables for Compose and TLS + + # Check if tls is enable from vic-machine's output and not trust ${certs} which some tests bypasses + ${tls_enabled}= Get Environment Variable DOCKER_TLS_VERIFY ${false} + + ### Compose case for no-tlsverify + + # Set environment variables if certs not used to create the VCH. This is NOT the recommended + # approach to running compose. There will be security warnings in the logs and some compose + # operations may not work properly because certs == false currently means we install with + # --no-tlsverify. Add CURL_CA_BUNDLE for a workaround in compose tests. If we change + # certs == false to install with --no-tls, then we need to change this again. + Run Keyword If ${tls_enabled} == ${false} Set Environment Variable CURL_CA_BUNDLE ${EMPTY} + + # Get around quirk in compose if no-tlsverify, then CURL_CA_BUNDLE must exist and compose called with --tls + Run Keyword If ${tls_enabled} == ${false} Set Environment Variable COMPOSE-PARAMS -H ${dockerHost} --tls + + ### Compose case for tlsverify (assumes DOCKER_TLS_VERIFY also set) + + Run Keyword If ${tls_enabled} == ${true} Set Environment Variable COMPOSE_TLS_VERSION TLSv1_2 + Run Keyword If ${tls_enabled} == ${true} Set Environment Variable COMPOSE-PARAMS -H ${dockerHost} + +Install VIC Appliance To Test Server + [Arguments] ${vic-machine}=bin/vic-machine-linux ${appliance-iso}=bin/appliance.iso ${bootstrap-iso}=bin/bootstrap.iso ${certs}=${true} ${vol}=default ${cleanup}=${true} + Set Test Environment Variables + # disable firewall + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.esxcli network firewall set -e false + # Attempt to cleanup old/canceled tests + Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Dangling VMs On Test Server + Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Datastore On Test Server + Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Dangling Networks On Test Server + Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Dangling vSwitches On Test Server + Run Keyword If ${cleanup} Run Keyword And Ignore Error Cleanup Dangling Containers On Test Server + + # Install the VCH now + Log To Console \nInstalling VCH to test server... + ${output}= Run VIC Machine Command ${vic-machine} ${appliance-iso} ${bootstrap-iso} ${certs} ${vol} + Log ${output} + Should Contain ${output} Installer completed successfully + Get Docker Params ${output} ${certs} + Log To Console Installer completed successfully: %{VCH-NAME}... + +Run VIC Machine Command + [Tags] secret + [Arguments] ${vic-machine} ${appliance-iso} ${bootstrap-iso} ${certs} ${vol} + ${output}= Run Keyword If ${certs} Run ${vic-machine} create --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --volume-store=%{TEST_DATASTORE}/test:${vol} ${vicmachinetls} + Run Keyword If ${certs} Should Contain ${output} Installer completed successfully + Return From Keyword If ${certs} ${output} + + ${output}= Run Keyword Unless ${certs} Run ${vic-machine} create --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL}%{TEST_DATACENTER} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --image-store=%{TEST_DATASTORE} --appliance-iso=${appliance-iso} --bootstrap-iso=${bootstrap-iso} --password=%{TEST_PASSWORD} --force=true --bridge-network=%{BRIDGE_NETWORK} --public-network=%{PUBLIC_NETWORK} --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --volume-store=%{TEST_DATASTORE}/test:${vol} --no-tlsverify + Run Keyword Unless ${certs} Should Contain ${output} Installer completed successfully + [Return] ${output} + +Run Secret VIC Machine Delete Command + [Tags] secret + [Arguments] ${vch-name} + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux delete --name=${vch-name} --target=%{TEST_URL}%{TEST_DATACENTER} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} + [Return] ${rc} ${output} + +Run Secret VIC Machine Inspect Command + [Tags] secret + [Arguments] ${name} + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux inspect --name=${name} --target=%{TEST_URL}%{TEST_DATACENTER} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --thumbprint=%{TEST_THUMBPRINT} + [Return] ${rc} ${output} + +Run VIC Machine Delete Command + ${rc} ${output}= Run Secret VIC Machine Delete Command %{VCH-NAME} + Wait Until Keyword Succeeds 6x 5s Check Delete Success %{VCH-NAME} + Should Be Equal As Integers ${rc} 0 + Should Contain ${output} Completed successfully + ${output}= Run rm -rf %{VCH-NAME} + [Return] ${output} + +Run VIC Machine Inspect Command + ${rc} ${output}= Run Secret VIC Machine Inspect Command %{VCH-NAME} + Get Docker Params ${output} ${true} + +Gather Logs From Test Server + [Tags] secret + Run Keyword And Continue On Failure Run zip %{VCH-NAME}-certs -r %{VCH-NAME} + ${out}= Run curl -k -D vic-admin-cookies -Fusername=%{TEST_USERNAME} -Fpassword=%{TEST_PASSWORD} %{VIC-ADMIN}/authentication + Log ${out} + ${out}= Run curl -k -b vic-admin-cookies %{VIC-ADMIN}/container-logs.zip -o ${SUITE NAME}-%{VCH-NAME}-container-logs.zip + Log ${out} + Remove File vic-admin-cookies + ${out}= Run govc datastore.download %{VCH-NAME}/vmware.log %{VCH-NAME}-vmware.log + Should Contain ${out} OK + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc logs -log=vmkernel -n=10000 > vmkernel.log + +Check For The Proper Log Files + [Arguments] ${container} + # Ensure container logs are correctly being gathered for debugging purposes + ${rc} ${output}= Run And Return Rc and Output curl -sk %{VIC-ADMIN}/authentication -XPOST -F username=%{TEST_USERNAME} -F password=%{TEST_PASSWORD} -D /tmp/cookies-%{VCH-NAME} + Should Be Equal As Integers ${rc} 0 + ${rc} ${output}= Run And Return Rc and Output curl -sk %{VIC-ADMIN}/container-logs.tar.gz -b /tmp/cookies-%{VCH-NAME} | tar tvzf - + Should Be Equal As Integers ${rc} 0 + Log ${output} + Should Contain ${output} ${container}/output.log + Should Contain ${output} ${container}/vmware.log + Should Contain ${output} ${container}/tether.debug + +Scrape Logs For the Password + [Tags] secret + ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/authentication -XPOST -F username=%{TEST_USERNAME} -F password=%{TEST_PASSWORD} -D /tmp/cookies-%{VCH-NAME} + Should Be Equal As Integers ${rc} 0 + + ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/logs/port-layer.log -b /tmp/cookies-%{VCH-NAME} | grep -q "%{TEST_PASSWORD}" + Should Be Equal As Integers ${rc} 1 + ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/logs/init.log -b /tmp/cookies-%{VCH-NAME} | grep -q "%{TEST_PASSWORD}" + Should Be Equal As Integers ${rc} 1 + ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/logs/docker-personality.log -b /tmp/cookies-%{VCH-NAME} | grep -q "%{TEST_PASSWORD}" + Should Be Equal As Integers ${rc} 1 + ${rc}= Run And Return Rc curl -sk %{VIC-ADMIN}/logs/vicadmin.log -b /tmp/cookies-%{VCH-NAME} | grep -q "%{TEST_PASSWORD}" + Should Be Equal As Integers ${rc} 1 + + Remove File /tmp/cookies-%{VCH-NAME} + +Cleanup VIC Appliance On Test Server + Log To Console Gathering logs from the test server %{VCH-NAME} + Gather Logs From Test Server + Log To Console Deleting the VCH appliance %{VCH-NAME} + ${output}= Run VIC Machine Delete Command + Run Keyword And Ignore Error Cleanup VCH Bridge Network %{VCH-NAME} + [Return] ${output} + +Cleanup VCH Bridge Network + [Arguments] ${name} + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.remove ${name}-bridge + ${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.info + Run Keyword If '%{HOST_TYPE}' == 'ESXi' Should Not Contain ${out} ${name}-bridge + +Cleanup Datastore On Test Server + ${out}= Run govc datastore.ls + ${items}= Split To Lines ${out} + :FOR ${item} IN @{items} + \ ${build}= Split String ${item} - + \ # Skip any item that is not associated with integration tests + \ Continue For Loop If '@{build}[0]' != 'VCH' + \ # Skip any item that is still running + \ ${state}= Get State Of Drone Build @{build}[1] + \ Continue For Loop If '${state}' == 'running' + \ Log To Console Removing the following item from datastore: ${item} + \ ${out}= Run govc datastore.rm ${item} + \ Wait Until Keyword Succeeds 6x 5s Check Delete Success ${item} + +Cleanup Dangling VMs On Test Server + ${out}= Run govc ls vm + ${vms}= Split To Lines ${out} + :FOR ${vm} IN @{vms} + \ ${vm}= Fetch From Right ${vm} / + \ ${build}= Split String ${vm} - + \ # Skip any VM that is not associated with integration tests + \ Continue For Loop If '@{build}[0]' != 'VCH' + \ # Skip any VM that is still running + \ ${state}= Get State Of Drone Build @{build}[1] + \ Continue For Loop If '${state}' == 'running' + \ ${uuid}= Run govc vm.info -json\=true ${vm} | jq -r '.VirtualMachines[0].Config.Uuid' + \ Log To Console Destroying dangling VCH: ${vm} + \ ${rc} ${output}= Run Secret VIC Machine Delete Command ${vm} + \ Wait Until Keyword Succeeds 6x 5s Check Delete Success ${vm} + +Cleanup Dangling Networks On Test Server + ${out}= Run govc ls network + ${nets}= Split To Lines ${out} + :FOR ${net} IN @{nets} + \ ${net}= Fetch From Right ${net} / + \ ${build}= Split String ${net} - + \ # Skip any Network that is not associated with integration tests + \ Continue For Loop If '@{build}[0]' != 'VCH' + \ # Skip any Network that is still running + \ ${state}= Get State Of Drone Build @{build}[1] + \ Continue For Loop If '${state}' == 'running' + \ ${uuid}= Run govc host.portgroup.remove ${net} + +Cleanup Dangling vSwitches On Test Server + ${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.vswitch.info | grep VCH + ${nets}= Split To Lines ${out} + :FOR ${net} IN @{nets} + \ ${net}= Fetch From Right ${net} ${SPACE} + \ ${build}= Split String ${net} - + \ # Skip any vSwitch that is not associated with integration tests + \ Continue For Loop If '@{build}[0]' != 'VCH' + \ # Skip any vSwitch that is still running + \ ${state}= Get State Of Drone Build @{build}[1] + \ Continue For Loop If '${state}' == 'running' + \ ${uuid}= Run govc host.vswitch.remove ${net} + +Get Scratch Disk From VM Info + [Arguments] ${vm} + ${disks}= Run govc vm.info -json ${vm} | jq -r '.VirtualMachines[].Layout.Disk[].DiskFile[]' + ${disks}= Split To Lines ${disks} + :FOR ${disk} IN @{disks} + \ ${disk}= Fetch From Right ${disk} ${SPACE} + \ ${status}= Run Keyword And Return Status Should Contain ${disk} scratch.vmdk + \ Return From Keyword If ${status} ${disk} + +Cleanup Dangling Containers On Test Server + ${vms}= Run govc ls vm + ${vms}= Split To Lines ${vms} + :FOR ${vm} IN @{vms} + \ # Ignore VCH's, we only care about containers at this point + \ ${status}= Run Keyword And Return Status Should Contain ${vm} VCH + \ Continue For Loop If ${status} + \ ${disk}= Get Scratch Disk From VM Info ${vm} + \ ${vch}= Fetch From Left ${disk} / + \ ${vch}= Split String ${vch} - + \ # Skip any VM that is not associated with integration tests + \ Continue For Loop If '@{vch}[0]' != 'VCH' + \ ${state}= Get State Of Drone Build @{vch}[1] + \ # Skip any VM that is still running + \ Continue For Loop If '${state}' == 'running' + \ # Destroy the VM and remove it from datastore because it is a dangling container + \ Log To Console Cleaning up dangling container: ${vm} + \ ${out}= Run govc vm.destroy ${vm} + \ ${name}= Fetch From Right ${vm} / + \ ${out}= Run govc datastore.rm ${name} + \ Wait Until Keyword Succeeds 6x 5s Check Delete Success ${name} + +# VCH upgrade helpers +Install VIC with version to Test Server + [Arguments] ${version}=7315 ${insecureregistry}= + Log To Console \nDownloading vic ${version} from bintray... + ${rc} ${output}= Run And Return Rc And Output wget https://bintray.com/vmware/vic-repo/download_file?file_path=vic_${version}.tar.gz -O vic.tar.gz + ${rc} ${output}= Run And Return Rc And Output tar zxvf vic.tar.gz + Set Environment Variable TEST_TIMEOUT 20m0s + Install VIC Appliance To Test Server vic-machine=./vic/vic-machine-linux appliance-iso=./vic/appliance.iso bootstrap-iso=./vic/bootstrap.iso certs=${false} vol=default ${insecureregistry} + Set Environment Variable VIC-ADMIN %{VCH-IP}:2378 + Set Environment Variable INITIAL-VERSION ${version} + +Clean up VIC Appliance And Local Binary + Cleanup VIC Appliance On Test Server + Run rm -rf vic.tar.gz vic + +Upgrade + Log To Console \nUpgrading VCH... + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux upgrade --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} + Should Contain ${output} Completed successfully + Should Not Contain ${output} Rolling back upgrade + Should Be Equal As Integers ${rc} 0 + +Check Upgraded Version + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux version + @{vers}= Split String ${output} + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux inspect --name=%{VCH-NAME} --target=%{TEST_URL} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --compute-resource=%{TEST_RESOURCE} + Should Contain ${output} Completed successfully + Should Contain ${output} @{vers}[2] + Should Not Contain ${output} %{INITIAL-VERSION} + Should Be Equal As Integers ${rc} 0 + Log ${output} + Get Docker Params ${output} ${true} + +Check Original Version + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux version + @{vers}= Split String ${output} + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux inspect --name=%{VCH-NAME} --target=%{TEST_URL} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --compute-resource=%{TEST_RESOURCE} + Should Contain ${output} Completed successfully + Should Contain ${output} @{vers}[2] + Should Be Equal As Integers ${rc} 0 + Log ${output} + Get Docker Params ${output} ${true} + +Rollback + Log To Console \nTesting rollback... + ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux upgrade --debug 1 --name=%{VCH-NAME} --target=%{TEST_URL} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --force=true --compute-resource=%{TEST_RESOURCE} --timeout %{TEST_TIMEOUT} --rollback + Should Contain ${output} Completed successfully + Should Be Equal As Integers ${rc} 0 + +Enable VCH SSH + [Arguments] ${vic-machine}=bin/vic-machine-linux ${rootpw}=%{TEST_PASSWORD} ${target}=%{TEST_URL} ${password}=%{TEST_PASSWORD} ${thumbprint}=%{TEST_THUMBPRINT} ${name}=%{VCH-NAME} ${user}=%{TEST_USERNAME} ${resource}=%{TEST_RESOURCE} + Log To Console \nEnable SSH on vch... + ${rc} ${output}= Run And Return Rc And Output ${vic-machine} debug --rootpw ${rootpw} --target ${target} --password ${password} --thumbprint ${thumbprint} --name ${name} --user ${user} --compute-resource ${resource} --enable-ssh + Should Be Equal As Integers ${rc} 0 + Should Contain ${output} Completed successfully diff --git a/tests/resources/Vsphere-Util.robot b/tests/resources/Vsphere-Util.robot index 03d9ef2bd..ffea25b85 100644 --- a/tests/resources/Vsphere-Util.robot +++ b/tests/resources/Vsphere-Util.robot @@ -1,215 +1,217 @@ -# Copyright Project Harbor Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License - -*** Settings *** -Documentation This resource contains any keywords dealing with operations being performed on a Vsphere instance, mostly govc wrappers - -*** Keywords *** -Power On VM OOB - [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} - ${rc} ${output}= Run And Return Rc And Output GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.power -on "${vm}" - Should Be Equal As Integers ${rc} 0 - Log To Console Waiting for VM to power on ... - Wait Until VM Powers On "${vm}" ${vc_host} ${vc_user} ${vc_password} - -Power Off VM OOB - [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} - ${rc} ${output}= Run And Return Rc And Output GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.power -off "${vm}" - Log To Console ${output} - Should Be Equal As Integers ${rc} 0 - Log To Console Waiting for VM to power off ... - Wait Until VM Powers Off "${vm}" ${vc_host} ${vc_user} ${vc_password} - -Destroy VM OOB - [Arguments] ${vm} - ${rc} ${output}= Run And Return Rc And Output govc vm.destroy "*-${vm}" - Should Be Equal As Integers ${rc} 0 - -Put Host Into Maintenance Mode - ${rc} ${output}= Run And Return Rc And Output govc host.maintenance.enter -host.ip=%{TEST_URL} - Should Contain ${output} entering maintenance mode... OK - -Remove Host From Maintenance Mode - ${rc} ${output}= Run And Return Rc And Output govc host.maintenance.exit -host.ip=%{TEST_URL} - Should Contain ${output} exiting maintenance mode... OK - -Reboot VM - [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} - Log To Console Rebooting ${vm} ... - Power Off VM OOB ${vm} ${vc_host} ${vc_user} ${vc_password} - Power On VM OOB ${vm} ${vc_host} ${vc_user} ${vc_password} - Log To Console ${vm} Powered On - -Reset VM - [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} - ${rc} ${output}= Run And Return Rc And Output GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.power -reset "${vm}" - Log To Console ${output} - Should Be Equal As Integers ${rc} 0 - Log To Console Waiting for VM to reset ... - Wait Until VM Powers On "${vm}" ${vc_host} ${vc_user} ${vc_password} - -Wait Until VM Powers On - [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} - :FOR ${idx} IN RANGE 0 30 - \ ${ret}= Run GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.info ${vm} - \ Set Test Variable ${out} ${ret} - \ ${status}= Run Keyword And Return Status Should Contain ${out} poweredOn - \ Return From Keyword If ${status} - \ Sleep 1 - Fail VM did not power on within 30 seconds - -Wait Until VM Powers Off - [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} - :FOR ${idx} IN RANGE 0 30 - \ ${ret}= Run GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.info ${vm} - \ Set Test Variable ${out} ${ret} - \ ${status}= Run Keyword And Return Status Should Contain ${out} poweredOff - \ Return From Keyword If ${status} - \ Sleep 1 - Fail VM did not power off within 30 seconds - -Wait Until VM Is Destroyed - [Arguments] ${vm} - :FOR ${idx} IN RANGE 0 30 - \ ${ret}= Run govc ls vm/${vm} - \ Set Test Variable ${out} ${ret} - \ ${status}= Run Keyword And Return Status Should Be Empty ${out} - \ Return From Keyword If ${status} - \ Sleep 1 - Fail VM was not destroyed within 30 seconds - -Get VM IP - [Arguments] ${vm} - ${rc} ${out}= Run And Return Rc And Output govc vm.ip ${vm} - Should Be Equal As Integers ${rc} 0 - [Return] ${out} - -Get VM Host Name - [Arguments] ${vm} - ${out}= Run govc vm.info ${vm} - ${out}= Split To Lines ${out} - ${host}= Fetch From Right @{out}[-1] ${SPACE} - [Return] ${host} - -Get VM Info - [Arguments] ${vm} - ${rc} ${out}= Run And Return Rc And Output govc vm.info -r ${vm} - Should Be Equal As Integers ${rc} 0 - [Return] ${out} - -vMotion A VM - [Arguments] ${vm} - ${host}= Get VM Host Name ${vm} - ${status}= Run Keyword And Return Status Should Contain ${host} ${esx1-ip} - Run Keyword If ${status} Run govc vm.migrate -host cls/${esx2-ip} -pool cls/Resources ${vm} - Run Keyword Unless ${status} Run govc vm.migrate -host cls/${esx1-ip} -pool cls/Resources ${vm} - -Create Test Server Snapshot - [Arguments] ${vm} ${snapshot} - Set Environment Variable GOVC_URL %{BUILD_SERVER} - ${rc} ${out}= Run And Return Rc And Output govc snapshot.create -vm ${vm} ${snapshot} - Should Be Equal As Integers ${rc} 0 - Should Be Empty ${out} - Set Environment Variable GOVC_URL %{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL} - -Revert Test Server Snapshot - [Arguments] ${vm} ${snapshot} - Set Environment Variable GOVC_URL %{BUILD_SERVER} - ${rc} ${out}= Run And Return Rc And Output govc snapshot.revert -vm ${vm} ${snapshot} - Should Be Equal As Integers ${rc} 0 - Should Be Empty ${out} - Set Environment Variable GOVC_URL %{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL} - -Delete Test Server Snapshot - [Arguments] ${vm} ${snapshot} - Set Environment Variable GOVC_URL %{BUILD_SERVER} - ${rc} ${out}= Run And Return Rc And Output govc snapshot.remove -vm ${vm} ${snapshot} - Should Be Equal As Integers ${rc} 0 - Should Be Empty ${out} - Set Environment Variable GOVC_URL %{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL} - -Setup Snapshot - ${hostname}= Get Test Server Hostname - Set Environment Variable TEST_HOSTNAME ${hostname} - Set Environment Variable SNAPSHOT vic-ci-test-%{DRONE_BUILD_NUMBER} - Create Test Server Snapshot %{TEST_HOSTNAME} %{SNAPSHOT} - -Get Datacenter Name - ${out}= Run govc datacenter.info - ${out}= Split To Lines ${out} - ${name}= Fetch From Right @{out}[0] ${SPACE} - [Return] ${name} - -Get Test Server Hostname - [Tags] secret - ${hostname}= Run sshpass -p $TEST_PASSWORD ssh $TEST_USERNAME@$TEST_URL hostname - [Return] ${hostname} - -Check Delete Success - [Arguments] ${name} - ${out}= Run govc ls vm - Log ${out} - Should Not Contain ${out} ${name} - ${out}= Run govc datastore.ls - Log ${out} - Should Not Contain ${out} ${name} - ${out}= Run govc ls host/*/Resources/* - Log ${out} - Should Not Contain ${out} ${name} - -Gather Logs From ESX Server - Environment Variable Should Be Set TEST_URL - ${out}= Run govc logs.download - -Change Log Level On Server - [Arguments] ${level} - ${out}= Run govc host.option.set Config.HostAgent.log.level ${level} - Should Be Empty ${out} - -Add Vsphere License - [Tags] secret - [Arguments] ${license} - ${out}= Run govc license.add ${license} - Should Contain ${out} Key: - -Assign Vsphere License - [Tags] secret - [Arguments] ${license} ${host} - ${out}= Run govc license.assign -host ${host} ${license} - Should Contain ${out} Key: - -Add Host To VCenter - [Arguments] ${host} ${user} ${dc} ${pw} - :FOR ${idx} IN RANGE 1 4 - \ ${out}= Run govc cluster.add -hostname=${host} -username=${user} -dc=${dc} -password=${pw} -noverify=true - \ ${status}= Run Keyword And Return Status Should Contain ${out} OK - \ Return From Keyword If ${status} - Fail Failed to add the host to the VC in 3 attempts - -Get Host Firewall Enabled - ${output}= Run govc host.esxcli network firewall get - Should Contain ${output} Enabled - @{output}= Split To Lines ${output} - :FOR ${line} IN @{output} - \ Run Keyword If "Enabled" in '''${line}''' Set Test Variable ${out} ${line} - ${enabled}= Fetch From Right ${out} : - ${enabled}= Strip String ${enabled} - Return From Keyword If '${enabled}' == 'false' ${false} - Return From Keyword If '${enabled}' == 'true' ${true} - -Enable Host Firewall - Run govc host.esxcli network firewall set --enabled true - -Disable Host Firewall +# Copyright Project Harbor Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +*** Settings *** +Documentation This resource contains any keywords dealing with operations being performed on a Vsphere instance, mostly govc wrappers + +*** Keywords *** +Power On VM OOB + [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} + ${rc} ${output}= Run And Return Rc And Output GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.power -on "${vm}" + Should Be Equal As Integers ${rc} 0 + Log To Console Waiting for VM to power on ... + Wait Until VM Powers On "${vm}" ${vc_host} ${vc_user} ${vc_password} + +Power Off VM OOB + [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} + ${rc} ${output}= Run And Return Rc And Output GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.power -off "${vm}" + Log To Console ${output} + Should Be Equal As Integers ${rc} 0 + Log To Console Waiting for VM to power off ... + Wait Until VM Powers Off "${vm}" ${vc_host} ${vc_user} ${vc_password} + +Destroy VM OOB + [Arguments] ${vm} + ${rc} ${output}= Run And Return Rc And Output govc vm.destroy "*-${vm}" + Should Be Equal As Integers ${rc} 0 + +Put Host Into Maintenance Mode + ${rc} ${output}= Run And Return Rc And Output govc host.maintenance.enter -host.ip=%{TEST_URL} + Should Contain ${output} entering maintenance mode... OK + +Remove Host From Maintenance Mode + ${rc} ${output}= Run And Return Rc And Output govc host.maintenance.exit -host.ip=%{TEST_URL} + Should Contain ${output} exiting maintenance mode... OK + +Reboot VM + [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} + Log To Console Rebooting ${vm} ... + Power Off VM OOB ${vm} ${vc_host} ${vc_user} ${vc_password} + Power On VM OOB ${vm} ${vc_host} ${vc_user} ${vc_password} + Log To Console ${vm} Powered On + +Reset VM + [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} + ${rc} ${output}= Run And Return Rc And Output GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.power -reset "${vm}" + Log To Console ${output} + Should Be Equal As Integers ${rc} 0 + Log To Console Waiting for VM to reset ... + Wait Until VM Powers On "${vm}" ${vc_host} ${vc_user} ${vc_password} + +Wait Until VM Powers On + [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} + FOR ${idx} IN RANGE 0 30 + ${ret}= Run GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.info ${vm} + Set Test Variable ${out} ${ret} + ${status}= Run Keyword And Return Status Should Contain ${out} poweredOn + Return From Keyword If ${status} + Sleep 1 + END + Fail VM did not power on within 30 seconds + +Wait Until VM Powers Off + [Arguments] ${vm} ${vc_host} ${vc_user} ${vc_password} + FOR ${idx} IN RANGE 0 30 + ${ret}= Run GOVC_URL=${vc_host} GOVC_USERNAME=${vc_user} GOVC_PASSWORD=${vc_password} GOVC_INSECURE=1 govc vm.info ${vm} + Set Test Variable ${out} ${ret} + ${status}= Run Keyword And Return Status Should Contain ${out} poweredOff + Return From Keyword If ${status} + Sleep 1 + END + Fail VM did not power off within 30 seconds + +Wait Until VM Is Destroyed + [Arguments] ${vm} + :FOR ${idx} IN RANGE 0 30 + \ ${ret}= Run govc ls vm/${vm} + \ Set Test Variable ${out} ${ret} + \ ${status}= Run Keyword And Return Status Should Be Empty ${out} + \ Return From Keyword If ${status} + \ Sleep 1 + Fail VM was not destroyed within 30 seconds + +Get VM IP + [Arguments] ${vm} + ${rc} ${out}= Run And Return Rc And Output govc vm.ip ${vm} + Should Be Equal As Integers ${rc} 0 + [Return] ${out} + +Get VM Host Name + [Arguments] ${vm} + ${out}= Run govc vm.info ${vm} + ${out}= Split To Lines ${out} + ${host}= Fetch From Right @{out}[-1] ${SPACE} + [Return] ${host} + +Get VM Info + [Arguments] ${vm} + ${rc} ${out}= Run And Return Rc And Output govc vm.info -r ${vm} + Should Be Equal As Integers ${rc} 0 + [Return] ${out} + +vMotion A VM + [Arguments] ${vm} + ${host}= Get VM Host Name ${vm} + ${status}= Run Keyword And Return Status Should Contain ${host} ${esx1-ip} + Run Keyword If ${status} Run govc vm.migrate -host cls/${esx2-ip} -pool cls/Resources ${vm} + Run Keyword Unless ${status} Run govc vm.migrate -host cls/${esx1-ip} -pool cls/Resources ${vm} + +Create Test Server Snapshot + [Arguments] ${vm} ${snapshot} + Set Environment Variable GOVC_URL %{BUILD_SERVER} + ${rc} ${out}= Run And Return Rc And Output govc snapshot.create -vm ${vm} ${snapshot} + Should Be Equal As Integers ${rc} 0 + Should Be Empty ${out} + Set Environment Variable GOVC_URL %{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL} + +Revert Test Server Snapshot + [Arguments] ${vm} ${snapshot} + Set Environment Variable GOVC_URL %{BUILD_SERVER} + ${rc} ${out}= Run And Return Rc And Output govc snapshot.revert -vm ${vm} ${snapshot} + Should Be Equal As Integers ${rc} 0 + Should Be Empty ${out} + Set Environment Variable GOVC_URL %{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL} + +Delete Test Server Snapshot + [Arguments] ${vm} ${snapshot} + Set Environment Variable GOVC_URL %{BUILD_SERVER} + ${rc} ${out}= Run And Return Rc And Output govc snapshot.remove -vm ${vm} ${snapshot} + Should Be Equal As Integers ${rc} 0 + Should Be Empty ${out} + Set Environment Variable GOVC_URL %{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL} + +Setup Snapshot + ${hostname}= Get Test Server Hostname + Set Environment Variable TEST_HOSTNAME ${hostname} + Set Environment Variable SNAPSHOT vic-ci-test-%{DRONE_BUILD_NUMBER} + Create Test Server Snapshot %{TEST_HOSTNAME} %{SNAPSHOT} + +Get Datacenter Name + ${out}= Run govc datacenter.info + ${out}= Split To Lines ${out} + ${name}= Fetch From Right @{out}[0] ${SPACE} + [Return] ${name} + +Get Test Server Hostname + [Tags] secret + ${hostname}= Run sshpass -p $TEST_PASSWORD ssh $TEST_USERNAME@$TEST_URL hostname + [Return] ${hostname} + +Check Delete Success + [Arguments] ${name} + ${out}= Run govc ls vm + Log ${out} + Should Not Contain ${out} ${name} + ${out}= Run govc datastore.ls + Log ${out} + Should Not Contain ${out} ${name} + ${out}= Run govc ls host/*/Resources/* + Log ${out} + Should Not Contain ${out} ${name} + +Gather Logs From ESX Server + Environment Variable Should Be Set TEST_URL + ${out}= Run govc logs.download + +Change Log Level On Server + [Arguments] ${level} + ${out}= Run govc host.option.set Config.HostAgent.log.level ${level} + Should Be Empty ${out} + +Add Vsphere License + [Tags] secret + [Arguments] ${license} + ${out}= Run govc license.add ${license} + Should Contain ${out} Key: + +Assign Vsphere License + [Tags] secret + [Arguments] ${license} ${host} + ${out}= Run govc license.assign -host ${host} ${license} + Should Contain ${out} Key: + +Add Host To VCenter + [Arguments] ${host} ${user} ${dc} ${pw} + :FOR ${idx} IN RANGE 1 4 + \ ${out}= Run govc cluster.add -hostname=${host} -username=${user} -dc=${dc} -password=${pw} -noverify=true + \ ${status}= Run Keyword And Return Status Should Contain ${out} OK + \ Return From Keyword If ${status} + Fail Failed to add the host to the VC in 3 attempts + +Get Host Firewall Enabled + ${output}= Run govc host.esxcli network firewall get + Should Contain ${output} Enabled + @{output}= Split To Lines ${output} + :FOR ${line} IN @{output} + \ Run Keyword If "Enabled" in '''${line}''' Set Test Variable ${out} ${line} + ${enabled}= Fetch From Right ${out} : + ${enabled}= Strip String ${enabled} + Return From Keyword If '${enabled}' == 'false' ${false} + Return From Keyword If '${enabled}' == 'true' ${true} + +Enable Host Firewall + Run govc host.esxcli network firewall set --enabled true + +Disable Host Firewall Run govc host.esxcli network firewall set --enabled false \ No newline at end of file