← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~smoser/cloud-init:cleanup/collect-logs-stderr into cloud-init:master

 


Diff comments:

> diff --git a/cloudinit/cmd/devel/logs.py b/cloudinit/cmd/devel/logs.py
> index 35ca478..9f8f540 100644
> --- a/cloudinit/cmd/devel/logs.py
> +++ b/cloudinit/cmd/devel/logs.py
> @@ -64,28 +83,48 @@ def collect_logs(tarfile, include_userdata):
>      log_dir = 'cloud-init-logs-{0}'.format(date)
>      with tempdir(dir='/tmp') as tmp_dir:
>          log_dir = os.path.join(tmp_dir, log_dir)
> -        _write_command_output_to_file(
> +        version = None
> +        version = _write_command_output_to_file(
>              ['dpkg-query', '--show', "-f=${Version}\n", 'cloud-init'],
> -            os.path.join(log_dir, 'version'))
> +            os.path.join(log_dir, 'dpkg-version'),
> +            "dpkg version", verbosity)
> +        if which('cloud-init'):
> +            version = _write_command_output_to_file(
> +                ['cloud-init', '--version'],
> +                os.path.join(log_dir, 'version'),
> +                "cloud-init --version", verbosity)
> +        if not version:
> +            version = "not-available"
> +        _debug("collected cloud-init version: %s\n" % version, 1, verbosity)
>          _write_command_output_to_file(
> -            ['dmesg'], os.path.join(log_dir, 'dmesg.txt'))
> +            ['dmesg'], os.path.join(log_dir, 'dmesg.txt'),
> +            "dmesg output", verbosity)
>          _write_command_output_to_file(
> -            ['journalctl', '-o', 'short-precise'],
> -            os.path.join(log_dir, 'journal.txt'))
> +            ['journalctl', '--boot=0', '-o', 'short-precise'],
> +            os.path.join(log_dir, 'journal.txt'),
> +            "systemd journal of current boot", verbosity)
> +
>          for log in CLOUDINIT_LOGS:
> -            copy(log, log_dir)
> +            _collect_file(log, log_dir, verbosity)
>          if include_userdata:
> -            copy(USER_DATA_FILE, log_dir)
> +            _collect_file(USER_DATA_FILE, log_dir, verbosity)
>          run_dir = os.path.join(log_dir, 'run')
>          ensure_dir(run_dir)
> -        shutil.copytree(CLOUDINIT_RUN_DIR, os.path.join(run_dir, 'cloud-init'))
> +        if os.path.exists(CLOUDINIT_RUN_DIR):

This also resolves LP:1766335 which we should document in the description.

> +            shutil.copytree(CLOUDINIT_RUN_DIR,
> +                            os.path.join(run_dir, 'cloud-init'))
> +            _debug("collected dir %s\n" % CLOUDINIT_RUN_DIR, 1, verbosity)
> +        else:
> +            _debug("directory '%s' did not exist\n" % CLOUDINIT_RUN_DIR, 1,
> +                   verbosity)
>          with chdir(tmp_dir):
>              subp(['tar', 'czvf', tarfile, log_dir.replace(tmp_dir + '/', '')])
> +    sys.stderr.write("Wrote %s\n" % tarfile)
>  
>  
>  def handle_collect_logs_args(name, args):
>      """Handle calls to 'cloud-init collect-logs' as a subcommand."""
> -    collect_logs(args.tarfile, args.userdata)
> +    collect_logs(args.tarfile, args.userdata, args.verbosity)
>  
>  
>  def main():
> diff --git a/cloudinit/cmd/devel/tests/test_logs.py b/cloudinit/cmd/devel/tests/test_logs.py
> index dc4947c..e1d945a 100644
> --- a/cloudinit/cmd/devel/tests/test_logs.py
> +++ b/cloudinit/cmd/devel/tests/test_logs.py
> @@ -92,10 +105,13 @@ class TestCollectLogs(FilesystemMockingTestCase):
>              ('dpkg-query', '--show', "-f=${Version}\n", 'cloud-init'):
>                  '0.7fake',
>              ('dmesg',): 'dmesg-out\n',
> -            ('journalctl', '-o', 'short-precise'): 'journal-out\n',
> +            ('journalctl', '--boot=0', '-o', 'short-precise'): 'journal-out\n',
>              ('tar', 'czvf', output_tarfile, date_logdir): ''
>          }
>  
> +        def fake_which(cmd):
> +            return cmd in ('dpkg-query',)

not sure why you have dpkg-query faked here and above, were you intending to perform a which on it in logs.py:87 before attempting that _write_command_output_to_file call?

> +
>          def fake_subp(cmd):
>              cmd_tuple = tuple(cmd)
>              if cmd_tuple not in expected_subp:


-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/344894
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:cleanup/collect-logs-stderr into cloud-init:master.


References