Wrong return_code in analyze boot
Bug report
The return_code of cloud-init analyze boot is 1, despite being able to successfully collect the information. I would expect a 0 exit code.
Steps to reproduce the problem
import logging
import pycloudlib
from pycloudlib import GCE
logging.basicConfig(level=logging.DEBUG)
cloud = GCE("test")
image = cloud.daily_image("focal")
inst = cloud.launch(image, wait=True)
r = inst.execute("cloud-init analyze boot")
>>> print(f"return_code={r.return_code}\nstdout={r.stdout}\nstderr={r.stderr}")
return_code=1
stdout=-- Most Recent Boot Record --
Kernel Started at: 2023-07-13 08:35:45.578054
Kernel ended boot at: 2023-07-13 08:35:46.914189
Kernel time to boot (seconds): 1.336134910583496
Cloud-init activated by systemd at: 2023-07-13 08:35:51.063430
Time between Kernel end boot and Cloud-init activation (seconds): 4.149240970611572
Cloud-init start: 2023-07-13 08:35:52.504000
stderr=successful
inst.delete(wait=False)
Environment details
- Cloud-init version: 23.1.2-0ubuntu0~20.04.2
- Operating System Distribution: Ubuntu 20.04
- Cloud provider, platform or installer type: GCE
cloud-init logs
@aciba90 can you assign this issue to me if it's okay with you? Would like to work on this task as well.
Thanks, @pasanchamikara, for reaching out and making cloud-init better. We typically do not assign issues to external contributors until they show a real commitment to do it, like a draft PR or so. Please, feel free to toss up a PR or ask for any guidance on how to approach the issue. Many thanks.
Hi @aciba90 because of return statement at the end of analyze_boot function. https://github.com/canonical/cloud-init/blob/main/cloudinit/analyze/init.py#L200
status_code is set at the beggining. For example in case of success.
kernel_info -> ('successful', 1739889197.1411157, 1739889200.2898357, 1739889201.1948047)
We dont have to return status_code as string. it causes sys exit non zero. What about to return just 0 or remove return statement?