Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Handle missing commands gracefully #785

Merged
merged 2 commits into from
Aug 23, 2022

Conversation

vinzenz
Copy link
Member

@vinzenz vinzenz commented Jul 22, 2022

Previously when leapp was executed but no cli commands were installed,
the leapp execution failed with an exception.

This patch will add specific handling to this particular scenario and
return a 1 exit code.

Signed-off-by: Vinzenz Feenstra vfeenstr@redhat.com
Jira ref.: OAMG-7148

@github-actions
Copy link

Thank you for contributing to the Leapp project!

Please note that every PR needs to comply with the Leapp Guidelines and must pass all tests in order to be mergable.
If you want to request a review or rebuild a package in copr, you can use following commands as a comment:

  • review please to notify leapp developers of review request
  • /packit copr-build to submit a public copr build using packit

To launch regression testing public members of oamg organization can leave the following comment:

  • /rerun to schedule basic regression tests using this pr build and leapp-repository*master* as artifacts
  • /rerun 42 to schedule basic regression tests using this pr build and leapp-repository*PR42* as artifacts
  • /rerun-all to schedule all tests (including sst) using this pr build and leapp-repository*master* as artifacts
  • /rerun-all 42 to schedule all tests (including sst) using this pr build and leapp-repository*PR42* as artifacts

Please open ticket in case you experience technical problem with the CI. (RH internal only)

Note: In case there are problems with tests not being triggered automatically on new PR/commit or pending for a long time, please consider rerunning the CI by commenting leapp-ci build (might require several comments). If the problem persists, contact leapp-infra.

@vinzenz vinzenz force-pushed the handle-missing-commands-gracefully branch 3 times, most recently from f0faa45 to d72b339 Compare July 26, 2022 09:42
@fernflower
Copy link
Member

/rerun

@github-actions
Copy link

Copr build succeeded: https://copr.fedorainfracloud.org/coprs/build/4685849

@github-actions
Copy link

Testing Farm request for RHEL-8.6-rhui/4656862;4685849 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-7.9-rhui/4656862;4685849 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-8.6.0-Nightly/4656862;4685849 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-7.9-ZStream/4656862;4685849 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

leapp/cli/__init__.py Outdated Show resolved Hide resolved
pirat89 added a commit to pirat89/leapp-repository that referenced this pull request Aug 18, 2022
The CLI for the leapp utility is provided nowadays by leapp-repository
packages. However, some people are used to install just `leapp` instead
of specific repository as we suggest (e.g. `leapp-upgrade`).

To handle the situation we decided to provide a proper error msg
to users suggesting what they should do. Inspired by DNF (hi guys \o)
we decided to set virtual provides in leapp-repository packages:
    leapp-command(CMD)
per each leapp CMD provided by particular package, so users can be
suggested to install missing packages e.g. by:
     dnf install 'leapp-command(upgrade)'
when they want to run `leapp upgrade`. Same for all other commands.

See the following PR in leapp handling this problem:
    oamg/leapp#785
@fernflower
Copy link
Member

/rerun

@github-actions
Copy link

Copr build succeeded: https://copr.fedorainfracloud.org/coprs/build/4746223

@github-actions
Copy link

Testing Farm request for RHEL-8.6-rhui/4744089;4746223 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-7.9-rhui/4744089;4746223 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-8.7.0-Nightly/4744089;4746223 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-8.6.0-Nightly/4744089;4746223 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

fernflower pushed a commit to oamg/leapp-repository that referenced this pull request Aug 18, 2022
The CLI for the leapp utility is provided nowadays by leapp-repository
packages. However, some people are used to install just `leapp` instead
of specific repository as we suggest (e.g. `leapp-upgrade`).

To handle the situation we decided to provide a proper error msg
to users suggesting what they should do. Inspired by DNF (hi guys \o)
we decided to set virtual provides in leapp-repository packages:
    leapp-command(CMD)
per each leapp CMD provided by particular package, so users can be
suggested to install missing packages e.g. by:
     dnf install 'leapp-command(upgrade)'
when they want to run `leapp upgrade`. Same for all other commands.

See the following PR in leapp handling this problem:
    oamg/leapp#785
@github-actions
Copy link

Testing Farm request for RHEL-7.9-ZStream/4744089;4746223 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-7.9-ZStream/4744089;4746223 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@fernflower
Copy link
Member

/rerun

@github-actions
Copy link

Copr build succeeded: https://copr.fedorainfracloud.org/coprs/build/4746686

@fernflower fernflower force-pushed the handle-missing-commands-gracefully branch from be46ad8 to a5b25ce Compare August 18, 2022 14:03
@fernflower
Copy link
Member

/packit copr-build

@fernflower
Copy link
Member

fernflower commented Aug 18, 2022

@pirat89 Sorry, being lazy here - how about we point the user to search for any leapp-command(*) package. And then, when they installs it and still invokes leapp with a non-existent command, we will let the framework+repositories do the job of telling them that it's not how leapp should be used?

[root@ip-10-29-163-158 ~]# leapp dddd
     
Command "dddd" is unknown.
Most likely you are missing particular leapp repositories that provide this command.
Try installing leapp-command(*) package first.

If they still invoke leapp with bad argument, the second invocation will be pretty informative

[root@ip-10-29-163-158 ~]# leapp ddd
usage: leapp [-h] [--version] command ...

Optional arguments:
  -h, --help  show this help message and exit
  --version   show program's version number and exit

Required arguments:
  command
    answer    Manage answerfile generation: register persistent user choices
              for specific dialog sections
    list-runs
              List previous Leapp upgrade executions
    preupgrade
              Generate preupgrade report
    rerun     Re-runs the upgrade from the given phase and using the
              information and progress from the last invocation of leapp
              upgrade.
    upgrade   Upgrade the current system to the next available major version.
error: argument command: invalid choice: 'ddd' (choose from 'answer', 'list-runs', 'preupgrade', 'rerun', 'upgrade')

@github-actions
Copy link

Testing Farm request for RHEL-7.9-rhui/4746605;4746686 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-8.7.0-Nightly/4746605;4746686 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-8.6.0-Nightly/4746605;4746686 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-7.9-ZStream/4746605;4746686 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-7.9-ZStream/4746605;4746686 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@pirat89
Copy link
Member

pirat89 commented Aug 19, 2022

# leapp dddd
     
Command "dddd" is unknown.
Most likely you are missing particular leapp repositories that provide this command.
Try installing leapp-command(*) package first.

@fernflower this could be confusing for users. They will not find the leapp-command(*) package as it does not exist. If they just copy paste that, it could have various outputs based on the current setup. What about this:

Command "dddd" is unknown.
Most likely there is a typo in the command or particular leapp repositories that provide this command
are not present on the system.
You can try to install the missing content by: `dnf install 'leapp-command(dddd)'`

When we can easily print the command, we should put it there instead of the asterisk. As on RHEL 7 we know that leapp-upgrade packages will be always installed with leapp, we are ok to refer to DNF as we know it will be installed as well - even when in such a case, seeing this msg will most likely mean a typo in the command :)
Update: added the info about the typo as well.

@pirat89 pirat89 added this to the 7.9/8.7 milestone Aug 19, 2022
@pirat89 pirat89 added the bug label Aug 19, 2022
@fernflower
Copy link
Member

fernflower commented Aug 22, 2022

@pirat89 Well, they can run dnf install -y leapp-command(*) and they will get the leapp-repository package installed. Isn't it the whole idea?
Whereas if they run dnf-install -y leapp-command(dddd) could leave them confused, as it will return No package found.

@Rezney @vinzenz wdyt? Let's agree on the wording and be done with this patch.

@pirat89
Copy link
Member

pirat89 commented Aug 22, 2022

@fernflower let's discuss that. in both cases, the command is wrong as apostrophes/quotes are missing. Additionally, asterisk is not good as it will start to try to install all packages providing any leapp command. The idea is to install the right package providing the desired command. So no, I am taking the replacement of the asterisk by the particular command as good practice.

leapp/cli/__init__.py Outdated Show resolved Hide resolved
Previously when leapp was executed but no cli commands were installed,
the leapp execution failed with an exception.

This patch will add specific handling to this particular scenario and
return a 1 exit code.

Co-authored-by: Petr Stodůlka <pstodulk@redhat.com>
Co-authored-by: Inessa Vasilevskaya <ivasilev@redhat.com>

Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
@fernflower fernflower force-pushed the handle-missing-commands-gracefully branch from 20adca4 to 87ba733 Compare August 22, 2022 13:40
@pirat89
Copy link
Member

pirat89 commented Aug 22, 2022

@vinzenz @fernflower so I have 1 good and 2 bad news. The fix works as expected for the commands when there is not any command installed:

[root@localhost ~]# leapp upgrade

Command "upgrade" is unknown.
Most likely there is a typo in the command or particular leapp repositories that provide this command
are not present on the system.
You can try to install the missing content e.g. by the following command: `dnf install 'leapp-command(upgrade)'`

But it has different behaviour when any command is provided:

leapp ohoo
usage: leapp [-h] [--version] command ...

Optional arguments:
  -h, --help  show this help message and exit
  --version   show program's version number and exit

Required arguments:
  command
    answer    Manage answerfile generation: register persistent user choices
              for specific dialog sections
    list-runs
              List previous Leapp upgrade executions
    preupgrade
              Generate preupgrade report
    rerun     Re-runs the upgrade from the given phase and using the
              information and progress from the last invocation of leapp
              upgrade.
    upgrade   Upgrade the current system to the next available major version.
error: argument command: invalid choice: 'ohoo' (choose from 'answer', 'list-runs', 'preupgrade', 'rerun', 'upgrade')

And when no commands are provided, also CLI options are treated as commands:

[root@localhost ~]# leapp --oko

Command "--oko" is unknown.
Most likely there is a typo in the command or particular leapp repositories that provide this command
are not present on the system.
You can try to install the missing content e.g. by the following command: `dnf install 'leapp-command(--oko)'`

@vinzenz @fernflower @oamg/developers how we will deal with this? To be honest, I am not strongly convinced that this is blocker now. As in case some commands are available, right now we know we are basically still ok. And if nothing is available, well, we expect that people will always call at least one command, so it should be still ok, like:

[root@localhost ~]# leapp upgrade --oko

Command "upgrade" is unknown.
Most likely there is a typo in the command or particular leapp repositories that provide this command
are not present on the system.
You can try to install the missing content e.g. by the following command: `dnf install 'leapp-command(upgrade)'`

If we can fix it quickly, let's fix it. If not, I think we should go with this. But I want to know your opinion on that as well.

@fernflower fernflower force-pushed the handle-missing-commands-gracefully branch from ef59117 to 8503174 Compare August 22, 2022 18:34
@fernflower
Copy link
Member

/rerun

@github-actions
Copy link

Copr build succeeded: https://copr.fedorainfracloud.org/coprs/build/4755951

@github-actions
Copy link

Testing Farm request for RHEL-7.9-rhui/4755849;4755951 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@fernflower
Copy link
Member

@pirat89 Only a straightforward easy fix comes to my mind, please see the latest commit (we can definitely tune the error message wording, it is just an example).

[root@ip-10-29-163-91 ~]# leapp --noarg
No such argument --noarg
[root@ip-10-29-163-91 ~]# leapp nocmd
Command "nocmd" is unknown.
Most likely there is a typo in the command or particular leapp repositories that provide this command are not present on the system.
You can try to install the missing content e.g. by the following command: `dnf install 'leapp-command(nocmd)'`

Imho we have solved the original problem with this patch - there is no more ugly confusing traceback and the user actually gets pointed in the right direction.

@github-actions
Copy link

Testing Farm request for RHEL-8.7.0-Nightly/4755849;4755951 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-8.6.0-Nightly/4755849;4755951 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-7.9-ZStream/4755849;4755951 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@github-actions
Copy link

Testing Farm request for RHEL-7.9-ZStream/4755849;4755951 regression testing has been created.
Once finished, results should be available here.
Full pipeline log.

@pirat89
Copy link
Member

pirat89 commented Aug 23, 2022

@pirat89 Only a straightforward easy fix comes to my mind, please see the latest commit (we can definitely tune the error message wording, it is just an example).

[root@ip-10-29-163-91 ~]# leapp --noarg
No such argument --noarg
[root@ip-10-29-163-91 ~]# leapp nocmd
Command "nocmd" is unknown.
Most likely there is a typo in the command or particular leapp repositories that provide this command are not present on the system.
You can try to install the missing content e.g. by the following command: `dnf install 'leapp-command(nocmd)'`

Imho we have solved the original problem with this patch - there is no more ugly confusing traceback and the user actually gets pointed in the right direction.

Agree. I think this is good enough. Works as written. Thanks :) Merging

@pirat89 pirat89 merged commit 649025b into oamg:master Aug 23, 2022
@pirat89 pirat89 added the changelog-checked The merger/reviewer checked the changelog draft document and updated it when relevant label Aug 23, 2022
pirat89 added a commit to pirat89/leapp that referenced this pull request Aug 23, 2022
## Packaging
-  bumped leapp-framework to 3.1 (oamg#677)

## Framework

### Fixes
- Fixed a problem where passing environment variables to an executed child process modified the environment variables of the parent process (​​oamg#784)
- Ignore invalid FQDNs (oamg#790)

### Enhancements
- Deprecate `reporting.(Tags|Flags)`, replaced by `reporting.Groups` (oamg#677, oamg#781, oamg#788)
- Introduce `is_inhibitor` function (oamg#677)
- Introduce a `Blob` model field (oamg#789)
- Introduce new report JSON schema v1.2.0 (default: 1.1.0) (oamg#677)

## Leapp (tool)

### Fixes
- Handle missing CLI commands gracefully (oamg#785)
- Requires to be executed by root only (oamg#775)
@pirat89 pirat89 mentioned this pull request Aug 23, 2022
pirat89 added a commit to pirat89/leapp that referenced this pull request Aug 23, 2022
## Packaging
-  bumped leapp-framework to 3.1 (oamg#677)

## Framework

### Fixes
- Fixed a problem where passing environment variables to an executed child process modified the environment variables of the parent process (​​oamg#784)
- Ignore invalid FQDNs (oamg#790)

### Enhancements
- Deprecate `reporting.(Tags|Flags)`, replaced by `reporting.Groups` (oamg#677, oamg#781, oamg#788)
- Introduce `is_inhibitor` function (oamg#677)
- Introduce a `Blob` model field (oamg#789)
- Introduce new report JSON schema v1.2.0 (default: 1.1.0) (oamg#677)

## Leapp (tool)

### Fixes
- Handle missing CLI commands gracefully (oamg#785)
- Requires to be executed by root only (oamg#775)

Signed-off-by: Petr Stodulka <pstodulk@redhat.com>
MichalHe pushed a commit that referenced this pull request Aug 23, 2022
## Packaging
-  bumped leapp-framework to 3.1 (#677)

## Framework

### Fixes
- Fixed a problem where passing environment variables to an executed child process modified the environment variables of the parent process (​​#784)
- Ignore invalid FQDNs (#790)

### Enhancements
- Deprecate `reporting.(Tags|Flags)`, replaced by `reporting.Groups` (#677, #781, #788)
- Introduce `is_inhibitor` function (#677)
- Introduce a `Blob` model field (#789)
- Introduce new report JSON schema v1.2.0 (default: 1.1.0) (#677)

## Leapp (tool)

### Fixes
- Handle missing CLI commands gracefully (#785)
- Requires to be executed by root only (#775)

Signed-off-by: Petr Stodulka <pstodulk@redhat.com>

Signed-off-by: Petr Stodulka <pstodulk@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug changelog-checked The merger/reviewer checked the changelog draft document and updated it when relevant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants