Skip to content

Commit

Permalink
refactored tests to accommodate for containerd
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Jun 15, 2021
1 parent fa56d64 commit 095f043
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 23 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
29 changes: 19 additions & 10 deletions tests/01-smoke/01-basic-flow.robot
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions tests/01-smoke/01-linux-nodes.clab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions tests/01-smoke/01-linux-single-node.clab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ topology:
l1:
kind: linux
image: alpine:3
cmd: ash -c "sleep 9999"
13 changes: 8 additions & 5 deletions tests/01-smoke/02-destroy-all.robot
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions tests/01-smoke/03-bridge.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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}
1 change: 1 addition & 0 deletions tests/01-smoke/03-linux-nodes-to-bridge.clab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ topology:
l1:
kind: linux
image: alpine:3
cmd: ash -c "sleep 9999"
br-clab:
kind: bridge

Expand Down
7 changes: 4 additions & 3 deletions tests/01-smoke/04-generate.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 4 additions & 1 deletion tests/rf-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
robot --consolecolors on -r none --variable runtime:$1 -l ./tests/out/$(basename $2)-$1-log --output ./tests/out/$(basename $2)-$1-out $2

0 comments on commit 095f043

Please sign in to comment.