Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick]Add Retain image last pull time API test case #18691

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/apitests/python/library/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def set_configurations(client, expect_status_code = 200, expect_response_body =
conf["audit_log_forward_endpoint"] = config.get("audit_log_forward_endpoint")
if "skip_audit_log_database" in config and config.get("skip_audit_log_database") is not None:
conf["skip_audit_log_database"] = config.get("skip_audit_log_database")
if "scanner_skip_update_pulltime" in config and config.get("scanner_skip_update_pulltime") is not None:
conf["scanner_skip_update_pulltime"] = config.get("scanner_skip_update_pulltime")

try:
_, status_code, _ = client.update_configurations_with_http_info(conf)
Expand Down Expand Up @@ -88,3 +90,8 @@ def set_configurations_of_audit_log_forword(self, audit_log_forward_endpoint=Non
client = self._get_client(**kwargs)
config=dict(audit_log_forward_endpoint=audit_log_forward_endpoint, skip_audit_log_database=skip_audit_log_database)
set_configurations(client, expect_status_code = expect_status_code, **config)

def set_configurations_of_retain_image_last_pull_time(self, is_skip, expect_status_code = 200, **kwargs):
client = self._get_client(**kwargs)
config=dict(scanner_skip_update_pulltime=is_skip)
set_configurations(client, expect_status_code = expect_status_code, **config)
1 change: 0 additions & 1 deletion tests/apitests/python/test_p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from library.user import User
from library.repository import Repository
from library.registry import Registry
from library.repository import pull_harbor_image
from library.artifact import Artifact
from library.preheat import Preheat
import v2_swagger_client
Expand Down
75 changes: 75 additions & 0 deletions tests/apitests/python/test_retain_image_last_pull_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from __future__ import absolute_import
import time
import unittest

from testutils import ADMIN_CLIENT, harbor_server, suppress_urllib3_warning
from library.user import User
from library.configurations import Configurations
from library.project import Project
from library.artifact import Artifact
from library.scan import Scan
from library.repository import push_self_build_image_to_project

class TestRetainImageLastPullTime(unittest.TestCase, object):

@suppress_urllib3_warning
def setUp(self):
self.user = User()
self.conf = Configurations()
self.project = Project()
self.artifact = Artifact()
self.scan = Scan()
self.image = "alpine"
self.tag = "latest"
self.default_time = "1-01-01 00:00:00"

def testRetainImageLastPullTime(self):
"""
Test case:
RetainImageLastPullTime
Test step and expected result:
1. Create a new user(UA);
2. Create a new private project(PA) by user(UA);
3. Push a new image(IA) in project(PA) by user(UA);
4. Enable the retain image last pull time on scanning;
5. Scan image(IA);
6. Check the last pull time of image(IA) is default time;
7. Disable the retain image last pull time on scanning;
8. Scan image(IA);
9. Check the last pull time of image(IA) is not default time;
"""
url = ADMIN_CLIENT["endpoint"]
user_password = "Aa123456"
# 1. Create a new user(UA);
_, user_name = self.user.create_user(user_password=user_password, **ADMIN_CLIENT)
USER_CLIENT = dict(endpoint = url, username = user_name, password = user_password, with_accessory = True)
# 2. Create a new private project(PA) by user(UA);
_, project_name = self.project.create_project(metadata = {"public": "false"}, **USER_CLIENT)
# 3. Push a new image(IA) in repository(RA) by user(UA);
push_self_build_image_to_project(project_name, harbor_server, user_name, user_password, self.image, self.tag)
# 4. Enable the retain image last pull time on scanning;
self.conf.set_configurations_of_retain_image_last_pull_time(True)
# 5. Scan image(IA);
self.scan.scan_artifact(project_name, self.image, self.tag, **USER_CLIENT)
time.sleep(15)
# 6. Check the last pull time of image(IA) is default time;
artifact_info = self.artifact.get_reference_info(project_name, self.image, self.tag, **USER_CLIENT)
self.assertEqual(artifact_info.pull_time.strftime("%Y-%m-%d %H:%M:%S"), self.default_time)
# 7. Disable the retain image last pull time on scanning;
self.conf.set_configurations_of_retain_image_last_pull_time(False)
# 8. Scan image(IA);
self.scan.scan_artifact(project_name, self.image, self.tag, **USER_CLIENT)
# 9. Check the last pull time of image(IA) is not default time;
pull_time = self.default_time
for _ in range(6):
artifact_info = self.artifact.get_reference_info(project_name, self.image, self.tag, **USER_CLIENT)
pull_time = artifact_info.pull_time.strftime("%Y-%m-%d %H:%M:%S")
if pull_time != self.default_time:
break
else:
time.sleep(5)
self.assertNotEqual(pull_time, self.default_time)


if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions tests/robot-cases/Group0-BAT/API_DB.robot
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,7 @@ Test Case - Scan Data Export
Test Case - Job Service Dashboard
[Tags] job_service_dashboard
Harbor API Test ./tests/apitests/python/test_job_service_dashboard.py

Test Case - Retain Image Last Pull Time
[Tags] retain_image_last_pull_time
Harbor API Test ./tests/apitests/python/test_retain_image_last_pull_time.py