Skip to content

Commit

Permalink
Deprecate some things that don't seem to be needed outside
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeiser committed May 19, 2015
1 parent 07f188c commit fe44932
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
54 changes: 31 additions & 23 deletions lib/chef/client.rb
Expand Up @@ -51,6 +51,7 @@
require 'chef/request_id'
require 'chef/platform/rebooter'
require 'chef/client/notification_registry'
require 'chef/mixin/deprecation'
require 'ohai'
require 'rbconfig'

Expand All @@ -62,6 +63,7 @@ class Client
include Chef::Mixin::PathSanity

extend NotificationRegistry
extend Chef::Mixin::Deprecation

#
# The status of the Chef run.
Expand All @@ -75,28 +77,23 @@ class Client
#
# @return [Chef::Node]
#
attr_accessor :node
def node
run_status.node
end

#
# The ohai system used by this client.
#
# @return [Ohai::System]
#
attr_accessor :ohai
attr_reader :ohai

#
# The rest object used to communicate with the Chef server.
#
# @return [Chef::REST]
#
attr_accessor :rest

#
# The runner used to converge.
#
# @return [Chef::Runner]
#
attr_accessor :runner
attr_reader :rest

#
# Extra node attributes that were applied to the node.
Expand Down Expand Up @@ -135,13 +132,12 @@ class Client
# @param args [Hash] Options:
# @option args [Array<RunList::RunListItem>] :override_runlist A runlist to
# use instead of the node's embedded run list.
# @option args [] :specific_recipes Recipes to run after all cookbooks have
# been compiled and loaded.
# @option args [Array<String>] :specific_recipes A list of recipe file paths
# to load after the run list has been loaded.
#
def initialize(json_attribs=nil, args={})
@json_attribs = json_attribs || {}
@node = nil
@runner = nil
@ohai = Ohai::System.new

event_handlers = configure_formatters + configure_event_loggers
Expand Down Expand Up @@ -416,8 +412,8 @@ def run_failed
#
def load_node
policy_builder.load_node
@node = policy_builder.node
Chef.set_node(@node)
run_status.node = policy_builder.node
Chef.set_node(policy_builder.node)
node
end

Expand Down Expand Up @@ -458,7 +454,7 @@ def sync_cookbooks
#
# @api private
def setup_run_context
run_context = policy_builder.setup_run_context(@specific_recipes)
run_context = policy_builder.setup_run_context(specific_recipes)
assert_cookbook_path_not_empty(run_context)
run_status.run_context = run_context
run_context
Expand All @@ -472,7 +468,7 @@ def setup_run_context
# @api private
#
def policy_builder
@policy_builder ||= Chef::PolicyBuilder.strategy.new(node_name, ohai.data, json_attribs, @override_runlist, events)
@policy_builder ||= Chef::PolicyBuilder.strategy.new(node_name, ohai.data, json_attribs, override_runlist, events)
end

#
Expand Down Expand Up @@ -625,7 +621,8 @@ def converge(run_context)
begin
@events.converge_start(run_context)
Chef::Log.debug("Converging node #{node_name}")
@runner = Chef::Runner.new(run_context)
runner = Chef::Runner.new(run_context)
@runner = runner
runner.converge
@events.converge_complete
rescue Exception => e
Expand Down Expand Up @@ -678,8 +675,7 @@ def converge_and_save(run_context)
# Triggers the audit_phase_start, audit_phase_complete and
# audit_phase_failed events.
#
# @param run_context The run context. (Deprecated, don't bother passing
# this, it is already in the class.)
# @param run_context The run context.
#
# @return Any thrown exceptions. `nil` if successful.
#
Expand All @@ -691,7 +687,6 @@ def converge_and_save(run_context)
# @api private
#
def run_audits(run_context)
audit_exception = nil
begin
@events.audit_phase_start(run_status)
Chef::Log.info("Starting audit phase")
Expand All @@ -701,12 +696,12 @@ def run_audits(run_context)
raise Chef::Exceptions::AuditsFailed.new(auditor.num_failed, auditor.num_total)
end
@events.audit_phase_complete
nil
rescue Exception => e
Chef::Log.error("Audit phase failed with error message: #{e.message}")
@events.audit_phase_failed(e)
audit_exception = e
e
end
audit_exception
end

#
Expand Down Expand Up @@ -770,9 +765,21 @@ def do_windows_admin_check
#
STDERR_FD = STDERR

#
# Deprecated writers
#

include Chef::Mixin::Deprecation
deprecated_attr_writer :node, "There is no alternative. Leave node alone!"
deprecated_attr_writer :ohai, "There is no alternative. Leave ohai alone!"
deprecated_attr_writer :rest, "There is no alternative. Leave rest alone!"
deprecated_attr :runner, "There is no alternative. Leave runner alone!"

private

attr_reader :override_runlist
attr_reader :specific_recipes

def empty_directory?(path)
!File.exists?(path) || (Dir.entries(path).size <= 2)
end
Expand All @@ -796,6 +803,7 @@ def assert_cookbook_path_not_empty(run_context)
else
Chef::Log.warn("Node #{node_name} has an empty run list.") if run_context.node.run_list.empty?
end

end

def has_admin_privileges?
Expand Down
28 changes: 28 additions & 0 deletions lib/chef/mixin/deprecation.rb
Expand Up @@ -95,6 +95,34 @@ def deprecated_ivar(obj, name, level=nil)
DeprecatedInstanceVariable.new(obj, name, level)
end

def deprecated_attr(name, alternative)
deprecated_attr_reader(name, alternative)
deprecated_attr_writer(name, alternative)
end

def deprecated_attr_reader(name, alternative)
instance_eval <<-EOM
def #{name}(value)
Chef::Log.deprecation("#{self}.#{name} is deprecated. Support will be removed in a future release.")
Chef::Log.deprecation(#{alternative.inspect})
Chef::Log.deprecation("Called from:")
caller[0..3].each {|l| log(l)}
@#{name}
end
EOM
end

def deprecated_attr_writer(name, alternative)
instance_eval <<-EOM
def #{name}=(value)
Chef::Log.deprecation("Writing to #{self}.#{name}= is deprecated. Support will be removed in a future release.")
Chef::Log.deprecation(#{alternative.inspect})
Chef::Log.deprecation("Called from:")
caller[0..3].each {|l| log(l)}
@#{name} = value
end
EOM
end
end
end
end

0 comments on commit fe44932

Please sign in to comment.