-
Notifications
You must be signed in to change notification settings - Fork 950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: fix can't set macaddress for endpoint #2222
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,3 +330,24 @@ func StringSliceEqual(s1, s2 []string) bool { | |
|
||
return true | ||
} | ||
|
||
// MergeMap merges the m2 into m1, if it has the same keys, m2 will overwrite m1. | ||
func MergeMap(m1 map[string]interface{}, m2 map[string]interface{}) (map[string]interface{}, error) { | ||
if m1 == nil && m2 == nil { | ||
return nil, fmt.Errorf("all of maps are nil") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it return an error? I think it is quite normal to merge two nil map. I think it is incorrect to return err. Instead, the upper caller could judge whether the returned value is nil to return error or something.
|
||
} | ||
|
||
if m1 == nil { | ||
return m2, nil | ||
} | ||
|
||
if m2 == nil { | ||
return m1, nil | ||
} | ||
|
||
for k, v := range m2 { | ||
m1[k] = v | ||
} | ||
|
||
return m1, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,15 @@ package main | |
import ( | ||
"net/url" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
"github.com/alibaba/pouch/test/command" | ||
"github.com/alibaba/pouch/test/environment" | ||
"github.com/alibaba/pouch/test/request" | ||
|
||
"github.com/go-check/check" | ||
"github.com/gotestyourself/gotestyourself/icmd" | ||
) | ||
|
||
// APIContainerCreateSuite is the test suite for container create API. | ||
|
@@ -231,3 +234,48 @@ func (suite *APIContainerCreateSuite) TestCreateNvidiaConfig(c *check.C) { | |
|
||
DelContainerForceMultyTime(c, cname) | ||
} | ||
|
||
func (suite *APIContainerCreateSuite) TestCreateWithMacAddress(c *check.C) { | ||
cname := "TestCreateWithMacAddress" | ||
mac := "00:16:3e:02:00:b7" | ||
q := url.Values{} | ||
q.Add("name", cname) | ||
query := request.WithQuery(q) | ||
|
||
obj := map[string]interface{}{ | ||
"Entrypoint": []string{"top"}, | ||
"Image": busyboxImage, | ||
"MacAddress": mac, | ||
"NetworkMode": "bridge", | ||
} | ||
body := request.WithJSONBody(obj) | ||
|
||
resp, err := request.Post("/containers/create", query, body) | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 201) | ||
|
||
q = url.Values{} | ||
q.Add("detachKeys", "EOF") | ||
query = request.WithQuery(q) | ||
|
||
resp, err = request.Post("/containers/"+cname+"/start", query) | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 204) | ||
|
||
ret := command.PouchRun("exec", cname, "ip", "addr", "show", "eth0") | ||
ret.Assert(c, icmd.Success) | ||
|
||
found := false | ||
for _, line := range strings.Split(ret.Stdout(), "\n") { | ||
if strings.Contains(line, "link/ether") { | ||
if mac == strings.Fields(line)[1] { | ||
found = true | ||
break | ||
} | ||
} | ||
} | ||
|
||
c.Assert(found, check.Equals, true) | ||
|
||
DelContainerForceMultyTime(c, cname) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have
Merge
funtion inutils.go
, can we use it ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't to merge the map as I want, I don't know and I don't want to knon what's wrong with it. 🐶