move backend creation to profile context

keeping it in the runner will create conflicts with rspec runners
This commit is contained in:
Dominik Richter 2015-10-14 23:44:15 +02:00
parent be614e9056
commit 132019a6d9
3 changed files with 41 additions and 37 deletions

View file

@ -4,6 +4,7 @@
require 'vulcano/rule'
require 'vulcano/dsl'
require 'train'
module Vulcano
class ProfileContext
@ -140,5 +141,36 @@ module Vulcano
end
# rubocop:enable all
end
# Create the transport backend with aggregated resources.
#
# @param [Hash] config for the transport backend
# @return [Transport] enriched transport instance
def self.create_backend(config)
conf = Train.target_config(config)
name = conf[:backend] || :local
transport = Train.create(name, conf)
if transport.nil?
fail "Can't find transport backend '#{name}'."
end
connection = transport.connection
if connection.nil?
fail "Can't connect to transport backend '#{name}'."
end
cls = Class.new do
define_method :backend do
connection
end
Vulcano::Resource.registry.each do |id, r|
define_method id.to_sym do |*args|
r.new(self, id.to_s, *args)
end
end
end
cls.new
end
end
end

View file

@ -5,7 +5,6 @@
# author: Christoph Hartmann
require 'uri'
require 'train'
require 'vulcano/targets'
require 'vulcano/profile_context'
# spec requirements
@ -38,35 +37,8 @@ module Vulcano
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
end
def self.create_backend(config)
conf = Train.target_config(config)
name = conf[:backend] || :local
transport = Train.create(name, conf)
if transport.nil?
fail "Can't find transport backend '#{name}'."
end
connection = transport.connection
if connection.nil?
fail "Can't connect to transport backend '#{name}'."
end
cls = Class.new do
define_method :backend do
connection
end
Vulcano::Resource.registry.each do |id, r|
define_method id.to_sym do |*args|
r.new(self, id.to_s, *args)
end
end
end
cls.new
end
def configure_transport
@backend = self.class.create_backend(@conf)
@backend = ProfileContext.create_backend(@conf)
end
def add_tests(tests)

View file

@ -14,7 +14,7 @@ SimpleCov.start do
end
require 'vulcano/resource'
require 'train'
require 'vulcano/profile_context'
class MockLoader
# pass the os identifier to emulate a specific operating system
@ -47,8 +47,11 @@ class MockLoader
scriptpath = ::File.realpath(::File.dirname(__FILE__))
# create mock backend
@backend = Train.create('mock')
mock = @backend.connection
@backend = Vulcano::ProfileContext.create_backend({ backend: :mock })
mock = @backend.backend
# set os emulation
mock.mock_os(@os)
# create all mock files
local = Train.create('local').connection
@ -92,11 +95,11 @@ class MockLoader
# create all mock commands
cmd = lambda {|x|
stdout = ::File.read(::File.join(scriptpath, '/unit/mock/cmd/'+x))
mock.mock_command(stdout, '', 0)
mock.mock_command('', stdout, '', 0)
}
empty = lambda {
mock.mock_command('', '', 0)
mock.mock_command('', '', '', 0)
}
mock.commands = {
@ -179,9 +182,6 @@ class MockLoader
'iptables -S' => cmd.call('iptables-s'),
}
# set os emulation
mock.os = @os
@backend
end