Bug #18742
closedUndocumented behavior with assigning all entities by specifying option with no value
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1359852
Description of problem:
There is an undocumented behavior on assigning entities using '--<entity>-ids' and providing no value - ALL entities will be assigned.
Omitting the key will assign no entities.
e.g.:
<not specifying "--domains" nor "--domain-ids" options>
# hammer -u admin -p changeme --csv organization create --name cli_org_2 Message,Id,Name Organization created,85,cli_org_2 production.log: 2016-07-25 10:17:52 [app] [I] Started POST "/katello/api/organizations" for ::1 at 2016-07-25 10:17:52 -0400 2016-07-25 10:17:52 [app] [I] Processing by Katello::Api::V2::OrganizationsController#create as JSON 2016-07-25 10:17:52 [app] [I] Parameters: {"name"=>"cli_org_2", "organization"=>{"name"=>"cli_org_2"}, "api_version"=>"v2"} 2016-07-25 10:17:52 [app] [I] Authorized user admin(admin) 2016-07-25 10:17:52 [app] [I] Expire fragment views/tabs_and_title_records-6 (0.2ms) 2016-07-25 10:17:52 [app] [I] Expire fragment views/tabs_and_title_records-1 (0.1ms) 2016-07-25 10:17:52 [app] [I] Expire fragment views/tabs_and_title_records-2 (0.1ms) 2016-07-25 10:17:52 [app] [I] Expire fragment views/tabs_and_title_records-16 (0.1ms) 2016-07-25 10:17:52 [app] [I] Expire fragment views/tabs_and_title_records-18 (0.1ms) 2016-07-25 10:17:52 [app] [I] Expire fragment views/tabs_and_title_records-12 (0.1ms) 2016-07-25 10:17:52 [app] [I] Expire fragment views/tabs_and_title_records-17 (0.1ms) 2016-07-25 10:17:52 [app] [I] Expire fragment views/tabs_and_title_records-9 (0.1ms) 2016-07-25 10:17:54 [app] [I] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.0.0.68/app/views/katello/api/v2/organizations/show.json.rabl within katello/api/v2/layouts/resource (446.9ms) 2016-07-25 10:17:54 [app] [I] Completed 200 OK in 2820ms (Views: 430.0ms | ActiveRecord: 244.4ms)
<specifying "--domains" with no|empty value>
# hammer -u admin -p changeme --csv organization create --name cli_org_1 --domains Message,Id,Name Organization created,84,cli_org_1 production.log: 2016-07-25 10:15:50 [app] [I] Started GET "/api/domains?search=" for ::1 at 2016-07-25 10:15:50 -0400 2016-07-25 10:15:50 [app] [I] Processing by Api::V2::DomainsController#index as JSON 2016-07-25 10:15:50 [app] [I] Parameters: {"search"=>"", "apiv"=>"v2", "domain"=>{}} 2016-07-25 10:15:50 [app] [I] Authorized user admin(admin) 2016-07-25 10:15:50 [app] [I] Rendered api/v2/domains/index.json.rabl within api/v2/layouts/index_layout (18.2ms) 2016-07-25 10:15:50 [app] [I] Completed 200 OK in 68ms (Views: 20.7ms | ActiveRecord: 17.4ms) 2016-07-25 10:15:50 [app] [I] Started POST "/katello/api/organizations" for ::1 at 2016-07-25 10:15:50 -0400 2016-07-25 10:15:50 [app] [I] Processing by Katello::Api::V2::OrganizationsController#create as JSON 2016-07-25 10:15:50 [app] [I] Parameters: {"name"=>"cli_org_1", "organization"=>{"name"=>"cli_org_1", "domain_ids"=>[6, 5, 4, 8, 7, 1, 2, 3, 9]}, "api_version"=>"v2"} 2016-07-25 10:15:50 [app] [I] Authorized user admin(admin) 2016-07-25 10:15:51 [app] [I] Expire fragment views/tabs_and_title_records-6 (0.2ms) 2016-07-25 10:15:51 [app] [I] Expire fragment views/tabs_and_title_records-1 (0.1ms) 2016-07-25 10:15:51 [app] [I] Expire fragment views/tabs_and_title_records-2 (0.1ms) 2016-07-25 10:15:51 [app] [I] Expire fragment views/tabs_and_title_records-16 (0.1ms) 2016-07-25 10:15:51 [app] [I] Expire fragment views/tabs_and_title_records-18 (0.1ms) 2016-07-25 10:15:51 [app] [I] Expire fragment views/tabs_and_title_records-12 (0.1ms) 2016-07-25 10:15:51 [app] [I] Expire fragment views/tabs_and_title_records-17 (0.1ms) 2016-07-25 10:15:51 [app] [I] Expire fragment views/tabs_and_title_records-9 (0.2ms) 2016-07-25 10:15:53 [app] [I] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.0.0.68/app/views/katello/api/v2/organizations/show.json.rabl within katello/api/v2/layouts/resource (429.4ms) 2016-07-25 10:15:53 [app] [I] Completed 200 OK in 3008ms (Views: 415.5ms | ActiveRecord: 282.6ms)
- as you can see on the 2nd try, there is a GET request to fetch all domains first in order to pass the returned list to a POST request.
This behavior is not documented in hammer docs.
Version-Release number of selected component (if applicable):
hammer-cli-foreman 0.9.0
How reproducible:
always
Steps to Reproduce:
1. have some domains created with no assignments
2. create an entity (e.g. Organization) without providing e.g. --domains option: hammer -u admin -p changeme organization create --name cli_org_1
3. create an entity (e.g. Organization) without providing e.g. --domains option: hammer -u admin -p changeme organization create --name cli_org_2 --domains
4. compare the Domain assignments.
Actual results:
none vs. all entities assigned
Expected results:
Hammer should support a special flag for specifying 'all'.
Updated by Daniel Lobato Garcia over 7 years ago
- Project changed from Foreman to Hammer CLI
Updated by Tomáš Strachota over 7 years ago
- Description updated (diff)
- Category set to Organizations and locations
- Target version set to 115
Updated by Tomáš Strachota over 7 years ago
This is caused by resolver that builds empty search query, which returns all records:
hammer -d organization create --name assign_test2 --domains [ INFO 2017-03-02T10:48:52 Init] Initialization of Hammer CLI (0.9.0) has started... [DEBUG 2017-03-02T10:48:52 Init] Running at ruby 2.3.0-p0 [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /etc/hammer/cli_config.yml has been loaded [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman.yml has been loaded [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_bootdisk.yml has been loaded [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_docker.yml has been loaded [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /etc/hammer/cli.modules.d/foreman_tasks.yml has been loaded [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /etc/hammer/cli.modules.d/import.yml has been loaded [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /etc/hammer/cli.modules.d/katello.yml has been loaded [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /root/.hammer/cli_config.yml has been loaded [ INFO 2017-03-02T10:48:52 Init] Configuration from the file /root/.hammer/defaults.yml has been loaded [DEBUG 2017-03-02T10:48:53 API] Global headers: { :content_type => "application/json", :accept => "application/json;version=2", "Accept-Language" => "en" } [DEBUG 2017-03-02T10:48:53 API] Follow redirects: never [DEBUG 2017-03-02T10:48:53 Connection] Registered: foreman [ INFO 2017-03-02T10:48:53 Modules] Extension module hammer_cli_foreman (0.9.0) loaded [ INFO 2017-03-02T10:48:53 Modules] Extension module hammer_cli_foreman_admin (0.0.6) loaded [ INFO 2017-03-02T10:48:53 Modules] Extension module hammer_cli_foreman_tasks (0.0.10) loaded [ INFO 2017-03-02T10:48:53 HammerCLI::MainCommand] subcommand organization (HammerCLIForeman::Organization) was removed. [ INFO 2017-03-02T10:48:53 HammerCLI::MainCommand] subcommand organization (HammerCLIKatello::Organization) was created. [ INFO 2017-03-02T10:48:53 Modules] Extension module hammer_cli_katello (0.3.0) loaded [DEBUG 2017-03-02T10:48:53 Init] Using locale 'en' [DEBUG 2017-03-02T10:48:53 Init] 'mo' files for locale domain 'hammer-cli' loaded from '/root/hammer/hammer-cli/locale' [DEBUG 2017-03-02T10:48:53 Init] 'mo' files for locale domain 'hammer-cli-foreman' loaded from '/root/hammer/hammer-cli-foreman/locale' [DEBUG 2017-03-02T10:48:53 Init] 'mo' files for locale domain 'hammer-cli-katello' loaded from '/root/hammer/hammer-cli-katello/locale' [ INFO 2017-03-02T10:48:53 HammerCLI::MainCommand] Called with options: {"option_debug"=>true} [ INFO 2017-03-02T10:48:53 HammerCLIKatello::Organization] Called with options: {} [ INFO 2017-03-02T10:48:53 HammerCLIKatello::Organization::CreateCommand] Called with options: {"option_domain_names"=>[], "option_name"=>"assign_test2"} [ INFO 2017-03-02T10:48:53 API] Server: https://devel.tstrachota.usersys.redhat.com/ [ INFO 2017-03-02T10:48:53 API] GET /api/domains [DEBUG 2017-03-02T10:48:53 API] Params: { :search => "" } [DEBUG 2017-03-02T10:48:53 API] Headers: { :params => { :search => "" } } ...
Updated by Tomáš Strachota over 7 years ago
- Status changed from New to Assigned
- Assignee set to Tomáš Strachota
- Target version changed from 115 to 1.13.0
Updated by The Foreman Bot over 7 years ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/hammer-cli-foreman/pull/301 added
Updated by Anonymous over 7 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset hammer-cli-foreman|69faab2a9603f525dfadfb46ca6ffecb6a6e979b.
Updated by Tomáš Strachota over 7 years ago
- Translation missing: en.field_release set to 243