Skip to content

Commit

Permalink
Merge pull request #24 from ak1ra24/change-behavior-netns-mng
Browse files Browse the repository at this point in the history
change behavior about netns mng
  • Loading branch information
slankdev authored Feb 3, 2020
2 parents d1ffb10 + c3a1b50 commit 4504182
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
7 changes: 7 additions & 0 deletions command_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func CmdUp(c *cli.Context) error {
}
}

for _, node := range tnconfig.Nodes {
if node.Type == "docker" || node.Type == "" {
delNsCmd := node.DelNsCmd()
utils.PrintCmd(os.Stdout, delNsCmd, verbose)
}
}

return nil
}

Expand Down
10 changes: 6 additions & 4 deletions internal/pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ func (node *Node) DeleteNode() []string {
} else if node.Type == "netns" {
deleteCmd = fmt.Sprintf("ip netns del %s", node.Name)
} else {
// err := fmt.Errorf("not supported node type...")
// log.Fatal(err)
return []string{""}
}

Expand Down Expand Up @@ -415,8 +413,6 @@ func (node *Node) CreateNode() []string {
} else if node.Type == "netns" {
createNodeCmd = fmt.Sprintf("ip netns add %s", node.Name)
} else {
// err := fmt.Errorf("unknown nodetype %s", node.Type)
// log.Fatal(err)
createNodeCmd = fmt.Sprintf("unknown nodetype %s", node.Type)
}

Expand Down Expand Up @@ -549,3 +545,9 @@ func GetContainerPid(nodename string) string {

return getpidcmd
}

// DelNsCmds
func (node *Node) DelNsCmd() string {
delNsCmd := fmt.Sprintf("ip netns del %s", node.Name)
return delNsCmd
}
50 changes: 50 additions & 0 deletions internal/pkg/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,3 +996,53 @@ func TestGetContainerPid(t *testing.T) {
})
}
}

func TestNode_DelNsCmd(t *testing.T) {
type fields struct {
Name string
Type string
NetBase string
Image string
Interfaces []Interface
Sysctls []Sysctl
Mounts []string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "node netns del",
fields: fields{
Name: "R1",
Image: "slankdev/frr",
Type: "docker",
Interfaces: []Interface{
Interface{
Name: "net0",
Type: "direct",
Args: "R2#net0",
},
},
},
want: "ip netns del R1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
node := &Node{
Name: tt.fields.Name,
Type: tt.fields.Type,
NetBase: tt.fields.NetBase,
Image: tt.fields.Image,
Interfaces: tt.fields.Interfaces,
Sysctls: tt.fields.Sysctls,
Mounts: tt.fields.Mounts,
}
if got := node.DelNsCmd(); got != tt.want {
t.Errorf("Node.DelNsCmd() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 4504182

Please sign in to comment.