Skip to content
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

Carry Fix docker inspect container only reports last assigned information #17393

Merged
merged 2 commits into from Oct 28, 2015

Conversation

tiborvass
Copy link
Contributor

Fixes #17352
Closes #17360

Ping @calavera

@@ -0,0 +1,28 @@
// Package v1p21 provides specific API types for the API version 1, patch 21.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this whole file 🔥 🤘

@calavera
Copy link
Contributor

Code LGTM. Waiting to see what janky thinks about it. 👏

@tiborvass
Copy link
Contributor Author

CI has issues, we need to run the tests locally

return strings.Trim(out, " \r\n'")
}

func (d *Daemon) findContainerIP(id string) string {
return findContainerIP(d.c, id, "--host", d.sock())
return findContainerIP(d.c, id, "--host")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiborvass Busy this day, get no time to read the notes from the github.

return findContainerIP(d.c, id, "--host") should be return findContainerIP(d.c, id, "bridge")

Sorry for my mistake in my PR, don't know why CI got green on my PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for looking @coolljt0725, and no need to apologize (that's where reviews are for, we're all human!)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah thanks
@tiborvass After investigating why return findContainerIP(d.c, id, "--host") unexpectedly make CI green and found that we can't call findContainerIP in func (d *Daemon) findContainerIP(id string) because findContainerIP connect to the daemon start by .integration-daemon-start, we should connect the daemon d here, so I think the correct fix here is

func (d *Daemon) findContainerIP(id string) string {
        out, _ := d.Cmd("inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.bridge.IPAddress }}'"), id)
        return strings.Trim(out, " \r\n'")
}

correct me if I'm wrong :-)

Though the original code findContainerIP(d.c, id, "--host", d.sock()) has set the "--host", d.sock() but it never been used in func findContainerIP(c *check.C, id string, vargs ...string)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go
index 67627af..850ad2e 100644
--- a/integration-cli/docker_utils.go
+++ b/integration-cli/docker_utils.go
@@ -783,12 +783,19 @@ func dockerCmdInDirWithTimeout(timeout time.Duration, path string, args ...strin
 }

 func findContainerIP(c *check.C, id string, network string) string {
-   out, _ := dockerCmd(c, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id)
+   out, err := dockerCmd(c, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id)
+   if err != nil {
+       c.Warn(err)
+   }
    return strings.Trim(out, " \r\n'")
 }

 func (d *Daemon) findContainerIP(id string) string {
-   return findContainerIP(d.c, id, "--host")
+   out, err := d.Cmd("inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.bridge.IPAddress }}'"), id)
+   if err != nil {
+       d.c.Warn(err)
+   }
+   return strings.TrimSpace(out)
 }

 func getContainerCount() (int, error) {

@calavera @coolljt0725 does this sound ok to you guys ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiborvass err will be an int in findContainerIP with 0 as value (or it will fail the test if an error occured — so the Warn feels useless). You probably want to use out, _, err := dockerCmdWithError(…) instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that if err != nil (from dockerCmd) won't compile (cannot convert nil to type int) I think @vdemeester

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@runcom Yeah even that 😅 😝

@tiborvass
Copy link
Contributor Author

@vdemeester @runcom @calavera @coolljt0725 fixed thank you

@calavera
Copy link
Contributor

@tiborvass it looks like c.Warn does not exist:

docker_utils.go:1010: c.Warn undefined (type *check.C has no field or method Warn)

Signed-off-by: Lei Jitang <leijitang@huawei.com>
@calavera
Copy link
Contributor

@tiborvass you need this patch:

diff --git c/integration-cli/docker_utils.go i/integration-cli/docker_utils.go
index 8aea980..581766d 100644
--- c/integration-cli/docker_utils.go
+++ i/integration-cli/docker_utils.go
@@ -785,7 +785,7 @@ func dockerCmdInDirWithTimeout(timeout time.Duration, path string, args ...strin
 func findContainerIP(c *check.C, id string, network string) string {
        out, _, err := dockerCmdWithError(c, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id)
        if err != nil {
-               c.Warn(err)
+               c.Log(err)
        }
        return strings.Trim(out, " \r\n'")
 }
@@ -793,7 +793,7 @@ func findContainerIP(c *check.C, id string, network string) string {
 func (d *Daemon) findContainerIP(id string) string {
        out, err := d.Cmd("inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.bridge.IPAddress }}'"), id)
        if err != nil {
-               d.c.Warn(err)
+               d.c.Log(err)
        }
        return strings.TrimSpace(out)
 }

@tiborvass
Copy link
Contributor Author

@calavera yes thank you I noticed it while rebasing :)

if err != nil {
d.c.Log(err)
}
return strings.Trim(out, " \r\n'")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calavera note that i just took what was at line 787

@calavera
Copy link
Contributor

LGTM

@tiborvass
Copy link
Contributor Author

putting merge label, since it already got okays in the pr this is carrying.

@@ -88,15 +88,25 @@ func (container *Container) setupLinkedContainers() ([]string, error) {
return nil, err
}

bridgeSettings := container.NetworkSettings.Networks["bridge"]
if bridgeSettings == nil {
return nil, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calavera @mavenugo this is the line i just changed, it doesnt error out now.

@calavera
Copy link
Contributor

@tiborvass

docker_cli_links_test.go:140:
    c.Fatal(err)
... Error: failed to inspect container one: Template parsing error: template: :1:18: executing "" at <.NetworkSettings.IPA...>: IPAddress is not a field of struct type *types.NetworkSettings

@tiborvass
Copy link
Contributor Author

@calavera fixed

@mrjana
Copy link
Contributor

mrjana commented Oct 27, 2015

changes LGTM. Let's wait for the CI to become green

@tiborvass
Copy link
Contributor Author

@mrjana CI has issues, please test locally

Keeping backwards compatibility.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Signed-off-by: Tibor Vass <tibor@docker.com>
@calavera
Copy link
Contributor

LGTM. We're going to open a PR in docker-py to fix the functional suite.

Merging.

calavera added a commit that referenced this pull request Oct 28, 2015
Carry Fix docker inspect container only reports last assigned information
@calavera calavera merged commit 9ab71b6 into moby:master Oct 28, 2015
@tiborvass
Copy link
Contributor Author

Ping @dnephin @aanand @shin- @abronan @vieux @aluzzardi this requires an API update.

@tiborvass
Copy link
Contributor Author

@thaJeztah removing changelog, since it's part of the new networking feature which is already in the changelog.

shin- added a commit to docker/docker-py that referenced this pull request Oct 28, 2015
moby/moby#17393 changes the network settings struct
a bit, which impacts tests checking values in inspect results

Signed-off-by: Joffrey F <joffrey@docker.com>
@tiborvass tiborvass removed their assignment Oct 29, 2015
@tiborvass tiborvass deleted the carry-17360 branch July 17, 2019 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants