summaryrefslogtreecommitdiff
path: root/tests/unittests/test_cli.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2017-09-12 10:27:07 -0600
committerScott Moser <smoser@brickies.net>2017-09-15 15:46:02 -0400
commite626966ee7d339b53d2c8b14a8f2ff8e3fe892ee (patch)
treebba6a1a7d8d31b1fc790b7bff1ca94183c278b78 /tests/unittests/test_cli.py
parentda1db792b2721d94ef85df8c136e78012c49c6e5 (diff)
downloadvyos-cloud-init-e626966ee7d339b53d2c8b14a8f2ff8e3fe892ee.tar.gz
vyos-cloud-init-e626966ee7d339b53d2c8b14a8f2ff8e3fe892ee.zip
cmdline: add collect-logs subcommand.
Add a new collect-logs sub command to the cloud-init CLI. This script will collect all logs pertinent to a cloud-init run and store them in a compressed tar-gzipped file. This tarfile can be attached to any cloud-init bug filed in order to aid in bug triage and resolution. A cloudinit.apport module is also added that allows apport interaction. Here is an example bug filed via ubuntu-bug cloud-init: LP: #1716975. Once the apport launcher is packaged in cloud-init, bugs can be filed against cloud-init with the following command: ubuntu-bug cloud-init LP: #1607345
Diffstat (limited to 'tests/unittests/test_cli.py')
-rw-r--r--tests/unittests/test_cli.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/tests/unittests/test_cli.py b/tests/unittests/test_cli.py
index 495bdc9f..258a9f08 100644
--- a/tests/unittests/test_cli.py
+++ b/tests/unittests/test_cli.py
@@ -72,18 +72,22 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
def test_conditional_subcommands_from_entry_point_sys_argv(self):
"""Subcommands from entry-point are properly parsed from sys.argv."""
+ stdout = six.StringIO()
+ self.patchStdoutAndStderr(stdout=stdout)
+
expected_errors = [
- 'usage: cloud-init analyze', 'usage: cloud-init devel']
- conditional_subcommands = ['analyze', 'devel']
+ 'usage: cloud-init analyze', 'usage: cloud-init collect-logs',
+ 'usage: cloud-init devel']
+ conditional_subcommands = ['analyze', 'collect-logs', 'devel']
# The cloud-init entrypoint calls main without passing sys_argv
for subcommand in conditional_subcommands:
- with mock.patch('sys.argv', ['cloud-init', subcommand]):
+ with mock.patch('sys.argv', ['cloud-init', subcommand, '-h']):
try:
cli.main()
except SystemExit as e:
- self.assertEqual(2, e.code) # exit 2 on proper usage docs
+ self.assertEqual(0, e.code) # exit 2 on proper -h usage
for error_message in expected_errors:
- self.assertIn(error_message, self.stderr.getvalue())
+ self.assertIn(error_message, stdout.getvalue())
def test_analyze_subcommand_parser(self):
"""The subcommand cloud-init analyze calls the correct subparser."""
@@ -94,6 +98,14 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
for subcommand in expected_subcommands:
self.assertIn(subcommand, error)
+ def test_collect_logs_subcommand_parser(self):
+ """The subcommand cloud-init collect-logs calls the subparser."""
+ # Provide -h param to collect-logs to avoid having to mock behavior.
+ stdout = six.StringIO()
+ self.patchStdoutAndStderr(stdout=stdout)
+ self._call_main(['cloud-init', 'collect-logs', '-h'])
+ self.assertIn('usage: cloud-init collect-log', stdout.getvalue())
+
def test_devel_subcommand_parser(self):
"""The subcommand cloud-init devel calls the correct subparser."""
self._call_main(['cloud-init', 'devel'])