libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnnyWalnut <...@git.apache.org>
Subject [GitHub] libcloud pull request #1043: Fix docker's list_containers function
Date Mon, 24 Apr 2017 17:07:37 GMT
GitHub user johnnyWalnut opened a pull request:

    https://github.com/apache/libcloud/pull/1043

    Fix docker's list_containers function

    add an extra check otherwise list_containers
    breaks with AttributeError
    
    ## Fix function list_containers for docker
    
    ### Description
    I tested locally docker's list_containers(), which was expected to return a list of containers.
    But i ended up with this 
    ```AttributeError                          Traceback (most recent call last)
    <ipython-input-5-34990fe7ad41> in <module>()
    ----> 1 con.list_containers()
    
    /home/johnny/Documents/mylibcloud/env/src/fork_libcloud/libcloud/libcloud/container/drivers/docker.py
in list_containers(self, image, all)
        301             raise
        302 
    --> 303         containers = [self._to_container(value) for value in result]
        304         return containers
        305 
    
    /home/johnny/Documents/mylibcloud/env/src/fork_libcloud/libcloud/libcloud/container/drivers/docker.py
in _to_container(self, data)
        622                 name = data.get('Names')[0].strip('/')
        623             except:
    --> 624                 name = data.get('Id')
        625         state = data.get('State')
        626         if isinstance(state, dict):
    
    AttributeError: 'list' object has no attribute 'get'
    ```
    I investigated more and i fixed this previous commit 
    https://github.com/apache/libcloud/pull/918/commits/2f9c3a3aa1b6654ede67a2a6e63dd3e59437c6de
    
    I added one more check, ``` 'create?fromImage' in self.request.url```, so to restrict
that check which
    refers to install_image. This way everything seems to work fine!
    
    ### done
    
    ### Checklist (tick everything that applies)
    
    - [x] [Code linting](http://libcloud.readthedocs.org/en/latest/development.html#code-style-guide)
(required, can be done after the PR checks)
    - [] [Tests](http://libcloud.readthedocs.org/en/latest/testing.html)
    
    function install_image works fine for me, but test_docker.py doesn't pass!
    
    ```PYTHONPATH=. python libcloud/test/container/test_docker.py
    ......E.....
    ======================================================================
    ERROR: test_install_image (__main__.DockerContainerDriverTestCase)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "libcloud/test/container/test_docker.py", line 56, in test_install_image
        image = driver.install_image('ubuntu:12.04')
      File "/home/johnny/Documents/mylibcloud/libcloudfine/fork_libcloud/libcloud/libcloud/container/drivers/docker.py",
line 215, in install_image
        method='POST')
      File "/home/johnny/Documents/mylibcloud/libcloudfine/fork_libcloud/libcloud/libcloud/common/base.py",
line 641, in request
        response = responseCls(**kwargs)
      File "/home/johnny/Documents/mylibcloud/libcloudfine/fork_libcloud/libcloud/libcloud/common/base.py",
line 163, in __init__
        self.object = self.parse_body()
      File "/home/johnny/Documents/mylibcloud/libcloudfine/fork_libcloud/libcloud/libcloud/container/drivers/docker.py",
line 72, in parse_body
        'ConnectionError: Failed to parse JSON response')
    Exception: ConnectionError: Failed to parse JSON response
    
    ----------------------------------------------------------------------
    Ran 12 tests in 0.057s
    
    FAILED (errors=1)```


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/johnnyWalnut/libcloud fix_docker_list_containers

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/libcloud/pull/1043.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1043
    
----
commit 6084fa3da46b0c16214e8dc9ef368e7bc5455dfa
Author: johnnyWalnut <ikarydis0@gmail.com>
Date:   2017-04-24T16:46:32Z

    add an extra check otherwise list_containers
    breaks with AttributeError

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message