2013-04-21 21:38:02 +00:00
|
|
|
module AcceptanceExampleGroup
|
|
|
|
def self.included(base)
|
|
|
|
base.metadata[:type] = :acceptance
|
|
|
|
end
|
|
|
|
|
2013-04-21 21:47:15 +00:00
|
|
|
ID_FILE = "/vagrant/spec/.vagrant/machines/default/lxc/id"
|
|
|
|
def vagrant_container_name
|
|
|
|
File.read(ID_FILE).strip.chomp if File.exists?(ID_FILE)
|
|
|
|
end
|
|
|
|
|
2013-04-21 21:38:02 +00:00
|
|
|
def destroy_container
|
2013-04-21 21:47:15 +00:00
|
|
|
if name = vagrant_container_name
|
|
|
|
`sudo lxc-shutdown -n #{name} 2>/dev/null`
|
|
|
|
`sudo lxc-wait -n #{name} --state STOPPED 2>/dev/null`
|
|
|
|
`sudo lxc-destroy -n #{name} 2>/dev/null`
|
|
|
|
end
|
2013-04-21 21:38:02 +00:00
|
|
|
`sudo killall -9 redir 2>/dev/null`
|
|
|
|
end
|
|
|
|
|
2013-04-21 21:47:15 +00:00
|
|
|
def with_vagrant_environment
|
|
|
|
opts = { cwd: 'spec', ui_class: TestUI }
|
2013-04-21 21:38:02 +00:00
|
|
|
env = Vagrant::Environment.new(opts)
|
2013-04-21 21:47:15 +00:00
|
|
|
yield env
|
2013-04-21 21:38:02 +00:00
|
|
|
env.unload
|
|
|
|
end
|
|
|
|
|
2013-04-21 21:47:15 +00:00
|
|
|
def vagrant_up
|
|
|
|
with_vagrant_environment do |env|
|
|
|
|
env.cli('up', '--provider', 'lxc')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-21 21:38:02 +00:00
|
|
|
def vagrant_halt
|
2013-04-21 21:47:15 +00:00
|
|
|
with_vagrant_environment do |env|
|
|
|
|
env.cli('halt')
|
|
|
|
end
|
2013-04-21 21:38:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def vagrant_destroy
|
2013-04-21 21:47:15 +00:00
|
|
|
with_vagrant_environment do |env|
|
|
|
|
env.cli('destroy', '-f')
|
|
|
|
end
|
2013-04-21 21:38:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def vagrant_ssh(cmd)
|
2013-04-21 21:47:15 +00:00
|
|
|
output = nil
|
|
|
|
with_vagrant_environment do |env|
|
|
|
|
result = env.cli('ssh', '-c', cmd)
|
|
|
|
if result.to_i != 0
|
|
|
|
raise "SSH command failed: '#{cmd}'\n#{env.ui.messages.inspect}"
|
|
|
|
end
|
|
|
|
output = env.ui.messages[:info].join("\n").chomp
|
2013-04-21 21:38:02 +00:00
|
|
|
end
|
|
|
|
output
|
|
|
|
end
|
|
|
|
end
|