2018-09-19 18:57:15 +02:00
# Copyright Project Harbor Authors
2017-08-07 08:02:38 +02:00
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
*** Settings ***
Documentation This resource provides helper functions for docker operations
Library OperatingSystem
Library Process
*** Keywords ***
Run Docker Info
[Arguments] ${docker-params}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker ${docker-params} info
2017-08-07 08:02:38 +02:00
Pull image
2019-11-29 07:28:51 +01:00
[Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag}=${null} ${is_robot}=${false}
2017-08-07 08:02:38 +02:00
Log To Console \nRunning docker pull ${image}...
2019-08-21 08:12:12 +02:00
${image_with_tag}= Set Variable If '${tag}'=='${null}' ${image} ${image}:${tag}
2019-11-29 07:28:51 +01:00
Run Keyword If ${is_robot}==${false} Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip}
... ELSE Wait Unitl Command Success docker login -u robot\\\$${user} -p ${pwd} ${ip}
2019-12-31 04:31:52 +01:00
${output}= Docker Pull ${ip}/${project}/${image_with_tag}
Log ${output}
Log To Console ${output}
2017-08-07 08:02:38 +02:00
Should Contain ${output} Digest:
Should Contain ${output} Status:
Should Not Contain ${output} No such image:
Push image
2019-11-29 07:28:51 +01:00
[Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${sha256}=${null} ${is_robot}=${false}
2019-09-12 07:56:56 +02:00
${image_with_sha256}= Set Variable If '${sha256}'=='${null}' ${image} ${image}@sha256:${sha256}
${image_with_tag}= Set Variable If '${sha256}'=='${null}' ${image} ${image}:${sha256}
2020-05-29 10:17:10 +02:00
Sleep 3
2019-09-12 07:56:56 +02:00
Log To Console \nRunning docker push ${image}...
2020-01-14 04:11:12 +01:00
Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image_with_sha256}
2019-11-29 07:28:51 +01:00
Run Keyword If ${is_robot}==${false} Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip}
... ELSE Wait Unitl Command Success docker login -u robot\\\$${user} -p ${pwd} ${ip}
2020-01-14 04:11:12 +01:00
Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image_with_sha256} ${ip}/${project}/${image_with_tag}
2019-07-24 04:56:42 +02:00
Wait Unitl Command Success docker push ${ip}/${project}/${image_with_tag}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker logout ${ip}
2019-09-12 07:56:56 +02:00
Sleep 1
2017-09-07 12:29:05 +02:00
Push Image With Tag
2019-05-30 09:59:09 +02:00
#tag1 is tag of image on docker hub,default latest,use a version existing if you do not want to use latest
2018-03-20 06:25:03 +01:00
[Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag} ${tag1}=latest
2017-09-07 12:29:05 +02:00
Log To Console \nRunning docker push ${image}...
2020-01-14 04:11:12 +01:00
Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image}:${tag1}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip}
2020-01-14 04:11:12 +01:00
Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image}:${tag1} ${ip}/${project}/${image}:${tag}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker push ${ip}/${project}/${image}:${tag}
Wait Unitl Command Success docker logout ${ip}
2017-08-07 08:02:38 +02:00
2019-05-24 09:45:08 +02:00
Cannot Docker Login Harbor
[Arguments] ${ip} ${user} ${pwd}
Command Should be Failed docker login -u ${user} -p ${pwd} ${ip}
2020-05-29 10:17:10 +02:00
Cannot Pull Image
[Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${tag}=${null} ${err_msg}=${null}
2019-07-24 04:56:42 +02:00
${image_with_tag}= Set Variable If '${tag}'=='${null}' ${image} ${image}:${tag}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip}
2020-05-29 10:17:10 +02:00
:FOR ${idx} IN RANGE 0 4
\ ${out} Run Keyword And Ignore Error Command Should be Failed docker pull ${ip}/${project}/${image_with_tag}
\ Exit For Loop If '${out[0]}'=='PASS'
\ Sleep 3
Log To Console Cannot Pull Image - Pull Log: ${out[1]}
Should Be Equal As Strings '${out[0]}' 'PASS'
Run Keyword If '${err_msg}' != '${null}' Should Contain ${out[1]} ${err_msg}
2017-08-07 08:02:38 +02:00
2017-11-03 07:36:40 +01:00
Cannot Pull Unsigned Image
2019-05-24 09:45:08 +02:00
[Arguments] ${ip} ${user} ${pass} ${proj} ${imagewithtag}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker login -u ${user} -p ${pass} ${ip}
2019-05-24 09:45:08 +02:00
${output}= Command Should be Failed docker pull ${ip}/${proj}/${imagewithtag}
2020-05-08 05:52:42 +02:00
Log To Console ${output}
2017-11-03 07:36:40 +01:00
Should Contain ${output} The image is not signed in Notary
2017-09-07 12:29:05 +02:00
Cannot Push image
2020-05-19 04:16:40 +02:00
[Arguments] ${ip} ${user} ${pwd} ${project} ${image} ${err_msg}=${null} ${err_msg_2}=${null}
2017-09-07 12:29:05 +02:00
Log To Console \nRunning docker push ${image}...
2020-01-14 04:11:12 +01:00
Docker Pull ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker login -u ${user} -p ${pwd} ${ip}
2020-01-14 04:11:12 +01:00
Wait Unitl Command Success docker tag ${LOCAL_REGISTRY}/${LOCAL_REGISTRY_NAMESPACE}/${image} ${ip}/${project}/${image}
2019-09-12 07:56:56 +02:00
${output}= Command Should be Failed docker push ${ip}/${project}/${image}
Run Keyword If '${err_msg}' != '${null}' Should Contain ${output} ${err_msg}
2020-05-19 04:16:40 +02:00
Run Keyword If '${err_msg_2}' != '${null}' Should Contain ${output} ${err_msg_2}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker logout ${ip}
2017-09-07 12:29:05 +02:00
2017-08-07 08:02:38 +02:00
Wait Until Container Stops
[Arguments] ${container}
:FOR ${idx} IN RANGE 0 60
\ ${out}= Run docker %{VCH-PARAMS} inspect ${container} | grep Status
\ ${status}= Run Keyword And Return Status Should Contain ${out} exited
\ Return From Keyword If ${status}
\ Sleep 1
Fail Container did not stop within 60 seconds
Hit Nginx Endpoint
[Arguments] ${vch-ip} ${port}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success wget ${vch-ip}:${port}
2017-08-07 08:02:38 +02:00
Get Container IP
[Arguments] ${docker-params} ${id} ${network}=default ${dockercmd}=docker
2019-01-31 09:08:58 +01:00
${ip}= Wait Unitl Command Success ${dockercmd} ${docker-params} network inspect ${network} | jq '.[0].Containers."${id}".IPv4Address' | cut -d \\" -f 2 | cut -d \\/ -f 1
2017-08-07 08:02:38 +02:00
[Return] ${ip}
# The local dind version is embedded in Dockerfile
# docker:1.13-dind
# If you are running this keyword in a container, make sure it is run with --privileged turned on
Start Docker Daemon Locally
${pid}= Run pidof dockerd
2020-03-30 11:44:56 +02:00
#${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/docker_config.sh
#Log ${output}
#Should Be Equal As Integers ${rc} 0
2017-08-07 08:02:38 +02:00
Return From Keyword If '${pid}' != '${EMPTY}'
OperatingSystem.File Should Exist /usr/local/bin/dockerd-entrypoint.sh
${handle}= Start Process /usr/local/bin/dockerd-entrypoint.sh dockerd>./daemon-local.log 2>&1 shell=True
Process Should Be Running ${handle}
:FOR ${IDX} IN RANGE 5
\ ${pid}= Run pidof dockerd
\ Exit For Loop If '${pid}' != '${EMPTY}'
\ Sleep 2s
Sleep 2s
[Return] ${handle}
2018-01-23 06:04:19 +01:00
Prepare Docker Cert
[Arguments] ${ip}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success mkdir -p /etc/docker/certs.d/${ip}
2019-05-22 05:19:08 +02:00
Wait Unitl Command Success cp harbor_ca.crt /etc/docker/certs.d/${ip}
2020-03-30 11:44:56 +02:00
Wait Unitl Command Success cp harbor_ca.crt /usr/local/share/ca-certificates/
Wait Unitl Command Success update-ca-certificates
2019-05-22 05:19:08 +02:00
2017-08-07 08:02:38 +02:00
Kill Local Docker Daemon
[Arguments] ${handle} ${dockerd-pid}
Terminate Process ${handle}
Process Should Be Stopped ${handle}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success kill -9 ${dockerd-pid}
2017-11-29 12:29:51 +01:00
Docker Login Fail
[Arguments] ${ip} ${user} ${pwd}
Log To Console \nRunning docker login ${ip} ...
2019-05-24 09:45:08 +02:00
${output}= Command Should be Failed docker login -u ${user} -p ${pwd} ${ip}
2020-04-10 15:06:05 +02:00
Should Contain ${output} unauthorized
2018-03-20 06:25:03 +01:00
Should Not Contain ${output} 500 Internal Server Error
2018-08-16 12:36:27 +02:00
Docker Login
[Arguments] ${server} ${username} ${password}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker login -u ${username} -p ${password} ${server}
2018-08-16 12:36:27 +02:00
Docker Pull
[Arguments] ${image}
2020-05-22 04:56:03 +02:00
${output}= Retry Keyword N Times When Error 10 Wait Unitl Command Success docker pull ${image}
2019-12-31 04:31:52 +01:00
Log ${output}
Log To Console Docker Pull: \n ${output}
[Return] ${output}
2018-08-16 12:36:27 +02:00
Docker Tag
[Arguments] ${src_image} ${dst_image}
2019-01-31 09:08:58 +01:00
Wait Unitl Command Success docker tag ${src_image} ${dst_image}
2018-08-16 12:36:27 +02:00
Docker Push
[Arguments] ${image}
2019-05-24 09:45:08 +02:00
Wait Unitl Command Success docker push ${image}
2020-03-30 11:44:56 +02:00
Docker Push Index
[Arguments] ${ip} ${user} ${pwd} ${index} ${image1} ${image2}
2020-04-01 10:24:38 +02:00
${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/docker_push_manifest_list.sh ${ip} ${user} ${pwd} ${index} ${image1} ${image2}
2020-03-30 11:44:56 +02:00
Log ${output}
Should Be Equal As Integers ${rc} 0