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

(QA-794) make vagrant vm size configurable through beaker #141

Merged
merged 1 commit into from
Feb 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

where does vagrant_memsize come from? There doesn't seem to be a way to set it in the current code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this will leave options['vagrant_memsize'] set to 1024 after this function exits. Is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in case you wish to refer to the memsize later you want to either preserve the setting selected by the user or set it to the default.

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 @@ -139,14 +154,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