Project

General

Profile

« Previous | Next » 

Revision c404041c

Added by Dominic Cleal about 8 years ago

fixes #13980 - don't merge NIC compute attrs on New Host form

Removes merging of NIC's compute attributes when refreshing interfaces
on compute profile or resource selections on the New Host form. Instead,
overwrite NIC attributes from the profile (as it did before 85e82d0) as
the UI needs refreshing completely on compute profile selection.

Merging of NIC compute attributes with the compute profile is retained
on the host API where it's still valuable for supplying a partial set
of compute attributes.

(cherry picked from commit b299f9c95102be50b1b755376963efed7b3bb6c2)

View differences:

app/controllers/api/v2/hosts_controller.rb
private
def apply_compute_profile(host)
host.apply_compute_profile(InterfaceMerge.new)
host.apply_compute_profile(InterfaceMerge.new(:merge_compute_attributes => true))
host.apply_compute_profile(ComputeAttributeMerge.new)
end
app/services/interface_merge.rb
class InterfaceMerge
attr_reader :merge_compute_attributes
def initialize(opts = {})
@merge_compute_attributes = !!opts[:merge_compute_attributes]
end
def run(host, compute_attrs)
return if compute_attrs.nil?
......
private
def merge(nic, vm_nic, compute_attrs)
nic.compute_attributes = vm_nic.merge(nic.compute_attributes)
nic.compute_attributes = if merge_compute_attributes
vm_nic.merge(nic.compute_attributes)
else
vm_nic
end
nic.compute_attributes['from_profile'] = compute_attrs.compute_profile.name
nic
end
test/functional/api/v2/hosts_controller_test.rb
Host.order('id asc').last
end
def expect_attribute_modifiers(*modifier_classes)
modifier_classes.each do |modifier_class|
Host.any_instance.expects(:apply_compute_profile).once.with do |modifier|
modifier.is_a? modifier_class
end
end
def expect_attribute_modifier(modifier_class, args)
modifier = mock(modifier_class.name)
modifier_class.expects(:new).with(*args).returns(modifier)
Host.any_instance.expects(:apply_compute_profile).with(modifier)
end
test "should get index" do
......
test "create applies attribute modifiers on the new host" do
disable_orchestration
expect_attribute_modifiers(ComputeAttributeMerge, InterfaceMerge)
expect_attribute_modifier(ComputeAttributeMerge, [])
expect_attribute_modifier(InterfaceMerge, [{:merge_compute_attributes => true}])
post :create, { :host => valid_attrs }
end
test "update applies attribute modifiers on the host" do
disable_orchestration
expect_attribute_modifiers(ComputeAttributeMerge, InterfaceMerge)
expect_attribute_modifier(ComputeAttributeMerge, [])
expect_attribute_modifier(InterfaceMerge, [{:merge_compute_attributes => true}])
put :update, { :id => @host.to_param, :host => valid_attrs }
end
test/functional/hosts_controller_test.rb
assert_response :not_found
end
test '#interfaces applies compute profile and returns interfaces partial' do
modifier = mock('InterfaceMerge')
InterfaceMerge.expects(:new).with().returns(modifier)
Host::Managed.any_instance.expects(:apply_compute_profile).with(modifier)
xhr :get, :interfaces, { :host => {:compute_resource_id => compute_resources(:one).id, :compute_profile_id => compute_profiles(:one).id}}, set_session_user
assert_response :success
assert_template :partial => '_interfaces'
end
private
def initialize_host
test/unit/interface_merge_test.rb
assert_equal 'eth2', interfaces[2].identifier
end
test "it does not overwrite compute attributes already set" do
test "it overwrites NIC compute attributes from the profile by default" do
interfaces = [
FactoryGirl.build(:nic_managed, :identifier => 'eth0', :compute_attributes => {'attr' => 9}),
]
@merge.run(stub(:interfaces => interfaces), @attributes)
assert_equal expected_attrs(1), interfaces[0].compute_attributes
assert_equal 'eth0', interfaces[0].identifier
end
test "it does not overwrite NIC compute attributes already set with :merge_compute_attributes" do
@merge = InterfaceMerge.new(:merge_compute_attributes => true)
interfaces = [
FactoryGirl.build(:nic_managed, :identifier => 'eth0', :compute_attributes => {'attr' => 9}),
]

Also available in: Unified diff