-
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
feature: support dns related flags when creating container through pouch cli #2380
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 |
---|---|---|
|
@@ -31,7 +31,7 @@ func (suite *PouchRunDNSSuite) TearDownTest(c *check.C) { | |
} | ||
|
||
// TestRunWithUserDefinedNetwork tests enabling libnetwork resolver if user-defined network. | ||
func (suite *PouchRunSuite) TestRunWithUserDefinedNetwork(c *check.C) { | ||
func (suite *PouchRunDNSSuite) TestRunWithUserDefinedNetwork(c *check.C) { | ||
cname := "TestRunWithUserDefinedNetwork" | ||
|
||
// Create a user-defined network | ||
|
@@ -52,7 +52,7 @@ func (suite *PouchRunSuite) TestRunWithUserDefinedNetwork(c *check.C) { | |
} | ||
|
||
// TestRunWithBridgeNetwork tests disabling libnetwork resolver if not user-defined network. | ||
func (suite *PouchRunSuite) TestRunWithBridgeNetwork(c *check.C) { | ||
func (suite *PouchRunDNSSuite) TestRunWithBridgeNetwork(c *check.C) { | ||
cname := "TestRunWithBridgeNetwork" | ||
|
||
// Use bridge network if not set --net. | ||
|
@@ -66,3 +66,72 @@ func (suite *PouchRunSuite) TestRunWithBridgeNetwork(c *check.C) { | |
|
||
c.Assert(res.Stdout(), check.Equals, hostRes.Stdout()) | ||
} | ||
|
||
// TestRunWithDNSFlags tests DNS related flags. | ||
func (suite *PouchRunDNSSuite) TestRunWithDNSFlags(c *check.C) { | ||
cname := "TestRunWithDNSFlags" | ||
|
||
res := command.PouchRun("run", "--name", cname, | ||
"--dns", "1.2.3.4", | ||
"--dns-option", "timeout:3", | ||
"--dns-search", "example.com", | ||
busyboxImage, | ||
"cat", "/etc/resolv.conf") | ||
defer DelContainerForceMultyTime(c, cname) | ||
res.Assert(c, icmd.Success) | ||
|
||
// test if the value is correct in container | ||
out := strings.Trim(res.Stdout(), "\n") | ||
c.Assert(strings.Contains(out, "nameserver 1.2.3.4"), check.Equals, true) | ||
c.Assert(strings.Contains(out, "options timeout:3"), check.Equals, true) | ||
c.Assert(strings.Contains(out, "search example.com"), check.Equals, true) | ||
|
||
// test if the value is in inspect result | ||
dns, err := inspectFilter(cname, ".HostConfig.DNS") | ||
c.Assert(err, check.IsNil) | ||
c.Assert(dns, check.Equals, "[1.2.3.4]") | ||
|
||
dnsOptions, err := inspectFilter(cname, ".HostConfig.DNSOptions") | ||
c.Assert(err, check.IsNil) | ||
c.Assert(dnsOptions, check.Equals, "[timeout:3]") | ||
|
||
dnsSearch, err := inspectFilter(cname, ".HostConfig.DNSSearch") | ||
c.Assert(err, check.IsNil) | ||
c.Assert(dnsSearch, check.Equals, "[example.com]") | ||
} | ||
|
||
// TestRunWithDNSRepeatFlags tests repeated DNS related flags. | ||
func (suite *PouchRunDNSSuite) TestRunWithDNSRepeatFlags(c *check.C) { | ||
cname := "TestRunWithDNSRepeatFlags" | ||
|
||
res := command.PouchRun("run", "--name", cname, | ||
"--dns", "1.2.3.4", | ||
"--dns", "2.3.4.5", | ||
"--dns-option", "timeout:3", | ||
"--dns-option", "ndots:9", | ||
"--dns-search", "mydomain", | ||
"--dns-search", "mydomain2", | ||
busyboxImage, | ||
"cat", "/etc/resolv.conf") | ||
defer DelContainerForceMultyTime(c, cname) | ||
res.Assert(c, icmd.Success) | ||
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. It's a good chioce to put 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. I saw the behavior was divergent in the cli test. 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.
LGTM, but waiting for the CI pass. |
||
|
||
// test if the value is correct in container | ||
out := strings.Trim(res.Stdout(), "\n") | ||
c.Assert(strings.Contains(out, "nameserver 1.2.3.4\nnameserver 2.3.4.5"), check.Equals, true) | ||
c.Assert(strings.Contains(out, "options timeout:3 ndots:9"), check.Equals, true) | ||
c.Assert(strings.Contains(out, "search mydomain mydomain2"), check.Equals, true) | ||
|
||
// test if the value is in inspect result | ||
dns, err := inspectFilter(cname, ".HostConfig.DNS") | ||
c.Assert(err, check.IsNil) | ||
c.Assert(dns, check.Equals, "[1.2.3.4 2.3.4.5]") | ||
|
||
dnsOptions, err := inspectFilter(cname, ".HostConfig.DNSOptions") | ||
c.Assert(err, check.IsNil) | ||
c.Assert(dnsOptions, check.Equals, "[timeout:3 ndots:9]") | ||
|
||
dnsSearch, err := inspectFilter(cname, ".HostConfig.DNSSearch") | ||
c.Assert(err, check.IsNil) | ||
c.Assert(dnsSearch, check.Equals, "[mydomain mydomain2]") | ||
} |
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.
since
res
not used, how aboutcommand.PouchRun(xx).(c, icmd.Success)
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.
Nope.
res
is used in line 84.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.
OK, got it , my mistake