Bug #28007
closedCannot create hostgroup parameter using the API via "python-foreman" module / hammer CLI in foreman 1.23
Description
hi,
i am using foreman 1.23, and i am getting an exception when trying to create a hostgroup parameter.
i get the same exception when using the python "python-foreman" module, as well as the hammer CLI.
i noticed the webui, is using a different HTTP verb and endpoint then the hammer CLI as well as the python client.
so is suspect that foreman 1.23 bricked the related endpoint. since this was working with foreman 1.22.
example hammer cli:
hammer hostgroup set-parameter --hostgroup-id 2742 --name blarg --parameter-type string --value blub Could not set hostgroup parameter: 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.
example python-foreman:
import foreman.client client = foreman.client.Foreman('https://foreman.example.com', ('username', 'password'), api_version=2) client.hostgroups.parameters_create(hostgroup_id=2742, parameter={'name': 'blarg', 'parameter_type': 'string', 'value': 'blub'}) ``` exception: Traceback (most recent call last): File "<input>", line 1, in <module> File "<string>", line 23, in parameters_create File "/Users/sschultchen/PycharmProjects/idms_gammel/venv/lib/python3.7/site-packages/foreman/client.py", line 929, in do_post return self._process_request_result(res) File "/Users/sschultchen/PycharmProjects/idms_gammel/venv/lib/python3.7/site-packages/foreman/client.py", line 897, in _process_request_result 'Something went wrong:%s' % res_to_str(res) foreman.client.ForemanException: Something went wrong: #################################### url = https://foreman.svc.sdcid.net/api/hostgroups/2742/parameters headers = {'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json; version=2', 'Connection': 'keep-alive', 'Content-type': 'application/json', 'Cookie': '_session_id=9f620c1d4cfd942b8148cca4656bead1; request_method=POST', 'Content-Length': '99', 'Authorization': '*****'} -------- data sent ----------------- {"hostgroup_id": 2742, "parameter": {"name": "blarg", "parameter_type": "string", "value": "blub"}} ------------------------------------ @@@@@ response @@@@@@@@@@@@@@@@ headers = {'Date': 'Mon, 07 Oct 2019 08:46:17 GMT', 'Server': 'Apache/2.4.6 (CentOS)', 'Foreman_version': '1.23.0', 'Foreman_api_version': '2', 'Foreman_current_organization': '; ANY', 'Foreman_current_location': '; ANY', 'Apipie-Checksum': '4be770720e89ae2ed776a93d3ff914dbb24942ec', 'Cache-Control': 'no-cache', 'X-Request-Id': '[SNIP]', 'X-Runtime': '0.044100', 'Strict-Transport-Security': 'max-age=631139040; includeSubdomains', 'X-Frame-Options': 'sameorigin', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'X-Download-Options': 'noopen', 'X-Permitted-Cross-Domain-Policies': 'none', 'Content-Security-Policy': "default-src 'self'; child-src 'self'; connect-src 'self' ws: wss:; img-src 'self' data: *.gravatar.com; script-src 'unsafe-eval' 'unsafe-inline' 'self'; style-src 'unsafe-inline' 'self'", 'X-Powered-By': 'Phusion Passenger 4.0.53', 'Set-Cookie': '_session_id=9f620c1d4cfd942b8148cca4656bead1; path=/; expires=Tue, 08 Oct 2019 08:46:17 -0000; HttpOnly; secure; SameSite=Lax', 'Status': '500 Internal Server Error', 'Connection': 'close', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json; charset=utf-8'} code = 500 reason = Internal Server Error --------- data received ------------ { "error": {"message":"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."} } ------------------------------------ ####################################
and this is what i get in the foreman production.log
019-10-07T10:49:56 [I|app|65a6a8ac] Started POST "/api/hostgroups/2742/parameters" for 10.201.201.82 at 2019-10-07 10:49:56 +0200 2019-10-07T10:49:56 [I|app|65a6a8ac] Processing by Api::V2::ParametersController#create as JSON 2019-10-07T10:49:56 [I|app|65a6a8ac] Parameters: {"hostgroup_id"=>"2742", "parameter"=>{"name"=>"blarg", "parameter_type"=>"string", "value"=>"[FILTERED]"}, "apiv"=>"v2"} 2019-10-07T10:49:56 [W|app|65a6a8ac] Action failed | ActiveModel::UnknownAttributeError: unknown attribute 'organization_id' for GroupParameter. | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:53:in `_assign_attribute' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:44:in `block in _assign_attributes' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:43:in `each' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:43:in `_assign_attributes' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/attribute_assignment.rb:23:in `_assign_attributes' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:35:in `assign_attributes' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/core.rb:314:in `initialize' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/inheritance.rb:66:in `new' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/inheritance.rb:66:in `new' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/reflection.rb:154:in `build_association' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/association.rb:276:in `build_record' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:106:in `build' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_proxy.rb:319:in `build' | /usr/share/foreman/app/controllers/api/v2/parameters_controller.rb:86:in `create' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/abstract_controller/base.rb:194:in `process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/rendering.rb:30:in `process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/abstract_controller/callbacks.rb:42:in `block in process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:109:in `block in run_callbacks' | /usr/share/foreman/app/controllers/api/v2/base_controller.rb:163:in `disable_json_root' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks' | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:10:in `set_timezone' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks' | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in `clear_thread' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks' | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in `set_topbar_sweeper_controller' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks' | /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/sweeper.rb:14:in `around' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks' | /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/sweeper.rb:14:in `around' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:136:in `run_callbacks' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/abstract_controller/callbacks.rb:41:in `process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/rescue.rb:22:in `process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in `block in instrument' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in `instrument' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/instrumentation.rb:32:in `process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/params_wrapper.rb:256:in `process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/railties/controller_runtime.rb:24:in `process_action' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/abstract_controller/base.rb:134:in `process' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionview-5.2.1/lib/action_view/rendering.rb:32:in `process' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal.rb:191:in `dispatch' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal.rb:252:in `dispatch' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:52:in `dispatch' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:34:in `serve' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:48:in `serve' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:52:in `block in serve' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:35:in `each' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:35:in `serve' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:840:in `call' | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.14/lib/apipie/static_dispatcher.rb:65:in `call' | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.14/lib/apipie/extractor/recorder.rb:137:in `call' | /usr/share/foreman/lib/foreman/middleware/telemetry.rb:10:in `call' | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.14/lib/apipie/middleware/checksum_in_headers.rb:27:in `call' | /usr/share/foreman/lib/foreman/middleware/catch_json_parse_errors.rb:9:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/tempfile_reaper.rb:15:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/etag.rb:25:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/conditional_get.rb:38:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/head.rb:12:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/http/content_security_policy.rb:18:in `call' | /usr/share/foreman/lib/foreman/middleware/logging_context_session.rb:22:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:232:in `context' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:226:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/cookies.rb:670:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:98:in `run_callbacks' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/rack/logger.rb:38:in `call_app' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/rack/logger.rb:28:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call' | /usr/share/foreman/lib/foreman/middleware/logging_context_request.rb:11:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/runtime.rb:22:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/static.rb:127:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/sendfile.rb:111:in `call' | /opt/theforeman/tfm/root/usr/share/gems/gems/secure_headers-6.0.0/lib/secure_headers/middleware.rb:13:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/engine.rb:524:in `call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/railtie.rb:190:in `public_send' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/railtie.rb:190:in `method_missing' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/urlmap.rb:68:in `block in call' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/urlmap.rb:53:in `each' | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/urlmap.rb:53:in `call' | /usr/share/passenger/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request' | /usr/share/passenger/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request' | /usr/share/passenger/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop' | /usr/share/passenger/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads' | /opt/theforeman/tfm/root/usr/share/gems/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
this is working when using the WebUI, but i noticed that the webui is using a different API endpoint to add the parameter.
from the foreman production.log:
2019-10-07T10:57:06 [I|app|a6a9d48f] Started PATCH "/hostgroups/2742-default-pcs_mgmttt" for 10.201.201.82 at 2019-10-07 10:57:06 +0200 2019-10-07T10:57:06 [I|app|a6a9d48f] Processing by HostgroupsController#update as */* 2019-10-07T10:57:06 [I|app|a6a9d48f] Parameters: {"utf8"=>"✓", "authenticity_token"=>"[SNIP]", "hostgroup"=>{"parent_id"=>"6", "name"=>"pcs_mgmttt", "description"=>"", "environment_id"=>"", "compute_resource_id"=>"", "compute_profile_id"=>"", "domain_id"=>"", "subnet_id"=>"", "realm_id"=>"", "architecture_id"=>"", "operatingsystem_id"=>"", "medium_id"=>"", "ptable_id"=>"", "pxe_loader"=>"", "group_parameters_attributes"=>{"1570438619896"=>{"name"=>"blarg", "parameter_type"=>"string", "value"=>"[FILTERED]", "hidden_value"=>"[FILTERED]", "_destroy"=>"false"}}, "location_ids"=>["9", "12", "13", "10", "14", ""], "organization_ids"=>["20", ""], "id"=>"2742"}, "id"=>"2742-default-pcs_mgmttt"} 2019-10-07T10:57:07 [I|aud|a6a9d48f] Hostgroup (2742) update event on description , 2019-10-07T10:57:07 [I|aud|a6a9d48f] Hostgroup (2742) update event on pxe_loader , 2019-10-07T10:57:07 [I|aud|a6a9d48f] Hostgroup (2742) update event on location_ids , 9, 12, 13, 10, 14 2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on name blarg 2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on value blub 2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on reference_id 2742 2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on hidden_value false 2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on key_type string
Updated by Martin Bacovsky about 5 years ago
Similar to host the API parameter_type should not be required and rather should have default value of 'string'.
Hammer parameters needs to be fixed to include the --parameter-type that shouldn't be required.
As a workaround the parameters can be created with direct API call
curl -k -u admin:pwd -X POST -H "Content-Type:application/json" -H "Accept:application/json" -d '{"parameter": {"name":"a", "value":"b", "parameter_type":"string"}}' https://foreman/api/v2/hostgroups/2/parameters
Updated by Martin Bacovsky about 5 years ago
- Project changed from Foreman to Hammer CLI
- Category changed from API to Host groups
- Team Backlog Hammer added
Updated by Kavita Gaikwad about 5 years ago
- Related to Feature #26092: When only one taxonomy of specific type is defined, api should default to that taxonomy added
Updated by Kavita Gaikwad about 5 years ago
I tried but direct API call is not working with latest master.
Parameter is not covered under taxonomy but user can define parameters on organization/location level.
That's why associations are defined on the Parameter model.
Using a fix of attached issue, it adds "(organization&location)_id" params to request's parameters.
As no (organization/location)_id columns present on parameter, it fails with ActiveModel::UnknownAttributeError.
Updated by Oleh Fedorenko about 5 years ago
- Project changed from Hammer CLI to Foreman
- Category changed from Host groups to API
- Status changed from New to Assigned
- Assignee set to Oleh Fedorenko
- Team Backlog deleted (
Hammer)
This is not hammer related issue since it doesn't work for direct API call even.
Moving to Foreman project.
Also, it doesn't work not only for host groups, but for all resources we can add a parameter to.
Updated by The Foreman Bot about 5 years ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/7104 added
Updated by Tomer Brisker about 5 years ago
- Is duplicate of Bug #27740: Cannot set parameter for hostgroup added
Updated by Tomer Brisker about 5 years ago
- Status changed from Ready For Testing to Duplicate