From 095f04388eb45e114278d8dcdbcda2cfa8641909 Mon Sep 17 00:00:00 2001 From: Roman Dodin Date: Tue, 15 Jun 2021 15:28:59 +0200 Subject: [PATCH] refactored tests to accommodate for containerd --- .github/workflows/cicd.yml | 7 +++-- tests/01-smoke/01-basic-flow.robot | 29 ++++++++++++------- tests/01-smoke/01-linux-nodes.clab.yml | 2 ++ tests/01-smoke/01-linux-single-node.clab.yml | 1 + tests/01-smoke/02-destroy-all.robot | 13 +++++---- tests/01-smoke/03-bridge.robot | 5 ++-- .../03-linux-nodes-to-bridge.clab.yml | 1 + tests/01-smoke/04-generate.robot | 7 +++-- tests/rf-run.sh | 5 +++- 9 files changed, 47 insertions(+), 23 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 3f4e8230d..376b56011 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -78,8 +78,11 @@ jobs: curl https://htmltest.wjdp.uk | bash ./bin/htmltest -c docs/htmltest.yml - smoke-tests: + smoke-tests-docker: runs-on: ubuntu-20.04 + strategy: + matrix: + runtime: ["docker", "containerd"] needs: - staticcheck - unit-test @@ -103,7 +106,7 @@ jobs: pip install -r tests/requirements.txt - name: Run smoke tests run: | - bash ./tests/rf-run.sh ./tests/01-smoke + bash ./tests/rf-run.sh ${{ matrix.runtime }} ./tests/01-smoke # upload test reports as a zip file - uses: actions/upload-artifact@v2 if: always() diff --git a/tests/01-smoke/01-basic-flow.robot b/tests/01-smoke/01-basic-flow.robot index 41691d242..27dea43fb 100644 --- a/tests/01-smoke/01-basic-flow.robot +++ b/tests/01-smoke/01-basic-flow.robot @@ -1,52 +1,61 @@ *** Settings *** Library OperatingSystem Library String -Suite Teardown Run sudo containerlab destroy -t ${CURDIR}/01-linux-nodes.clab.yml --cleanup +Suite Teardown Run sudo containerlab --runtime ${runtime} destroy -t ${CURDIR}/01-linux-nodes.clab.yml --cleanup *** Variables *** ${lab-name} 2-linux-nodes +${runtime} docker +# runtime command to execute tasks in a container +# defaults to docker exec. Will be rewritten to containerd `ctr` if needed in "Define runtime exec" test +${runtime-cli-exec-cmd} sudo docker exec *** Test Cases *** Deploy ${lab-name} lab Log ${CURDIR} ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab deploy -t ${CURDIR}/01-linux-nodes.clab.yml + ... sudo containerlab --runtime ${runtime} deploy -t ${CURDIR}/01-linux-nodes.clab.yml Log ${output} Should Be Equal As Integers ${rc} 0 Inspect ${lab-name} lab ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab inspect -n ${lab-name} + ... sudo containerlab --runtime ${runtime} inspect -n ${lab-name} Log ${output} Should Be Equal As Integers ${rc} 0 +Define runtime exec command + IF "${runtime}" == "containerd" + Set Suite Variable ${runtime-cli-exec-cmd} sudo ctr -n clab t exec --exec-id clab + END + Verify links in node l1 ${rc} ${output} = Run And Return Rc And Output - ... sudo docker exec clab-${lab-name}-l1 ip link show eth1 + ... ${runtime-cli-exec-cmd} clab-${lab-name}-l1 ip link show eth1 Log ${output} Should Be Equal As Integers ${rc} 0 Should Contain ${output} state UP ${rc} ${output} = Run And Return Rc And Output - ... sudo docker exec clab-${lab-name}-l1 ip link show eth2 + ... ${runtime-cli-exec-cmd} clab-${lab-name}-l1 ip link show eth2 Log ${output} Should Be Equal As Integers ${rc} 0 Should Contain ${output} state UP Verify links in node l2 ${rc} ${output} = Run And Return Rc And Output - ... sudo docker exec clab-${lab-name}-l2 ip link show eth1 + ... ${runtime-cli-exec-cmd} clab-${lab-name}-l2 ip link show eth1 Log ${output} Should Be Equal As Integers ${rc} 0 Should Contain ${output} state UP ${rc} ${output} = Run And Return Rc And Output - ... sudo docker exec clab-${lab-name}-l2 ip link show eth2 + ... ${runtime-cli-exec-cmd} clab-${lab-name}-l2 ip link show eth2 Log ${output} Should Be Equal As Integers ${rc} 0 Should Contain ${output} state UP Ensure "inspect all" outputs IP addresses ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab inspect --all + ... sudo containerlab --runtime ${runtime} inspect --all Log ${output} Should Be Equal As Integers ${rc} 0 ${line} = String.Get Line ${output} -2 @@ -58,10 +67,10 @@ Ensure "inspect all" outputs IP addresses Should Match Regexp ${ipv4} ^[\\d\\.]+/\\d{1,2}$ # verify ipv6 address ${ipv6} = String.Strip String ${data}[11] - Should Match Regexp ${ipv6} ^[\\d:]+/\\d{1,2}$ + Should Match Regexp ${ipv6} ^[\\d:abcdef]+/\\d{1,2}$ Destroy ${lab-name} lab ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab destroy -t ${CURDIR}/01-linux-nodes.clab.yml --cleanup + ... sudo containerlab --runtime ${runtime} destroy -t ${CURDIR}/01-linux-nodes.clab.yml --cleanup Log ${output} Should Be Equal As Integers ${rc} 0 diff --git a/tests/01-smoke/01-linux-nodes.clab.yml b/tests/01-smoke/01-linux-nodes.clab.yml index 53788f097..edb0878ea 100644 --- a/tests/01-smoke/01-linux-nodes.clab.yml +++ b/tests/01-smoke/01-linux-nodes.clab.yml @@ -9,9 +9,11 @@ topology: l1: kind: linux image: alpine:3 + cmd: ash -c "sleep 9999" l2: kind: linux image: alpine:3 + cmd: ash -c "sleep 9999" links: - endpoints: ["l1:eth1", "l2:eth1"] diff --git a/tests/01-smoke/01-linux-single-node.clab.yml b/tests/01-smoke/01-linux-single-node.clab.yml index c94f395e8..c30c39df7 100644 --- a/tests/01-smoke/01-linux-single-node.clab.yml +++ b/tests/01-smoke/01-linux-single-node.clab.yml @@ -9,3 +9,4 @@ topology: l1: kind: linux image: alpine:3 + cmd: ash -c "sleep 9999" diff --git a/tests/01-smoke/02-destroy-all.robot b/tests/01-smoke/02-destroy-all.robot index 7c764b858..648219690 100644 --- a/tests/01-smoke/02-destroy-all.robot +++ b/tests/01-smoke/02-destroy-all.robot @@ -1,28 +1,31 @@ *** Settings *** Library OperatingSystem -Suite Teardown Run sudo containerlab destroy --all --cleanup +Suite Teardown Run sudo containerlab --runtime ${runtime} destroy --all --cleanup + +*** Variables *** +${runtime} docker *** Test Cases *** Deploy first lab ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab deploy -t ${CURDIR}/01-linux-nodes.clab.yml + ... sudo containerlab --runtime ${runtime} deploy -t ${CURDIR}/01-linux-nodes.clab.yml Log ${output} Should Be Equal As Integers ${rc} 0 Deploy second lab ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab deploy -t ${CURDIR}/01-linux-single-node.clab.yml + ... sudo containerlab --runtime ${runtime} deploy -t ${CURDIR}/01-linux-single-node.clab.yml Log ${output} Should Be Equal As Integers ${rc} 0 Destroy all labs ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab destroy --all --cleanup + ... sudo containerlab --runtime ${runtime} destroy --all --cleanup Log ${output} Should Be Equal As Integers ${rc} 0 Check all labs have been removed ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab inspect --all + ... sudo containerlab --runtime ${runtime} inspect --all Log ${output} Should Contain ${output} no containers found diff --git a/tests/01-smoke/03-bridge.robot b/tests/01-smoke/03-bridge.robot index 8263ff4d0..c87890ed7 100644 --- a/tests/01-smoke/03-bridge.robot +++ b/tests/01-smoke/03-bridge.robot @@ -9,6 +9,7 @@ ${lab-file} 03-linux-nodes-to-bridge.clab.yml ${bridge-name} br-clab ${br-link1-name} l1-eth1 ${br-link2-name} l1-eth2 +${runtime} docker *** Test Cases *** Create linux bridge @@ -19,7 +20,7 @@ Create linux bridge Deploy ${lab-name} lab ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab deploy -t ${CURDIR}/${lab-file} + ... sudo containerlab --runtime ${runtime} deploy -t ${CURDIR}/${lab-file} Log ${output} Should Be Equal As Integers ${rc} 0 @@ -35,5 +36,5 @@ Verify links in bridge *** Keywords *** Cleanup - Run sudo containerlab destroy -t ${CURDIR}/${lab-file} --cleanup + Run sudo containerlab --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup Run sudo ip l del ${bridge-name} diff --git a/tests/01-smoke/03-linux-nodes-to-bridge.clab.yml b/tests/01-smoke/03-linux-nodes-to-bridge.clab.yml index b27f024b9..f22d03cb2 100644 --- a/tests/01-smoke/03-linux-nodes-to-bridge.clab.yml +++ b/tests/01-smoke/03-linux-nodes-to-bridge.clab.yml @@ -9,6 +9,7 @@ topology: l1: kind: linux image: alpine:3 + cmd: ash -c "sleep 9999" br-clab: kind: bridge diff --git a/tests/01-smoke/04-generate.robot b/tests/01-smoke/04-generate.robot index 5393821c5..ff783b7aa 100644 --- a/tests/01-smoke/04-generate.robot +++ b/tests/01-smoke/04-generate.robot @@ -4,17 +4,18 @@ Suite Teardown Cleanup *** Variables *** ${lab-name} 3-clab-gen +${runtime} docker *** Test Cases *** Deploy ${lab-name} lab with generate command ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab generate --name ${lab-name} --kind linux --image alpine:latest --nodes 2,1,1 --deploy + ... sudo containerlab --runtime ${runtime} generate --name ${lab-name} --kind linux --image ghcr.io/hellt/network-multitool --nodes 2,1,1 --deploy Log ${output} Should Be Equal As Integers ${rc} 0 Verify nodes ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab inspect --name ${lab-name} + ... sudo containerlab --runtime ${runtime} inspect --name ${lab-name} Log ${output} Should Be Equal As Integers ${rc} 0 Should Contain ${output} clab-${lab-name}-node1-1 @@ -25,7 +26,7 @@ Verify nodes *** Keywords *** Cleanup ${rc} ${output} = Run And Return Rc And Output - ... sudo containerlab destroy -t ${lab-name}.clab.yml --cleanup + ... sudo containerlab --runtime ${runtime} destroy -t ${lab-name}.clab.yml --cleanup Log ${output} Should Be Equal As Integers ${rc} 0 OperatingSystem.Remove File ${lab-name}.clab.yml diff --git a/tests/rf-run.sh b/tests/rf-run.sh index 79272bf0a..2253101f1 100755 --- a/tests/rf-run.sh +++ b/tests/rf-run.sh @@ -3,5 +3,8 @@ # Licensed under the BSD 3-Clause License. # SPDX-License-Identifier: BSD-3-Clause +# arguments +# $1 - container runtime: [docker, containerd] +# $2 - test suite to execute -robot --consolecolors on -r none -l ./tests/out/$(basename $1)-log --output ./tests/out/$(basename $1)-out $1 \ No newline at end of file +robot --consolecolors on -r none --variable runtime:$1 -l ./tests/out/$(basename $2)-$1-log --output ./tests/out/$(basename $2)-$1-out $2 \ No newline at end of file