kernel/v2: support merging properly
This commit is contained in:
parent
10d5416a90
commit
3aaa57cac9
|
@ -65,7 +65,6 @@ module VagrantPlugins
|
||||||
other_networks = other.instance_variable_get(:@__networks)
|
other_networks = other.instance_variable_get(:@__networks)
|
||||||
|
|
||||||
result.instance_variable_set(:@__networks, @__networks.merge(other_networks))
|
result.instance_variable_set(:@__networks, @__networks.merge(other_networks))
|
||||||
result.instance_variable_set(:@provisioners, @provisioners + other.provisioners)
|
|
||||||
|
|
||||||
# Merge defined VMs by first merging the defined VM keys,
|
# Merge defined VMs by first merging the defined VM keys,
|
||||||
# preserving the order in which they were defined.
|
# preserving the order in which they were defined.
|
||||||
|
@ -107,6 +106,27 @@ module VagrantPlugins
|
||||||
new_overrides[key] += blocks
|
new_overrides[key] += blocks
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Merge provisioners. First we deal with overrides and making
|
||||||
|
# sure the ordering is good there. Then we merge them.
|
||||||
|
new_provs = []
|
||||||
|
@provisioners.each do |p|
|
||||||
|
if p.id
|
||||||
|
other_p = other.provisioners.find { |o| p.id == o.id }
|
||||||
|
if other_p
|
||||||
|
# There is an override. Take it.
|
||||||
|
other_p.config = p.config.merge(other_p.config)
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# There is an override, merge it into the
|
||||||
|
new_provs << p.dup
|
||||||
|
end
|
||||||
|
other.provisioners.each do |p|
|
||||||
|
new_provs << p.dup
|
||||||
|
end
|
||||||
|
result.instance_variable_set(:@provisioners, new_provs)
|
||||||
|
|
||||||
# Merge synced folders.
|
# Merge synced folders.
|
||||||
other_folders = other.instance_variable_get(:@__synced_folders)
|
other_folders = other.instance_variable_get(:@__synced_folders)
|
||||||
new_folders = {}
|
new_folders = {}
|
||||||
|
|
|
@ -18,7 +18,7 @@ module VagrantPlugins
|
||||||
# The configuration associated with the provisioner, if there is any.
|
# The configuration associated with the provisioner, if there is any.
|
||||||
#
|
#
|
||||||
# @return [Object]
|
# @return [Object]
|
||||||
attr_reader :config
|
attr_accessor :config
|
||||||
|
|
||||||
def initialize(id, name)
|
def initialize(id, name)
|
||||||
@logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
|
@logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
|
||||||
|
@ -45,6 +45,11 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def initialize_copy(orig)
|
||||||
|
super
|
||||||
|
@config = @config.dup if @config
|
||||||
|
end
|
||||||
|
|
||||||
def add_config(**options, &block)
|
def add_config(**options, &block)
|
||||||
return if invalid?
|
return if invalid?
|
||||||
|
|
||||||
|
|
|
@ -36,5 +36,44 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||||
expect(r.length).to eql(1)
|
expect(r.length).to eql(1)
|
||||||
expect(r[0]).to be_invalid
|
expect(r[0]).to be_invalid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "merging" do
|
||||||
|
it "copies the configs" do
|
||||||
|
subject.provision("shell", inline: "foo")
|
||||||
|
subject_provs = subject.provisioners
|
||||||
|
|
||||||
|
other = described_class.new
|
||||||
|
other.provision("shell", inline: "bar")
|
||||||
|
|
||||||
|
merged = subject.merge(other)
|
||||||
|
merged_provs = merged.provisioners
|
||||||
|
|
||||||
|
expect(merged_provs.length).to eql(2)
|
||||||
|
expect(merged_provs[0].config.inline).
|
||||||
|
to eq(subject_provs[0].config.inline)
|
||||||
|
expect(merged_provs[0].config.object_id).
|
||||||
|
to_not eq(subject_provs[0].config.object_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "uses the proper order when merging overrides" do
|
||||||
|
subject.provision("shell", inline: "foo", id: "original")
|
||||||
|
subject.provision("shell", inline: "other", id: "other")
|
||||||
|
|
||||||
|
other = described_class.new
|
||||||
|
other.provision("shell", inline: "bar")
|
||||||
|
other.provision("shell", inline: "foo-overload", id: "original")
|
||||||
|
|
||||||
|
merged = subject.merge(other)
|
||||||
|
merged_provs = merged.provisioners
|
||||||
|
|
||||||
|
expect(merged_provs.length).to eql(3)
|
||||||
|
expect(merged_provs[0].config.inline).
|
||||||
|
to eq("other")
|
||||||
|
expect(merged_provs[1].config.inline).
|
||||||
|
to eq("bar")
|
||||||
|
expect(merged_provs[2].config.inline).
|
||||||
|
to eq("foo-overload")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue