Merge pull request #8680 from briancain/7685/master/add-unique-id-to-provisioners

Add a unique identifier to provision objects
This commit is contained in:
Brian Cain 2017-06-13 16:48:17 -07:00 committed by GitHub
commit a9be8e8a14
3 changed files with 47 additions and 11 deletions

View File

@ -145,18 +145,16 @@ module VagrantPlugins
new_provs = []
other_provs = other.provisioners.dup
@provisioners.each do |p|
if p.name
other_p = other_provs.find { |o| p.name == o.name }
if other_p
# There is an override. Take it.
other_p.config = p.config.merge(other_p.config)
other_p.run ||= p.run
next if !other_p.preserve_order
other_p = other_provs.find { |o| p.id == o.id }
if other_p
# There is an override. Take it.
other_p.config = p.config.merge(other_p.config)
other_p.run ||= p.run
next if !other_p.preserve_order
# We're preserving order, delete from other
p = other_p
other_provs.delete(other_p)
end
# We're preserving order, delete from other
p = other_p
other_provs.delete(other_p)
end
# There is an override, merge it into the

View File

@ -9,6 +9,15 @@ module VagrantPlugins
# @return [String]
attr_reader :name
# Internal unique name for this provisioner
# Set to the given :name if exists, otherwise
# it's set as a UUID.
#
# Note: This is for internal use only.
#
# @return [String]
attr_reader :id
# The type of the provisioner that should be registered
# as a plugin.
#
@ -35,6 +44,7 @@ module VagrantPlugins
@logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
@logger.debug("Provisioner defined: #{name}")
@id = name || SecureRandom.uuid
@config = nil
@invalid = false
@name = name

View File

@ -424,6 +424,24 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
expect{ subject.finalize! }.to_not raise_error
end
it "generates a uuid if no name was provided" do
allow(SecureRandom).to receive(:uuid).and_return("MY_CUSTOM_VALUE")
subject.provision("shell", path: "foo") { |s| s.inline = "foo" }
subject.finalize!
r = subject.provisioners
expect(r[0].id).to eq("MY_CUSTOM_VALUE")
end
it "sets id as name if a name was provided" do
subject.provision("ghost", type: "shell", path: "motoko") { |s| s.inline = "motoko" }
subject.finalize!
r = subject.provisioners
expect(r[0].id).to eq(:ghost)
end
describe "merging" do
it "ignores non-overriding runs" do
subject.provision("shell", inline: "foo", run: "once")
@ -439,6 +457,16 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
expect(merged_provs[1].run).to eq("always")
end
it "does not merge duplicate provisioners" do
subject.provision("shell", inline: "foo")
subject.provision("shell", inline: "bar")
merged = subject.merge(subject)
merged_provs = merged.provisioners
expect(merged_provs.length).to eql(2)
end
it "copies the configs" do
subject.provision("shell", inline: "foo")
subject_provs = subject.provisioners