Skip to content

Commit

Permalink
Restores vm name uniqueness.
Browse files Browse the repository at this point in the history
Fixes bug introduced by test-kitchen#366. By specifying a name in the Vagrantfile,
we lose uniqueness added by the [Vagrant SetName
class](https://github.com/hashicorp/vagrant/blob/85acf0cac724ef4bfda593a66e0c17f7e4110da0/plugins/providers/virtualbox/action/set_name.rb#L29).
This PR restores uniqueness.

Closes test-kitchen#376.
  • Loading branch information
Frederik Thuysbaert committed Apr 30, 2019
1 parent 9af5388 commit b018a07
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
52 changes: 26 additions & 26 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1269,9 +1269,9 @@ def run_command(_cmd, options = {})
it "sets :name for virtualbox GUI" do
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
end
RUBY
Expand Down Expand Up @@ -1300,9 +1300,9 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
p.customize ["modifyvm", :id, "--a_key", "some value"]
p.customize ["modifyvm", :id, "--something", "else"]
Expand All @@ -1321,9 +1321,9 @@ def run_command(_cmd, options = {})
config[:gui] = false
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.gui = false
p.customize ["modifyvm", :id, "--audio", "none"]
end
Expand All @@ -1334,9 +1334,9 @@ def run_command(_cmd, options = {})
config[:gui] = true
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.gui = true
p.customize ["modifyvm", :id, "--audio", "none"]
end
Expand All @@ -1355,9 +1355,9 @@ def run_command(_cmd, options = {})
config[:linked_clone] = false
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.linked_clone = false
p.customize ["modifyvm", :id, "--audio", "none"]
end
Expand All @@ -1368,9 +1368,9 @@ def run_command(_cmd, options = {})
config[:linked_clone] = true
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.linked_clone = true
p.customize ["modifyvm", :id, "--audio", "none"]
end
Expand All @@ -1386,9 +1386,9 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.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
Expand All @@ -1410,9 +1410,9 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.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]
Expand All @@ -1431,9 +1431,9 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
p.customize ["storagectl", :id, "--name", "Custom SATA Controller", "--add", "sata", "--controller", "IntelAHCI", "--portcount", 4]
end
Expand All @@ -1456,9 +1456,9 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
p.customize ["storagectl", :id, "--name", "Custom SATA Controller", "--add", "sata", "--controller", "IntelAHCI"]
p.customize ["storagectl", :id, "--name", "Custom SATA Controller", "--portcount", 4]
Expand All @@ -1475,9 +1475,9 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
p.customize ["storageattach", :id, "--type", "hdd", "--port", 1]
end
Expand Down Expand Up @@ -1505,9 +1505,9 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
p.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 1, "--device", 0, "--type", "hdd", "--medium", "./d1.vmdk"]
p.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 1, "--device", 1, "--type", "hdd", "--medium", "./d2.vmdk"]
Expand All @@ -1521,9 +1521,9 @@ def run_command(_cmd, options = {})
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
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.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.customize ["modifyvm", :id, "--audio", "none"]
p.customize ["modifyvm", :id, "--cpuidset", "00000001", "00000002"]
end
Expand Down
4 changes: 2 additions & 2 deletions templates/Vagrantfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Vagrant.configure("2") do |c|
c.vm.provider :<%= config[:provider] %> do |p|
<% case config[:provider]
when "virtualbox" %>
p.name = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>"
p.name = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>-<%= SecureRandom.uuid %>"
<% end %>

<% case config[:provider]
Expand All @@ -108,7 +108,7 @@ Vagrant.configure("2") do |c|
p.linked_clone = <%= config[:linked_clone] %>
<% end
when "hyperv" %>
p.vmname = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>"
p.vmname = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>-<%= SecureRandom.uuid %>"
<% if config[:linked_clone] == true || config[:linked_clone] == false %>
p.linked_clone = <%= config[:linked_clone] %>
<% end
Expand Down

0 comments on commit b018a07

Please sign in to comment.