Skip to content

Commit

Permalink
unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
networkop committed May 5, 2021
1 parent 3b139b0 commit f2e6124
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
33 changes: 33 additions & 0 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func WithTimeout(dur time.Duration) ClabOption {
func WithRuntime(name string, d bool, dur time.Duration, gracefulShutdown bool) ClabOption {
return func(c *CLab) {
c.Runtime = runtime.NewRuntime(name, d, dur, gracefulShutdown)
c.Runtime.SetMgmtNet(c.Config.Mgmt)
}
}

Expand Down Expand Up @@ -83,12 +84,44 @@ func NewContainerLab(opts ...ClabOption) *CLab {
Nodes: make(map[string]*types.Node),
Links: make(map[int]*Link),
}

err := c.initMgmtNetwork()
if err != nil {
log.Fatalf("initMgmtNetwork: %s", err)
}

for _, o := range opts {
o(c)
}

return c
}

// initMgmtNetwork sets management network config
func (c *CLab) initMgmtNetwork() error {
if c.Config.Mgmt.Network == "" {
c.Config.Mgmt.Network = dockerNetName
}
if c.Config.Mgmt.IPv4Subnet == "" && c.Config.Mgmt.IPv6Subnet == "" {
if c.Config.Mgmt.IPv4Subnet == "" {
c.Config.Mgmt.IPv4Subnet = dockerNetIPv4Addr
}
if c.Config.Mgmt.IPv6Subnet == "" {
c.Config.Mgmt.IPv6Subnet = dockerNetIPv6Addr
}
}
// init docker network mtu
if c.Config.Mgmt.MTU == "" {
m, err := getDefaultDockerMTU()
if err != nil {
log.Warnf("Error occurred during getting the default docker MTU: %v", err)
}
c.Config.Mgmt.MTU = m
}

return nil
}

func (c *CLab) CreateNode(ctx context.Context, node *types.Node, certs *Certificates) error {
if certs != nil {
c.m.Lock()
Expand Down
35 changes: 1 addition & 34 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,43 +144,10 @@ type Endpoint struct {
EndpointName string
}

// initMgmtNetwork sets management network config
func (c *CLab) initMgmtNetwork() error {
if c.Config.Mgmt.Network == "" {
c.Config.Mgmt.Network = dockerNetName
}
if c.Config.Mgmt.IPv4Subnet == "" && c.Config.Mgmt.IPv6Subnet == "" {
if c.Config.Mgmt.IPv4Subnet == "" {
c.Config.Mgmt.IPv4Subnet = dockerNetIPv4Addr
}
if c.Config.Mgmt.IPv6Subnet == "" {
c.Config.Mgmt.IPv6Subnet = dockerNetIPv6Addr
}
}
// init docker network mtu
if c.Config.Mgmt.MTU == "" {
m, err := getDefaultDockerMTU()
if err != nil {
log.Warnf("Error occurred during getting the default docker MTU: %v", err)
}
c.Config.Mgmt.MTU = m
}

c.Runtime.SetMgmtNet(c.Config.Mgmt)

return nil
}

// ParseTopology parses the lab topology
func (c *CLab) ParseTopology() error {
log.Infof("Parsing & checking topology file: %s", c.TopoFile.fullName)
log.Debugf("Lab name: %s", c.Config.Name)
// initialize Management network config
err := c.initMgmtNetwork()
if err != nil {
return err
}
log.Debugf("DockerInfo: %v", c.Config.Mgmt)

if c.Config.ConfigPath == "" {
c.Config.ConfigPath, _ = filepath.Abs(os.Getenv("PWD"))
Expand All @@ -199,7 +166,7 @@ func (c *CLab) ParseTopology() error {
// initialize the Node information from the topology map
idx := 0
for nodeName, node := range c.Config.Topology.Nodes {
if err = c.NewNode(nodeName, node, idx); err != nil {
if err := c.NewNode(nodeName, node, idx); err != nil {
return err
}
idx++
Expand Down
2 changes: 1 addition & 1 deletion cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func toTableData(det []containerDetails) [][]string {
return tabData
}

func printContainerInspect(c *clab.CLab, containers []types.GenericContainer, bridgeName string, format string) {
func printContainerInspect(c *clab.CLab, containers []types.GenericContainer, bridgeName, format string) {
contDetails := make([]containerDetails, 0, len(containers))
// do not print published ports unless mysocketio kind is found
printMysocket := false
Expand Down
2 changes: 1 addition & 1 deletion runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func (c *DockerRuntime) DeleteContainer(ctx context.Context, name string) error

// linkContainerNS creates a symlink for containers network namespace
// so that it can be managed by iproute2 utility
func (c *DockerRuntime) LinkContainerNS(nspath string, containerName string) error {
func (c *DockerRuntime) LinkContainerNS(nspath, containerName string) error {
utils.CreateDirectory("/run/netns/", 0755)
dst := "/run/netns/" + containerName
err := os.Symlink(nspath, dst)
Expand Down

0 comments on commit f2e6124

Please sign in to comment.