Remove the log in testcase (#17500)

Remove logs that do not need to be printed

Signed-off-by: Yang Jiao <jiaoya@vmware.com>
This commit is contained in:
Yang Jiao 2022-09-06 14:15:45 +08:00 committed by GitHub
parent 7bd6c9480d
commit a56d927143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 70 additions and 87 deletions

View File

@ -130,38 +130,28 @@ def restart_process(process):
run_command_with_popen("ps aux |grep " + full_process_name)
def run_command_with_popen(command):
print("Command: ", command)
try:
proc = subprocess.Popen(command, universal_newlines=True, shell=True,
stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
output, errors = proc.communicate()
except Exception as e:
print("Run command caught exception:", e)
output = None
else:
print(proc.returncode, errors, output)
finally:
proc.stdout.close()
print("output: ", output)
return output
def run_command(command, expected_error_message = None):
print("Command: ", subprocess.list2cmdline(command))
try:
output = subprocess.check_output(command,
stderr=subprocess.STDOUT,
universal_newlines=True)
except subprocess.CalledProcessError as e:
print("Run command error:", str(e))
print("expected_error_message:", expected_error_message)
if expected_error_message is not None:
if str(e.output).lower().find(expected_error_message.lower()) < 0:
raise Exception(r"Error message {} is not as expected {}".format(str(e.output), expected_error_message))
raise Exception(r"Error message is not as expected {}".format(expected_error_message))
else:
raise Exception('Error: Exited with error code: %s. Output:%s'% (e.returncode, e.output))
raise Exception('Error: Exited with error code: %s.'% (e.returncode))
else:
print("output:", output)
return output
class Base(object):

View File

@ -23,17 +23,12 @@ def cnab_fixup_bundle(bundle_file, target, auto_update_bundle = True):
command = ["cnab-to-oci", "--log-level", "debug", "fixup", bundle_file, "--target", target, "--bundle", fixed_bundle_file]
if auto_update_bundle == True:
command.append("--auto-update-bundle")
#fixed_bundle_file = bundle_file
print("Command: ", command)
ret = base.run_command(command)
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)
ret = base.run_command(command)
print("Command return: ", ret)
for line in ret.split("\n"):
line = line.replace('\"', '')
if line.find('sha256') >= 0:

View File

@ -7,13 +7,10 @@ import docker_api
def ctr_images_pull(username, password, oci):
command = ["ctr", "images", "pull","--snapshotter", "native", "-u", username+":"+password, oci]
ret = base.run_command(command)
print("Command return: ", ret)
def ctr_images_list(oci_ref = None):
command = ["ctr", "images", "list", "--q"]
print("Command: ", command)
ret = base.run_command(command)
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))

View File

@ -3,7 +3,7 @@
import base
import subprocess
import json
from testutils import DOCKER_USER, DOCKER_PWD, BASE_IMAGE, BASE_IMAGE_ABS_PATH_NAME
from testutils import BASE_IMAGE, BASE_IMAGE_ABS_PATH_NAME
try:
import docker
@ -27,14 +27,12 @@ def docker_login_cmd(harbor_host, username, password, cfg_file = "./tests/apites
if enable_manifest == True:
try:
ret = subprocess.check_output([cfg_file], shell=False)
print("docker login cmd ret:", ret)
except subprocess.CalledProcessError as exc:
raise Exception("Failed to update docker config, error is {} {}.".format(exc.returncode, exc.output))
raise Exception("Failed to update docker config.")
def docker_manifest_create(index, manifests):
command = ["docker","manifest","create", "--amend", index]
command.extend(manifests)
print( "Docker Manifest Command: ", command)
base.run_command(command)
def docker_images_all_list():
@ -55,7 +53,6 @@ def docker_image_clean_all():
def docker_manifest_push(index):
command = ["docker","manifest","push",index]
print( "Docker Manifest Command: ", command)
ret = base.run_command(command)
index_sha256=""
manifest_list=[]
@ -111,22 +108,22 @@ class DockerAPI(object):
try:
ret = self.DCLIENT.login(registry = registry, username=username, password=password)
except Exception as err:
print( "Docker image pull catch exception:", str(err))
print( "Docker image pull catch exception")
err_message = str(err)
if expected_error_message is None:
raise Exception(r" Docker pull image {} failed, error is [{}]".format (image, str(err)))
raise Exception(r" Docker pull image failed")
else:
print("Docker image login did not catch exception and return message is:", ret)
print("Docker image login did not catch exception")
err_message = ret
finally:
if expected_error_message is not None:
if str(err_message).lower().find(expected_error_message.lower()) < 0:
raise Exception(r" Failed to catch error [{}] when login registry {}, return message: {}".format (expected_error_message, registry, err_message))
raise Exception(r" err message is different from expected error message")
else:
print(r"Docker image login got expected error message:{}".format(expected_error_message))
print(r"Docker image login got expected error message")
else:
if str(err_message).lower().find("error".lower()) >= 0:
raise Exception(r" It's was not suppose to catch error when login registry {}, return message is [{}]".format (registry, err_message))
raise Exception(r" It's was not suppose to catch error when login registry")
def docker_image_pull(self, image, tag = None, expected_error_message = None, is_clean_all_img = True):
ret = ""
@ -198,7 +195,7 @@ class DockerAPI(object):
raise Exception(r" It's was not suppose to catch error when push image {}, return message is [{}]".format (harbor_registry, err_message))
docker_images_all_list()
def docker_image_build(self, harbor_registry, tags=None, size=1, expected_error_message = None):
def docker_image_build(self, harbor_registry, tags=None, size=1, expected_error_message = None, clean_images=True):
ret = ""
err_message = ""
docker_images_all_list()
@ -243,4 +240,5 @@ class DockerAPI(object):
else:
if str(err_message).lower().find("error".lower()) >= 0:
raise Exception(r" It's was not suppose to catch error when build image {}, return message is [{}]".format (harbor_registry, err_message))
docker_image_clean_all()
if clean_images:
docker_image_clean_all()

View File

@ -16,7 +16,6 @@ class Registry(base.Base, object):
registry = v2_swagger_client.Registry(name=name, url=url,
description= description, type=registry_type,
insecure=insecure, credential=registryCredential)
print("registry:", registry)
_, status_code, header = client.create_registry_with_http_info(registry)
base._assert_status_code(expect_status_code, status_code)
return base._get_id_from_header(header), _

View File

@ -53,8 +53,13 @@ def push_special_image_to_project(project_name, registry, username, password, im
_docker_api.docker_login(registry, username, password, expected_error_message = expected_login_error_message)
time.sleep(2)
if expected_login_error_message in [None, ""]:
return _docker_api.docker_image_build(r'{}/{}/{}'.format(registry, project_name, image), tags = tags, size=int(size), expected_error_message=expected_error_message)
return _docker_api.docker_image_build(r'{}/{}/{}'.format(registry, project_name, image), tags = tags, size=int(size), expected_error_message=expected_error_message, clean_images=False)
def push_local_image_to_project(registry, username, password, original_image, original_tag, target_image, target_tag):
_docker_api = DockerAPI()
_docker_api.docker_login(registry, username, password)
new_harbor_registry, new_tag = _docker_api.docker_image_tag(r'{}:{}'.format(original_image, original_tag), target_image, tag = target_tag)
_docker_api.docker_image_push(new_harbor_registry, new_tag)
class Repository(base.Base, object):
def __init__(self):

View File

@ -4,7 +4,7 @@ import unittest
from testutils import harbor_server, created_project, created_user, \
TEARDOWN, ADMIN_CLIENT,suppress_urllib3_warning
from library.repository import Repository
from library.repository import push_image_to_project
from library.repository import push_self_build_image_to_project, push_local_image_to_project
from library.system import System
class TestProjects(unittest.TestCase):
@ -25,12 +25,13 @@ class TestProjects(unittest.TestCase):
1. Create a new user(UA);
2. Create a new private project(PA) by user(UA);
3. Add user(UA) as a member of project(PA) with project-admin role;
4. Push an image to project(PA) by user(UA), then check the project quota usage;
5. Check quota change
6. Push the image with another tag to project(PA) by user(UA)
7. Check quota not changed
8. Delete repository(RA) by user(UA);
9. Delete image, the quota should be changed to 0.
4. Check quota is 0
5. Push an image to project(PA) by user(UA), then check the project quota usage;
6. Check quota change
7. Push the image with another tag to project(PA) by user(UA)
8. Check quota not changed
9. Delete repository(RA) by user(UA);
10. Delete image, the quota should be changed to 0.
Tear down:
1. Delete repository(RA) by user(UA);
2. Delete project(PA);
@ -43,27 +44,31 @@ class TestProjects(unittest.TestCase):
#2. Create a new private project(PA) by user(UA);
#3. Add user(UA) as a member of project(PA) with project-admin role;
with created_project(metadata={"public": "false"}, user_id=user_id) as (project_id, project_name):
#4. Push an image to project(PA) by user(UA), then check the project quota usage; -- {"count": 1, "storage": 2791709}
#4. Check quota is 0
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
self.assertEqual(quota[0].used["storage"], 0)
#5. Push an image to project(PA) by user(UA), then check the project quota usage;
image, tag = "goharbor/alpine", "3.10"
image_alias_name = "_alias"
push_image_to_project(project_name, harbor_server, user_name, user_001_password, image, tag)
push_self_build_image_to_project(project_name, harbor_server, user_name, user_001_password, image, tag)
#5. Get project quota
#6. Get project quota
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
self.assertEqual(quota[0].used["storage"], 2789002)
quota_size = quota[0].used["storage"]
self.assertNotEqual(quota_size, 0)
#6. Push the image with another tag to project(PA) by user(UA), the check the project quota usage; -- {"count": 1, "storage": 2791709}
push_image_to_project(project_name, harbor_server, user_name, user_001_password, image, tag, new_image=image+image_alias_name)
#7. Push the image with another tag to project(PA) by user(UA), the check the project quota usage;
push_local_image_to_project(harbor_server, user_name, user_001_password, "{}/{}/{}".format(harbor_server, project_name, image), tag, "{}/{}/{}{}".format(harbor_server, project_name, image, image_alias_name), tag + image_alias_name)
#7. Get project quota
#8. Get project quota
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
self.assertEqual(quota[0].used["storage"], 2789002)
self.assertEqual(quota[0].used["storage"], quota_size)
#8. Delete repository(RA) by user(UA);
#9. Delete repository(RA) by user(UA);
self.repo.delete_repository(project_name, "goharbor%2Falpine", **ADMIN_CLIENT)
self.repo.delete_repository(project_name, "goharbor%2Falpine"+image_alias_name, **ADMIN_CLIENT)
#9. Quota should be 0
#10. Quota should be 0
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
self.assertEqual(quota[0].used["storage"], 0)

View File

@ -10,7 +10,7 @@ from library.artifact import Artifact
from library.project import Project
from library.user import User
from library.repository import Repository
from library.repository import push_image_to_project
from library.repository import push_self_build_image_to_project
class TestProjects(unittest.TestCase):
@suppress_urllib3_warning
@ -70,8 +70,7 @@ class TestProjects(unittest.TestCase):
profix = "aaa/bbb"
#5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA);
TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_sign_image_name, harbor_server, user_sign_image_name, user_001_password, image, src_tag, profix_for_image=profix)
TestProjects.repo_name, tag = push_self_build_image_to_project(TestProjects.project_sign_image_name, harbor_server, user_sign_image_name, user_001_password, profix+"/"+image, src_tag)
#7. Get signature of image with tag(TA), it should be exist.
full_name = urllib.parse.quote(profix+"/"+image,'utf-8')

View File

@ -14,9 +14,8 @@ Setup API Test
Harbor API Test
[Arguments] ${testcase_name}
${current_dir}= Run pwd
Log To Console ${current_dir}
Log To Console ${ip}
${prev_lvl} Set Log Level NONE
${rc} ${output}= Run And Return Rc And Output SWAGGER_CLIENT_PATH=${current_dir}/harborclient HARBOR_HOST=${ip} DOCKER_USER=${DOCKER_USER} DOCKER_PWD=${DOCKER_PWD} python ${testcase_name}
Log To Console ${output}
${prev_lvl} Set Log Level ${prev_lvl}
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Be Equal As Integers ${rc} 0

View File

@ -212,13 +212,17 @@ Clean All Local Images
Docker Login Fail
[Arguments] ${ip} ${user} ${pwd}
Log To Console \nRunning docker login ${ip} ...
${prev_lvl} Set Log Level NONE
${output}= Command Should be Failed docker login -u ${user} -p ${pwd} ${ip}
${prev_lvl} Set Log Level ${prev_lvl}
Should Contain ${output} unauthorized
Should Not Contain ${output} 500 Internal Server Error
Docker Login
[Arguments] ${server} ${username} ${password}
${prev_lvl} Set Log Level NONE
Wait Unitl Command Success docker login -u ${username} -p ${password} ${server}
${prev_lvl} Set Log Level ${prev_lvl}
Docker Logout
[Arguments] ${server}

View File

@ -101,9 +101,9 @@ Create A New Endpoint
Select From List By Value ${provider_selector} ${provider}
Retry Text Input xpath=${destination_name_xpath} ${name}
Run Keyword If '${provider}' == 'harbor' or '${provider}' == 'gitlab' Run keyword Retry Text Input xpath=${destination_url_xpath} ${url}
Run Keyword If '${provider}' == 'aws-ecr' or '${provider}' == 'google-gcr' Run keyword Select Destination URL ${url}
Run Keyword If '${provider}' != 'google-gcr' and '${username}' != '${null}' Retry Text Input xpath=${destination_username_xpath} ${username}
Run Keyword If '${pwd}' != '${null}' Retry Text Input xpath=${destination_password_xpath} ${pwd}
Run Keyword If '${provider}' == 'aws-ecr' or '${provider}' == 'google-gcr' Run keyword Select Destination URL ${url}
Run Keyword If '${provider}' != 'google-gcr' and '${username}' != '${null}' Retry Password Input xpath=${destination_username_xpath} ${username}
Run Keyword If '${pwd}' != '${null}' Retry Password Input xpath=${destination_password_xpath} ${pwd}
#cancel verify cert since we use a selfsigned cert
Retry Element Click ${destination_insecure_xpath}
Run Keyword If '${save}' == 'Y' Run keyword Retry Double Keywords When Error Retry Element Click ${replication_save_xpath} Retry Wait Until Page Not Contains Element ${replication_save_xpath}
@ -122,7 +122,7 @@ Create A Rule With Existing Endpoint
... ELSE Run Keywords Retry Element Click ${replication_mode_radio_pull} AND Select Source Registry ${endpoint}
#set filter
Retry Text Input ${filter_name_id} ${filter_project_name}
Retry Password Input ${filter_name_id} ${filter_project_name}
Run Keyword If '${filter_tag_model}' != 'matching' Select Filter Tag Model ${filter_tag_model}
Run Keyword If '${filter_tag}' != '${false}' Retry Text Input ${filter_tag_id} ${filter_tag}
Run Keyword If '${filter_label_model}' != 'matching' Select Filter Label Model ${filter_label_model}

View File

@ -43,8 +43,6 @@ Nightly Test Setup In Photon
Log To Console wget mariadb ...
Run wget ${prometheus_chart_file_url}
Prepare Helm Plugin
#Prepare docker image for push special image keyword in replication test
Run Keyword If '${DOCKER_USER}' != '${EMPTY}' Docker Login "" ${DOCKER_USER} ${DOCKER_PWD}
Nightly Test Setup In Ubuntu
[Arguments] ${ip} ${HARBOR_PASSWORD} ${ip1}==${EMPTY}
@ -53,8 +51,6 @@ Nightly Test Setup In Ubuntu
Log To Console Start Docker Daemon Locally ...
Run Keyword Start Docker Daemon Locally
Prepare Helm Plugin
#Docker login
Run Keyword If '${DOCKER_USER}' != '${EMPTY}' Docker Login "" ${DOCKER_USER} ${DOCKER_PWD}
Nightly Test Setup In Ubuntu For Upgrade
[Arguments] ${ip} ${HARBOR_PASSWORD} ${ip1}==${EMPTY}
@ -65,8 +61,6 @@ Nightly Test Setup In Ubuntu For Upgrade
Prepare Helm Plugin
#For upgrade pipeline: get notary targets key from last execution.
${rc} ${output}= Run And Return Rc And Output [ -f "/key_store/private_keys_backup.tar.gz" ] && tar -zxvf /key_store/private_keys_backup.tar.gz -C /
#Docker login
Run Keyword If '${DOCKER_USER}' != '${EMPTY}' Docker Login "" ${DOCKER_USER} ${DOCKER_PWD}
CA Setup In ubuntu
[Arguments] ${ip} ${HARBOR_PASSWORD} ${cert}

View File

@ -94,6 +94,12 @@ Retry Action Keyword
[Arguments] ${keyword} @{param}
Retry Keyword N Times When Error 4 ${keyword} @{param}
Retry Action Keyword And No Output
[Arguments] ${keyword} @{param}
${prev_lvl} Set Log Level NONE
Retry Keyword N Times When Error 4 ${keyword} @{param}
${prev_lvl} Set Log Level ${prev_lvl}
Retry Wait Element
[Arguments] ${element_xpath}
@{param} Create List ${element_xpath}
@ -129,6 +135,10 @@ Retry Text Input
@{param} Create List ${element_xpath} ${text}
Retry Action Keyword Text Input @{param}
Retry Password Input
[Arguments] ${element_xpath} ${text}
Retry Action Keyword And No Output Text Input ${element_xpath} ${text}
Retry Clear Element Text
[Arguments] ${element_xpath}
@{param} Create List ${element_xpath}
@ -242,9 +252,7 @@ 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]}
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

View File

@ -56,15 +56,6 @@ Test Case - Harbor Endpoint Verification
Endpoint Is Unpingable
Close Browser
##Test Case - DockerHub Endpoint Add
#This case need vailid info and selfsign cert
##Init Chrome Driver
##${d}= Get Current Date result_format=%m%s
##Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
##Switch To Registries
##Create A New Endpoint docker-hub edp1${d} https://hub.docker.com/ ${DOCKER_USER} ${DOCKER_PWD} Y
##Close Browser
Test Case - Harbor Endpoint Add
#This case need vailid info and selfsign cert
Init Chrome Driver
@ -297,14 +288,13 @@ Test Case - Replication Of Push Images from Self To Harbor By Push Event
Test Case - Replication Of Pull Images from AWS-ECR To Self
Init Chrome Driver
${d}= Get Current Date result_format=%m%s
#login source
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
Create An New Project And Go Into Project project${d}
${d}= Get Current Date result_format=%m%s
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
Create An New Project And Go Into Project project${d}
Switch To Registries
Create A New Endpoint aws-ecr e${d} us-east-2 ${ecr_ac_id} ${ecr_ac_key} Y
Create A New Endpoint aws-ecr e${d} us-east-2 ${ecr_ac_id} ${ecr_ac_key} Y
Switch To Replication Manage
Create A Rule With Existing Endpoint rule${d} pull a/* image e${d} project${d}
Create A Rule With Existing Endpoint rule${d} pull a/* image e${d} project${d}
Select Rule And Replicate rule${d}
Image Should Be Replicated To Project project${d} httpd
Image Should Be Replicated To Project project${d} alpine
@ -356,7 +346,7 @@ Test Case - Replication Of Pull Manifest List and CNAB from Harbor To Self
${image2}= Get From Dictionary ${image2_with_tag} image
${image3}= Get From Dictionary ${image3_with_tag} image
@{target_images}= Create List '&{image1_with_tag}' '&{image2_with_tag}' '&{image3_with_tag}'
Body Of Replication Of Pull Images from Registry To Self harbor https://cicd.harbor.vmwarecna.net admin qA5ZgV nightly/{${image1},${image2},${image3}} ${null} Y Flatten 1 Level @{target_images}
Body Of Replication Of Pull Images from Registry To Self harbor https://cicd.harbor.vmwarecna.net ${null} ${null} nightly/{${image1},${image2},${image3}} ${null} Y Flatten 1 Level @{target_images}
Test Case - Image Namespace Level Flattening
[tags] flattening