lib/testlab.rb in testlab-0.0.3 vs lib/testlab.rb in testlab-0.0.4
- old
+ new
@@ -20,15 +20,17 @@
autoload :Network, 'testlab/network'
autoload :Link, 'testlab/link'
@@ui ||= nil
- def initialize(ui=ZTK::UI.new)
- labfile = ZTK::Locator.find('Labfile')
+ def initialize(options={})
+ labfile = (options[:labfile] || 'Labfile')
+ labfile_path = ZTK::Locator.find(labfile)
- @@ui = ui
- @labfile = TestLab::Labfile.load(labfile)
+ @@ui = (options[:ui] || ZTK::UI.new)
+
+ @labfile = TestLab::Labfile.load(labfile_path)
end
def nodes
TestLab::Node.all
end
@@ -80,23 +82,35 @@
false
end
end
+ def setup
+ self.dead? and raise TestLabError, "You must have a running node in order to setup your infrastructure!"
+
+ node_method_proxy(:setup)
+ end
+
+ def teardown
+ self.dead? and raise TestLabError, "You must have a running node in order to teardown your infrastructure!"
+
+ node_method_proxy(:teardown)
+ end
+
# Proxy various method calls to our subordinate classes
- def method_proxy(method_name, *method_args)
+ def node_method_proxy(method_name, *method_args)
@@ui.logger.debug { "TestLab.#{method_name}" }
TestLab::Node.all.map do |node|
node.send(method_name.to_sym, *method_args)
end
end
# Method missing handler
def method_missing(method_name, *method_args)
@@ui.logger.debug { "TESTLAB METHOD MISSING: #{method_name.inspect}(#{method_args.inspect})" }
- if TestLab::Provider::PROXY_METHODS.include?(method_name)
- method_proxy(method_name, *method_args)
+ if TestLab::Provider::PROXY_METHODS.include?(method_name) # || %w(setup teardown).map(&:to_sym).include?(method_name))
+ node_method_proxy(method_name, *method_args)
else
super(method_name, *method_args)
end
end