You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by InAnimaTe <gi...@git.apache.org> on 2016/10/13 19:36:22 UTC
[GitHub] libcloud pull request #905: Return Object Changes and State Handling Fixup
GitHub user InAnimaTe opened a pull request:
https://github.com/apache/libcloud/pull/905
Return Object Changes and State Handling Fixup
## Return Object Changes and State Handling Fixup
### Description
> This should hopefully be my last PR for a long-time regarding the Rancher driver. At least until `v2` comes out ;)
This PR changes the way the `start_container`, `stop_container`, and `destroy_container` functions work. They still return a container object as expected, but that object is now made from the actual response we receive from Rancher (which is not just a empty 204, but the full json for the container question), not another `get_container` call.
This is most certainly the better way to handle this:
```
In [1]: con = driver.get_container('1i24')
In [2]: con
Out[2]: <Container: id=1i24, name=newconbr0,state=running, provider=Rancher ...>
In [3]: stopcon = driver.stop_container(con)
In [4]: stopcon
Out[4]: <Container: id=1i24, name=newconbr0,state=terminated, provider=Rancher ...>
In [5]: stopcon.extra['state']
Out[5]: 'stopping'
In [6]: startcon = driver.start_container(stopcon)
In [7]: startcon
Out[7]: <Container: id=1i24, name=newconbr0,state=terminated, provider=Rancher ...>
In [8]: startcon.extra['state']
Out[8]: 'starting'
In [9]: destroycon = driver.destroy_container(startcon)
In [10]: destroycon
Out[10]: <Container: id=1i24, name=newconbr0,state=terminated, provider=Rancher ...>
In [11]: destroycon.extra['state']
Out[11]: 'stopping'
```
#### State Handling Fix
While the above output shows that our return objects are much better, it shows another issue. For some reason, `state=terminated` when we're in the process of a transition (starting, stopping, etc..). Looking deeper, I found my `elif` for terminated state doesn't work as expected. I've fixed this by using `any`. I've also modified the tests to properly check for this.
Now it works as expected:
```
In [4]: con = driver.get_container('1i31')
In [5]: con
Out[5]: <Container: id=1i31, name=newcontainer,state=stopped, provider=Rancher ...>
In [6]: startcon = driver.start_container(con)
In [7]: startcon
Out[7]: <Container: id=1i31, name=newcontainer,state=pending, provider=Rancher ...>
In [8]: startcon.extra['state']
Out[8]: 'starting'
In [9]: startcon.extra['transitioning']
Out[9]: 'yes'
```
### Status
- done, ready for review
### 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)
- [x] [Tests](http://libcloud.readthedocs.org/en/latest/testing.html)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ArroyoNetworks/libcloud return_changes
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/libcloud/pull/905.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 #905
----
commit 6e32861f77cc16fc90b599026367b64dad083455
Author: Mario Loria <ma...@arroyonetworks.com>
Date: 2016-10-13T18:47:37Z
return actual action object
commit 5ff1805da19da24627b4d7b4e511bb2294b06fdf
Author: Mario Loria <ma...@arroyonetworks.com>
Date: 2016-10-13T18:54:09Z
modify tests, flake8
commit 3ec0fe30705ee5bde0ef47a684691569cb341725
Author: Mario Loria <ma...@arroyonetworks.com>
Date: 2016-10-13T19:34:13Z
fix state handling
----
---
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.
---
[GitHub] libcloud pull request #905: Return Object Changes and State Handling Fixup
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/libcloud/pull/905
---
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.
---