Project

General

Profile

Actions

Bug #16206

open

Hammer should warn when user puts multiple options that are intended to be used only once

Added by Renzo Nuccitelli over 8 years ago. Updated almost 5 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Visibility
Target version:
-
Difficulty:
Triaged:
Yes
Team Backlog:
Fixed in Releases:
Found in Releases:
In Kanboard:

Description

Hammer allows to specify each option multiple times and the last value wins. This can be confusing to users:

I have tried a assign several roles at once. Hammer probably is not designed to do this. But it does not failure when passing multiple --role-id options:

[root@foo ~]# hammer -d -v -u admin -p ***** user add-role --id 5 --role-id 11 --role-id 9
[ INFO 2016-08-19 13:40:56 Init] Initialization of Hammer CLI (0.5.1.11) has started...
[DEBUG 2016-08-19 13:40:56 Init] Running at ruby 2.2.2-p95
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli_config.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/csv.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_bootdisk.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_discovery.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_docker.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_remote_execution.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_tasks.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/import.yml has been loaded
[ INFO 2016-08-19 13:40:56 Init] Configuration from the file /etc/hammer/cli.modules.d/katello.yml has been loaded
[DEBUG 2016-08-19 13:40:56 Connection] Registered: foreman
[DEBUG 2016-08-19 13:40:56 API] Global headers: {
        :content_type => "application/json",
              :accept => "application/json;version=2",
    "Accept-Language" => "en" 
}
[DEBUG 2016-08-19 13:40:56 API] Follow redirects: never
[ INFO 2016-08-19 13:40:56 Modules] Extension module hammer_cli_foreman (0.5.1.9) loaded
[ INFO 2016-08-19 13:40:56 Modules] Extension module hammer_cli_foreman_bootdisk (0.1.3.3) loaded
[ INFO 2016-08-19 13:40:56 Modules] Extension module hammer_cli_foreman_discovery (0.0.2.3) loaded
[ INFO 2016-08-19 13:40:57 Modules] Extension module hammer_cli_import (0.11.2) loaded
[ INFO 2016-08-19 13:40:57 HammerCLI::MainCommand] subcommand organization (HammerCLIForeman::Organization) was removed.
[ INFO 2016-08-19 13:40:57 HammerCLI::MainCommand] subcommand organization (HammerCLIKatello::Organization) was created.
[ INFO 2016-08-19 13:40:58 Modules] Extension module hammer_cli_katello (0.0.22.23) loaded
[DEBUG 2016-08-19 13:40:58 Init] Using locale 'en'
[DEBUG 2016-08-19 13:40:58 Init] 'mo' files for locale domain 'hammer-cli' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.5.1.11/locale'
[DEBUG 2016-08-19 13:40:58 Init] 'mo' files for locale domain 'hammer-cli-foreman' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-0.5.1.9/locale'
[DEBUG 2016-08-19 13:40:58 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 2016-08-19 13:40:58 Init] 'mo' files for locale domain 'hammer-cli-katello' loaded from '/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_katello-0.0.22.23/locale'
[ INFO 2016-08-19 13:40:58 HammerCLI::MainCommand] Called with options: {"option_verbose"=>true, "option_debug"=>true, "option_username"=>"admin", "option_password"=>"***"}
[ INFO 2016-08-19 13:40:58 HammerCLIForeman::User] Called with options: {}
[ INFO 2016-08-19 13:40:58 HammerCLIForeman::User::UserAddRoleCommand] Called with options: {"option_role_id"=>9, "option_id"=>"5"}
[ INFO 2016-08-19 13:40:58 API] Server: https://localhost/
[ INFO 2016-08-19 13:40:58 API] GET /api/users/5
[DEBUG 2016-08-19 13:40:58 API] Params: {}
[DEBUG 2016-08-19 13:40:58 API] Headers: {
    :params => {}
}
[DEBUG 2016-08-19 13:40:58 API] Response: {
               "firstname" => "9HnK1L09bh",
                "lastname" => "Ri0CsVpxxj",
                    "mail" => "3edzhg@example.com",
                   "admin" => true,
          "auth_source_id" => 1,
        "auth_source_name" => "Internal",
                "timezone" => nil,
                  "locale" => nil,
           "last_login_on" => "2016-08-11 19:09:37 UTC",
              "created_at" => "2016-08-11 19:06:01 UTC",
              "updated_at" => "2016-08-11 19:09:37 UTC",
                      "id" => 5,
                   "login" => "3edzhg",
        "default_location" => nil,
               "locations" => [],
    "default_organization" => nil,
           "organizations" => [],
    "auth_source_internal" => {
          "id" => 1,
        "type" => "AuthSourceInternal",
        "name" => "Internal" 
    },
      "mail_notifications" => [],
                   "roles" => [
        [0] {
            "name" => "View hosts",
              "id" => 9
        },
        [1] {
            "name" => "Anonymous",
              "id" => 14
        }
    ],
              "usergroups" => []
}
[DEBUG 2016-08-19 13:40:58 API] Response headers: {
                      :date => "Fri, 19 Aug 2016 17:40:58 GMT",
                    :server => "Apache/2.4.6 (Red Hat Enterprise Linux)",
           :x_frame_options => "SAMEORIGIN",
          :x_xss_protection => "1; mode=block",
    :x_content_type_options => "nosniff",
           :foreman_version => "1.11.0.49",
       :foreman_api_version => "2",
           :apipie_checksum => "5d126cac0ca6038faa774a0c7af7f5dc",
             :cache_control => "max-age=0, private, must-revalidate",
              :x_request_id => "4712b898-91e1-490d-9507-f6d566f9a81e",
                 :x_runtime => "0.086214",
              :x_powered_by => "Phusion Passenger 4.0.18",
                :set_cookie => [
        [0] "_session_id=13e2c4c39086a73092da66505ce18630; path=/; secure; HttpOnly" 
    ],
                      :etag => "\"d0f7d79493b9634ffb58c9a74df17401-gzip\"",
                    :status => "200 OK",
                      :vary => "Accept-Encoding",
          :content_encoding => "gzip",
            :content_length => "319",
              :content_type => "application/json; charset=utf-8" 
}
[ INFO 2016-08-19 13:40:58 API] Server: https://localhost/
[ INFO 2016-08-19 13:40:58 API] PUT /api/users/5
[DEBUG 2016-08-19 13:40:58 API] Params: {
    "user" => {
        "role_ids" => [
            [0] "9",
            [1] "14" 
        ]
    }
}
[DEBUG 2016-08-19 13:40:58 API] Headers: {}
[DEBUG 2016-08-19 13:40:58 API] Response: {
               "firstname" => "9HnK1L09bh",
                "lastname" => "Ri0CsVpxxj",
                    "mail" => "3edzhg@example.com",
                   "admin" => true,
          "auth_source_id" => 1,
        "auth_source_name" => "Internal",
                "timezone" => nil,
                  "locale" => nil,
           "last_login_on" => "2016-08-11 19:09:37 UTC",
              "created_at" => "2016-08-11 19:06:01 UTC",
              "updated_at" => "2016-08-11 19:09:37 UTC",
                      "id" => 5,
                   "login" => "3edzhg",
        "default_location" => nil,
               "locations" => [],
    "default_organization" => nil,
           "organizations" => [],
    "auth_source_internal" => {
          "id" => 1,
        "type" => "AuthSourceInternal",
        "name" => "Internal" 
    },
      "mail_notifications" => [],
                   "roles" => [
        [0] {
            "name" => "View hosts",
              "id" => 9
        },
        [1] {
            "name" => "Anonymous",
              "id" => 14
        }
    ],
              "usergroups" => []
}
[DEBUG 2016-08-19 13:40:58 API] Response headers: {
                      :date => "Fri, 19 Aug 2016 17:40:58 GMT",
                    :server => "Apache/2.4.6 (Red Hat Enterprise Linux)",
           :x_frame_options => "SAMEORIGIN",
          :x_xss_protection => "1; mode=block",
    :x_content_type_options => "nosniff",
           :foreman_version => "1.11.0.49",
       :foreman_api_version => "2",
           :apipie_checksum => "5d126cac0ca6038faa774a0c7af7f5dc",
             :cache_control => "max-age=0, private, must-revalidate",
              :x_request_id => "21e09a90-630a-4e7f-a7e4-e70efc08d895",
                 :x_runtime => "0.110168",
              :x_powered_by => "Phusion Passenger 4.0.18",
                :set_cookie => [
        [0] "request_method=PUT; path=/",
        [1] "_session_id=310dff7cc3fa37d253af168b49a674cb; path=/; secure; HttpOnly" 
    ],
                      :etag => "\"d0f7d79493b9634ffb58c9a74df17401-gzip\"",
                    :status => "200 OK",
                      :vary => "Accept-Encoding",
          :content_encoding => "gzip",
            :content_length => "319",
              :content_type => "application/json; charset=utf-8" 
}
User role has been assigned

Besides command doesn't show any error, it ignored the first role with id "11" passed as parameter:

[root@foo ~]# hammer -u admin -p ***** user info --id 5
Id:                   5
Login:                3edzhg
Name:                 9HnK1L09bh Ri0CsVpxxj
Email:                3edzhg@example.com
Admin:                yes
Authorized by:        Internal
Locale:               default
Timezone:             default
Last login:           2016/08/11 19:09:37
Default organization:
Default location:
Roles:
    View hosts
    Anonymous
User groups:

Created at:           2016/08/11 19:06:01
Updated at:           2016/08/11 19:09:37

List of host

[root@foo ~]# hammer -u admin -p ***** role list
---|-------------------------
ID | NAME
---|-------------------------
6  | Access Insights Admin
5  | Access Insights Viewer
14 | Anonymous
1  | Boot disk access
18 | Compliance manager
17 | Compliance viewer
19 | Create ARF report
13 | Default user
16 | Discovery Manager
15 | Discovery Reader
10 | Edit hosts
8  | Edit partition tables
7  | Manager
4  | Red Hat Access Logs
21 | Remote Execution Manager
20 | Remote Execution User
12 | Site manager
2  | Tasks Manager
3  | Tasks Reader
11 | Viewer
9  | View hosts
---|-------------------------

So this command should:

1) Assign all roles present on multiple role-id option or;
2) Return an error msg informing multiple role-id options are not allowed


Related issues 1 (0 open1 closed)

Related to Hammer CLI - Tracker #2823: Tracker for usability issuesClosed

Actions
Actions #1

Updated by Renzo Nuccitelli over 8 years ago

Forget to mention, I am from satellite QE team, username rnuccite.

Actions #2

Updated by Tomáš Strachota over 8 years ago

  • Category set to Hammer core

This is issue for all options in hammer commands. Clamp (the framework we build on top of) allows to overwrite parameters without any warning:

hammer template list --per-page 10 --per-page 5
---|----------------------------|----------
ID | NAME                       | TYPE     
---|----------------------------|----------
7  | Alterator default          | provision
8  | Alterator default finish   | finish   
9  | Alterator default PXELinux | PXELinux 
44 | alterator_pkglist          | snippet  
10 | Atomic Kickstart default   | provision
---|----------------------------|----------
Page 1 of 13 (use --page and --per-page for navigation)

We should either fail with error or at least print a warning in such case.

Actions #3

Updated by Tomáš Strachota over 8 years ago

  • Subject changed from add-role --role-id does not give errors when trying multiple roles to Hammer should warn when user puts multiple options that are intended to be used only once
  • Description updated (diff)

I updated the title to cover the issue in general.

Actions #4

Updated by Tomáš Strachota over 8 years ago

Actions #5

Updated by Oleh Fedorenko almost 5 years ago

  • Triaged changed from No to Yes
Actions #6

Updated by Shira Maximov almost 5 years ago

  • Category changed from Hammer core to Visibility
Actions

Also available in: Atom PDF