Bug 1611004 - hammer auth-source -h: Error: undefined method `resource' for HammerCLI::MainCommand:Class
Summary: hammer auth-source -h: Error: undefined method `resource' for HammerCLI::Main...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Hammer
Version: 6.4
Hardware: Unspecified
OS: Unspecified
high
low
Target Milestone: Unspecified
Assignee: Marek Hulan
QA Contact: Jan Hutař
URL:
Whiteboard:
Depends On:
Blocks: 1447403
TreeView+ depends on / blocked
 
Reported: 2018-08-01 21:21 UTC by Jan Hutař
Modified: 2019-08-20 12:13 UTC (History)
8 users (show)

Fixed In Version: tfm-rubygem-hammer_cli-0.13.1-1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-08-20 12:13:14 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 24488 0 Normal Closed Help rendering fails 2020-01-28 17:39:34 UTC

Description Jan Hutař 2018-08-01 21:21:49 UTC
Description of problem:
Getting error when I attempt to get help for hammer's "auth-source" endpoint:

Error: undefined method `resource' for HammerCLI::MainCommand:Class

On the other hand, `hammer auth -h` is OK.


Version-Release number of selected component (if applicable):
satellite-6.4.0-10.beta.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_openscap-0.1.6-1.el7sat.noarch
tfm-rubygem-hammer_cli_katello-0.13.4-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_admin-0.0.8-2.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_tasks-0.0.12-2.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_templates-0.1.0-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_docker-0.0.6-3.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_discovery-1.0.0-2.el7sat.noarch
tfm-rubygem-hammer_cli-0.13.0-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_remote_execution-0.1.0-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman-0.13.1-1.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_virt_who_configure-0.0.3-2.el7sat.noarch
tfm-rubygem-hammer_cli_csv-2.3.1-2.el7sat.noarch
tfm-rubygem-hammer_cli_foreman_bootdisk-0.1.3.3-3.el7sat.noarch


How reproducible:
always on my setup


Steps to Reproduce:
1. Have 6.4.0 snap 15
2. # hammer auth-source -h


Actual results:
# hammer -d auth-source -h
[ INFO 2018-08-01T17:17:45 Init] Initialization of Hammer CLI (0.13.0) has started...
[DEBUG 2018-08-01T17:17:45 Init] Running at ruby 2.4.3-p205
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli_config.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/csv.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_admin.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_admin_logging_core.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_admin_logging_katello.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_bootdisk.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_discovery.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_docker.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_openscap.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_remote_execution.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_tasks.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_templates.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_virt_who_configure.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /etc/hammer/cli.modules.d/katello.yml has been loaded
[ INFO 2018-08-01T17:17:45 Init] Configuration from the file /root/.hammer/cli.modules.d/foreman.yml has been loaded
[DEBUG 2018-08-01T17:17:45 SSLoptions] SSL options: {
    :ssl_ca_file => "/etc/pki/katello/certs/katello-server-ca.crt",
     :verify_ssl => true
}
[DEBUG 2018-08-01T17:17:45 API] Global headers: {
        :content_type => "application/json",
              :accept => "application/json;version=2",
    "Accept-Language" => "en"
}
[DEBUG 2018-08-01T17:17:45 API] Follow redirects: never
[DEBUG 2018-08-01T17:17:45 Connection] Registered: foreman
[ INFO 2018-08-01T17:17:46 Modules] Extension module hammer_cli_foreman (0.13.1) loaded.
[ INFO 2018-08-01T17:17:46 Modules] Extension module hammer_cli_foreman_admin (0.0.8) loaded.
[ INFO 2018-08-01T17:17:46 Modules] Extension module hammer_cli_foreman_bootdisk (0.1.3.3) loaded.
[ INFO 2018-08-01T17:17:46 Modules] Extension module hammer_cli_foreman_discovery (1.0.0) loaded.
[ WARN 2018-08-01T17:17:46 HammerCLIForeman::Host::PuppetRunCommand] Resource 'puppet_hosts' does not exist in the API
[ INFO 2018-08-01T17:17:46 Modules] Extension module hammer_cli_foreman_openscap (0.1.6) loaded.
[ WARN 2018-08-01T17:17:47 HammerCLIForemanTemplates::ImportCommand] Resource 'template' does not exist in the API
[ WARN 2018-08-01T17:17:47 HammerCLIForemanTemplates::ExportCommand] Resource 'template' does not exist in the API
[ INFO 2018-08-01T17:17:47 Modules] Extension module hammer_cli_foreman_templates (0.1.0) loaded.
[ INFO 2018-08-01T17:17:47 HammerCLI::MainCommand] subcommand organization (HammerCLIForeman::Organization) was removed.
[ INFO 2018-08-01T17:17:47 HammerCLI::MainCommand] subcommand organization (HammerCLIKatello::Organization) was created.
[ INFO 2018-08-01T17:17:47 Modules] Extension module hammer_cli_katello (0.13.4) loaded.
[DEBUG 2018-08-01T17:17:47 Init] Using locale 'en'
[DEBUG 2018-08-01T17:17:47 Init] 'mo' files for locale domain 'hammer-cli' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/locale'
[DEBUG 2018-08-01T17:17:47 Init] 'mo' files for locale domain 'hammer-cli-foreman' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-0.13.1/locale'
[DEBUG 2018-08-01T17:17:47 Init] 'mo' files for locale domain 'hammer-cli-csv' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_csv-2.3.1/locale'
[DEBUG 2018-08-01T17:17:47 Init] 'mo' files for locale domain 'hammer_cli_foreman_docker' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman_docker-0.0.6/locale'
[DEBUG 2018-08-01T17:17:47 Init] 'mo' files for locale domain 'hammer-cli-foreman-virt-who-configure' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman_virt_who_configure-0.0.3/locale'
[DEBUG 2018-08-01T17:17:47 Init] 'mo' files for locale domain 'hammer-cli-katello' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_katello-0.13.4/locale'
[ INFO 2018-08-01T17:17:47 HammerCLI::MainCommand] Called with options: {"option_debug"=>true}
[ WARN 2018-08-01T17:17:47 HammerCLIForeman::AuthSource] Resource 'auth_sources' does not exist in the API
[DEBUG 2018-08-01T17:17:47 Exception] Using exception handler HammerCLIForeman::ExceptionHandler#handle_help_wanted
[DEBUG 2018-08-01T17:17:47 Exception] Using exception handler HammerCLI::ExceptionHandler#handle_general_exception
[ERROR 2018-08-01T17:17:47 Exception] Error: undefined method `resource' for HammerCLI::MainCommand:Class
Error: undefined method `resource' for HammerCLI::MainCommand:Class
[ERROR 2018-08-01T17:17:47 Exception] 

NoMethodError (undefined method `resource' for HammerCLI::MainCommand:Class):
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/apipie/resource.rb:10:in `resource'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/apipie/command.rb:41:in `help'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/exception_handler.rb:78:in `handle_help_wanted'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/exception_handler.rb:31:in `handle_exception'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/messages.rb:26:in `handle_exception'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/abstract.rb:32:in `rescue in run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/abstract.rb:28:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/abstract.rb:29:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:132:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/bin/hammer:143:in `<top (required)>'
    /usr/bin/hammer:23:in `load'
    /usr/bin/hammer:23:in `<main>'


Expected results:
Should work


Additional info:
Satellite I'm testing on is a 6.3 upgraded to snap15, where I have hit this upgrade issue: bug 1611000, so this bug might be caused by this busted upgrade. I'm reporting it only asap, but I'll try to reproduce again on different host soon.

Comment 4 Marek Hulan 2018-08-02 06:52:44 UTC
this is most likely an unrelated issue masking another problem, linking upstream issue that I recently sent a fix for

Comment 5 Marek Hulan 2018-08-02 06:53:18 UTC
sorry, as a workaround try different command

Comment 6 Jan Hutař 2018-08-02 08:31:01 UTC
(In reply to Marek Hulan from comment #5)
> sorry, as a workaround try different command

`hammer auth -h` (and what I have tried) works. `hammer auth-source -h` seems to be the only one with the problem.

Comment 7 Martin Bacovsky 2018-08-02 09:09:31 UTC
I can not reproduce it on my instance. From the error it seems it is caused by the incomplete upgrade. The reproducing situation seems to be when hammer has a command defined for a resource that is missing from API. This is a bug definitely and needs to be fixed upstream but it shouldn't be hit in downstream so I suggest to remove the blocker flag. In this case I guess foreman-rake apipie:cache:index or re-running the installer will fix the issue.

Comment 8 Martin Bacovsky 2018-08-02 11:32:30 UTC
After some more investigation the error might appear in Satellite when there is a plugin installed in hammer and correspondent feature plugin is missing on the server. Still likely not a blocker.

Comment 9 Martin Bacovsky 2018-08-02 12:07:00 UTC
Also you can confirm this is by unfinished upgrade by observing the warning in hammer log 

[ WARN 2018-08-01T17:17:47 HammerCLIForeman::AuthSource] Resource 'auth_sources' does not exist in the API

Comment 10 Jan Hutař 2018-08-02 12:17:22 UTC
So I did clean upgrade from 6.3 to 6.4 and issue was still there. Then and with comment #4 and #5, I have realized this is most probably bit more annoying duplicate of bug 1447403:

[root@host-8-254-27 ~]# hammer full-help >640.txt
Error: undefined method `resource' for NilClass:Class
[root@host-8-254-27 ~]# stat /root/.cache/apipie_bindings/https___<hostname>/v2/*
  File: ‘/root/.cache/apipie_bindings/https___<hostname>/v2/33ed92375f7b85794c4b92f3fa13a49a.en.json’
  Size: 1067248   	Blocks: 2088       IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 25231216    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:cache_home_t:s0
Access: 2018-08-02 04:16:51.574604478 -0400
Modify: 2018-08-02 04:16:51.572604478 -0400
Change: 2018-08-02 04:16:51.572604478 -0400
 Birth: -

^^^ timestamp +-mathches to the time when I have installed 6.3.0 and used hammer for a first time.

[root@host-8-254-27 ~]# hammer -u admin -p changeme auth-source list
---|----------|--------------------
ID | NAME     | TYPE OF AUTH SOURCE
---|----------|--------------------
1  | Internal | AuthSourceInternal 
---|----------|--------------------
[root@host-8-254-27 ~]# hammer -u admin -p changeme auth-source -h
Usage:
    hammer auth-source [OPTIONS] SUBCOMMAND [ARG] ...

Parameters:
 SUBCOMMAND                    Subcommand
 [ARG] ...                     Subcommand arguments

Subcommands:
 ldap                          Manage LDAP auth sources
 list                          List all auth sources.

Options:
 -h, --help                    Print help
[root@host-8-254-27 ~]# stat /root/.cache/apipie_bindings/https___<hostname>/v2/*
  File: ‘/root/.cache/apipie_bindings/https___host-8-254-27.host.centralci.eng.rdu2.redhat.com/v2/547603bbb53e66a5101e6ef2f2d0628b0fd8ab16.en.json’
  Size: 1420403   	Blocks: 2776       IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 25231237    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:cache_home_t:s0
Access: 2018-08-02 08:07:06.591604478 -0400
Modify: 2018-08-02 08:07:06.590604478 -0400
Change: 2018-08-02 08:07:06.590604478 -0400
 Birth: -

So, removing "Regression" keyword (as I believe same issue existed in 6.2 -> 6.3 upgrade) and will let up to development to decide if this should be considered as a duplicate of bug 1447403, or we will keep this open to track issue when hammer do not purge its cache at a correct time (is it even possible?).

Comment 11 Jan Hutař 2018-08-02 12:20:16 UTC
(In reply to Martin Bacovsky from comment #9)
> Also you can confirm this is by unfinished upgrade by observing the warning
> in hammer log 
> 
> [ WARN 2018-08-01T17:17:47 HammerCLIForeman::AuthSource] Resource
> 'auth_sources' does not exist in the API

Please see the comment above: I can reproduce on correct upgrade as well. This is because `hammer ... -h` does not update apipie_bindings cache. So IMO this is a valid bug, but severity is low (not touching "priority", but I guess it should be changed as well).

Thank you very much for investigation and hints!

Comment 12 Martin Bacovsky 2018-08-02 12:26:50 UTC
From my perspective it is worth to keep the bug to track the behavior of hammer when it does not find the resource in the API description. It clearly shouldn't fail with error but rather print the help and inform that the command won't work when used. 

One of the ways how we can get to such situation is matter of the other mentioned bug and a different thing.

Comment 13 Satellite Program 2018-08-02 15:34:17 UTC
Upstream bug assigned to mhulan

Comment 14 Satellite Program 2018-08-02 15:34:22 UTC
Upstream bug assigned to mhulan

Comment 15 Satellite Program 2018-08-06 16:04:27 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/24488 has been resolved.

Comment 20 Martin Bacovsky 2019-08-20 12:13:14 UTC
This fix was released in hammer-cli 0.14.0 and Satellite 6.5


Note You need to log in before you can comment on or make changes to this bug.