Skip to content

Commit

Permalink
Add podman pull & push testcase
Browse files Browse the repository at this point in the history
Fix goharbor#18788

Signed-off-by: Yang Jiao <[email protected]>
  • Loading branch information
Yang Jiao authored and YangJiao0817 committed Jun 6, 2023
1 parent 6e2b79a commit 219c619
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 4 deletions.
18 changes: 18 additions & 0 deletions tests/apitests/python/library/podman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
import base

def login(registry, username, password):
command = ["podman", "login", "-u", username, "-p", password, registry]
base.run_command(command)

def logout(registry):
command = ["podman", "logout", registry]
base.run_command(command)

def pull(artifact):
command = ["podman", "pull", artifact]
base.run_command(command)

def push(source_artifact, target_artifact):
command = ["podman", "push", source_artifact, target_artifact]
base.run_command(command)
76 changes: 76 additions & 0 deletions tests/apitests/python/test_podman_pull_push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import unittest

from testutils import harbor_server, ADMIN_CLIENT, suppress_urllib3_warning
from library import podman
from library.project import Project
from library.user import User
from library.artifact import Artifact
from library.repository import push_self_build_image_to_project

class TestPodmanPullPush(unittest.TestCase):

@suppress_urllib3_warning
def setUp(self):
self.project= Project()
self.user= User()
self.artifact = Artifact()
self.image = "image_test"
self.tag = "v1"
self.source_image = "ghcr.io/goharbor/harbor-core"
self.source_tag = "v2.8.2"

def testPodman(self):
"""
Test case:
Podman pull and push
Test step and expected result:
1. Create a new user;
2. Create a new project by user;
3. Push a new image in project by user;
4. Podman login harbor;
5. Podman pull image from project(PA) by user;
6. Podman pull soure image;
7. Podman push soure image to project by user;
8. Verify the image;
9. Podman logout harbor;
"""
url = ADMIN_CLIENT["endpoint"]
user_password = "Aa123456"

# 1. Create 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 private project(PA) by user(UA)
_, project_name = self.project.create_project(metadata = {"public": "false"}, **user_client)

# 3. Push a new image(IA) in project(PA) by user(UA)
push_self_build_image_to_project(project_name, harbor_server, user_name, user_password, self.image, self.tag)

# 4. Podman login harbor
podman.login(harbor_server, user_name, user_password)

# 5. Podman pull image from project(PA) by user
podman.pull("{}/{}/{}:{}".format(harbor_server, project_name, self.image, self.tag))

# 6. Podman pull soure image
podman.pull("{}:{}".format(self.source_image, self.source_tag))

# 7. Podman push soure image to project by user
podman.push("{}:{}".format(self.source_image, self.source_tag), "{}/{}/{}:{}".format(harbor_server, project_name, self.image, self.tag))

# 8. Verify the image
image_info = self.artifact.get_reference_info(project_name, self.image, self.tag, **user_client)
self.assertIsNotNone(image_info)
self.assertIsNotNone(image_info.digest)
self.assertEqual(len(image_info.tags), 1)
self.assertEqual(image_info.tags[0].name, self.tag)

# 9. Podman logout harbor
podman.logout(harbor_server)

if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions tests/apitests/python/test_referrers_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def testReferrersApi(self):
6. Sign image(IA) SBOM with cosign;
7. Call the referrers api successfully;
8. Call the referrers api and filter artifact_type;
Tear down:
1. Delete project(PA);
2. Delete user(UA).
"""
url = ADMIN_CLIENT["endpoint"]
user_password = "Aa123456"
Expand Down
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 @@ -186,3 +186,7 @@ Test Case - Retain Image Last Pull Time
Test Case - Referrers API
[Tags] referrers
Harbor API Test ./tests/apitests/python/test_referrers_api.py

Test Case - Podman Pull And Push To Harbor
[Tags] podman_pull_push
Harbor API Test ./tests/apitests/python/test_podman_pull_push.py
4 changes: 3 additions & 1 deletion tests/test-engine-image/Dockerfile.api_test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ENV COSIGN_OCI_EXPERIMENTAL=1

COPY --from=tool_builder /tool/tools.tar.gz /usr/local/bin

RUN tdnf install -y \
RUN tdnf update -y && tdnf install -y \
wget \
git \
openjdk8 \
Expand Down Expand Up @@ -45,4 +45,6 @@ RUN chmod +x /usr/local/bin/dockerd-entrypoint.sh && \
echo Harbor12345 > password.ca && \
certutil -d sql:$HOME/.pki/nssdb -N -f password.ca

RUN tdnf install -y podman

VOLUME /var/lib/docker

0 comments on commit 219c619

Please sign in to comment.