Merge pull request #12188 from danfengliu/add-singularity-py-test

Add singularity py-test
This commit is contained in:
danfengliu 2020-06-10 14:16:47 +08:00 committed by GitHub
commit d5cce98d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 123 additions and 3 deletions

View File

@ -147,6 +147,21 @@ jobs:
mkdir -p oras-install/ mkdir -p oras-install/
tar -zxf oras_0.8.1_*.tar.gz -C oras-install/ tar -zxf oras_0.8.1_*.tar.gz -C oras-install/
sudo mv oras-install/oras /usr/local/bin/ sudo mv oras-install/oras /usr/local/bin/
sudo apt-get update && sudo apt-get install -y \
build-essential \
uuid-dev \
libgpgme-dev \
squashfs-tools \
libseccomp-dev \
pkg-config \
cryptsetup-bin
export VERSION=3.5.3 && \
wget https://github.com/sylabs/singularity/releases/download/v${VERSION}/singularity-${VERSION}.tar.gz && \
tar -xzf singularity-${VERSION}.tar.gz && \
cd singularity
./mconfig && \
make -C builddir && \
sudo make -C builddir install
- name: install - name: install
run: | run: |
cd src/github.com/goharbor/harbor cd src/github.com/goharbor/harbor

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
import os
import base
from datetime import datetime
singularity_cmd = "singularity"
timestamp = datetime.now().strftime(r'%m%s')
def set_singularity_login_env(user, password):
os.environ.setdefault('SINGULARITY_DOCKER_USERNAME', user)
os.environ.setdefault('SINGULARITY_DOCKER_PASSWORD', password)
def singularity_push_to_harbor(harbor_server, sif_file, project, image, tag):
ret = base.run_command( [singularity_cmd, "push", sif_file, "oras://"+harbor_server + "/" + project + "/" + image+":"+ tag] )
def singularity_pull(out_file, from_sif_file):
ret = base.run_command( [singularity_cmd, "pull", out_file, from_sif_file] )
def push_singularity_to_harbor(from_URI, from_namespace, harbor_server, user, password, project, image, tag):
tmp_sif_file = image+timestamp+".sif"
set_singularity_login_env(user, password)
singularity_pull(tmp_sif_file, from_URI+"//"+from_namespace + image+":" + tag)
singularity_push_to_harbor(harbor_server, tmp_sif_file, project, image, tag)

View File

@ -40,7 +40,7 @@ class TestProjects(unittest.TestCase):
1. Create user-001 1. Create user-001
2. Create a new private project(PA) by user(UA); 2. Create a new private project(PA) by user(UA);
3. ORAS CLI push artifacts; 3. ORAS CLI push artifacts;
4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by ORAS CLI;; 4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by ORAS CLI;
5. Get and verify artifacts by tag; 5. Get and verify artifacts by tag;
6. ORAS CLI pull artifacts index by tag; 6. ORAS CLI pull artifacts index by tag;
7. Verfiy MD5 between artifacts pushed by ORAS and artifacts pulled by ORAS; 7. Verfiy MD5 between artifacts pushed by ORAS and artifacts pulled by ORAS;
@ -62,7 +62,7 @@ class TestProjects(unittest.TestCase):
md5_list_push = library.oras.oras_push(harbor_server, user_name, user_001_password, TestProjects.project_name, self.repo_name, self.tag) 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 print "md5_list_push:",md5_list_push
#4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by ORAS CLI;; #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) repo_data = self.repo.get_repository(TestProjects.project_name, self.repo_name, **TestProjects.USER_CLIENT)
print "repo_data:", repo_data print "repo_data:", repo_data
self.assertEqual(repo_data.name, TestProjects.project_name + "/" + self.repo_name) self.assertEqual(repo_data.name, TestProjects.project_name + "/" + self.repo_name)

View File

@ -0,0 +1,78 @@
from __future__ import absolute_import
import unittest
import urllib
import library.singularity
from library.sign import sign_image
from testutils import ADMIN_CLIENT
from testutils import harbor_server
from testutils import TEARDOWN
from library.user import User
from library.project import Project
from library.repository import Repository
from library.artifact import Artifact
class TestProjects(unittest.TestCase):
@classmethod
def setUp(self):
self.project = Project()
self.user = User()
self.artifact = Artifact()
self.repo = Repository()
self.repo_name = "busybox"
self.tag = "1.28"
@classmethod
def tearDown(self):
print "Case completed"
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
#1. Delete user(UA);
self.user.delete_user(TestProjects.user_sign_image_id, **ADMIN_CLIENT)
def testPushSingularity(self):
"""
Test case:
Push Singularity file With Singularity CLI
Test step and expected result:
1. Create user-001
2. Create a new private project(PA) by user(UA);
3. Push a sif file to harbor by singularity;
4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by singularity CLI;
5. Get and verify artifacts by tag;
6. Pull sif file from harbor by singularity;
Tear down:
NA
"""
url = ADMIN_CLIENT["endpoint"]
user_001_password = "Aa123456"
#1. Create user-001
TestProjects.user_sign_image_id, user_name = self.user.create_user(user_password = user_001_password, **ADMIN_CLIENT)
TestProjects.USER_CLIENT=dict(with_signature = True, endpoint = url, username = user_name, password = user_001_password)
#2. Create a new private project(PA) by user(UA);
TestProjects.project_id, TestProjects.project_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CLIENT)
#3. Push a sif file to harbor by singularity;
library.singularity.push_singularity_to_harbor("library:", "library/default/", harbor_server, user_name, user_001_password, TestProjects.project_name, self.repo_name, self.tag)
#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;
library.singularity.singularity_pull(TestProjects.project_name + ".sif", "oras://"+harbor_server + "/" + TestProjects.project_name + "/" + self.repo_name+":"+ self.tag)
if __name__ == '__main__':
unittest.main()

View File

@ -100,4 +100,7 @@ Test Case - Push Image With Special Name
Harbor API Test ./tests/apitests/python/test_push_image_with_special_name.py Harbor API Test ./tests/apitests/python/test_push_image_with_special_name.py
Test Case - Push Artifact With ORAS CLI Test Case - Push Artifact With ORAS CLI
[Tags] oras [Tags] oras
Harbor API Test ./tests/apitests/python/test_oras_cli.py Harbor API Test ./tests/apitests/python/test_push_files_by_oras.py
Test Case - Push Singularity file With Singularity CLI
[Tags] singularity
Harbor API Test ./tests/apitests/python/test_push_sif_by_singularity.py