Skip to content

Commit

Permalink
Merge pull request #141 from anodelman/vagrant-mem-size
Browse files Browse the repository at this point in the history
(QA-794) make vagrant vm size configurable through beaker
  • Loading branch information
Branan Purvine-Riley committed Feb 20, 2014
2 parents 54ba486 + cee83d0 commit 9ac309b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/beaker/hypervisor/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def randip
"10.255.#{rand_chunk}.#{rand_chunk}"
end

def make_vfile hosts
def make_vfile hosts, options = {}
#HACK HACK HACK - add checks here to ensure that we have box + box_url
#generate the VagrantFile
v_file = "Vagrant.configure(\"2\") do |c|\n"
Expand All @@ -34,7 +34,7 @@ def make_vfile hosts
@logger.debug "created Vagrantfile for VagrantHost #{host.name}"
end
v_file << " c.vm.provider :virtualbox do |vb|\n"
v_file << " vb.customize [\"modifyvm\", :id, \"--memory\", \"1024\"]\n"
v_file << " vb.customize [\"modifyvm\", :id, \"--memory\", \"#{options['vagrant_memsize'] ||= '1024'}\"]\n"
v_file << " end\n"
v_file << "end\n"
File.open(@vagrant_file, 'w') do |f|
Expand Down Expand Up @@ -117,7 +117,7 @@ def provision
#make sure that any old boxes are dead dead dead
vagrant_cmd("destroy --force") if File.file?(@vagrant_file)

make_vfile @vagrant_hosts
make_vfile @vagrant_hosts, @options

vagrant_cmd("up")
else #set host ip of already up boxes
Expand Down
22 changes: 19 additions & 3 deletions spec/beaker/hypervisor/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ module Beaker
expect( File.read( File.expand_path( File.join( path, "Vagrantfile") ) ) ).to be === "Vagrant.configure(\"2\") do |c|\n c.vm.define 'vm1' do |v|\n v.vm.hostname = 'vm1'\n v.vm.box = 'vm1_of_my_box'\n v.vm.box_url = 'http://address.for.my.box.vm1'\n v.vm.base_mac = '0123456789'\n v.vm.network :private_network, ip: \"ip.address.for.vm1\", :netmask => \"255.255.0.0\"\n end\n c.vm.define 'vm2' do |v|\n v.vm.hostname = 'vm2'\n v.vm.box = 'vm2_of_my_box'\n v.vm.box_url = 'http://address.for.my.box.vm2'\n v.vm.base_mac = '0123456789'\n v.vm.network :private_network, ip: \"ip.address.for.vm2\", :netmask => \"255.255.0.0\"\n end\n c.vm.define 'vm3' do |v|\n v.vm.hostname = 'vm3'\n v.vm.box = 'vm3_of_my_box'\n v.vm.box_url = 'http://address.for.my.box.vm3'\n v.vm.base_mac = '0123456789'\n v.vm.network :private_network, ip: \"ip.address.for.vm3\", :netmask => \"255.255.0.0\"\n end\n c.vm.provider :virtualbox do |vb|\n vb.customize [\"modifyvm\", :id, \"--memory\", \"1024\"]\n end\nend\n"
end

it "uses the memsize defined per vagrant host" do
FakeFS.activate!
path = vagrant.instance_variable_get( :@vagrant_path )
vagrant.stub( :randmac ).and_return( "0123456789" )

vagrant.make_vfile( @hosts, {'vagrant_memsize' => 'hello!'} )

generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) )

match = generated_file.match(/vb.customize \["modifyvm", :id, "--memory", "hello!"]/)

expect( match ).to_not be nil

end

it "can generate a new /etc/hosts file referencing each host" do

@hosts.each do |host|
Expand Down Expand Up @@ -132,14 +147,15 @@ module Beaker
end

it "can provision a set of hosts" do
vagrant.should_receive( :make_vfile ).with( @hosts ).once
options = vagrant.instance_variable_get( :@options )
vagrant.should_receive( :make_vfile ).with( @hosts, options ).once
vagrant.should_receive( :vagrant_cmd ).with( "destroy --force" ).never
vagrant.provision
end

it "destroys an existing set of hosts before provisioning" do
vagrant.make_vfile(@hosts)
vagrant.should_receive(:vagrant_cmd).with("destroy --force").once
vagrant.make_vfile( @hosts )
vagrant.should_receive( :vagrant_cmd ).with( "destroy --force" ).once
vagrant.provision
end

Expand Down

0 comments on commit 9ac309b

Please sign in to comment.