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

Could not clean up containers by execute DockerCmd(self, 'rm', "container_name").execute() #99

Closed
gouyang opened this issue Apr 24, 2014 · 6 comments

Comments

@gouyang
Copy link
Contributor

gouyang commented Apr 24, 2014

it extent the "container_name" into a list ['c', 'o', 'n', 't', 'a', 'i', 'n', 'e', 'r', '_', 'n', 'a', 'm', 'e']:

$ tail -n 7 workdir.py

def cleanup(self):
    super(workdir, self).cleanup()
    if self.config['remove_after_test']:
        dkrcmd = DockerCmd(self, 'rm', "exist_dir")
        cmd = dkrcmd.execute()
        print cmd

$ ./autotest-local run docker --args=docker_cli/workdir
17:59:45 INFO | Writing results to /var/www/html/autotest/client/results/default
17:59:46 INFO | START ---- ---- timestamp=1398333586 localtime=Apr 24 17:59:46
17:59:46 INFO | START docker/subtests/docker_cli/workdir.test_1-of-1 docker/subtests/docker_cli/workdir.test_1-of-1 timestamp=1398333586 timeout=600 localtime=Apr 24 17:59:46
17:59:46 INFO | RUNNING ---- ---- timestamp=1398333586 localtime=Apr 24 17:59:46 INFO: initialize()
17:59:46 INFO | RUNNING ---- ---- timestamp=1398333586 localtime=Apr 24 17:59:46 INFO: run_once() iteration 1 of 1
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: postprocess_iteration(), iteration #1
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: postprocess()
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: Commands: /usr/bin/docker -D run --workdir=/var/log --name=exist_dir fedora:20 pwd
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: workdir /var/log set successful for container
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: Commands: /usr/bin/docker -D run --workdir=/tmp/mdAhsaPSTVxC --name=nonexist_dir fedora:20 pwd
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: workdir /tmp/mdAhsaPSTVxC set successful for container
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: Commands: /usr/bin/docker -D run --workdir=tmp/mdAhsaPSTVxC --name=invalid_dir fedora:20 pwd
17:59:50 ERROR| RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 ERROR: Intend to fail:
2014/04/24 17:59:49 The working directory is invalid. It needs to be an absolute path.
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: Commands: /usr/bin/docker -D run --workdir=/etc/hosts --name=file_as_dir fedora:20 pwd
17:59:50 ERROR| RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 ERROR: Intend to fail:
[debug] utils.go:267 [hijack] End of stdout
[debug] commands.go:1905 End of CmdRun(), Waiting for hijack to finish.
2014/04/24 17:59:50 Error: Cannot start container e8f5283749b462491372cfa838ba62be0bcf2d91b1d141b001b0a3cbdc3e82f6: Cannot mkdir: /etc/hosts is not a directory
17:59:50 INFO | RUNNING ---- ---- timestamp=1398333590 localtime=Apr 24 17:59:50 INFO: cleanup()
17:59:50 INFO | * Command:
17:59:50 INFO | /usr/bin/docker -D rm e x i s t _ d i r
17:59:50 INFO | Exit status: 1
17:59:50 INFO | Duration: 0.019348859787
17:59:50 INFO |
17:59:50 INFO | stderr:
17:59:50 INFO | Error: No such container: e
17:59:50 INFO | Error: No such container: x
17:59:50 INFO | Error: No such container: i
17:59:50 INFO | Error: No such container: s
17:59:50 INFO | Error: No such container: t
17:59:50 INFO | Error: No such container: _
17:59:50 INFO | Error: No such container: d
17:59:50 INFO | Error: No such container: i
17:59:50 INFO | Error: No such container: r
17:59:50 INFO | 2014/04/24 17:59:50 Error: failed to remove one or more containers
17:59:52 INFO | GOOD docker/subtests/docker_cli/workdir.test_1-of-1 docker/subtests/docker_cli/workdir.test_1-of-1 timestamp=1398333592 localtime=Apr 24 17:59:52 completed successfully
17:59:52 INFO | END GOOD docker/subtests/docker_cli/workdir.test_1-of-1 docker/subtests/docker_cli/workdir.test_1-of-1 timestamp=1398333592 localtime=Apr 24 17:59:52
17:59:52 INFO | END GOOD ---- ---- timestamp=1398333592 localtime=Apr 24 17:59:52
17:59:52 INFO | Report successfully generated at /var/www/html/autotest/client/results/default/job_report.html

@gouyang
Copy link
Contributor Author

gouyang commented Apr 24, 2014

however it works with below method in other test case, don't know what the difference:
dkrcmd = DockerCmd(self, 'rm', [self.stuff['container_name']])
dkrcmd.execute()

@cevich
Copy link
Member

cevich commented Apr 24, 2014

This is a python-language "feature" where strings are iterable sequences of characters. In other words, containing the string inside a list is key, so:

[self.stuff['container_name']] vs. self.stuff['container_name']

Both satisfy the "iterable" condition, and because "duck-typing" is used, see http://en.wikipedia.org/wiki/Duck_typing both are accepted as an "iterable". Here's the docstring (which I see is not properly rendered into documentation): https://github.com/autotest/autotest-docker/blob/master/dockertest/dockercmd.py#L29

BTW: I have run into this exact same problem before. Since you've now hit it, it must be more common than I assumed. I'm open if you @ouyanggh have ideas, but I think there are at least two simple solutions here:

  1. Move the __init__() docstring into the main class docstring so the parameter docs show up in the documentation (oops).
  2. Add a warning message if subargs is found to be string-like.

@cevich cevich added this to the Dockertest API Version 0.7.1 milestone Apr 24, 2014
@cevich
Copy link
Member

cevich commented Apr 24, 2014

Here's where the parameter docs are not rendering properly, it's an issue across all of our code with a cut-paste fix:
http://docker-autotest.readthedocs.org/en/latest/#dockertest.dockercmd.DockerCmdBase

@Lorquas would you mind looking into #1 and #2 above (and any additional ideas you have) for the dockercmd module?

@jzupka Could you help fix the same documentation (#1) problem in the images and container modules?

@ldoktor Could you help fix docker_daemon, networking and subtest?

I'll pick up the remaining modules. Let me know if anyone has questions.

@cevich cevich self-assigned this Apr 24, 2014
@cevich
Copy link
Member

cevich commented Apr 24, 2014

Documentation fix PR: #100

@gouyang
Copy link
Contributor Author

gouyang commented Apr 25, 2014

I will use it in a list so far.

@cevich
Copy link
Member

cevich commented Apr 29, 2014

Closing this since fix is in
#100

@cevich cevich closed this as completed Apr 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants