stx-openstack: Failed to parse multi-word options in container-backed CLIs

Bug #2036447 reported by Luan Nunes Utimura
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
StarlingX
Fix Released
Low
Luan Nunes Utimura

Bug Description

Brief Description
-----------------
When using container-backed OpenStack CLIs, it has been observed that commands with multi-word options are failing to run due to poor interpretation of parameters by the clients wrapper script.

Severity
--------
Minor.

Only affects commands with multi-word options and it can be worked around with quote escaping.

Steps to Reproduce
------------------
Logged in as `sysadmin`:
1) Source /var/opt/openstack/admin-openrc;
2) Run command with multi-word options, e.g.:
   ```
   openstack project create --description="words separated by space" my_project
   ```

Expected Behavior
------------------
Project `my_project` is created successfully.

Actual Behavior
----------------
Options are poorly parsed and command is not executed.

Reproducibility
---------------
Reproducible.

System Configuration
--------------------
Seen on AIO-SX, but should affect all system configurations.

Branch/Pull Time/Commit
-----------------------
StarlingX (master).
StarlingX OpenStack (master).

Last Pass
---------
N/A.

Timestamp/Logs
--------------
```
[sysadmin@controller-0 ~(keystone_admin)]$ openstack project create --description="words separated by space" my_project
usage: openstack project create [-h] [-f {json,shell,table,value,yaml}] [-c COLUMN] [--noindent] [--prefix PREFIX] [--max-width <integer>] [--fit-width] [--print-empty] [--domain <domain>] [--parent <project>] [--description <description>] [--enable | --disable] [--property <key=value>] [--or-show] [--tag <tag>] <project-name>
openstack project create: error: unrecognized arguments: by space my_project
command terminated with exit code 2
```

Test Activity
-------------
Regression Testing.

Workaround
----------
Run command with multi-word options with escaped quotes:
```
[sysadmin@controller-0 ~(keystone_admin)]$ openstack project create --description=\"words separated by space\" my_project
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | words separated by space |
| domain_id | default |
| enabled | True |
| id | 1e84526b1aca43728273f1b7cb24d0a0 |
| is_domain | False |
| name | my_project |
| options | {} |
| parent_id | default |
| tags | [] |
+-------------+----------------------------------+
```

Changed in starlingx:
assignee: nobody → Luan Nunes Utimura (lutimura)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to openstack-armada-app (master)
Changed in starlingx:
status: New → In Progress
tags: added: stx.9.0 stx.distro.openstack
summary: - stx-openstack: Failed to parse multi-word options in the container-
- backed CLI
+ stx-openstack: Failed to parse multi-word options in container-backed
+ CLIs
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to openstack-armada-app (master)

Reviewed: https://review.opendev.org/c/starlingx/openstack-armada-app/+/895718
Committed: https://opendev.org/starlingx/openstack-armada-app/commit/670ec0c6e598b3c872d2206392bd37b239e2fc28
Submitter: "Zuul (22348)"
Branch: master

commit 670ec0c6e598b3c872d2206392bd37b239e2fc28
Author: Luan Nunes Utimura <email address hidden>
Date: Mon Sep 18 14:06:14 2023 -0300

    clients: Fix multi-word option parsing in CLIs

    When using container-backed OpenStack CLIs, it has been observed that
    commands with multi-word options are failing to run due to poor parsing
    of parameters by the wrapper script.

    Currently, all commands that are redirected to the clients container are
    expanded using the * parameter, i.e., $* [1]. However, according to [2],
    a more appropriate option would be to expand the * parameter with the
    Q operator, since:

    > The expansion is a string that is the value of _parameter_ quoted in
      a format that can be reused as input.

    Which is exactly what we are doing with the wrapper script -- reusing
    inputs but in a containerized environment.

    [1] https://opendev.org/starlingx/openstack-armada-app/src/commit/4c238a8063c27815954c3aa151cdcae7dd5f67cb/stx-openstack-helm-fluxcd/stx-openstack-helm-fluxcd/helm-charts/clients/templates/bin/_clients-wrapper.sh.tpl#L63-L64
    [2] https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

    Test Plan:
    PASS - Build stx-openstack-helm-fluxcd package
    PASS - Build stx-openstack helm charts
    PASS - Upload/apply stx-openstack
    PASS - Source `/var/opt/openstack/admin-openrc`
    PASS - Run command with multi-word option(s), e.g.:
           $ openstack project create \
             --description="words separated by space" my_project
           and confirm that it's executed successfully
    PASS - Remove/delete stx-openstack

    Closes-Bug: 2036447

    Change-Id: I6441cf077e0bcfe386d7086ea90298e6dd247a2a
    Signed-off-by: Luan Nunes Utimura <email address hidden>

Changed in starlingx:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to openstack-armada-app (f/antelope)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to openstack-armada-app (f/antelope)

Reviewed: https://review.opendev.org/c/starlingx/openstack-armada-app/+/895786
Committed: https://opendev.org/starlingx/openstack-armada-app/commit/c4c0ad9e042dbf6b3a658cf5331646dd050dee43
Submitter: "Zuul (22348)"
Branch: f/antelope

commit c4c0ad9e042dbf6b3a658cf5331646dd050dee43
Author: Luan Nunes Utimura <email address hidden>
Date: Mon Sep 18 14:06:14 2023 -0300

    clients: Fix multi-word option parsing in CLIs

    When using container-backed OpenStack CLIs, it has been observed that
    commands with multi-word options are failing to run due to poor parsing
    of parameters by the wrapper script.

    Currently, all commands that are redirected to the clients container are
    expanded using the * parameter, i.e., $* [1]. However, according to [2],
    a more appropriate option would be to expand the * parameter with the
    Q operator, since:

    > The expansion is a string that is the value of _parameter_ quoted in
      a format that can be reused as input.

    Which is exactly what we are doing with the wrapper script -- reusing
    inputs but in a containerized environment.

    [1] https://opendev.org/starlingx/openstack-armada-app/src/commit/4c238a8063c27815954c3aa151cdcae7dd5f67cb/stx-openstack-helm-fluxcd/stx-openstack-helm-fluxcd/helm-charts/clients/templates/bin/_clients-wrapper.sh.tpl#L63-L64
    [2] https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

    Test Plan:
    PASS - Build stx-openstack-helm-fluxcd package
    PASS - Build stx-openstack helm charts
    PASS - Upload/apply stx-openstack
    PASS - Source `/var/opt/openstack/admin-openrc`
    PASS - Run command with multi-word option(s), e.g.:
           $ openstack project create \
             --description="words separated by space" my_project
           and confirm that it's executed successfully
    PASS - Remove/delete stx-openstack

    Closes-Bug: 2036447

    Change-Id: I6441cf077e0bcfe386d7086ea90298e6dd247a2a
    Signed-off-by: Luan Nunes Utimura <email address hidden>
    (cherry picked from commit 670ec0c6e598b3c872d2206392bd37b239e2fc28)

tags: added: in-f-antelope
Ghada Khalil (gkhalil)
Changed in starlingx:
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.