Skip to content

Commit

Permalink
Merge pull request #23 from ak1ra24/support-default-tinet-volume
Browse files Browse the repository at this point in the history
support default tinet volume
  • Loading branch information
slankdev committed Feb 3, 2020
2 parents ecd65c6 + 4d04f37 commit 631d89e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
7 changes: 7 additions & 0 deletions internal/pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Node struct {
Name string `yaml:"name" mapstructure:"name"`
Type string `yaml:"type" mapstructure:"type"`
NetBase string `yaml:"net_base" mapstructure:"net_base"`
VolumeBase string `yaml:"volume" mapstructure:"volume"`
Image string `yaml:"image" mapstructure:"image"`
Interfaces []Interface `yaml:"interfaces" mapstructure:"interfaces"`
Sysctls []Sysctl `yaml:"sysctls" mapstructure:"sysctls"`
Expand Down Expand Up @@ -403,6 +404,12 @@ func (node *Node) CreateNode() []string {
}
}

if node.VolumeBase == "" {
createNodeCmd += fmt.Sprintf("-v /tmp/tinet:/tinet ")
} else {
createNodeCmd += fmt.Sprintf("-v %s:/tinet ", node.VolumeBase)
}

if len(node.Mounts) != 0 {
for _, mount := range node.Mounts {
createNodeCmd += fmt.Sprintf("-v %s ", mount)
Expand Down
26 changes: 22 additions & 4 deletions internal/pkg/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ func TestNode_CreateNode(t *testing.T) {
Name string
Type string
NetBase string
VolumeBase string
Image string
Interfaces []Interface
Sysctls []Sysctl
Expand All @@ -500,7 +501,7 @@ func TestNode_CreateNode(t *testing.T) {
},
},
},
want: []string{"docker run -td --hostname R1 --net none --name R1 --rm --privileged slankdev/frr"},
want: []string{"docker run -td --hostname R1 --net none --name R1 --rm --privileged -v /tmp/tinet:/tinet slankdev/frr"},
},
{
name: "create docker node net None with sysctls",
Expand All @@ -523,7 +524,7 @@ func TestNode_CreateNode(t *testing.T) {
},
},
},
want: []string{"docker run -td --hostname R1 --net none --name R1 --rm --privileged --sysctl net.ipv4.ip_forward=1 --sysctl net.ipv6.conf.all.forwarding=1 slankdev/frr"},
want: []string{"docker run -td --hostname R1 --net none --name R1 --rm --privileged --sysctl net.ipv4.ip_forward=1 --sysctl net.ipv6.conf.all.forwarding=1 -v /tmp/tinet:/tinet slankdev/frr"},
},
{
name: "create docker node net bridge",
Expand All @@ -539,7 +540,7 @@ func TestNode_CreateNode(t *testing.T) {
},
},
},
want: []string{"docker run -td --hostname R1 --net bridge --name R1 --rm --privileged slankdev/frr"},
want: []string{"docker run -td --hostname R1 --net bridge --name R1 --rm --privileged -v /tmp/tinet:/tinet slankdev/frr"},
},
{
name: "create netns node",
Expand Down Expand Up @@ -614,7 +615,23 @@ func TestNode_CreateNode(t *testing.T) {
"/usr/share/vim:/mnt/vim",
},
},
want: []string{"docker run -td --hostname T1 --net none --name T1 --rm --privileged -v `pwd`:/mnt/test -v /usr/share/vim:/mnt/vim slankdev/frr"},
want: []string{"docker run -td --hostname T1 --net none --name T1 --rm --privileged -v /tmp/tinet:/tinet -v `pwd`:/mnt/test -v /usr/share/vim:/mnt/vim slankdev/frr"},
},
{
name: "create node with specify tinet volume",
fields: fields{
Name: "T1",
Image: "slankdev/frr",
VolumeBase: "/tmp/ak1ra24",
Interfaces: []Interface{
Interface{
Name: "net0",
Type: "direct",
Args: "T2#net0",
},
},
},
want: []string{"docker run -td --hostname T1 --net none --name T1 --rm --privileged -v /tmp/ak1ra24:/tinet slankdev/frr"},
},
}
for _, tt := range tests {
Expand All @@ -623,6 +640,7 @@ func TestNode_CreateNode(t *testing.T) {
Name: tt.fields.Name,
Type: tt.fields.Type,
NetBase: tt.fields.NetBase,
VolumeBase: tt.fields.VolumeBase,
Image: tt.fields.Image,
Interfaces: tt.fields.Interfaces,
Sysctls: tt.fields.Sysctls,
Expand Down

0 comments on commit 631d89e

Please sign in to comment.