Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid colliding guest names on libvirt when running multiple kit… #495

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1619,8 +1619,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 :libvirt do |p|
p.default_prefix = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.a_key = "some value"
p.something = "else"
p.a_number_key = 1024
Expand All @@ -1634,8 +1635,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 :libvirt do |p|
p.default_prefix = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.storage :file, :size => '32G'
end
RUBY
Expand All @@ -1651,8 +1653,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 :libvirt do |p|
p.default_prefix = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99-.*"
p.storage :file, :size => '1G'
p.storage :file, :size => '128G', :bus => 'sata'
p.storage :file, :size => '64G', :bus => 'sata'
Expand Down
1 change: 1 addition & 0 deletions templates/Vagrantfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Vagrant.configure("2") do |c|
<% config[:customize].each do |key, value| %>
<% case config[:provider]
when "libvirt" %>
p.default_prefix = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>-<%= SecureRandom.uuid %>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if it would be better to modify line 114 to include when "hyperv", "libvirt" to get the same behaviour. Currently this would be the wrong place to put this especially without wrapping it in if key == :default_prefix block as multiple customize parameters for libvirt would then cause this line to get added to Vagrantfile multiple times. Wrapping it with a special key call would also allow for current functionality and make this an optional addition to the machine name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 114 use p.vmname but that afaik is not available on libvirt provider thats why default_prefix was used. Now i understand that if a user overrides using default_prefix it could be duplicated.

<% if key == :storage %>
<% if value.is_a? String %>
p.storage <%= value %>
Expand Down