Class: Cucumber::Chef::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/chef/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cucumber/chef/client.rb', line 31

def initialize
  tag = Cucumber::Chef.tag("cucumber-chef")
  puts(">>> #{tag}")
  Cucumber::Chef.boot(tag)

  @ui = ZTK::UI.new(:logger => Cucumber::Chef.logger)

  if !((@test_lab = Cucumber::Chef::TestLab.new(@ui)) && @test_lab.alive?)
    message = "No running cucumber-chef test labs to connect to!"
    @ui.logger.fatal { message }
    raise message
  end

end

Instance Attribute Details

#test_labObject

Returns the value of attribute test_lab.



27
28
29
# File 'lib/cucumber/chef/client.rb', line 27

def test_lab
  @test_lab
end

Instance Method Details

#after(scenario) ⇒ Object



121
122
# File 'lib/cucumber/chef/client.rb', line 121

def after(scenario)
end

#at_exitObject



126
127
# File 'lib/cucumber/chef/client.rb', line 126

def at_exit
end

#before(scenario) ⇒ Object



115
116
117
# File 'lib/cucumber/chef/client.rb', line 115

def before(scenario)
  $scenario = scenario
end

#up(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cucumber/chef/client.rb', line 48

def up(options={})

  # PUSH CHEF-REPO
  #################

  # Upload all of the chef-repo environments
  ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo environments to the test lab", :mark => "completed in %0.4f seconds.") do
    @test_lab.knife_cli(%(environment from file ./environments/*.rb), :silence => true)
  end

  # Upload all of the chef-repo cookbooks
  ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo cookbooks to the test lab", :mark => "completed in %0.4f seconds.") do
    cookbook_paths = Cucumber::Chef::Config.chef[:cookbook_paths]
    @test_lab.knife_cli(%(cookbook upload --all --cookbook-path #{cookbook_paths.join(':')} --force), :silence => true)
  end

  # Upload all of the chef-repo roles
  ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo roles to the test lab", :mark => "completed in %0.4f seconds.") do
    @test_lab.knife_cli(%(role from file ./roles/*.rb), :silence => true)
  end

  # Upload all of our chef-repo data bags
  Dir.glob("./data_bags/*").each do |data_bag_path|
    next if !File.directory?(data_bag_path)
    ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo data bag '#{File.basename(data_bag_path)}' to the test lab", :mark => "completed in %0.4f seconds.") do
      data_bag = File.basename(data_bag_path)
      @test_lab.knife_cli(%(data bag create "#{data_bag}"), :silence => true)
      @test_lab.knife_cli(%(data bag from file "#{data_bag}" "#{data_bag_path}"), :silence => true)
    end
  end

  # PURGE CONTAINERS
  ###################
  if environment_variable_set?("PURGE")
    @ui.logger.warn { "PURGING CONTAINERS!  Container attributes will be reset!" }
    @test_lab.containers.list.each do |name|
      ZTK::Benchmark.bench(:message => ">>> Destroying container '#{name}'", :mark => "completed in %0.4f seconds.") do
        @test_lab.containers.destroy(name)
      end
    end
  else
    @ui.logger.info { "Allowing existing containers to persist." }
  end

  # CREATE CONTAINERS
  ####################
  Cucumber::Chef::Container.all.each do |container|
    ZTK::Benchmark.bench(:message => ">>> Creating container '#{container.id}'", :mark => "completed in %0.4f seconds.") do
      @test_lab.containers.create(container)
    end
  end

  # PROVISION CONTAINERS
  #######################
  @test_lab.containers.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
                                              :validation_client_name => "chef-validator")
  Cucumber::Chef::Container.all.each do |container|
    ZTK::Benchmark.bench(:message => ">>> Provisioning container '#{container.id}'", :mark => "completed in %0.4f seconds.") do
      @test_lab.containers.provision(container)
    end
  end

  true
end