Fix bug in :each provisioner sorting
Ensure each provisioners are properly inserted into the final provisioner array
This commit is contained in:
parent
c189e4d255
commit
271d427c57
|
@ -45,8 +45,6 @@ module Vagrant
|
||||||
|
|
||||||
# Sorts provisioners based on order specified with before/after options
|
# Sorts provisioners based on order specified with before/after options
|
||||||
#
|
#
|
||||||
# TODO: make sure all defined provisioners work here (i.e. even thoughs defined in separate but loaded Vagrantfile)
|
|
||||||
#
|
|
||||||
# @return [Array<Provisioner, Hash>]
|
# @return [Array<Provisioner, Hash>]
|
||||||
def sort_provisioner_instances(pvs)
|
def sort_provisioner_instances(pvs)
|
||||||
final_provs = []
|
final_provs = []
|
||||||
|
@ -70,8 +68,6 @@ module Vagrant
|
||||||
# extract all provisioners
|
# extract all provisioners
|
||||||
all_provs = pvs.map { |p,o| [p,o] if o[:before] == :all || o[:after] == :all }.reject(&:nil?)
|
all_provs = pvs.map { |p,o| [p,o] if o[:before] == :all || o[:after] == :all }.reject(&:nil?)
|
||||||
|
|
||||||
# TODO: Log here, that provisioner order is being changed
|
|
||||||
|
|
||||||
# insert provisioners in order
|
# insert provisioners in order
|
||||||
final_provs = root_provs
|
final_provs = root_provs
|
||||||
dep_provs.each do |p,options|
|
dep_provs.each do |p,options|
|
||||||
|
@ -90,26 +86,22 @@ module Vagrant
|
||||||
# Add :each and :all provisioners in reverse to preserve order in Vagrantfile
|
# Add :each and :all provisioners in reverse to preserve order in Vagrantfile
|
||||||
|
|
||||||
# add each to final array
|
# add each to final array
|
||||||
# TODO: This doesn't work if before each provisioners are defined before after provisioners
|
tmp_final_provs = []
|
||||||
#
|
|
||||||
# Maybe do before and after individually instead??
|
|
||||||
tmp_final_provs = final_provs.dup
|
|
||||||
index_offset = 0
|
|
||||||
final_provs.each_with_index.map do |(prv,o), i|
|
final_provs.each_with_index.map do |(prv,o), i|
|
||||||
|
tmp_before = []
|
||||||
|
tmp_after = []
|
||||||
|
|
||||||
each_provs.reverse_each do |p, options|
|
each_provs.reverse_each do |p, options|
|
||||||
idx = 0
|
|
||||||
if options[:before]
|
if options[:before]
|
||||||
idx = (i+index_offset+1)-1 unless i == 0
|
tmp_before << [p,options]
|
||||||
puts "b: #{idx}"
|
|
||||||
index_offset += 1
|
|
||||||
tmp_final_provs.insert(idx, [p,options])
|
|
||||||
elsif options[:after]
|
elsif options[:after]
|
||||||
idx = (i+index_offset)+1
|
tmp_after << [p,options]
|
||||||
index_offset += 1
|
|
||||||
puts "a: #{idx}"
|
|
||||||
tmp_final_provs.insert(idx, [p,options])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tmp_final_provs += tmp_before unless tmp_before.empty?
|
||||||
|
tmp_final_provs += [[prv,o]]
|
||||||
|
tmp_final_provs += tmp_after unless tmp_after.empty?
|
||||||
end
|
end
|
||||||
final_provs = tmp_final_provs
|
final_provs = tmp_final_provs
|
||||||
|
|
||||||
|
|
|
@ -188,9 +188,6 @@ describe Vagrant::Action::Builtin::MixinProvisioners do
|
||||||
|
|
||||||
it "puts the each shortcut provisioners in place" do
|
it "puts the each shortcut provisioners in place" do
|
||||||
result = subject.provisioner_instances(env)
|
result = subject.provisioner_instances(env)
|
||||||
result.each do |p,o|
|
|
||||||
puts o[:name]
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(result[0].last[:name]).to eq("before-test")
|
expect(result[0].last[:name]).to eq("before-test")
|
||||||
expect(result[1].last[:name]).to eq("root-test")
|
expect(result[1].last[:name]).to eq("root-test")
|
||||||
|
|
Loading…
Reference in New Issue