Bug 1595126

Summary: `hammer host create ...` returns ISE instead of an error message when LibVirt compute-resource is not in correct organization
Product: Red Hat Satellite Reporter: Jan Hutař <jhutar>
Component: Compute Resources - libvirtAssignee: Sebastian Gräßl <sgraessl>
Status: CLOSED WONTFIX QA Contact: Sanket Jagtap <sjagtap>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.4CC: egolov, mhulan, mmccune, oprazak, sgraessl, sjagtap
Target Milestone: UnspecifiedKeywords: Regression, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: foreman-1.18.0.24-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1666700 (view as bug list) Environment:
Last Closed: 2020-05-01 13:31:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1666700    

Description Jan Hutař 2018-06-26 08:08:02 UTC
Description of problem:
`hammer host create ...` returns ISE instead of an error message when LibVirt compute-resource is not in correct organization


Version-Release number of selected component (if applicable):
satellite-6.4.0-9.beta.el7sat.noarch


How reproducible:
always


Steps to Reproduce:
1. # hammer -v -u admin -p changeme host create --architecture-id="3" --compute-resource-id="2" --domain-id="3" --environment-id="5" --ip="148.172.224.43" --location-id="5" --mac="94:e3:d9:06:72:48" --medium-id="10" --name="jhutar$RANDOM" --operatingsystem-id="3" --organization-id="6" --partition-table-id="141" --puppet-proxy-id="1" --root-password="\xea\xae\x8f\xf0\x98\x87\x8a\xe9\xb5\xa8\xd0\x9e\xec\x8b\xa4\xe6\xa9\x88\xe0\xae\x88\xe1\x8b\xb8\xe5\x83\x95\xf0\x97\xbf\xa3\xe7\x87\x93\xf0\x96\xa6\x9e\xeb\xa9\x83\xe7\x88\x8a\xe6\x88\x8f\xe7\x9d\x8d\xea\x85\xa0\xef\xac\x85"


Actual results:
[ERROR 2018-06-26T04:01:02 API] 500 Internal Server Error
[ERROR 2018-06-26T04:01:02 Exception] Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs.
Could not create the host:
  Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs.
[ERROR 2018-06-26T04:01:02 Exception] 

RestClient::InternalServerError (500 Internal Server Error):
    /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:67:in `post'
    /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:
Should return nice error message that compute resource is not in a correct organization.


Additional info:
Entities used in the command above are configured exactly same as in bug 1595120 (there are all these `hammer * info --id ...` outputs) except for the compute resource where I have removed organization used in the command above:

# hammer -u admin -p changeme compute-resource info --id 2
Id:            2
Name:          9zZ6tf
Provider:      Libvirt
Url:           qemu+ssh://root@<libvirt>/system
Description:   
User:          
Locations:     
    Default Location
    tQvGVGLW
Organizations: 
    Default Organization
Created at:    2018/06/26 07:36:02
Updated at:    2018/06/26 07:39:19

Comment 4 Marek Hulan 2018-07-10 06:27:11 UTC
Ondrej, could you please take a quick look if this is that same as BZ 1595120 and the same fix helps? Or does this needs to be fixed in host form so that we don't display compute resources unavailable in org/loc combination selected for the host?

Comment 5 Ondřej Pražák 2018-07-23 11:52:41 UTC
Created redmine issue http://projects.theforeman.org/issues/24348 from this bug

Comment 6 Ondřej Pražák 2018-07-23 11:56:29 UTC
This is something different, cloning upstream.

Comment 9 Sanket Jagtap 2018-09-20 12:44:15 UTC
Build: Satellite 6.4.0 snap22

I am still able to re-produce the error.
All the entities are in Default org and location, expect the Compute resource which is in ORG "abc"

hammer> compute-resource info --id 4
Id:            4
Name:          sjagtap_libvirt
Provider:      Libvirt
Url:           qemu+tcp://<libvirt>/system
Description:   
User:          
Locations:     
    Default Location
Organizations: 
    Default Organization
Created at:    2018/09/20 12:26:38
Updated at:    2018/09/20 12:26:38

hammer> host create --name host1 --architecture-id=1 --compute-resource-id=4 --domain-id=1 --environment-id=1 --ip="148.172.224.43" --location-id="2" --mac="94:e3:d9:06:72:48" --medium-id="1" --operatingsystem-id=3 --organization-id="1" --partition-table-id=94 --puppet-proxy-id="1" --root-password=dog8code
Host created.

compute-resource update --id 4 --organizations abc
Compute resource updated.
hammer> compute-resource info --id 4
Id:            4
Name:          sjagtap_libvirt
Provider:      Libvirt
Url:           qemu+tcp://<libvirt>/system
Description:   
User:          
Locations:     
    Default Location
Organizations: 
    abc
Created at:    2018/09/20 12:26:38
Updated at:    2018/09/20 12:26:38


hammer -v host create --name host2 --architecture-id=1 --compute-resource-id=4 --domain-id=1 --environment-id=1 --ip="148.172.224.43" --location-id="2" --mac="94:e3:d9:06:72:48" --medium-id="1" --operatingsystem-id=3 --organization-id="1" --partition-table-id=94 --puppet-proxy-id="1" --root-password=dog8code
[ERROR 2018-09-20T08:30:45 API] 500 Internal Server Error
[ERROR 2018-09-20T08:30:45 Exception] Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs.
Could not create the host:
  Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs.
[ERROR 2018-09-20T08:30:45 Exception] 

RestClient::InternalServerError (500 Internal Server Error):
    /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:67:in `post'
    /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.1/lib/hammer_cli/apipie/command.rb:51:in `send_request'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-0.13.2/lib/hammer_cli_foreman/commands.rb:168:in `send_request'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.1/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.1/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.1/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.1/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.1/bin/hammer:143:in `<top (required)>'
    /usr/bin/hammer:23:in `load'
    /usr/bin/hammer:23:in `<main>'

Comment 12 Sebastian Gräßl 2018-11-29 08:29:01 UTC
Can it be that the actual issue is trying to create another host, but with the same MAC and IPv4 address? 

Looking at the logs it seems that there is an issue validating the NIC, which too should not error and show a validation instead, but it would be good to verify first that this is the cause.

Mind trying to do the same, but change MAC as well as IP for the second host when trying to create in a different Org/Loc.

Comment 13 Sanket Jagtap 2018-12-14 06:26:56 UTC
Sorry for the delay, I tested this on 6.4.1. 

This time using a different Mac-address and IP , I was still able to reproduce the issue.

In the logs I see this, 

2018-12-14T01:24:53 [I|app|] Started POST "/api/hosts" for 10.16.64.253 at 2018-12-14 01:24:53 -0500
2018-12-14T01:24:53 [I|app|b6d5e] Processing by Api::V2::HostsController#create as JSON
2018-12-14T01:24:53 [I|app|b6d5e]   Parameters: {"location_id"=>2, "organization_id"=>1, "host"=>{"name"=>"host1", "location_id"=>2, "organization_id"=>1, "environment_id"=>1, "ip"=>"148.172.224.44", "mac"=>"94:e3:d9:06:72:49", "architecture_id"=>1, "domain_id"=>1, "puppet_proxy_id"=>"1", "puppetclass_ids"=>[], "operatingsystem_id"=>3, "medium_id"=>1, "ptable_id"=>94, "compute_resource_id"=>4, "compute_attributes"=>{"volumes_attributes"=>{}}, "content_facet_attributes"=>{}, "subscription_facet_attributes"=>{}, "build"=>true, "managed"=>true, "enabled"=>true, "overwrite"=>true, "interfaces_attributes"=>[], "root_pass"=>"[FILTERED]"}, "apiv"=>"v2"}
2018-12-14T01:24:53 [I|app|b6d5e] Current user: foreman_admin (administrator)
2018-12-14T01:24:53 [I|app|b6d5e] Authorized user admin(Admin User)
2018-12-14T01:24:53 [I|app|b6d5e] Current user: admin (administrator)
2018-12-14T01:24:54 [W|app|b6d5e] Action failed
NoMethodError: undefined method `provided_attributes' for nil:NilClass
/usr/share/foreman/app/models/concerns/orchestration/compute.rb:30:in `compute_provides?'
/usr/share/foreman/app/models/nic/base.rb:173:in `compute_provides_ip?'
/usr/share/foreman/app/services/nic_ip_required/base.rb:58:in `compute_provides_ip?'
/usr/share/foreman/app/services/nic_ip_required/base.rb:20:in `required?'
/usr/share/foreman/app/models/nic/base.rb:157:in `require_ip4_validation?'
/usr/share/foreman/app/models/nic/base.rb:35:in `block in <class:Base>'

Comment 15 Bryan Kearney 2020-05-01 13:31:25 UTC
Satellite 6.4 is now End of Life. These bus will not be fixed on the 6.4 stream. Users of Satellite should upgrade to the latest version of Satellite to get access to the most current set of bugfixes and feature improvements.