Class: Cucumber::Chef::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/chef/provider.rb,
lib/cucumber/chef/providers/aws.rb,
lib/cucumber/chef/providers/vagrant.rb

Defined Under Namespace

Classes: AWS, AWSError, Vagrant, VagrantError

Constant Summary collapse

PROXY_METHODS =
%w(create destroy up down reload status id state username ip port alive? dead? exists?)

Instance Method Summary collapse

Constructor Details

#initialize(ui = ZTK::UI.new) ⇒ Provider

Returns a new instance of Provider.



34
35
36
37
38
39
40
41
42
43
# File 'lib/cucumber/chef/provider.rb', line 34

def initialize(ui=ZTK::UI.new)
  @ui = ui

  @provider = case Cucumber::Chef::Config.provider
  when :aws then
    Cucumber::Chef::Provider::AWS.new(@ui)
  when :vagrant then
    Cucumber::Chef::Provider::Vagrant.new(@ui)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *method_args) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/cucumber/chef/provider.rb', line 84

def method_missing(method_name, *method_args)
  if Cucumber::Chef::Provider::PROXY_METHODS.include?(method_name.to_s)
    result = @provider.send(method_name.to_sym, *method_args)
    splat = [method_name, *method_args].flatten.compact
    @ui.logger.debug { "Provider: #{splat.inspect}=#{result.inspect}" }
    result
  else
    super(method_name, *method_args)
  end
end

Instance Method Details

#ipObject



74
75
76
# File 'lib/cucumber/chef/provider.rb', line 74

def ip
  (Cucumber::Chef.lab_ip || super(:ip))
end

#portObject



78
79
80
# File 'lib/cucumber/chef/provider.rb', line 78

def port
  (Cucumber::Chef.lab_ssh_port || super(:port))
end

#statusObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cucumber/chef/provider.rb', line 47

def status
  if exists?

    headers = %w(provider id state username ip_address ssh_port).map(&:to_sym)
    results = ZTK::Report.new.list([nil], headers) do |noop|

      OpenStruct.new(
        :provider => @provider.class,
        :id => self.id,
        :state => self.state,
        :username => self.username,
        :ip_address => self.ip,
        :ssh_port => self.port
      )
    end
  else
    raise ProviderError, "No test labs exists!"
  end

rescue Exception => e
  @ui.logger.fatal { e.message }
  @ui.logger.fatal { e.backtrace.join("\n") }
  raise ProviderError, e.message
end