From 76f90fc03f924eff6c525a7d0dad79af32aef1ca Mon Sep 17 00:00:00 2001 From: henderiw Date: Tue, 8 Sep 2020 11:28:59 +0200 Subject: [PATCH] robustness-dymmy-int added robustness for the hanging resources when a deployment fails. --- clab/netlink.go | 18 ++++++++++++++++++ cmd/deploy.go | 2 ++ cmd/destroy.go | 1 + 3 files changed, 21 insertions(+) diff --git a/clab/netlink.go b/clab/netlink.go index 54ff34660..3b4a20a49 100644 --- a/clab/netlink.go +++ b/clab/netlink.go @@ -7,10 +7,27 @@ import ( log "github.com/sirupsen/logrus" ) +func (c *cLab) InitVirtualWiring() { + log.Debug("delete dummyA eth link") + var cmd *exec.Cmd + var err error + cmd = exec.Command("sudo", "ip", "link", "del", "dummyA") + err = runCmd(cmd) + if err != nil { + log.Debugf("%s failed with: %v", cmd.String(), err) + } + cmd = exec.Command("sudo", "ip", "link", "del", "dummyB") + err = runCmd(cmd) + if err != nil { + log.Debugf("%s failed with: %v", cmd.String(), err) + } +} + // CreateVirtualWiring provides the virtual topology between the containers func (c *cLab) CreateVirtualWiring(id int, link *Link) (err error) { log.Infof("Create virtual wire : %s, %s, %s, %s", link.A.Node.LongName, link.B.Node.LongName, link.A.EndpointName, link.B.EndpointName) + CreateDirectory("/run/netns/", 0755) var src, dst string @@ -226,6 +243,7 @@ func (c *cLab) DeleteVirtualWiring(id int, link *Link) (err error) { log.Debugf("%s failed with: %v", cmd.String(), err) } } + return nil } diff --git a/cmd/deploy.go b/cmd/deploy.go index 157d339c4..dbda2cab5 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -72,6 +72,8 @@ var deployCmd = &cobra.Command{ log.Error(err) } } + // cleanup hanging resources if a deployment failed before + c.InitVirtualWiring() // wire the links between the nodes based on cabling plan for i, link := range c.Links { if err = c.CreateVirtualWiring(i, link); err != nil { diff --git a/cmd/destroy.go b/cmd/destroy.go index 5c524f0cb..2352ab2f6 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -78,6 +78,7 @@ var destroyCmd = &cobra.Command{ log.Error(err) } } + c.InitVirtualWiring() }, }