Project

General

Profile

Actions

Bug #16403

closed

Updating hostgroups via API with environment_id set fails to find host group

Added by Guido Günther over 7 years ago. Updated over 7 years ago.

Status:
Duplicate
Priority:
Normal
Assignee:
-
Category:
API
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

This worked in 1.10

curl -u user:password -H'Content-Type: application/json'  -X PUT -d'{"name": "a123", "title": "a123", "environment_id": 1}' http://localhost:3000/api/v2/hostgroups/5

and it works in Foreman as of 42ba771cc8bfc09257c15c5d388542d4d1b69358 if I leave out the environment_id parameter but not with it.

I've tried different parameters (environment_id, realm_id) but changing these fail with

{
"error": {"message":"Resource hostgroup not found by id '5'"}
}

The log has

08:03:43 rails.1   | 2016-09-01T08:03:43 0a08d560 [app] [I] Started PUT "/api/v2/hostgroups/5" for 127.0.0.1 at 2016-09-01 08:03:43 +0200
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [I] Processing by Api::V2::HostgroupsController#update as JSON
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [I] Parameters: {"name"=>"a123", "title"=>"a123", "environment_id"=>1, "apiv"=>"v2", "id"=>"5", "hostgroup"=>{"name"=>"a123", "environment_id"=>1, "title"=>"a123"}}
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [D] Setting current user thread-local variable to foreman_admin
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [D] Setting current user thread-local variable to nil
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [D] Setting current user thread-local variable to foreman_admin
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [D] Setting current user thread-local variable to nil
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [D] Setting current user thread-local variable to user
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [I] Authorized user user(user)
08:03:43 rails.1 | 2016-09-01T08:03:43 0a08d560 [app] [D] Setting current user thread-local variable to user
08:03:44 rails.1 | 2016-09-01T08:03:44 0a08d560 [app] [I] Couldn't find Hostgroup with 'id'=5 [WHERE ("environments"."id" = 1 OR "environments"."name" = '1')] (ActiveRecord::RecordNotFound)
08:03:44 rails.1 | 2016-09-01T08:03:44 0a08d560 [app] [I] Rendered api/v2/errors/not_found.json.rabl within api/v2/layouts/error_layout (0.6ms)
08:03:44 rails.1 | 2016-09-01T08:03:44 0a08d560 [app] [I] Completed 404 Not Found in 69ms (Views: 3.7ms | ActiveRecord: 47.3ms)

Related issues 1 (0 open1 closed)

Related to Foreman - Bug #13775: Not able to change an HG for a host using API callClosedAmit Karsale02/17/2016Actions
Actions #1

Updated by Dominic Cleal over 7 years ago

  • Related to Bug #13775: Not able to change an HG for a host using API call added
Actions #2

Updated by Dominic Cleal over 7 years ago

  • Subject changed from Updating hostgroups via API fails to Updating hostgroups via API with environment_id set fails to find host group
  • Category set to API

The log shows that it's interpreting the environment ID as a search clause, it's finding a host group where the environment ID is 1.

I think this is probably the same as #13775, where the attribute is interpreted as a nested API call. If you wrap the whole data structure in {"hostgroup":{...}} then it should be ignored.

Actions #3

Updated by Guido Günther over 7 years ago

  • Status changed from New to Closed

Yes, this is indeed a duplicate of #13775.

Actions #4

Updated by Dominic Cleal over 7 years ago

  • Status changed from Closed to Duplicate
Actions

Also available in: Atom PDF