Skip to content

Commit

Permalink
disable audio by default with VirtualBox guests
Browse files Browse the repository at this point in the history
Fixes #388

As mentioned in that issue, modifying the VM to have audio set to "none"
will disable sound for the VM and prevent VirtualBox from connecting to
the host's audio which really cramps a user's style when they're
listening to something over bluetooth headphones.

This change opts to be simple-but-repetitive in the tests to include the
new default in each example VM config.

Signed-off-by: Robb Kidd <[email protected]>
  • Loading branch information
robbkidd committed Jan 28, 2019
1 parent 1cad7a7 commit 850c4fe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
29 changes: 29 additions & 0 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1272,10 +1272,27 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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"]
end
RUBY
end

it "disables audio by default" do
cmd

expect(vagrantfile).to include(%{p.customize ["modifyvm", :id, "--audio", "none"]})
end

it "allows audio to be enabled with :customize" do
config[:customize] = {
audio: "pulse",
}
cmd

expect(vagrantfile).to include(%{p.customize ["modifyvm", :id, "--audio", "pulse"]})
expect(vagrantfile).not_to include(%{p.customize ["modifyvm", :id, "--audio", "none"]})
end

it "adds a line for each element in :customize" do
config[:customize] = {
a_key: "some value",
Expand All @@ -1286,6 +1303,7 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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 ["modifyvm", :id, "--a_key", "some value"]
p.customize ["modifyvm", :id, "--something", "else"]
end
Expand All @@ -1307,6 +1325,7 @@ def run_command(_cmd, options = {})
c.vm.provider :virtualbox do |p|
p.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99"
p.gui = false
p.customize ["modifyvm", :id, "--audio", "none"]
end
RUBY
end
Expand All @@ -1319,6 +1338,7 @@ def run_command(_cmd, options = {})
c.vm.provider :virtualbox do |p|
p.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99"
p.gui = true
p.customize ["modifyvm", :id, "--audio", "none"]
end
RUBY
end
Expand All @@ -1339,6 +1359,7 @@ def run_command(_cmd, options = {})
c.vm.provider :virtualbox do |p|
p.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99"
p.linked_clone = false
p.customize ["modifyvm", :id, "--audio", "none"]
end
RUBY
end
Expand All @@ -1351,6 +1372,7 @@ def run_command(_cmd, options = {})
c.vm.provider :virtualbox do |p|
p.name = "kitchen-#{File.basename(config[:kitchen_root])}-suitey-fooos-99"
p.linked_clone = true
p.customize ["modifyvm", :id, "--audio", "none"]
end
RUBY
end
Expand All @@ -1367,6 +1389,7 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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
RUBY
Expand All @@ -1390,6 +1413,7 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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
Expand All @@ -1410,6 +1434,7 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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 ["storagectl", :id, "--name", "Custom SATA Controller", "--add", "sata", "--controller", "IntelAHCI", "--portcount", 4]
end
RUBY
Expand All @@ -1434,6 +1459,7 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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 ["storagectl", :id, "--name", "Custom SATA Controller", "--add", "sata", "--controller", "IntelAHCI"]
p.customize ["storagectl", :id, "--name", "Custom SATA Controller", "--portcount", 4]
end
Expand All @@ -1452,6 +1478,7 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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 ["storageattach", :id, "--type", "hdd", "--port", 1]
end
RUBY
Expand Down Expand Up @@ -1481,6 +1508,7 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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 ["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"]
end
Expand All @@ -1496,6 +1524,7 @@ def run_command(_cmd, options = {})
expect(vagrantfile).to match(regexify(<<-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 ["modifyvm", :id, "--cpuidset", "00000001", "00000002"]
end
RUBY
Expand Down
7 changes: 6 additions & 1 deletion templates/Vagrantfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Vagrant.configure("2") do |c|
when "virtualbox" %>
p.name = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>"
<% end %>
<% case config[:provider]
when "virtualbox", /^vmware_/
if config[:gui] == true || config[:gui] == false %>
Expand All @@ -114,6 +114,11 @@ Vagrant.configure("2") do |c|
<% end
end %>
<% if config[:provider] == "virtualbox" &&
!config[:customize].has_key?(:audio) %>
p.customize ["modifyvm", :id, "--audio", "none"]
<% end %>
<% config[:customize].each do |key, value| %>
<% case config[:provider]
when "libvirt" %>
Expand Down

0 comments on commit 850c4fe

Please sign in to comment.