Sha256: 8fc5bc558e1dd293649fdc26fe05ef19bce11600aa493676acb7457c6f451d29

Contents?: true

Size: 1.77 KB

Versions: 13

Compression:

Stored size: 1.77 KB

Contents

require 'serverspec'
require 'pathname'
require 'net/ssh'


set :backend, :ssh

def run(cmd)
  unless(system(cmd, out: $stdout, err: :out))
    puts 'Failed to setup vagrant machine'
    exit 1
  end
end

<% if(options[:bench_enable]) -%>
class StopWatch
  attr_accessor :total
  def stop
    @total = Time.now - @start
  end

  def reset
    @start = Time.now	
  end
end

WATCH = StopWatch.new
<% end -%>

RSpec.configure do |c|
  c.before :suite do
    c.host  = ENV['TARGET_HOST']
    c.ssh.close if c.ssh
    options = Net::SSH::Config.for(c.host)
    if(!ENV['LOCAL'])
	run("vagrant destroy #{c.host} -f") unless ENV['SKIP_DESTROY']
      <% if(options[:bench_enable]) %>
      WATCH.reset
      <% end %>
	run("vagrant up #{c.host}")
      config = `vagrant ssh-config #{c.host}`
      sshhost =  sshuser = ''
      if config != ''
        config.each_line do |line|
          if match = /HostName (.*)/.match(line)
            sshhost = match[1]
          elsif  match = /User (.*)/.match(line)
            options[:user] = match[1]
          elsif match = /IdentityFile (.*)/.match(line)
            options[:keys] =  [match[1].gsub(/"/,'')]
          elsif match = /Port (.*)/.match(line)
            options[:port] = match[1]
          end
        end
      end
    else
      sshhost = 'localhost' 
	options[:user] = 'vagrant'
    end
    set :host, sshhost
    set :ssh_options,options
  end

  c.after :suite do
    c.host  = ENV['TARGET_HOST']
    <% if(options[:bench_enable]) %>
    WATCH.stop
    rev = %x{git rev-parse HEAD}.chomp
    File.open('benchmark.json', 'a') { |f| 
	json = {:total => WATCH.total.to_i, :host => c.host, :revision => rev, :time => Time.now}.to_json
	f.write("#{json}\n") 
    }
    <% end %>
    run("vagrant destroy #{c.host} -f") unless ENV['SKIP_DESTROY']
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
opskeleton-0.10.1 templates/parent/spec/spec_helper.erb
opskeleton-0.9.9 templates/parent/spec/spec_helper.erb
opskeleton-0.9.8 templates/parent/spec/spec_helper.erb
opskeleton-0.9.7 templates/parent/spec/spec_helper.erb
opskeleton-0.9.6 templates/parent/spec/spec_helper.erb
opskeleton-0.9.5 templates/parent/spec/spec_helper.erb
opskeleton-0.9.4 templates/parent/spec/spec_helper.erb
opskeleton-0.9.3 templates/parent/spec/spec_helper.erb
opskeleton-0.9.2 templates/parent/spec/spec_helper.erb
opskeleton-0.9.1 templates/parent/spec/spec_helper.erb
opskeleton-0.9.0 templates/parent/spec/spec_helper.erb
opskeleton-0.8.12 templates/parent/spec/spec_helper.erb
opskeleton-0.8.11 templates/parent/spec/spec_helper.erb