diff options
author | Chad Smith <chad.smith@canonical.com> | 2017-12-14 22:06:29 -0700 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2017-12-14 22:06:29 -0700 |
commit | 4089e20c0a20bc2ad5c21b106687c4f3faf84b4b (patch) | |
tree | ef2aef7bf8b3ba52339befd1e61cc1a917ded53c /cloudinit/cmd/main.py | |
parent | c87588bf1e118095445ed0713f60866592b36ca1 (diff) | |
download | vyos-cloud-init-4089e20c0a20bc2ad5c21b106687c4f3faf84b4b.tar.gz vyos-cloud-init-4089e20c0a20bc2ad5c21b106687c4f3faf84b4b.zip |
cli: Fix error in cloud-init modules --mode=init.
The cli help docs and argument parser allow the 'init' mode value
which caused a traceback.
Fix the cli to support 'init', 'config' and 'final' modes for the
cloud-init modules subcommand.
Add a check in the cli to raise a ValueError if a new
subcommand ends up allowing an unsupported/unimplemented modes.
Drive by unit test additions for a bit better coverage of error
handling.
LP: #1736600
Diffstat (limited to 'cloudinit/cmd/main.py')
-rw-r--r-- | cloudinit/cmd/main.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py index aa56225d..30b37fe1 100644 --- a/cloudinit/cmd/main.py +++ b/cloudinit/cmd/main.py @@ -603,7 +603,11 @@ def status_wrapper(name, args, data_d=None, link_d=None): else: raise ValueError("unknown name: %s" % name) - modes = ('init', 'init-local', 'modules-config', 'modules-final') + modes = ('init', 'init-local', 'modules-init', 'modules-config', + 'modules-final') + if mode not in modes: + raise ValueError( + "Invalid cloud init mode specified '{0}'".format(mode)) status = None if mode == 'init-local': @@ -615,16 +619,18 @@ def status_wrapper(name, args, data_d=None, link_d=None): except Exception: pass + nullstatus = { + 'errors': [], + 'start': None, + 'finished': None, + } if status is None: - nullstatus = { - 'errors': [], - 'start': None, - 'finished': None, - } status = {'v1': {}} for m in modes: status['v1'][m] = nullstatus.copy() status['v1']['datasource'] = None + elif mode not in status['v1']: + status['v1'][mode] = nullstatus.copy() v1 = status['v1'] v1['stage'] = mode |