Method: Chef::Client#load_required_recipe

Defined in:
lib/chef/client.rb

#load_required_recipe(rest, run_context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a required recipe as specified by the Chef Server

TODO: @rest doesn’t appear to be used anywhere outside of client.register except for here. If it’s common practice to create your own rest client, perhaps we should do that here but it seems more appropriate to reuse one that we know is already created. for ease of testing, we’ll pass the existing rest client in as a parameter

Returns:

  • The modified run context

API:

  • private



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/chef/client.rb', line 513

def load_required_recipe(rest, run_context)
  required_recipe_contents = rest.get("required_recipe")
  logger.info("Required Recipe found, loading it")
  Chef::FileCache.store("required_recipe", required_recipe_contents)
  required_recipe_file = Chef::FileCache.load("required_recipe", false)

  # TODO: add integration tests with resource reporting turned on
  #       (presumably requires changes to chef-zero)
  #
  # Chef::Recipe.new takes a cookbook name and a recipe name along
  # with the run context. These names are eventually used in the
  # resource reporter, and if the cookbook name cannot be found in the
  # cookbook collection then we will fail with an exception. Cases where
  # we currently also fail:
  #   - specific recipes
  #   - chef-apply would fail if resource reporting was enabled
  #
  recipe = Chef::Recipe.new(nil, nil, run_context)
  recipe.from_file(required_recipe_file)
  run_context
rescue Net::HTTPClientException => e
  case e.response
  when Net::HTTPNotFound
    logger.trace("Required Recipe not configured on the server, skipping it")
  else
    raise
  end
end