Skip to content

Commit

Permalink
cmd: Don't write json status files for non-boot stages (#4478)
Browse files Browse the repository at this point in the history
Don't use status_wrapper() for `cloud-init modules --mode init`.
      
Both status.json and result.json are currently written when `cloud-init
modules --mode init` is ran. This is unecessary since this is not a boot
command used by cloud-init, and as a workaround for previous bugs related to
this behavior this leaves behind unwanted keys in status.json.

This aligns cloud-init code's behavior with documented behavior.
  • Loading branch information
holmanb authored Oct 9, 2023
1 parent 9fde069 commit f780cf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cloudinit/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@ def status_wrapper(name, args, data_d=None, link_d=None):
modes = (
"init",
"init-local",
"modules-init",
"modules-config",
"modules-final",
)
Expand Down Expand Up @@ -1059,7 +1058,10 @@ def main(sysv_args=None):
# Setup signal handlers before running
signal_handler.attach_handlers()

if name in ("modules", "init"):
# Write boot stage data to write status.json and result.json
# Exclude modules --mode=init, since it is not a real boot stage and
# should not be written into status.json
if "init" == name or ("modules" == name and "init" != args.mode):
functor = status_wrapper

rname = None
Expand Down
8 changes: 8 additions & 0 deletions tests/unittests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def myaction(name, args):
cli.status_wrapper("init", myargs, data_d, link_d)
# No errors reported in status
status_v1 = m_json.call_args_list[1][0][1]["v1"]
assert status_v1.keys() == {
"datasource",
"init-local",
"init",
"modules-config",
"modules-final",
"stage",
}
assert ["an error"] == status_v1["init-local"]["errors"]
assert "SomeDatasource" == status_v1["datasource"]
assert False is os.path.exists(
Expand Down

0 comments on commit f780cf9

Please sign in to comment.