Skip to content

Commit

Permalink
Fixes #11767 - avoid cleaning of interface attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ares committed Sep 14, 2015
1 parent 44dac2f commit f5d377f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
14 changes: 3 additions & 11 deletions app/controllers/hosts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def process_hostgroup

def process_taxonomy
return head(:not_found) unless @location || @organization
@host = Host.new(clean_interfaces_attributes)
@host = Host.new(params[:host])
# revert compute resource to "Bare Metal" (nil) if selected
# compute resource is not included taxonomy
Taxonomy.as_taxonomy @organization, @location do
Expand All @@ -546,7 +546,8 @@ def process_taxonomy
end

def template_used
host = Host.new(clean_interfaces_attributes.except(:host_parameters_attributes))
host = params[:id] ? Host.find(params[:id]) : Host.new
host.attributes = params[:host].except(:host_parameters_attributes)
templates = host.available_template_kinds(params[:provisioning])
return not_found if templates.empty?
render :partial => 'provisioning', :locals => { :templates => templates }
Expand Down Expand Up @@ -724,13 +725,4 @@ def cleanup_passwords
end
end
end

def clean_interfaces_attributes
attributes = params[:host].dup
if params[:host][:interfaces_attributes]
attributes[:interfaces_attributes] = params[:host][:interfaces_attributes].dup.except(:created_at, :updated_at, :attrs)
attributes[:interfaces_attributes][:id] = nil
end
attributes
end
end
2 changes: 1 addition & 1 deletion app/views/hosts/_operating_system.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div class="form-group">
<label class="col-xs-2 control-label"><%= _('Provisioning templates') %></label>
<div class="col-xs-10">
<%= link_to_function icon_text("refresh", _("Resolve")), "template_info('#templates_info','#{template_used_hosts_url}')", :class => "btn btn-default" %>
<%= link_to_function icon_text("refresh", _("Resolve")), "template_info('#templates_info','#{template_used_hosts_url(:id => @host.id)}')", :class => "btn btn-default" %>
<div class="help-block">
<%= _("Display the templates that will be used to provision this host") %>
</div>
Expand Down
8 changes: 4 additions & 4 deletions test/functional/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,8 @@ class Host::Valid < Host::Managed; end
@host.setBuild
nic=FactoryGirl.create(:nic_managed, :host => @host)
attrs = @host.attributes
attrs[:interfaces_attributes] = nic.attributes
xhr :put, :template_used, {:provisioning => 'build', :host => attrs }, set_session_user
attrs[:interfaces_attributes] = nic.attributes.except 'updated_at', 'created_at', 'attrs'
xhr :put, :template_used, {:provisioning => 'build', :host => attrs, :id => @host.id }, set_session_user
assert_response :success
assert_template :partial => '_provisioning'
end
Expand All @@ -882,9 +882,9 @@ class Host::Valid < Host::Managed; end
end

test 'process_taxonomy renders a host from the params correctly' do
nic=FactoryGirl.create(:nic_managed, :host => @host)
nic = FactoryGirl.build(:nic_managed, :host => @host)
attrs = @host.attributes
attrs[:interfaces_attributes] = nic.attributes
attrs[:interfaces_attributes] = nic.attributes.except 'updated_at', 'created_at', 'attrs'
xhr :put, :process_taxonomy, { :host => attrs }, set_session_user
assert_response :success
assert response.body.include?(nic.attributes["mac"])
Expand Down

0 comments on commit f5d377f

Please sign in to comment.