Bug #24183
closedCannot add location to organizations via CLI
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1597501
How reproducible:
Always on CLI
Steps to Reproduce:
[root@qe-sat6-upgrade-rhel7 ~]# hammer -v -u admin -p changeme --output=csv organization create --name="c8E8qp1"
Message,Id,Name
Organization created,222,c8E8qp1
[root@qe-sat6-upgrade-rhel7 ~]# hammer -v -u admin -p changeme --output=csv location create --name="5rQAoW20JW1"
Message,Id,Name
Location created.,223,5rQAoW20JW1
[root@qe-sat6-upgrade-rhel7 ~]# hammer -v -u admin -p changeme organization add-location --id=222 --location-id=223
[ERROR 2018-07-03T01:38:44 API] 404 Not Found
[ERROR 2018-07-03T01:38:44 Exception] Resource organization not found by id '222'
Could not associate the location:
Resource organization not found by id '222'
Actual results:
[ERROR 2018-07-03T01:38:44 Exception]
RestClient::NotFound (404 Not Found):
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/abstract_response.rb:223:in `exception_with_response'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/abstract_response.rb:103:in `return!'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:353:in `block in rest_client_call_block'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:807:in `process_result'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:725:in `block in transmit'
/opt/rh/rh-ruby24/root/usr/share/ruby/net/http.rb:877:in `start'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:715:in `transmit'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:145:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:52:in `execute'
/opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/resource.rb:76:in `put'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:327:in `call_client'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:240:in `http_call'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:190:in `call_action'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:185:in `call'
/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/resource.rb:21:in `call'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/apipie/command.rb:51:in `send_request'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-0.13.0/lib/hammer_cli_foreman/commands.rb:168:in `send_request'
/opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.0/lib/hammer_cli/apipie/command.rb:34: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/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/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:
Location should have been added successfully
Additional info:
Looking into debug output, it looks like api searches for the organization in the location.
Updated by Daniel Lobato Garcia over 6 years ago
- Project changed from Foreman to Katello
- Subject changed from Cannot add location to organizations via CLI to Cannot add location to organizations via CLI
- Category changed from Organizations and Locations to Organizations and Locations
It looks like the problem is that the Katello OrganizationsController is handling this update. On the UI, Foreman's OrganizationsController is able to do it just fine. Moving to Katello as this is not a bug without the plugin.
Updated by Daniel Lobato Garcia over 6 years ago
- Project changed from Katello to Hammer CLI
- Category changed from Organizations and Locations to Organizations and locations
After more careful inspection, I think it's hammer to blame here. It's making a request with 'location_id' where it should be 'organization_id'.
hammer -v -u dlobatog -p changeme --output=csv organization add-location --id=15 --location-id=16
[ INFO 2018-07-06T11:24:42 API] PUT /katello/api/organizations/15 [DEBUG 2018-07-06T11:24:42 API] Params: { "location_id" => 16, "organization" => { "location_ids" => [ [0] "16" ] } }
Updated by Daniel Lobato Garcia over 6 years ago
Adding other resources like users works fine. E.g: add-user --user-id 5 results on
[ INFO 2018-07-06T11:32:37 API] PUT /katello/api/organizations/15 [DEBUG 2018-07-06T11:32:37 API] Params: { "organization" => { "user_ids" => [ [0] "5" ] } }
Updated by Marek Hulán over 6 years ago
- Bugzilla link changed from 1597501 to 1597042
Updated by Akshay Mendhe over 6 years ago
The issue is already resolved. The command
hammer organization add-location --id=5 --location-id=7
adds location according to the organization id specified.
Updated by Tomáš Strachota over 6 years ago
- Status changed from New to Resolved
Closing as resolved. Thanks Akshay!