cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

Argument parsing issue

Open sshedi opened this issue 1 year ago • 1 comments

Bug report

The order of args in cloud-init-24.1.4 is causing problem while cloud init is invoked via cli.

Following is the error:

root@ph5dev [ ~/t ]# cloud-init --file=user-data -d modules --mode config
usage: /usr/bin/cloud-init [-h] [--version] [--debug] [--force]
                           {init,modules,single,query,features,analyze,devel,collect-logs,clean,status,schema} ...
/usr/bin/cloud-init: error: unrecognized arguments: --file=user-data

Steps to reproduce the problem

cloud-init --file=user-data -d modules --mode config --> fails

cloud-init -d modules --mode config --file user-data --> works

In previous versions of cloud-init this order didn't matter. And from an user point of view, it shouln't matter now as well.

Environment details

  • Cloud-init version: cloud-init-24.1.4
  • Operating System Distribution: Photon OS
  • Cloud provider, platform or installer type: NA

sshedi avatar May 18 '24 10:05 sshedi

Additional info:

This started happening after: https://github.com/canonical/cloud-init/pull/4559

I think this should be added back to main.py

--- /usr/lib/python3.11/site-packages/cloudinit/cmd/main.py	2024-05-18 10:37:34.296793290 +0000
+++ main.py	2024-05-18 10:37:16.348792428 +0000
@@ -877,7 +877,14 @@ def main(sysv_args=None):
         dest="force",
         default=False,
     )
-
+    parser.add_argument(
+        "--file",
+        "-f",
+        action="append",
+        dest="files",
+        help="Use additional yaml configuration files.",
+        type=argparse.FileType("rb"),
+    )
     parser.set_defaults(reporter=None)
     subparsers = parser.add_subparsers(title="Subcommands", dest="subcommand")

cc: @blackboxsw @CalvoM

sshedi avatar May 18 '24 10:05 sshedi

@sshedi , upstream, we have decided we're going to keep this as a breaking change given that the old argument placement did not make sense. Since the --file argument cannot apply to all cloud-init commands, it does not make sense to include it as a top-level flag.

Downstream, Ubuntu has added a patch to remove this behavior from existing/supported releases. See the downstream bug for more details.

Since the behavior change is intentional, I'm going to close this bug, but feel free to comment or re-open if I have missed something.

TheRealFalcon avatar May 20 '24 17:05 TheRealFalcon

Thanks @TheRealFalcon I will take it forward from here.

sshedi avatar May 20 '24 17:05 sshedi