Skip to content

Commit

Permalink
refactored filtering procedure + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Jun 17, 2021
1 parent c8142b6 commit 38b11a3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
20 changes: 19 additions & 1 deletion runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,29 @@ func (c *DockerRuntime) ListContainers(ctx context.Context, gfilters []*types.Ge
if c.Mgmt.Network == "" {
nctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
// fetch containerlab created networks
f := filters.NewArgs()
f.Add("label", "containerlab")
nr, err = c.Client.NetworkList(nctx, dockerTypes.NetworkListOptions{
Filters: f,
})

nr, err = c.Client.NetworkList(nctx, dockerTypes.NetworkListOptions{})
if err != nil {
return nil, err
}

// fetch default bridge network
f = filters.NewArgs()
f.Add("name", "bridge")
bridgenet, err := c.Client.NetworkList(nctx, dockerTypes.NetworkListOptions{
Filters: f,
})

if err != nil {
return nil, err
}

nr = append(nr, bridgenet...)
}
return c.produceGenericContainerList(ctrs, nr)
}
Expand Down
15 changes: 15 additions & 0 deletions tests/01-smoke/05-docker-bridge.clab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Nokia
# Licensed under the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause

name: 05-docker-bridge
# use the default docker network named "bridge"
mgmt:
network: bridge

topology:
nodes:
l1:
kind: linux
image: alpine:3
cmd: ash -c "sleep 9999"
34 changes: 34 additions & 0 deletions tests/01-smoke/05-docker-bridge.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
*** Settings ***
Library OperatingSystem
Library String
Suite Teardown Cleanup

*** Variables ***
${lab-name} 05-docker-bridge
${lab-file} 05-docker-bridge.clab.yml
${runtime} docker

*** Test Cases ***
Deploy ${lab-name} lab
${rc} ${output} = Run And Return Rc And Output
... sudo containerlab --runtime ${runtime} deploy -t ${CURDIR}/${lab-file}
Log ${output}
Should Be Equal As Integers ${rc} 0

Ensure inspect outputs IP addresses
${rc} ${output} = Run And Return Rc And Output
... sudo containerlab --runtime ${runtime} inspect -n ${lab-name}
Log ${output}
Should Be Equal As Integers ${rc} 0
${line} = String.Get Line ${output} -2
Log ${line}
@{data} = Split String ${line} |
Log ${data}
# verify ipv4 address
${ipv4} = String.Strip String ${data}[8]
Should Match Regexp ${ipv4} ^[\\d\\.]+/\\d{1,2}$

*** Keywords ***
Cleanup
${rc} ${output} = Run And Return Rc And Output sudo containerlab --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup
Log ${output}

0 comments on commit 38b11a3

Please sign in to comment.