Project

General

Profile

Actions

Bug #12197

open

Better error handling when API request isn't rooted (e.g. {'minion': {"param": "value"}})

Added by Volker None about 9 years ago. Updated almost 9 years ago.

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

Description

Trying to update a minions salt_proxy_id via the REST-Api fails with

{
"error": {"message":"undefined method `delete' for nil:NilClass"}
}

The request is:
curl -k -u admin:password \
-H "Accept: version=2,application/json" \
-H "Content-Type: application/json" \
-X PUT \
-d '{ "salt_proxy_id":5 }' \
https://api.domain.de/salt/api/salt_minions/jessie-naked

This is also true for the other minion-parameters

salt_environment_id
salt_environment_name
salt_proxy_name
salt_proxy_id
salt_states

and also using python-requests + client-certificates.

Full debug trace of production.log for salt_proxy_id is attached.


Files

foreman_set_salt_proxy_id.log foreman_set_salt_proxy_id.log 16 KB Volker None, 10/16/2015 09:33 AM
update_salt_proxy_id.log update_salt_proxy_id.log 21.2 KB Volker None, 11/10/2015 08:04 AM
Actions #1

Updated by Dominic Cleal about 9 years ago

  • Project changed from Foreman to Salt
Actions #2

Updated by Stephen Benjamin about 9 years ago

The parameters should be in a "minion" key, this will work:

The request is:
curl -k -u admin:password \
-H "Accept: version=2,application/json" \
-H "Content-Type: application/json" \
-X PUT \
-d '{"minion": { "salt_proxy_id":5 }}' \
https://api.domain.de/salt/api/salt_minions/jessie-naked

Leaving open to make the error better

Actions #3

Updated by Stephen Benjamin about 9 years ago

  • Subject changed from REST-Api fails to update salt_proxy_id to Better error handling when API request isn't rooted (e.g. {'minion': {"param": "value"}})
  • Category set to API
Actions #4

Updated by The Foreman Bot about 9 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman_salt/pull/52 added
  • Pull request deleted ()
Actions #5

Updated by Anonymous about 9 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions #6

Updated by Volker None about 9 years ago

Sorry for taking so long, but i just tried the above and it generally works. But only as long as i set a non-existent proxy-id.

root@foreman01:/etc/foreman# hammer proxy list
---|-------------------------------------|--------------------------------------------------|--------------------------
ID | NAME | URL | FEATURES
---|-------------------------------------|--------------------------------------------------|--------------------------
2 | salt01.domain.de | https://salt01.domain.de:8443 | Salt
---|-------------------------------------|--------------------------------------------------|--------------------------

I only have on testing proxy defined with the id 2.

I can freely set any proxy-id i like for a minion:

###
curl -k -u admin:password -H Accept: version=2,application/json -H Content-Type: application/json -X PUT -d {"minion": { "salt_proxy_id":3 }} https://foreman01domain.de/salt/api/salt_minions/server01.domain.de

{"architecture_id":null,"build":false,"certname":"server01.domain.de","comment":"","compute_profile_id":null,"compute_resource_id":null,"created_at":"2015-11-05T09:25:25Z","disk":null,"enabled":true,"environment_id":null,"grub_pass":"","hostgroup_id":null,"id":4,"image_file":"","image_id":null,"installed_at":null,"last_compile":null,"last_report":"2015-11-09T14:40:07Z","location_id":null,"managed":true,"medium_id":null,"model_id":null,"name":"server01.domain.de","operatingsystem_id":null,"organization_id":null,"otp":null,"owner_id":3,"owner_type":"User","provision_method":"build","ptable_id":null,"puppet_ca_proxy_id":null,"puppet_proxy_id":null,"puppet_status":8283,"realm_id":null,"root_pass":null,"salt_environment_id":1,"salt_proxy_id":3,"updated_at":"2015-11-10T12:52:35Z","use_image":null,"uuid":null} ###

But if i try to set the actually existing proxy-id 2, it fails.

###
curl -k -u admin:password -H Accept: version=2,application/json -H Content-Type: application/json -X PUT -d {"minion": { "salt_proxy_id":2 }} https://foreman01.domain.de/salt/api/salt_minions/server01.domai.de {
"error": {"message":"undefined method `build?' for nil:NilClass"}
}###

Full debug.log is attached.

The intended use-case here is to regularly set a minions proxy-id whenever it switches to another master (i.e. another smart-proxy) and to keep the minion-proxy-mapping in foreman up to date. The request to update the proxy-id is done, whenever a minion sends a "start"-event to its master and the master "forwards" this by updating the proxy-id of that minion in foreman. This can also mean, that the same proxy-id as before is sent if the minion just restarted and did not switch masters.

Actions #7

Updated by Stephen Benjamin about 9 years ago

  • Status changed from Closed to New

Thanks, I'll have a look

Actions #8

Updated by Volker None almost 9 years ago

Stephen Benjamin wrote:

Thanks, I'll have a look

With a little help i pinned it down to

foreman_salt-3.0.2/app/models/foreman_salt/concerns/orchestration/salt.rb

"old" seems not to be set to something workable.

30         def queue_update_salt_autosign$
31 # Host has been built --> remove auto sign$
32 if old.build? and !build?$
33 queue.create(:name => _('Remove autosign entry for %s') % self, :priority => 50, :action => [self, :del_salt_autosign ])$
34 end$
35 end$

The ugly workaround it to just skip it for now: ###
30 def queue_update_salt_autosign$
31 # Host has been built --> remove auto sign$
32 unless old.is_a? Object$
33 if old.build? and !build?$
34 queue.create(:name => _('Remove autosign entry for %s') % self, :priority => 50, :action => [self, :del_salt_autosign ])$
35 end$
36 end$
37 end$ ###

Actions #9

Updated by Volker None almost 9 years ago

Stephen Benjamin wrote:

Thanks, I'll have a look

With a little help i pinned it down to

foreman_salt-3.0.2/app/models/foreman_salt/concerns/orchestration/salt.rb

"old" seems not to be set to something workable.

30         def queue_update_salt_autosign$
31 # Host has been built --> remove auto sign$
32 if old.build? and !build?$
33 queue.create(:name => _('Remove autosign entry for %s') % self, :priority => 50, :action => [self, :del_salt_autosign ])$
34 end$
35 end$

The ugly workaround it to just skip it for now:

30         def queue_update_salt_autosign$
31 # Host has been built --> remove auto sign$
32 unless old.is_a? Object$
33 if old.build? and !build?$
34 queue.create(:name => _('Remove autosign entry for %s') % self, :priority => 50, :action => [self, :del_salt_autosign ])$
35 end$
36 end$
37 end$
Actions

Also available in: Atom PDF