Merge lp:~frankban/lpsetup/lp-lxc-ip into lp:lpsetup
Status: | Merged |
---|---|
Merged at revision: | 15 |
Proposed branch: | lp:~frankban/lpsetup/lp-lxc-ip |
Merge into: | lp:lpsetup |
Diff against target: |
766 lines (+677/-6) 10 files modified
.bzrignore (+1/-0) README.rst (+31/-0) lp-lxc-ip/lxcip.py (+201/-0) lp-lxc-ip/tests/test_helpers.py (+86/-0) lp-lxc-ip/tests/test_lxcip.py (+92/-0) lp-lxc-ip/tests/test_utils.py (+123/-0) lp-lxc-ip/tests/utils.py (+132/-0) lpsetup/__init__.py (+1/-1) lpsetup/tests/test_handlers.py (+5/-5) setup.cfg (+5/-0) |
To merge this branch: | bzr merge lp:~frankban/lpsetup/lp-lxc-ip |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gary Poster (community) | Approve | ||
Review via email: mp+103502@code.launchpad.net |
Description of the change
== Changes ==
1. Introduced the lp-lxc-ip project.
*lp-lxc-ip* provides the ability to obtain the ip address of a running LXC container.
The application is contained in a standalone file lp-lxc-ip/lxcip.py that will be installed in /usr/local/
sudo lp-lxc-ip/lxcip.py -n your_container
The application uses ctypes to call underlying C functions, in order to obtain the init pid (liblxc) and to switch the network namespace (libc). In the near future lpsetup will be refactored to use *lp-lxc-ip* for ssh connections to the container, rather than rely on the dns resolver.
2. Switched to nosetests.
== Tests ==
$ nosetests
.......
Name Stmts Miss Cover Missing
-------
lpsetup 6 1 83% 16
lpsetup.argparser 125 6 95% 113, 221, 278-279, 298, 307
lpsetup.exceptions 5 0 100%
lpsetup.handlers 55 1 98% 55
lpsetup.settings 30 0 100%
lpsetup.subcommands 0 0 100%
lpsetup.utils 103 26 75% 67-71, 91-101, 117, 145, 155, 176-178, 196-202
-------
TOTAL 324 34 90%
-------
Ran 48 tests in 0.564s
OK
$ cd lp-lxc-ip/ && sudo nosetests -v
test_error (tests.
test_short (tests.
test_verbose (tests.
test_redirection (tests.
test_as_root (tests.
test_as_
test_failure (tests.
test_success (tests.
test_get_ip (tests.
test_invalid_
test_invalid_name (tests.
test_invalid_pid (tests.
test_loopback (tests.
test_not_root (tests.
test_race_condition (tests.
test_restart (tests.
test_assertion (tests.
test_assertion_
test_assertion_
test_assertion_
test_create (tests.
test_destroy (tests.
test_start (tests.
test_stop (tests.
test_write_config (tests.
test_mock (tests.
test_failure (tests.
test_success (tests.
-------
Ran 28 tests in 11.473s
OK
Francesco, this is great! This uses all kinds of things I've never or barely used, so it was a nice learning experience to review; and the end result reads very well. The tests are very nice to have, and also read surprisingly well for what they are doing.
I had a lot of small comments from the discussion we had, but they were lost when I reloaded this page by mistake. Therefore, here's what I remember, plus some other bits I came up with while I was writing this up.
* In your README.rst, it would be mildly helpful to note that you can install nosetests by running `apt-get install python-nose`.
* Get SIOCGIFADDR and other constants from Python or C, rather than defining them yourself, if possible. We already determined in the call that termios does not have SIOCGIFADDR, so these may have to be ctypes imports.
* Define what those constants mean in some comments, at least enough for someone to basically follow along.
* AFAICT _redirect_stderr is generically useful to someone using ctypes. Do with that what you will.
* I suggest you add a comment or embellish the docstring to explain why _redirect_stderr is valuable with ctypes. You explain in line 190 of the diff, as you pointed out, but it would be nice to see the point while you are reading the function.
* I think it would be cleaner if __enter__ of SetNamespace had the self.set(pid) call.
* It would be nice if SetNamespace's __exit__ explained why 1 was an acceptable constant.
* When I ran the lxc-ip tests I got two failures: http:// pastebin. ubuntu. com/945997/ (the main suite passed fine after I installed the python-shelltoolbox package from the yellow PPA). This seemed intermittent.
* I don't like the buffer overflow magic number determined experimentally. Could you check with Serge or someone else to see if `return get_init_ pid(name[ :85])` could get a magic number that was identified more systematically?
* Similarly, I don't understand why we truncate at :15 when AFAICT we ought to be able to truncate at :256 in "pack = struct.pack('256s', interface[:15])". A comment or something would be nice if possible.
* I'd like to have some more comments explaining what is going on in that ActiveState recipe. I think I mostly understand it now thanks to your explanation, but would be nice for others/the future.
* In test_redirection, I suggest you explain that you need to mimic C writing to stderr, which is why you do the ctypes dance.
* Mention in get_ip why it is required, as opposed to the similar Python function you mentioned.
* diff line 93 typo: ouput -> output
* diff line 73 typo: exits -> exist
Again, very nice branch. I do wish that the common usage pattern could be simpler/shorter than "ssh -A `sudo lp-lxc-ip -s -n lpdev`", but that's why we have aliases, I suppose. Thank you!