module Pennyworth::SpecHelper

Public Instance Methods

start_system(opts) click to toggle source
# File lib/pennyworth/spec.rb, line 45
def start_system(opts)
  opts = {
    skip_ssh_setup: false
  }.merge(opts)
  username = opts[:username] || "root"
  if opts[:box]
    runner = VagrantRunner.new(opts[:box], RSpec.configuration.vagrant_dir, username)
    password = opts[:password] || "vagrant"
  elsif opts[:image]
    runner = ImageRunner.new(opts[:image], username)
    password = opts[:password] || "linux"
  elsif opts[:host]
    config = HostConfig.new(RSpec.configuration.hosts_file)
    config.read
    runner = HostRunner.new(opts[:host], config, username)
  elsif opts[:local]
    runner = LocalRunner.new(env: opts[:env])
  end

  raise "No image specified." unless runner

  system = VM.new(runner)

  # Make sure to stop the machine again when the example group is done
  self.class.after(:all) do
    system.stop
  end

  measure("Boot machine '#{opts[:box] || opts[:image] || opts[:host]}'") do
    system.start
  end
  if !opts[:skip_ssh_setup] && !opts[:host] && !opts[:local]
    SshKeysImporter.import(system.ip, username, password)
  end

  system
end