Skip to content

Commit

Permalink
cicd, tests: Make tests run sudoless
Browse files Browse the repository at this point in the history
  • Loading branch information
vista- committed Jan 30, 2025
1 parent 2845390 commit b886c5d
Show file tree
Hide file tree
Showing 41 changed files with 152 additions and 151 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ jobs:
with:
name: containerlab
- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VER }}
Expand Down Expand Up @@ -226,7 +226,7 @@ jobs:
with:
name: containerlab
- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VER }}
Expand Down Expand Up @@ -289,7 +289,7 @@ jobs:
with:
name: containerlab
- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VER }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cisco_iol-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
name: containerlab

- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab

- uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fortigate-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
name: containerlab

- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab

- uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/kind-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
name: containerlab

- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab

- uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
name: containerlab

- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab

- name: Setup Podman
if: matrix.runtime == 'podman'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/srlinux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
name: containerlab

- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab

- name: Setup Podman
if: matrix.runtime == 'podman'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sros-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
name: containerlab

- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab

- uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vxlan-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
name: containerlab

- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chown root:root /usr/bin/containerlab && sudo chown 4755 /usr/bin/containerlab

- uses: actions/setup-python@v5
with:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ifndef suite
override suite = .
endif
robot-test: build-with-podman-debug
sudo chown root:root $(BINARY) && sudo chmod 4755 $(BINARY)
CLAB_BIN=$(BINARY) $$PWD/tests/rf-run.sh $(runtime) $$PWD/tests/$(suite)

MOCKDIR = ./mocks
Expand Down
28 changes: 14 additions & 14 deletions tests/01-smoke/01-basic-flow.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Library String
Library Process
Resource ../common.robot

Suite Teardown Run sudo -E ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/01-linux-nodes.clab.yml --cleanup
Suite Teardown Run ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/01-linux-nodes.clab.yml --cleanup


*** Variables ***
Expand All @@ -29,7 +29,7 @@ Verify number of Hosts entries before deploy
Deploy ${lab-name} lab
Log ${CURDIR}
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab-file}
... ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab-file}
Log ${output}
Should Be Equal As Integers ${rc} 0
# save output to be used in next steps
Expand All @@ -44,7 +44,7 @@ Ensure exec node option works
Exec command with no filtering
[Documentation] This tests ensures that when `exec` command is called without user provided filters, the command is executed on all nodes of the lab.
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --cmd 'uname -n'
... ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --cmd 'uname -n'
Log ${output}
Should Be Equal As Integers ${rc} 0
# check if output contains the escaped string, as this is how logrus prints to non tty outputs.
Expand All @@ -61,7 +61,7 @@ Exec command with no filtering
Exec command with filtering
[Documentation] This tests ensures that when `exec` command is called with user provided filters, the command is executed ONLY on selected nodes of the lab.
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --cmd 'uname -n'
... ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --cmd 'uname -n'
Log ${output}
Should Be Equal As Integers ${rc} 0
# check if output contains the escaped string, as this is how logrus prints to non tty outputs.
Expand All @@ -74,7 +74,7 @@ Exec command with filtering
Exec command with json output and filtering
[Documentation] This tests ensures that when `exec` command is called with user provided filters and json output, the command is executed ONLY on selected nodes of the lab and the actual JSON is populated to stdout.
${output} = Process.Run Process
... sudo -E ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --format json --cmd 'cat /test.json' | jq '.[][0].stdout.containerlab'
... ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --format json --cmd 'cat /test.json' | jq '.[][0].stdout.containerlab'
... shell=True
Log ${output.stdout}
Log ${output.stderr}
Expand All @@ -87,7 +87,7 @@ Ensure CLAB_INTFS env var is set
... This test ensures that the CLAB_INTFS environment variable is set in the container
... and that it contains the correct number of interfaces.
${output} = Process.Run Process
... sudo -E ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --cmd 'ash -c "echo $CLAB_INTFS"'
... ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --cmd 'ash -c "echo $CLAB_INTFS"'
... shell=True
Log ${output.stdout}
Log ${output.stderr}
Expand All @@ -104,7 +104,7 @@ Ensure default no_proxy env var is set
... This test ensures that the NO_PROXY env var is populated by clab automatically
... with the relevant addresses and names
${output} = Process.Run Process
... sudo -E ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --cmd 'ash -c "echo $NO_PROXY"'
... ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --cmd 'ash -c "echo $NO_PROXY"'
... shell=True
Log ${output.stdout}
Log ${output.stderr}
Expand All @@ -116,7 +116,7 @@ Ensure default no_proxy env var is set

Inspect ${lab-name} lab using its name
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} inspect --name ${lab-name}
... ${CLAB_BIN} --runtime ${runtime} inspect --name ${lab-name}
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand Down Expand Up @@ -203,7 +203,7 @@ Verify links on host

Ensure "inspect all" outputs IP addresses
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} inspect --all
... ${CLAB_BIN} --runtime ${runtime} inspect --all
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand Down Expand Up @@ -371,7 +371,7 @@ Verify DNS-Options Config
Verify Exec rc == 0 on containers match
[Documentation] Checking that the return code is != 0 if on the exce call not containers match
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --cmd "echo test"
... ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --cmd "echo test"
Log ${output}
Should Contain ${output} test
Should Not Contain ${output} Error: filter did not match any containers
Expand All @@ -380,7 +380,7 @@ Verify Exec rc == 0 on containers match
Verify Exec rc != 0 on no containers match
[Documentation] Checking that the return code is != 0 if on the exce call not containers match
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name=nonexist --cmd "echo test"
... ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name=nonexist --cmd "echo test"
Log ${output}
Should Not Contain ${output} test
Should Contain ${output} Error: filter did not match any containers
Expand All @@ -403,7 +403,7 @@ Verify l1 node is healthy

Destroy ${lab-name} lab
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup
... ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand Down Expand Up @@ -449,7 +449,7 @@ Verify containerlab version
[Documentation] Ensures that 'containerlab version' subcommand runs successfully
... and prints basic version fields.
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} version
... ${CLAB_BIN} version
Log ${output}
# The command should exit with 0
Should Be Equal As Integers ${rc} 0
Expand All @@ -463,7 +463,7 @@ Verify containerlab version check
[Documentation] Ensures that 'containerlab version check' either says you're on latest version
... or that a new version is available. Also verifies the command succeeds.
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} version check
... ${CLAB_BIN} version check
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand Down
20 changes: 10 additions & 10 deletions tests/01-smoke/02-destroy-all.robot
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Library OperatingSystem
Library Process
Resource ../common.robot

Suite Teardown Run sudo -E ${CLAB_BIN} --runtime ${runtime} destroy --all --cleanup
Suite Teardown Run ${CLAB_BIN} --runtime ${runtime} destroy --all --cleanup


*** Variables ***
Expand All @@ -25,7 +25,7 @@ ${lab2-name} single-node
*** Test Cases ***
Deploy first lab
${result} = Run Process
... sudo -E ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab1-file}
... ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab1-file}
... shell=True
Log ${result.stdout}
Log ${result.stderr}
Expand All @@ -36,7 +36,7 @@ Deploy first lab

Deploy second lab
${result} = Run Process
... sudo -E ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab2-file}
... ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab2-file}
... cwd=/tmp # using a different cwd to check lab resolution via container labels
... shell=True
Log ${result.stdout}
Expand All @@ -46,7 +46,7 @@ Deploy second lab

Inspect ${lab2-name} lab using its name
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} inspect --name ${lab2-name}
... ${CLAB_BIN} --runtime ${runtime} inspect --name ${lab2-name}
Log \n--> LOG: Inspect output\n${output} console=True
Should Be Equal As Integers ${rc} 0

Expand All @@ -57,7 +57,7 @@ Inspect ${lab2-name} lab using its name

Inspect ${lab2-name} lab using topology file reference
${result} = Run Process
... sudo -E ${CLAB_BIN} --runtime ${runtime} inspect -t ${orig_dir}/${lab2-file}
... ${CLAB_BIN} --runtime ${runtime} inspect -t ${orig_dir}/${lab2-file}
... shell=True
Log \n--> LOG: Inspect output\n${result.stdout} console=True
Log ${result.stderr}
Expand All @@ -69,7 +69,7 @@ Inspect ${lab2-name} lab using topology file reference

Inspect all
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} inspect --all
... ${CLAB_BIN} --runtime ${runtime} inspect --all
Log \n--> LOG: Inspect all output\n${output} console=True
Should Be Equal As Integers ${rc} 0

Expand All @@ -90,13 +90,13 @@ Verify host mode networking for node l3
Verify ipv4-range is set correctly
Skip If '${runtime}' != 'docker'
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} inspect -t ${CURDIR}/01-linux-single-node.clab.yml
... ${CLAB_BIN} --runtime ${runtime} inspect -t ${CURDIR}/01-linux-single-node.clab.yml
Log ${output}
Should Contain ${output} 172.20.30.9

Redeploy second lab
${result} = Run Process
... sudo -E ${CLAB_BIN} --runtime ${runtime} redeploy -c -t ${CURDIR}/${lab2-file}
... ${CLAB_BIN} --runtime ${runtime} redeploy -c -t ${CURDIR}/${lab2-file}
... cwd=/tmp # using a different cwd to check lab resolution via container labels
... shell=True
Log ${result.stdout}
Expand All @@ -106,13 +106,13 @@ Redeploy second lab

Destroy all labs
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} destroy --all --cleanup
... ${CLAB_BIN} --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 -E ${CLAB_BIN} --runtime ${runtime} inspect --all
... ${CLAB_BIN} --runtime ${runtime} inspect --all
Log ${output}
Should Contain ${output} no containers found
Should Not Exist /tmp/single-node
Expand Down
6 changes: 3 additions & 3 deletions tests/01-smoke/03-bridges-and-host.robot
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Create linux bridge

Deploy ${lab-name} lab
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} deploy --skip-labdir-acl -t ${CURDIR}/${lab-file}
... ${CLAB_BIN} --runtime ${runtime} deploy --skip-labdir-acl -t ${CURDIR}/${lab-file}
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand All @@ -58,7 +58,7 @@ Verify management network is using user-specified bridge
# show management interface info and cut the information about the ifindex of the remote veth
# note that exec returns the info in the stderr stream, thus we use stderr to parse the ifindex
${rc} ${iface} = OperatingSystem.Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --cmd "ip l show eth0" 2>&1 | perl -lne '/.*[0-9]+: .*\\@if(.*:) .*/ && print $1'
... ${CLAB_BIN} --runtime ${runtime} exec -t ${CURDIR}/${lab-file} --label clab-node-name\=l1 --cmd "ip l show eth0" 2>&1 | perl -lne '/.*[0-9]+: .*\\@if(.*:) .*/ && print $1'
Log ${iface}
Should Be Equal As Integers ${rc} 0
${rc} ${res} = OperatingSystem.Run And Return Rc And Output
Expand Down Expand Up @@ -115,7 +115,7 @@ Setup

Cleanup
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup
... ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand Down
8 changes: 4 additions & 4 deletions tests/01-smoke/04-generate.robot
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ ${runtime} docker
Deploy ${lab-name} lab with generate command
Skip If '${runtime}' != 'docker'
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} generate --name ${lab-name} --kind linux --image ghcr.io/srl-labs/network-multitool --nodes 2,1,1 --deploy
... ${CLAB_BIN} --runtime ${runtime} generate --name ${lab-name} --kind linux --image ghcr.io/srl-labs/network-multitool --nodes 2,1,1 --deploy
Log ${output}
Should Be Equal As Integers ${rc} 0

Verify nodes
Skip If '${runtime}' != 'docker'
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} inspect --name ${lab-name}
... ${CLAB_BIN} --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 @@ -34,7 +34,7 @@ Deploy ${lab-name}-scale lab with generate command
... This test verifies that scaled topology can be deployed without concurrent errors.
Skip If '${runtime}' != 'docker'
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} generate --name ${lab-name}-scale --kind linux --image alpine:3 --nodes 5,5,5 --deploy
... ${CLAB_BIN} --runtime ${runtime} generate --name ${lab-name}-scale --kind linux --image alpine:3 --nodes 5,5,5 --deploy
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Not Contain ${output} failed
Expand All @@ -49,7 +49,7 @@ Cleanup

Skip If '${runtime}' != 'docker'
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} destroy -t ${lab-name}.clab.yml --cleanup
... ${CLAB_BIN} --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
Loading

0 comments on commit b886c5d

Please sign in to comment.