Project

General

Profile

Actions

Bug #10421

closed

Adding a parameter to a host via API fails based on URL used

Added by Tom McLaughlin about 9 years ago. Updated about 9 years ago.

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

Description

Was trying to use python-foreman to create host parameters but it threw exceptions on me. Narrowed it down to an issue with the URL being used using "/api/hosts/i-036c522c.example.com/parameters" works while "/api/hosts/i-036c522c.example.com" does not. I'm not sure if this is a bug in the Foreman API or in python Foreman and could use some clarification. Below are two examples.

$ curl -u <removed> -H "Content-Type:application/json" -H "Accept:application/json;version=2" -X PUT -d '{"host": {"parameters": [{"name": "key1", "value": "val1"}]}}' http://foreman.example.com/api/hosts/i-036c522c.example.com
{
  "error": {"message":"undefined method `id' for nil:NilClass"}
}
  • production.log
    Started PUT "/api/hosts/i-036c522c.jana-net.com" for 10.181.22.149 at 2015-05-08 00:23:17 +0000
    Processing by Api::V2::HostsController#update as JSON
      Parameters: {"host"=>{"parameters"=>[{"name"=>"k9", "value"=>"[FILTERED]"}]}, "apiv"=>"v2", "id"=>"i-036c522c.jana-net.com"}
      User Load (0.9ms)  SELECT "users".* FROM "users" WHERE "users"."lower_login" = 'tom' LIMIT 1
      AuthSource Load (0.8ms)  SELECT "auth_sources".* FROM "auth_sources" WHERE "auth_sources"."id" = 1 LIMIT 1
      CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."lower_login" = 'tom' LIMIT 1
    Authenticated user Tom McLaughlin against INTERNAL authentication source
      User Load (0.8ms)  SELECT "users".* FROM "users" WHERE "users"."lower_login" = 'foreman_admin' LIMIT 1
    Setting current user thread-local variable to foreman_admin
       (0.6ms)  BEGIN
       (0.8ms)  UPDATE "users" SET "last_login_on" = '2015-05-08 00:23:17.197197', "updated_at" = '2015-05-08 00:23:17.198544' WHERE "users"."id" = 4
    Expire fragment views/tabs_and_title_records-4 0.1ms
      Role Load (0.7ms)  SELECT "roles".* FROM "roles" WHERE "roles"."name" = 'Anonymous' LIMIT 1
      SQL (0.8ms)  SELECT "roles".id FROM "roles" INNER JOIN "user_roles" ON "roles"."id" = "user_roles"."role_id" WHERE "user_roles"."owner_id" = 4 AND "user_roles"."owner_type" = 'User'
       (3.3ms)  COMMIT
      CACHE (0.0ms)  SELECT "roles".* FROM "roles" WHERE "roles"."name" = 'Anonymous' LIMIT 1
      Role Exists (0.8ms)  SELECT 1 AS one FROM "roles" INNER JOIN "user_roles" ON "roles"."id" = "user_roles"."role_id" WHERE "user_roles"."owner_id" = 4 AND "user_roles"."owner_type" = 'User' AND "roles"."i
    d" = 8 LIMIT 1
    Setting current user thread-local variable to nil
    Setting current user thread-local variable to tom
      AuthSourceHidden Load (0.8ms)  SELECT "auth_sources".* FROM "auth_sources" WHERE "auth_sources"."type" IN ('AuthSourceHidden')
      User Load (0.9ms)  SELECT "users".* FROM "users" WHERE "users"."lower_login" = 'tom' AND (users.auth_source_id <> 2) ORDER BY firstname LIMIT 1
    Authorized user tom(Tom McLaughlin)
    Setting current user thread-local variable to tom
      Host::Managed Load (1.1ms)  SELECT "hosts".* FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."name" = 'i-036c522c.jana-net.com' LIMIT 1
       (0.6ms)  BEGIN
      HostParameter Load (0.8ms)  SELECT "parameters".* FROM "parameters" WHERE "parameters"."type" IN ('HostParameter') AND "parameters"."name" = 'k9' ORDER BY parameters.name LIMIT 1
       (0.6ms)  ROLLBACK
    undefined method `id' for nil:NilClass (NoMethodError)
    /usr/share/foreman/app/models/concerns/has_many_common.rb:61:in `block (2 levels) in has_many_names_for'
    /usr/share/foreman/app/models/concerns/has_many_common.rb:60:in `map'
    /usr/share/foreman/app/models/concerns/has_many_common.rb:60:in `block in has_many_names_for'
    

This method is successful:

$ curl -u  <removed> -H "Content-Type:application/json" -H "Accept:application/json,version=2" -X POST -d  '{"name":"key2","value":"val2"}'  http://foreman.example.com/api/hosts/i-036c522c.example.com/parameters
{"id":26,"name":"key2","value":"val2","priority":4,"created_at":"2015-05-08T00:35:34Z","updated_at":"2015-05-08T00:35:34Z"}

Actions #1

Updated by Tom McLaughlin about 9 years ago

Narrowed this down as a python-foreman issue and something to do with the API definitions cache retrieved from Foreman and used by the module. Following up on that end instead.

Actions #2

Updated by Dominic Cleal about 9 years ago

  • Status changed from New to Rejected
Actions

Also available in: Atom PDF