Merge lp://qastaging/~mew/charm-helpers/commandant into lp://qastaging/charm-helpers

Proposed by Matthew Wedgwood
Status: Merged
Merged at revision: 72
Proposed branch: lp://qastaging/~mew/charm-helpers/commandant
Merge into: lp://qastaging/charm-helpers
Diff against target: 519 lines (+464/-0)
8 files modified
bin/chlp (+7/-0)
charmhelpers/cli/README.rst (+57/-0)
charmhelpers/cli/__init__.py (+147/-0)
charmhelpers/cli/commands.py (+2/-0)
charmhelpers/cli/host.py (+14/-0)
setup.py (+2/-0)
tests/cli/test_cmdline.py (+189/-0)
tests/cli/test_function_signature_analysis.py (+46/-0)
To merge this branch: bzr merge lp://qastaging/~mew/charm-helpers/commandant
Reviewer Review Type Date Requested Status
Nicola Larosa (community) Approve
Matthew Wedgwood (community) Needs Resubmitting
Review via email: mp+177982@code.qastaging.launchpad.net

Description of the change

Add CLI support to charm-helpers, allowing helpers to be used in charms written in other languages.

charmhelpers.cli adds a framework for building CLI commands from helpers. New commands are implemented by defining wrapper methods decorated with CommandLine.subcommand or CommandLine.subcommand_builder. Two examples from the hosts module are included.

To post a comment you must log in.
30. By Matthew Wedgwood

Include CLI when charmhelpers is installed

Revision history for this message
Nicola Larosa (teknico) wrote :

All this looks well put together. The CommandLine class makes my head spin a little, but I guess it'll just take some getting accustomed to it. :-)

There is a bug in charmhelpers/cli/__init__.py . Line 137:

        positional_args = argspec.args[:len(argspec.defaults)]

should be:

        positional_args = argspec.args[:-len(argspec.defaults)]

It does not show up in the test_positional_arguments test in tests/cli/test_function_signature_analysis.py because the call to cli.describe_arguments has no default arguments, and the other ones only have one positional argument each.

Add "z=2" to the cli.describe_arguments call parameters in test_positional_arguments, and watch the "y" disappear from the test output. Add the minus sign above to the code, and watch the "y" appear again.

Getting one error when running tests, in tests.core.test_host.HelpersTest.test_installs_apt_packages_with_possible_errors . Same thing in trunk, though.

I also get this near the beginning of the test run:

    usage: nosetests [-h] [--format FMT | -r | -j | -p | -y | -c | -t]
                     {payload} ...
    nosetests: error: invalid choice: 'd' (choose from 'payload')

Add flake8 <https://pypi.python.org/pypi/flake8> to test requirements.

Fix lint errors as shown by "make lint".

Wrap lines in ReST docs, so that changes are readable in diffs.

review: Needs Fixing
31. By Matthew Wedgwood

Fixed indexing error in parameter inspection. Silenced parse_args output during tests.

Updated tests to catch indexing error in parameter inspection function, then
applied fix suggested by teknico. Also suppressed superfluous error message from
argparse during tests.

Revision history for this message
Matthew Wedgwood (mew) wrote :

Thanks for the review, and for catching that bug.

I've fixed the tests to catch the condition you spotted, then applied the fix. I've also suppressed the confusing output from parse_args during the invalid-args test.

review: Needs Resubmitting
Revision history for this message
Nicola Larosa (teknico) wrote :

Thank you. That's enough to approve: how about the other remarks, though?

Here's the error that also happens in trunk:

======================================================================
ERROR: tests.core.test_host.HelpersTest.test_installs_apt_packages_with_possible_errors
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/nl/canonical/Cloud/code/charm-helpers/commandant/tests/core/test_host.py", line 445, in test_installs_apt_packages_with_possible_errors
    fetch.apt_install(packages, options, fatal=True)
  File "/home/nl/canonical/Cloud/code/charm-helpers/commandant/charmhelpers/fetch/__init__.py", line 52, in apt_install
    options))
  File "/home/nl/canonical/Cloud/code/charm-helpers/commandant/charmhelpers/core/hookenv.py", line 65, in log
    subprocess.call(command)
  File "/usr/lib/python2.7/subprocess.py", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1308, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

And here's the lint output:

$ make lint
Checking for Python syntax...
charmhelpers/fetch/bzrurl.py:44:1: W391 blank line at end of file
charmhelpers/cli/commands.py:1:1: F401 'CommandLine' imported but unused
charmhelpers/cli/commands.py:2:1: F401 'host' imported but unused
charmhelpers/cli/host.py:10:1: E302 expected 2 blank lines, found 1
tests/fetch/test_bzrurl.py:45:5: E303 too many blank lines (2)
tests/fetch/test_bzrurl.py:54:5: E303 too many blank lines (2)
tests/fetch/test_bzrurl.py:69:5: E303 too many blank lines (2)
tests/fetch/test_bzrurl.py:80:1: W391 blank line at end of file
tests/core/test_host.py:451:5: E303 too many blank lines (2)
tests/core/test_host.py:457:78: E202 whitespace before ')'
tests/core/test_host.py:461:5: E303 too many blank lines (2)
tests/core/test_host.py:467:78: E202 whitespace before ')'
tests/core/test_host.py:471:5: E303 too many blank lines (2)
tests/core/test_host.py:482:5: E303 too many blank lines (2)
tests/core/test_host.py:494:5: E303 too many blank lines (2)
tests/contrib/hahelpers/test_ceph_utils.py:130:13: E128 continuation line under-indented for visual indent
tests/contrib/hahelpers/test_ceph_utils.py:131:1: W391 blank line at end of file
make: *** [lint] Error 1

Most of them are already in trunk, too.

review: Approve
Revision history for this message
Matthew Wedgwood (mew) wrote :

Ah, sorry. I've fixed the test failure in a separate MP (https://code.launchpad.net/~mew/charm-helpers/apt-test-fixes/+merge/181340, already merged)

I'll submit another for these lint cleanups. Thanks for being vigilant. I think we're getting close to a 1.0 release for charm-helpers, and at that point I'll loop in Tarmac to catch those issues in the future.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches