Skip to content

Commit

Permalink
Merge branch 'master' of github.com:srl-labs/containerlab into keepmg…
Browse files Browse the repository at this point in the history
…mtnet
  • Loading branch information
steiler committed Jun 18, 2021
2 parents cab4781 + f92fadd commit 98b93de
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion runtime/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {

func (c *ContainerdRuntime) Init(opts ...runtime.RuntimeOption) error {
var err error
log.Info("Runtime: containerd")
log.Debug("Runtime: containerd")
c.keepMgmtNet = false
c.client, err = containerd.New("/run/containerd/containerd.sock")
if err != nil {
Expand Down
24 changes: 19 additions & 5 deletions runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type DockerRuntime struct {

func (c *DockerRuntime) Init(opts ...runtime.RuntimeOption) error {
var err error
log.Info("Runtime: Docker")
log.Debug("Runtime: Docker")
c.keepMgmtNet = false
c.Client, err = dockerC.NewClientWithOpts(dockerC.FromEnv, dockerC.WithAPIVersionNegotiation())
if err != nil {
Expand Down Expand Up @@ -371,17 +371,31 @@ func (c *DockerRuntime) ListContainers(ctx context.Context, gfilters []*types.Ge
}
var nr []dockerTypes.NetworkResource
if c.Mgmt.Network == "" {
netFilter := filters.NewArgs()
netFilter.Add("label", "containerlab")
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: netFilter,
Filters: f,
})

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 98b93de

Please sign in to comment.