Enable api tests in travis (#5900)

This commit is to enable parallel run jobs with travis, and add API for DB and API for LDAP in travis.

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
Yan 2018-09-19 17:49:43 +08:00 committed by GitHub
parent e77a116e1d
commit 002e5a2b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 205 additions and 70 deletions

View File

@ -3,30 +3,43 @@ sudo: true
language: go language: go
go: go:
- 1.9.2 - 1.9.2
go_import_path: github.com/goharbor/harbor go_import_path: github.com/goharbor/harbor
services: services:
- docker - docker
dist: trusty dist: trusty
matrix:
include:
- go: "1.9.2"
env:
- UTTEST=true
- go: "1.9.2"
env:
- APITEST_DB=true
- go: "1.9.2"
env:
- APITEST_LDAP=true
env: env:
POSTGRESQL_HOST: localhost global:
POSTGRESQL_PORT: 5432 - POSTGRESQL_HOST: localhost
POSTGRESQL_USR: postgres - POSTGRESQL_PORT: 5432
POSTGRESQL_PWD: root123 - POSTGRESQL_USR: postgres
POSTGRESQL_DATABASE: registry - POSTGRESQL_PWD: root123
ADMINSERVER_URL: http://127.0.0.1:8888 - POSTGRESQL_DATABASE: registry
DOCKER_COMPOSE_VERSION: 1.7.1 - ADMINSERVER_URL: http://127.0.0.1:8888
HARBOR_ADMIN: admin - DOCKER_COMPOSE_VERSION: 1.22.0
HARBOR_ADMIN_PASSWD: Harbor12345 - HARBOR_ADMIN: admin
CORE_SECRET: tempString - HARBOR_ADMIN_PASSWD: Harbor12345
KEY_PATH: /data/secretkey - CORE_SECRET: tempString
REDIS_HOST: localhost - KEY_PATH: /data/secretkey
REG_VERSION: v2.6.2 - REDIS_HOST: localhost
UI_BUILDER_VERSION: 1.6.0 - REG_VERSION: v2.6.2
- UI_BUILDER_VERSION: 1.6.0
addons: addons:
apt: apt:
@ -37,59 +50,20 @@ apt:
- google-chrome-beta - google-chrome-beta
before_install: before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sudo ./tests/hostcfg.sh
- sudo ./tests/generateCerts.sh
- sudo ./make/prepare
- sudo mkdir -p "/data/redis"
- sudo mkdir -p /etc/core/ca/ && sudo mv ./tests/ca.crt /etc/core/ca/
- sudo mkdir -p /harbor && sudo mv ./VERSION /harbor/UIVERSION
- sudo ./tests/testprepare.sh
install:
- sudo apt-get update && sudo apt-get install -y libldap2-dev
- go get -d github.com/docker/distribution
- go get -d github.com/docker/libtrust
- go get -d github.com/lib/pq
- go get github.com/golang/lint/golint
- go get github.com/GeertJohan/fgt
- go get github.com/dghubble/sling
- go get github.com/stretchr/testify
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- go get -u github.com/client9/misspell/cmd/misspell
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose - chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin - sudo mv docker-compose /usr/local/bin
- IP=`ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}'` - IP=`ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}'`
- sudo sed -i '$a DOCKER_OPTS=\"--insecure-registry '$IP':5000\"' /etc/default/docker - sudo sed -i '$a DOCKER_OPTS=\"--insecure-registry '$IP':5000\"' /etc/default/docker
- export IP=$IP
- sudo service docker restart - sudo service docker restart
- sudo service postgresql stop
before_script: install:
- cd src/portal - if [ "$UTTEST" == true ]; then bash ./tests/travis/ut_install.sh ; fi
- npm install -g -q --no-progress angular-cli - if [ "$APITEST_DB" == true ]; then bash ./tests/travis/api_common_install.sh $IP DB; fi
- npm install -g -q --no-progress karma - if [ "$APITEST_LDAP" == true ]; then bash ./tests/travis/api_common_install.sh $IP LDAP; fi
- npm install -q --no-progress
- npm run build_lib && npm run link_lib && cd ../..
- export POSTGRESQL_HOST=$IP
- export REGISTRY_URL=$IP:5000
- echo $REGISTRY_URL
- cd tests && sudo ./ldapprepare.sh && cd ..
- sudo ./tests/admiral.sh
- sudo make compile_adminserver
- sudo make -f make/photon/Makefile _build_adminserver _build_db _build_registry -e VERSIONTAG=dev -e CLAIRDBVERSION=dev -e REGISTRYVERSION=${REG_VERSION}
- sudo sed -i 's/__reg_version__/${REG_VERSION}-dev/g' ./make/docker-compose.test.yml
- sudo sed -i 's/__version__/dev/g' ./make/docker-compose.test.yml
- sudo mkdir -p ./make/common/config/registry/ && sudo mv ./tests/reg_config.yml ./make/common/config/registry/config.yml
script: script:
- cd src/portal && npm run lint && npm run lint:lib && npm run test && cd ../.. - if [ "$UTTEST" == true ]; then bash ./tests/travis/ut_run.sh $IP; fi
- sudo docker-compose -f ./make/docker-compose.test.yml up -d - if [ "$APITEST_DB" == true ]; then bash ./tests/travis/api_run.sh DB $IP; fi
- make go_check - if [ "$APITEST_LDAP" == true ]; then bash ./tests/travis/api_run.sh LDAP $IP; fi
- ./tests/pushimage.sh
- go test -race -i ./src/core ./src/adminserver ./src/jobservice
- sudo -E env "PATH=$PATH" "POSTGRES_MIGRATION_SCRIPTS_PATH=/home/travis/gopath/src/github.com/goharbor/harbor/make/migrations/postgresql/" ./tests/coverage4gotest.sh
- goveralls -coverprofile=profile.cov -service=travis-ci

View File

@ -26,7 +26,7 @@ def _create_client(server, credential, debug):
return swagger_client.ProductsApi(swagger_client.ApiClient(cfg)) return swagger_client.ProductsApi(swagger_client.ApiClient(cfg))
def _random_name(prefix): def _random_name(prefix):
return "%s-%d" % (prefix, time.time()) return "%s-%d" % (prefix, int(round(time.time() * 1000)))
def _get_id_from_header(header): def _get_id_from_header(header):
location = header["Location"] location = header["Location"]

View File

@ -5,8 +5,10 @@ import base
import swagger_client import swagger_client
class Project(base.Base): class Project(base.Base):
def create_project(self, name=base._random_name("project"), def create_project(self, name=None,
metadata = {}, **kwargs): metadata = {}, **kwargs):
if name is None:
name = base._random_name("project")
client = self._get_client(**kwargs) client = self._get_client(**kwargs)
_, _, header = client.projects_post_with_http_info( _, _, header = client.projects_post_with_http_info(
swagger_client.ProjectReq(name, metadata)) swagger_client.ProjectReq(name, metadata))

View File

@ -5,3 +5,12 @@ PROTOCOL='https'
#echo $IP #echo $IP
sudo sed "s/reg.mydomain.com/$IP/" -i make/harbor.cfg sudo sed "s/reg.mydomain.com/$IP/" -i make/harbor.cfg
sudo sed "s/^ui_url_protocol = .*/ui_url_protocol = $PROTOCOL/g" -i make/harbor.cfg sudo sed "s/^ui_url_protocol = .*/ui_url_protocol = $PROTOCOL/g" -i make/harbor.cfg
if [ "$1" = 'LDAP' ]; then
sudo sed "s/db_auth/ldap_auth/" -i make/harbor.cfg
sudo sed "s/ldaps:\/\/ldap.mydomain.com/ldap:\/\/$IP/g" -i make/harbor.cfg
sudo sed "s/#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com/ldap_searchdn = cn=admin,dc=example,dc=com/" -i make/harbor.cfg
sudo sed "s/#ldap_search_pwd = password/ldap_search_pwd = admin/" -i make/harbor.cfg
sudo sed "s/ldap_basedn = ou=people,dc=mydomain,dc=com/ldap_basedn = dc=example,dc=com/" -i make/harbor.cfg
sudo sed "s/ldap_uid = uid/ldap_uid = cn/" -i make/harbor.cfg
fi

View File

@ -5,6 +5,9 @@ Setup API Test
Should Be Equal As Integers ${rc} 0 Should Be Equal As Integers ${rc} 0
Harbor API Test Harbor API Test
[Arguments] ${testcase_name} [Arguments] ${testcase_name}
${rc} ${output}= Run And Return Rc And Output SWAGGER_CLIENT_PATH=./harborclient HARBOR_HOST=${ip} python ${testcase_name} ${current_dir}= Run pwd
Log ${output} 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 Should Be Equal As Integers ${rc} 0

View File

@ -0,0 +1,31 @@
*** Settings ***
Documentation Harbor BATs
Resource ../../resources/APITest-Util.robot
Resource ../../resources/Docker-Util.robot
Library ../../apitests/python/library/Harbor.py ${SERVER_CONFIG}
Library OperatingSystem
Library String
Library Collections
Library requests
Library Process
Default Tags APIDB
*** Variables ***
${SERVER} ${ip}
${SERVER_URL} https://${SERVER}
${SERVER_API_ENDPOINT} ${SERVER_URL}/api
&{SERVER_CONFIG} endpoint=${SERVER_API_ENDPOINT} verify_ssl=False
*** Test Cases ***
Test Case - Create Project
${project_id} ${project_name} = Create Project
Log To Console ${project_name}
Test Case - Push Image
Sleep 1
Docker Pull hello-world:latest
${project_id} ${project_name} = Create Project
Log To Console ${project_name}
Docker Login ${SERVER} admin Harbor12345
Docker Tag hello-world:latest ${SERVER}/${project_name}/hello-world:1.0
Docker Push ${SERVER}/${project_name}/hello-world:1.0

View File

@ -0,0 +1,19 @@
*** Settings ***
Documentation Harbor BATs
Resource ../../resources/APITest-Util.robot
Library OperatingSystem
Library String
Library Collections
Library requests
Library Process
Default Tags API
*** Test Cases ***
Test Case - LDAP Group Admin Role
Harbor API Test ./tests/apitests/python/test_ldap_admin_role.py
Test Case - LDAP Group User Group
Harbor API Test ./tests/apitests/python/test_user_group.py
Test Case - Run LDAP Group Related API Test
Harbor API Test ./tests/apitests/python/test_assign_role_to_ldap_group.py

View File

@ -0,0 +1,26 @@
#!/bin/bash
set +e
sudo rm -fr /data/*
sudo mkdir -p /data
set -e
# prepare cert ...
sudo sed "s/127.0.0.1/$1/" -i tests/generateCerts.sh
sudo ./tests/generateCerts.sh
sudo mkdir -p /etc/docker/certs.d/$1 && sudo cp ./harbor_ca.crt /etc/docker/certs.d/$1/
if [ "$2" = 'LDAP' ]; then
sudo ./tests/hostcfg.sh LDAP
cd tests && sudo ./ldapprepare.sh && cd ..
fi
if [ "$2" = 'DB' ]; then
sudo ./tests/hostcfg.sh
fi
sudo apt-get update && sudo apt-get install -y --no-install-recommends python-dev openjdk-7-jdk libssl-dev && sudo apt-get autoremove -y && sudo rm -rf /var/lib/apt/lists/*
sudo wget https://bootstrap.pypa.io/get-pip.py && sudo python ./get-pip.py && sudo pip install --ignore-installed urllib3 chardet requests && sudo pip install robotframework robotframework-httplibrary requests dbbot robotframework-pabot --upgrade
sudo make swagger_client
sudo make install GOBUILDIMAGE=golang:1.9.2 COMPILETAG=compile_golangimage CLARITYIMAGE=goharbor/harbor-clarity-ui-builder:1.6.0 NOTARYFLAG=true CLAIRFLAG=true CHARTFLAG=true
sleep 10

13
tests/travis/api_run.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
set -e
docker ps
# run db auth api cases
if [ "$1" = 'DB' ]; then
pybot -v ip:$2 -v HARBOR_PASSWORD:Harbor12345 /home/travis/gopath/src/github.com/goharbor/harbor/tests/robot-cases/Group0-BAT/API_DB.robot
fi
# run ldap api cases
if [ "$1" = 'LDAP' ]; then
pybot -v ip:$2 -v HARBOR_PASSWORD:Harbor12345 /home/travis/gopath/src/github.com/goharbor/harbor/tests/robot-cases/Group0-BAT/API_LDAP.robot
fi

View File

@ -0,0 +1,39 @@
#!/bin/bash
set -e
cd ./src/portal
npm install -g -q --no-progress angular-cli
npm install -g -q --no-progress karma
npm install -q --no-progress
npm run build_lib && npm run link_lib && cd ../..
sudo apt-get update && sudo apt-get install -y libldap2-dev
go get -d github.com/docker/distribution
go get -d github.com/docker/libtrust
go get -d github.com/lib/pq
go get github.com/golang/lint/golint
go get github.com/GeertJohan/fgt
go get github.com/dghubble/sling
go get github.com/stretchr/testify
go get golang.org/x/tools/cmd/cover
go get github.com/mattn/goveralls
go get -u github.com/client9/misspell/cmd/misspell
sudo service postgresql stop
sleep 2
sudo -E env "PATH=$PATH" make go_check
sudo ./tests/hostcfg.sh
sudo ./tests/generateCerts.sh
sudo ./make/prepare
sudo mkdir -p "/data/redis"
sudo mkdir -p /etc/core/ca/ && sudo mv ./tests/ca.crt /etc/core/ca/
sudo mkdir -p /harbor && sudo mv ./VERSION /harbor/UIVERSION
sudo ./tests/testprepare.sh
cd tests && sudo ./ldapprepare.sh && sudo ./admiral.sh && cd ..
sudo make compile_adminserver
sudo make -f make/photon/Makefile _build_adminserver _build_db _build_registry -e VERSIONTAG=dev -e CLAIRDBVERSION=dev -e REGISTRYVERSION=${REG_VERSION}
sudo sed -i 's/__reg_version__/${REG_VERSION}-dev/g' ./make/docker-compose.test.yml
sudo sed -i 's/__version__/dev/g' ./make/docker-compose.test.yml
sudo mkdir -p ./make/common/config/registry/ && sudo mv ./tests/reg_config.yml ./make/common/config/registry/config.yml

19
tests/travis/ut_run.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
export POSTGRESQL_HOST=$1
export REGISTRY_URL=$1:5000
export CHROME_BIN=chromium-browser
export DISPLAY=:99.0
sh -e /etc/init.d/xvfb start
cd ./src/portal && npm run lint && npm run lint:lib && npm run test && cd -
sudo docker-compose -f ./make/docker-compose.test.yml up -d
sleep 10
./tests/pushimage.sh
docker ps
go test -race -i ./src/core ./src/adminserver ./src/jobservice
sudo -E env "PATH=$PATH" "POSTGRES_MIGRATION_SCRIPTS_PATH=/home/travis/gopath/src/github.com/goharbor/harbor/make/migrations/postgresql/" ./tests/coverage4gotest.sh
goveralls -coverprofile=profile.cov -service=travis-ci