Bug #6998

Cannot rename host by API due to DHCP conflict - cannot set 'overwrite' flag

Added by Aaron Stone over 3 years ago. Updated over 3 years ago.

Status:Closed
Priority:Normal
Assigned To:Aaron Stone
Category:API
Target version:Sprint 27
Difficulty: Bugzilla link:
Found in release: Pull request:https://github.com/theforeman/foreman/pull/1677
Story points-
Velocity based estimate-
Release1.6.0Release relationshipAuto

Description

Steps in UI:
In the Foreman UI, rename a host.
Foreman shows a DHCP conflict for the MAC Address to the old name.
Click the Overwrite button.

Steps in API:
Submit form to /api/hosts/hostid with content {"name": "newname"} and an APIv2 header version
Receive error message {"error"=>{"full_messages"=>["Conflict DHCP records spare-12345-macaddr/ipaddr and spare-12345-macaddr/ipaddr already exists"] ... }
Try again with {"name": "newname", "overwrite": true}
Receive same error.

Expected:
I should be able to overwrite from the API.

This is with Foreman 1.5.1.

Associated revisions

Revision a0d231da
Added by Aaron Stone over 3 years ago

Fixes #6998 - Accept native true for overwrite parameter to host API.

Revision 8f7d8b3c
Added by Aaron Stone over 3 years ago

Fixes #6998 - Accept native true for overwrite parameter to host API.

(cherry picked from commit a0d231daf018694a4aec708c2d8e32e69492a84a)

History

#1 Updated by Aaron Stone over 3 years ago

Does this commit for Foreman 1.6.0 implement overwrite? @isratrade
https://github.com/theforeman/foreman/commit/c980e9a8917cc9fdee5835732428462e22fa3f5b

#2 Updated by Dominic Cleal over 3 years ago

  • Category set to API

That commit will help if you're using an unwrapped set of JSON, i.e. it'll make {"overwrite":true, ...} work. Before it, only the wrapped version {"host":{"overwrite":true, ...}} will work.

#3 Updated by Aaron Stone over 3 years ago

Actually, I found that I had to set {"overwrite":"true"} in quotes, because of this:

https://github.com/theforeman/foreman/blob/develop/app/models/host/managed.rb#L611-614

  # We have to coerce the value back to boolean. It is not done for us by the framework.
  def overwrite=(value)
    @overwrite = value == "true" 
  end

Is there some way to put a flexible truthiness test into the API or Controller, rather than in the model?

#4 Updated by Dominic Cleal over 3 years ago

Ah. It could be at the controller level, but it'd be much less duplication in the model - you could simply use value.to_s == "true" instead. Generally Rails does string/bool stuff at the ActiveRecord layer, which isn't applicable for a setter.

#5 Updated by Aaron Stone over 3 years ago

I will submit a PR shortly!

#6 Updated by The Foreman Bot over 3 years ago

  • Status changed from New to Ready For Testing
  • Target version set to Sprint 27
  • Pull request https://github.com/theforeman/foreman/pull/1677 added

#7 Updated by Dominic Cleal over 3 years ago

  • Assigned To set to Aaron Stone

#8 Updated by Dominic Cleal over 3 years ago

  • Release set to 1.6.0

#9 Updated by Aaron Stone over 3 years ago

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

Also available in: Atom PDF