Skip to content

Commit

Permalink
Vagrantfile: disk check
Browse files Browse the repository at this point in the history
Checking if virtual disk already exists when specifying createhd command. Updated unit-tests to replace regex check with substring check. Regex check was too permissive. This commit is based on PR #389

Signed-off-by: Vikram Karve <vikram.karve@progress.com>
  • Loading branch information
vkarve-chef committed Aug 8, 2021
1 parent e3fae39 commit fdf13b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
33 changes: 20 additions & 13 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1391,12 +1391,12 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(Regexp.new(<<-RUBY.gsub(/^ {8}/, "").chomp))
c.vm.provider :virtualbox do |p|
p.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
p.customize ["createhd", "--filename", "./d1.vmdk", "--size", 10240]
end
expect(vagrantfile).to include(<<-RUBY.gsub(/^ {8}/, "").chomp)
unless File.file?("./d1.vmdk")
RUBY

expect(vagrantfile).to include(<<-RUBY.gsub(/^ {8}/, "").chomp)
p.customize ["createhd", "--filename", "./d1.vmdk", "--size", 10240]
RUBY
end

Expand All @@ -1415,13 +1415,20 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(Regexp.new(<<-RUBY.gsub(/^ {8}/, "").chomp))
c.vm.provider :virtualbox do |p|
p.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
p.customize ["createhd", "--filename", "./d1.vmdk", "--size", 10240]
p.customize ["createhd", "--filename", "./d2.vmdk", "--size", 20480]
end
expect(vagrantfile).to include(<<-RUBY.gsub(/^ {8}/, "").chomp)
unless File.file?("./d1.vmdk")
RUBY

expect(vagrantfile).to include(<<-RUBY.gsub(/^ {8}/, "").chomp)
p.customize ["createhd", "--filename", "./d1.vmdk", "--size", 10240]
RUBY

expect(vagrantfile).to include(<<-RUBY.gsub(/^ {8}/, "").chomp)
unless File.file?("./d2.vmdk")
RUBY

expect(vagrantfile).to include(<<-RUBY.gsub(/^ {8}/, "").chomp)
p.customize ["createhd", "--filename", "./d2.vmdk", "--size", 20480]
RUBY
end

Expand Down
4 changes: 3 additions & 1 deletion templates/Vagrantfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ Vagrant.configure("2") do |c|
<% if key == :createhd %>
<% value = [value] unless value.instance_of?(Array) %>
<% value.each do |item| %>
p.customize ["createhd", "--filename", "<%= item[:filename] %>", "--size", <%= item[:size] %>]
unless File.file?("<%= item[:filename] %>")
p.customize ["createhd", "--filename", "<%= item[:filename] %>", "--size", <%= item[:size] %>]
end
<% end %>
<% elsif key == :storageattach || key == :storagectl %>
<% value = [value] unless value.instance_of?(Array) %>
Expand Down

0 comments on commit fdf13b5

Please sign in to comment.