spec/beaker/hypervisor/vagrant_spec.rb in beaker-vagrant-0.5.0 vs spec/beaker/hypervisor/vagrant_spec.rb in beaker-vagrant-0.6.0
- old
+ new
@@ -176,10 +176,65 @@
expect( vagrantfile ).not_to match(/v.vm.synced_folder '\/invalid2', '', create: true/)
expect( vagrantfile ).not_to match(/v.vm.synced_folder '', '\/invalid3', create: true/)
expect( vagrantfile ).to match(/v.vm.synced_folder '\/valid', '\/valid', create: true/)
end
+ it "can make a Vagrantfile with optional shell provisioner" do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+
+ shell_path = '/path/to/shell/script'
+ hosts = make_hosts({
+ :shell_provisioner => {
+ :path => shell_path
+ }
+ }, 1)
+ vagrant.make_vfile( hosts, options )
+
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
+ expect( vagrantfile ).to match(/v.vm.provision 'shell', :path => '#{shell_path}'/)
+ end
+
+ it "can make a Vagrantfile with optional shell provisioner with args" do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+
+ shell_path = '/path/to/shell/script.sh'
+ shell_args = 'arg1 arg2'
+ hosts = make_hosts({
+ :shell_provisioner => {
+ :path => shell_path,
+ :args => shell_args
+ }
+ }, 1)
+ vagrant.make_vfile( hosts, options )
+
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
+ expect( vagrantfile ).to match(/v.vm.provision 'shell', :path => '#{shell_path}', :args => '#{shell_args}'/)
+ end
+
+ it "raises an error if path is not set on shell_provisioner" do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+
+ hosts = make_hosts({:shell_provisioner => {}}, 1)
+ expect{ vagrant.make_vfile( hosts, options ) }.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
+ end
+
+ it "raises an error if path is EMPTY on shell_provisioner" do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+
+ empty_shell_path = ''
+ hosts = make_hosts({
+ :shell_provisioner => {
+ :path => empty_shell_path
+ }
+ }, 1)
+ expect{ vagrant.make_vfile( hosts, options ) }.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
+ end
+
context "when generating a windows config" do
before do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
@hosts[0][:platform] = 'windows'
@@ -387,42 +442,124 @@
vagrant.copy_ssh_to_root( host, options )
end
end
- it "can generate a ssh-config file" do
- host = @hosts[0]
- name = host.name
- allow( Dir ).to receive( :chdir ).and_yield()
- out = double( 'stdout' )
- allow( out ).to receive( :read ).and_return("Host #{name}
- HostName 127.0.0.1
- User vagrant
- Port 2222
- UserKnownHostsFile /dev/null
- StrictHostKeyChecking no
- PasswordAuthentication no
- IdentityFile /home/root/.vagrant.d/insecure_private_key
- IdentitiesOnly yes")
+ describe "set_ssh_config" do
+ let( :out ) { double( 'stdout' ) }
+ let( :host ) { @hosts[0] }
+ let( :name ) { host.name }
+ let( :file ) { double( 'file' ) }
- wait_thr = OpenStruct.new
- state = double( 'state' )
- allow( state ).to receive( :success? ).and_return( true )
- wait_thr.value = state
+ before :each do
+ allow( Dir ).to receive( :chdir ).and_yield()
+ wait_thr = OpenStruct.new
+ state = double( 'state' )
+ allow( state ).to receive( :success? ).and_return( true )
+ wait_thr.value = state
- allow( Open3 ).to receive( :popen3 ).with( {"RUBYLIB"=>""}, 'vagrant', 'ssh-config', name ).and_return( [ "", out, "", wait_thr ])
+ allow( Open3 ).to receive( :popen3 ).with( {"RUBYLIB"=>""}, 'vagrant', 'ssh-config', name ).and_return( [ "", out, "", wait_thr ])
- file = double( 'file' )
- allow( file ).to receive( :path ).and_return( '/path/sshconfig' )
- allow( file ).to receive( :rewind ).and_return( true )
+ allow( file ).to receive( :path ).and_return( '/path/sshconfig' )
+ allow( file ).to receive( :rewind ).and_return( true )
- expect( Tempfile ).to receive( :new ).with( "#{host.name}").and_return( file )
- expect( file ).to receive( :write ).with("Host ip.address.for.#{name}\n HostName 127.0.0.1\n User root\n Port 2222\n UserKnownHostsFile /dev/null\n StrictHostKeyChecking no\n PasswordAuthentication no\n IdentityFile /home/root/.vagrant.d/insecure_private_key\n IdentitiesOnly yes")
+ allow( out ).to receive( :read ).and_return("Host #{name}
+ HostName 127.0.0.1
+ User vagrant
+ Port 2222
+ UserKnownHostsFile /dev/null
+ StrictHostKeyChecking no
+ PasswordAuthentication no
+ IdentityFile /home/root/.vagrant.d/insecure_private_key
+ IdentitiesOnly yes")
+ end
- vagrant.set_ssh_config( host, 'root' )
- expect( host['ssh'] ).to be === { :config => file.path }
- expect( host['user']).to be === 'root'
+ it "can generate a ssh-config file" do
+ expect( Tempfile ).to receive( :new ).with( "#{host.name}").and_return( file )
+ expect( file ).to receive( :write ).with("Host ip.address.for.#{name}\n HostName 127.0.0.1\n User root\n Port 2222\n UserKnownHostsFile /dev/null\n StrictHostKeyChecking no\n PasswordAuthentication no\n IdentityFile /home/root/.vagrant.d/insecure_private_key\n IdentitiesOnly no")
+ vagrant.set_ssh_config( host, 'root' )
+ expect( host['ssh'] ).to be === { :config => file.path }
+ expect( host['user']).to be === 'root'
+ end
+
+ context "when :forward_ssh_agent is false" do
+ it "should not change IdentitiesOnly to no" do
+ options = vagrant.instance_variable_get( :@options )
+ options['forward_ssh_agent'] = false
+ options = vagrant.instance_variable_set( :@options, options )
+
+ expect( Tempfile ).to receive( :new ).with( "#{host.name}").and_return( file )
+ expect( file ).to receive( :write ).with("Host ip.address.for.#{name}\n HostName 127.0.0.1\n User root\n Port 2222\n UserKnownHostsFile /dev/null\n StrictHostKeyChecking no\n PasswordAuthentication no\n IdentityFile /home/root/.vagrant.d/insecure_private_key\n IdentitiesOnly yes")
+
+ vagrant.set_ssh_config( host, 'root' )
+ expect( host['ssh'] ).to be === { :config => file.path }
+ expect( host['user']).to be === 'root'
+ end
+ end
+ end
+
+ context 'with options[:provision] = false' do
+ let(:options) { super().merge(provision: false) }
+
+ context 'when Vagrantfile does not exist' do
+ it 'raises an error' do
+ expect { vagrant.configure }.to raise_error RuntimeError, /no vagrant file was found/
+ end
+ end
+
+ it 'calls #get_ip_from_vagrant_file' do
+ vagrant.make_vfile(@hosts)
+
+ @hosts.each do |host|
+ allow(vagrant).to receive(:set_ssh_config).with(host, anything)
+ expect(vagrant).to receive(:get_ip_from_vagrant_file).with(host.name)
+ end
+
+ vagrant.configure
+ end
+
+ it 'calls #set_all_ssh_config' do
+ vagrant.make_vfile(@hosts)
+ expect(vagrant).to receive(:set_all_ssh_config)
+ vagrant.configure
+ end
+ end
+
+ describe '#set_all_ssh_config' do
+ before do
+ allow(vagrant).to receive(:set_ssh_config)
+ end
+
+ it 'calls #set_ssh_config' do
+ @hosts.each do |host|
+ expect(vagrant).to receive(:set_ssh_config).with(host, 'vagrant')
+ expect(vagrant).to receive(:set_ssh_config).with(host, host['user'])
+ end
+
+ vagrant.set_all_ssh_config
+ end
+
+ it 'calls #copy_ssh_to_root' do
+ @hosts.each do |host|
+ expect(vagrant).to receive(:copy_ssh_to_root).with(host, options)
+ end
+
+ vagrant.set_all_ssh_config
+ end
+
+ it 'calls #enable_root_login' do
+ @hosts.each do |host|
+ expect(vagrant).to receive(:enable_root_login).with(host, options)
+ end
+
+ vagrant.set_all_ssh_config
+ end
+
+ it 'calls #hack_etc_hosts' do
+ expect(vagrant).to receive(:hack_etc_hosts).with(@hosts, options)
+ vagrant.set_all_ssh_config
+ end
end
describe "get_ip_from_vagrant_file" do
before :each do
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )