Class: ChefSpec::ServerRunner

Inherits:
SoloRunner show all
Includes:
ServerMethods
Defined in:
lib/chefspec/server_runner.rb,
lib/chefspec/chef_backwards_compat.rb

Instance Attribute Summary

Attributes inherited from SoloRunner

#options, #run_context

Instance Method Summary collapse

Methods included from ServerMethods

#client, #clients, #create_client, #create_data_bag, #create_environment, #create_node, #create_role, #data, #data_bag, entity, #environment, #environments, #get, #has_client?, #has_data_bag?, #has_environment?, #has_node?, #has_role?, #load_data, #node, #nodes, #role, #roles, #server

Methods inherited from SoloRunner

#compiling?, converge, #dry_run?, #find_resource, #find_resources, #inspect, #method_missing, #node, #resource_collection, #respond_to_missing?, #step_into?, #to_s

Methods included from Normalize

#resource_name

Constructor Details

#initialize(options = {}) {|node, _self| ... } ⇒ ServerRunner

Returns a new instance of ServerRunner

Yields:

Yield Parameters:

See Also:

  • ChefSpec::ServerRunner.(SoloRunner(SoloRunner#initialize)

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chefspec/server_runner.rb', line 13

def initialize(options = {})
  # Call super, but do not pass in the block because we want to customize
  # our yielding.
  super(options, &nil)

  Chef::Config[:client_key]      = client_key
  Chef::Config[:client_name]     = 'chefspec'
  Chef::Config[:node_name]       = 'chefspec'
  Chef::Config[:solo]            = false

  Chef::Config[:chef_server_url]  = server.url
  Chef::Config[:http_retry_count] = 0

  # Start the Chef Zero instance in the background
  server.start_background
  at_exit { server.stop if server.running? }

  # Unlike the SoloRunner, the node AND server object are yielded for
  # customization
  yield node, self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ChefSpec::SoloRunner

Instance Method Details

#converge(*recipe_names) ⇒ Object

See Also:

  • ChefSpec::ServerRunner.(SoloRunner(SoloRunner#converge)

57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chefspec/server_runner.rb', line 57

def converge(*recipe_names)
  upload_cookbooks!

  super do
    yield if block_given?

    # Save the node back to the server for searching purposes
    client.register
    node.save
  end
end

#cookbook_uploader_for(loader) ⇒ Object

The method airty for the Chef::CookbookUploader used to accept a list of cookbook paths. This restores that behavior.


52
53
54
# File 'lib/chefspec/server_runner.rb', line 52

def cookbook_uploader_for(loader)
  Chef::CookbookUploader.new(loader.cookbooks)
end

#upload_cookbooks!Object

Upload the cookbooks to the Chef Server.


38
39
40
41
42
# File 'lib/chefspec/server_runner.rb', line 38

def upload_cookbooks!
  loader = Chef::CookbookLoader.new(Chef::Config[:cookbook_path])
  loader.load_cookbooks
  cookbook_uploader_for(loader).upload_cookbooks
end