summaryrefslogtreecommitdiff
path: root/chef
diff options
context:
space:
mode:
authorPrajaktaPurohit <prajakta@opscode.com>2012-10-04 12:42:47 -0700
committerPrajaktaPurohit <prajakta@opscode.com>2012-10-04 12:42:47 -0700
commitc23fea89e6e847bbf6f948efaf80e19ea757b024 (patch)
tree89ead2742057a3bdd010e012b99008d1612b1532 /chef
parentdcdfdecbfd20a07de735989e66741871114d2e96 (diff)
parent37e11b41f964dc8d59b7b1d95760b4034babb7f8 (diff)
downloadchef-c23fea89e6e847bbf6f948efaf80e19ea757b024.tar.gz
Merge branch '10-stable' into reporting_with_summary_only
Diffstat (limited to 'chef')
-rw-r--r--chef/lib/chef/config.rb2
-rw-r--r--chef/lib/chef/platform.rb2
-rw-r--r--chef/lib/chef/provider/cookbook_file.rb8
-rw-r--r--chef/lib/chef/provider/deploy.rb6
-rw-r--r--chef/lib/chef/provider/directory.rb3
-rw-r--r--chef/lib/chef/provider/file.rb52
-rw-r--r--chef/lib/chef/provider/http_request.rb27
-rw-r--r--chef/lib/chef/provider/package.rb2
-rw-r--r--chef/lib/chef/provider/remote_file.rb2
-rw-r--r--chef/lib/chef/provider/service.rb22
-rw-r--r--chef/lib/chef/provider/template.rb10
-rw-r--r--chef/lib/chef/resource.rb2
-rw-r--r--chef/lib/chef/resource/cookbook_file.rb1
-rw-r--r--chef/lib/chef/resource/cron.rb5
-rw-r--r--chef/lib/chef/resource/deploy.rb7
-rw-r--r--chef/lib/chef/resource/directory.rb6
-rw-r--r--chef/lib/chef/resource/env.rb5
-rw-r--r--chef/lib/chef/resource/erl_call.rb3
-rw-r--r--chef/lib/chef/resource/execute.rb3
-rw-r--r--chef/lib/chef/resource/file.rb10
-rw-r--r--chef/lib/chef/resource/group.rb5
-rw-r--r--chef/lib/chef/resource/http_request.rb3
-rw-r--r--chef/lib/chef/resource/ifconfig.rb5
-rw-r--r--chef/lib/chef/resource/link.rb7
-rw-r--r--chef/lib/chef/resource/log.rb35
-rw-r--r--chef/lib/chef/resource/mdadm.rb5
-rw-r--r--chef/lib/chef/resource/mount.rb5
-rw-r--r--chef/lib/chef/resource/ohai.rb14
-rw-r--r--chef/lib/chef/resource/package.rb3
-rw-r--r--chef/lib/chef/resource/remote_directory.rb5
-rw-r--r--chef/lib/chef/resource/route.rb7
-rw-r--r--chef/lib/chef/resource/ruby_block.rb11
-rw-r--r--chef/lib/chef/resource/scm.rb4
-rw-r--r--chef/lib/chef/resource/script.rb3
-rw-r--r--chef/lib/chef/resource/service.rb5
-rw-r--r--chef/lib/chef/resource/subversion.rb3
-rw-r--r--chef/lib/chef/resource/template.rb1
-rw-r--r--chef/lib/chef/resource/user.rb4
-rw-r--r--chef/lib/chef/resource_reporter.rb7
-rw-r--r--chef/lib/chef/scan_access_control.rb2
-rw-r--r--chef/lib/chef/version.rb2
-rw-r--r--chef/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb19
-rw-r--r--chef/spec/unit/platform_spec.rb18
-rw-r--r--chef/spec/unit/provider/cookbook_file_spec.rb3
-rw-r--r--chef/spec/unit/provider/deploy_spec.rb22
-rw-r--r--chef/spec/unit/provider/directory_spec.rb33
-rw-r--r--chef/spec/unit/provider/file_spec.rb75
-rw-r--r--chef/spec/unit/provider/http_request_spec.rb6
-rw-r--r--chef/spec/unit/provider/package_spec.rb4
-rw-r--r--chef/spec/unit/provider/remote_directory_spec.rb5
-rw-r--r--chef/spec/unit/provider/remote_file_spec.rb7
-rw-r--r--chef/spec/unit/resource/cookbook_file_spec.rb43
-rw-r--r--chef/spec/unit/resource/cron_spec.rb27
-rw-r--r--chef/spec/unit/resource/deploy_spec.rb27
-rw-r--r--chef/spec/unit/resource/directory_spec.rb20
-rw-r--r--chef/spec/unit/resource/env_spec.rb19
-rw-r--r--chef/spec/unit/resource/erl_call_spec.rb12
-rw-r--r--chef/spec/unit/resource/execute_spec.rb16
-rw-r--r--chef/spec/unit/resource/group_spec.rb18
-rw-r--r--chef/spec/unit/resource/http_request_spec.rb13
-rw-r--r--chef/spec/unit/resource/ifconfig_spec.rb46
-rw-r--r--chef/spec/unit/resource/link_spec.rb21
-rw-r--r--chef/spec/unit/resource/log_spec.rb10
-rw-r--r--chef/spec/unit/resource/mdadm_spec.rb22
-rw-r--r--chef/spec/unit/resource/mount_spec.rb20
-rw-r--r--chef/spec/unit/resource/ohai_spec.rb18
-rw-r--r--chef/spec/unit/resource/package_spec.rb3
-rw-r--r--chef/spec/unit/resource/remote_directory_spec.rb22
-rw-r--r--chef/spec/unit/resource/remote_file_spec.rb40
-rw-r--r--chef/spec/unit/resource/route_spec.rb19
-rw-r--r--chef/spec/unit/resource/ruby_block_spec.rb11
-rw-r--r--chef/spec/unit/resource/scm_spec.rb20
-rw-r--r--chef/spec/unit/resource/script_spec.rb14
-rw-r--r--chef/spec/unit/resource/service_spec.rb21
-rw-r--r--chef/spec/unit/resource/user_spec.rb21
-rw-r--r--chef/spec/unit/resource_reporter_spec.rb6
76 files changed, 927 insertions, 88 deletions
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb
index 51b36329fc..8ad0648eec 100644
--- a/chef/lib/chef/config.rb
+++ b/chef/lib/chef/config.rb
@@ -201,7 +201,7 @@ class Chef
why_run false
color false
client_fork false
- enable_reporting false
+ enable_reporting true
# Set these to enable SSL authentication / mutual-authentication
# with the server
diff --git a/chef/lib/chef/platform.rb b/chef/lib/chef/platform.rb
index a25cf78155..2cb6690da1 100644
--- a/chef/lib/chef/platform.rb
+++ b/chef/lib/chef/platform.rb
@@ -369,7 +369,7 @@ class Chef
return platform, version
end
- def provider_for_resource(resource, action)
+ def provider_for_resource(resource, action=:nothing)
node = resource.run_context && resource.run_context.node
raise ArgumentError, "Cannot find the provider for a resource with no run context set" unless node
provider = find_provider_for_node(node, resource).new(resource, resource.run_context)
diff --git a/chef/lib/chef/provider/cookbook_file.rb b/chef/lib/chef/provider/cookbook_file.rb
index 88a3ec96c3..431f3f2367 100644
--- a/chef/lib/chef/provider/cookbook_file.rb
+++ b/chef/lib/chef/provider/cookbook_file.rb
@@ -29,10 +29,7 @@ class Chef
def load_current_resource
@current_resource = Chef::Resource::CookbookFile.new(@new_resource.name)
- @new_resource.path.gsub!(/\\/, "/") # for Windows
- @current_resource.path(@new_resource.path)
- setup_acl
- @current_resource
+ super
end
def action_create
@@ -47,6 +44,9 @@ class Chef
Chef::Log.debug("#{@new_resource} staging #{file_cache_location} to #{tempfile.path}")
tempfile.close
FileUtils.cp(file_cache_location, tempfile.path)
+ # Since the @new_resource.path file will not be updated
+ # at the time of converge, we must use the tempfile
+ update_new_file_state(tempfile.path)
end
Chef::Log.info("#{@new_resource} created file #{@new_resource.path}")
end
diff --git a/chef/lib/chef/provider/deploy.rb b/chef/lib/chef/provider/deploy.rb
index 69b3222579..2920917d11 100644
--- a/chef/lib/chef/provider/deploy.rb
+++ b/chef/lib/chef/provider/deploy.rb
@@ -408,10 +408,10 @@ class Chef
end
def run_callback_from_file(callback_file)
- if ::File.exist?(callback_file)
+ Chef::Log.info "#{@new_resource} queueing checkdeploy hook #{callback_file}"
+ recipe_eval do
Dir.chdir(release_path) do
- Chef::Log.info "#{@new_resource} running deploy hook #{callback_file}"
- recipe_eval { from_file(callback_file) }
+ from_file(callback_file) if ::File.exist?(callback_file)
end
end
end
diff --git a/chef/lib/chef/provider/directory.rb b/chef/lib/chef/provider/directory.rb
index ea9de5df34..0329aeb1ad 100644
--- a/chef/lib/chef/provider/directory.rb
+++ b/chef/lib/chef/provider/directory.rb
@@ -33,9 +33,12 @@ class Chef
def load_current_resource
@current_resource = Chef::Resource::Directory.new(@new_resource.name)
@current_resource.path(@new_resource.path)
+ load_current_resource_attrs
setup_acl
+
@current_resource
end
+
def define_resource_requirements
# this must be evaluated before whyrun messages are printed
access_controls.requires_changes?
diff --git a/chef/lib/chef/provider/file.rb b/chef/lib/chef/provider/file.rb
index faaf469984..659afc6517 100644
--- a/chef/lib/chef/provider/file.rb
+++ b/chef/lib/chef/provider/file.rb
@@ -58,12 +58,14 @@ class Chef
def is_binary?(path)
::File.open(path) do |file|
+
buff = file.read(Chef::Config[:diff_filesize_threshold])
buff = "" if buff.nil?
return buff !~ /^[\r[:print:]]*$/
end
end
+
def diff_current(temp_path)
suppress_resource_reporting = false
@@ -123,13 +125,39 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::File.new(@new_resource.name)
+ # Every child should be specifying their own constructor, so this
+ # should only be run in the file case.
+ @current_resource ||= Chef::Resource::File.new(@new_resource.name)
@new_resource.path.gsub!(/\\/, "/") # for Windows
@current_resource.path(@new_resource.path)
- if @new_resource.content && ::File.exist?(@new_resource.path)
- @current_resource.checksum(checksum(@new_resource.path))
+ if !::File.directory?(@new_resource.path)
+ if ::File.exist?(@new_resource.path)
+ @current_resource.checksum(checksum(@new_resource.path))
+ end
end
+ load_current_resource_attrs
setup_acl
+
+ @current_resource
+ end
+
+ def load_current_resource_attrs
+ if ::File.exist?(@new_resource.path)
+ stat = ::File.stat(@new_resource.path)
+ @current_resource.owner(stat.uid)
+ @current_resource.mode(stat.mode & 07777)
+ @current_resource.group(stat.gid)
+
+ if @new_resource.group.nil?
+ @new_resource.group(@current_resource.group)
+ end
+ if @new_resource.owner.nil?
+ @new_resource.owner(@current_resource.owner)
+ end
+ if @new_resource.mode.nil?
+ @new_resource.mode(@current_resource.mode)
+ end
+ end
end
def setup_acl
@@ -183,6 +211,19 @@ class Chef
end
end
+ # if you are using a tempfile before creating, you must
+ # override the default with the tempfile, since the
+ # file at @new_resource.path will not be updated on converge
+ def update_new_file_state(path=@new_resource.path)
+ stat = ::File.stat(path)
+ @new_resource.owner(stat.uid)
+ @new_resource.mode(stat.mode & 07777)
+ @new_resource.group(stat.gid)
+ if !::File.directory?(path)
+ @new_resource.checksum(checksum(path))
+ end
+ end
+
def action_create
if !::File.exists?(@new_resource.path)
description = []
@@ -190,10 +231,13 @@ class Chef
desc << " with content checksum #{short_cksum(new_resource_content_checksum)}" if new_resource.content
description << desc
description << diff_current_from_content(@new_resource.content)
+
converge_by(description) do
+ Chef::Log.info("entered create")
::File.open(@new_resource.path, "w+") {|f| f.write @new_resource.content }
access_controls.set_all
Chef::Log.info("#{@new_resource} created file #{@new_resource.path}")
+ update_new_file_state
end
else
set_content unless @new_resource.content.nil?
@@ -205,6 +249,8 @@ class Chef
if access_controls.requires_changes?
converge_by(access_controls.describe_changes) do
access_controls.set_all
+ #Update file state with new access values
+ update_new_file_state
end
end
end
diff --git a/chef/lib/chef/provider/http_request.rb b/chef/lib/chef/provider/http_request.rb
index d21cdad19b..0ea5f8289f 100644
--- a/chef/lib/chef/provider/http_request.rb
+++ b/chef/lib/chef/provider/http_request.rb
@@ -34,18 +34,21 @@ class Chef
# Send a HEAD request to @new_resource.url, with ?message=@new_resource.message
def action_head
- converge_by("#{@new_resource} HEAD to #{@new_resource.url}") do
- message = check_message(@new_resource.message)
- modified = @rest.run_request(
- :HEAD,
- @rest.create_url("#{@new_resource.url}?message=#{message}"),
- @new_resource.headers,
- false,
- 10,
- false
- )
- Chef::Log.info("#{@new_resource} HEAD to #{@new_resource.url} successful")
- Chef::Log.debug("#{@new_resource} HEAD request response: #{modified}")
+ message = check_message(@new_resource.message)
+ # returns true from Chef::REST if returns 2XX (Net::HTTPSuccess)
+ modified = @rest.run_request(
+ :HEAD,
+ @rest.create_url("#{@new_resource.url}?message=#{message}"),
+ @new_resource.headers,
+ false,
+ 10,
+ false
+ )
+ Chef::Log.info("#{@new_resource} HEAD to #{@new_resource.url} successful")
+ Chef::Log.debug("#{@new_resource} HEAD request response: #{modified}")
+ # :head is usually used to trigger notifications, which converge_by now does
+ if modified
+ converge_by("#{@new_resource} HEAD to #{@new_resource.url} returned modified, trigger notifications") {}
end
end
diff --git a/chef/lib/chef/provider/package.rb b/chef/lib/chef/provider/package.rb
index 424792000e..a28a6f93fb 100644
--- a/chef/lib/chef/provider/package.rb
+++ b/chef/lib/chef/provider/package.rb
@@ -78,6 +78,7 @@ class Chef
end
description = install_version ? "version #{install_version} of" : ""
converge_by("install #{description} package #{@new_resource.package_name}") do
+ @new_resource.version(install_version)
install_package(@new_resource.package_name, install_version)
end
end
@@ -88,6 +89,7 @@ class Chef
elsif @current_resource.version == candidate_version
Chef::Log.debug("#{@new_resource} is at the latest version - nothing to do")
else
+ @new_resource.version(candidate_version)
orig_version = @current_resource.version || "uninstalled"
converge_by("upgrade package #{@new_resource.package_name} from #{orig_version} to #{candidate_version}") do
status = upgrade_package(@new_resource.package_name, candidate_version)
diff --git a/chef/lib/chef/provider/remote_file.rb b/chef/lib/chef/provider/remote_file.rb
index 3b796f79ce..fa79747846 100644
--- a/chef/lib/chef/provider/remote_file.rb
+++ b/chef/lib/chef/provider/remote_file.rb
@@ -27,8 +27,8 @@ class Chef
class RemoteFile < Chef::Provider::File
def load_current_resource
+ @current_resource = Chef::Resource::RemoteFile.new(@new_resource.name)
super
- @current_resource.checksum(checksum(@current_resource.path)) if ::File.exist?(@current_resource.path)
end
def action_create
diff --git a/chef/lib/chef/provider/service.rb b/chef/lib/chef/provider/service.rb
index 22098a0d6b..decca7fd7c 100644
--- a/chef/lib/chef/provider/service.rb
+++ b/chef/lib/chef/provider/service.rb
@@ -34,6 +34,17 @@ class Chef
true
end
+ def load_new_resource_state
+ # If the user didn't specify a change in enabled state,
+ # it will be the same as the old resource
+ if ( @new_resource.enabled.nil? )
+ @new_resource.enabled(@current_resource.enabled)
+ end
+ if ( @new_resource.running.nil? )
+ @new_resource.running(@current_resource.running)
+ end
+ end
+
def shared_resource_requirements
end
@@ -56,6 +67,8 @@ class Chef
Chef::Log.info("#{@new_resource} enabled")
end
end
+ load_new_resource_state
+ @new_resource.enabled(true)
end
def action_disable
@@ -67,6 +80,8 @@ class Chef
else
Chef::Log.debug("#{@new_resource} already disabled - nothing to do")
end
+ load_new_resource_state
+ @new_resource.enabled(false)
end
def action_start
@@ -78,6 +93,8 @@ class Chef
else
Chef::Log.debug("#{@new_resource} already running - nothing to do")
end
+ load_new_resource_state
+ @new_resource.running(true)
end
def action_stop
@@ -89,6 +106,8 @@ class Chef
else
Chef::Log.debug("#{@new_resource} already stopped - nothing to do")
end
+ load_new_resource_state
+ @new_resource.running(false)
end
def action_restart
@@ -96,6 +115,8 @@ class Chef
restart_service
Chef::Log.info("#{@new_resource} restarted")
end
+ load_new_resource_state
+ @new_resource.running(true)
end
def action_reload
@@ -105,6 +126,7 @@ class Chef
Chef::Log.info("#{@new_resource} reloaded")
end
end
+ load_new_resource_state
end
def enable_service
diff --git a/chef/lib/chef/provider/template.rb b/chef/lib/chef/provider/template.rb
index bcf2151088..c937b9d980 100644
--- a/chef/lib/chef/provider/template.rb
+++ b/chef/lib/chef/provider/template.rb
@@ -31,8 +31,8 @@ class Chef
include Chef::Mixin::Template
def load_current_resource
+ @current_resource = Chef::Resource::Template.new(@new_resource.name)
super
- @current_resource.checksum(checksum(@current_resource.path)) if ::File.exist?(@current_resource.path)
end
def define_resource_requirements
@@ -64,6 +64,14 @@ class Chef
FileUtils.mv(rendered_template.path, @new_resource.path)
Chef::Log.info("#{@new_resource} updated content")
access_controls.set_all!
+ stat = ::File.stat(@new_resource.path)
+
+ # template depends on the checksum not changing, and updates it
+ # itself later in the code, so we cannot set it here, as we do with
+ # all other < File child provider classes
+ @new_resource.owner(stat.uid)
+ @new_resource.mode(stat.mode & 07777)
+ @new_resource.group(stat.gid)
end
end
end
diff --git a/chef/lib/chef/resource.rb b/chef/lib/chef/resource.rb
index 808b634d53..810c19cfd0 100644
--- a/chef/lib/chef/resource.rb
+++ b/chef/lib/chef/resource.rb
@@ -606,8 +606,8 @@ F
raise customize_exception(e)
end
ensure
- events.resource_completed(self)
@elapsed_time = Time.now - start_time
+ events.resource_completed(self)
end
end
diff --git a/chef/lib/chef/resource/cookbook_file.rb b/chef/lib/chef/resource/cookbook_file.rb
index 255257890f..de758aef71 100644
--- a/chef/lib/chef/resource/cookbook_file.rb
+++ b/chef/lib/chef/resource/cookbook_file.rb
@@ -1,6 +1,7 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Seth Chisamore (<schisamo@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008, 2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
diff --git a/chef/lib/chef/resource/cron.rb b/chef/lib/chef/resource/cron.rb
index 7dfb86b3ed..5f858cec81 100644
--- a/chef/lib/chef/resource/cron.rb
+++ b/chef/lib/chef/resource/cron.rb
@@ -1,5 +1,6 @@
#
# Author:: Bryan McLellan (btm@loftninjas.org)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Bryan McLellan
# License:: Apache License, Version 2.0
#
@@ -22,6 +23,10 @@ class Chef
class Resource
class Cron < Chef::Resource
+ identity_attr :command
+
+ state_attrs :minute, :hour, :day, :month, :weekday, :user
+
def initialize(name, run_context=nil)
super
@resource_name = :cron
diff --git a/chef/lib/chef/resource/deploy.rb b/chef/lib/chef/resource/deploy.rb
index 037c172183..8b614028bf 100644
--- a/chef/lib/chef/resource/deploy.rb
+++ b/chef/lib/chef/resource/deploy.rb
@@ -1,5 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@kallistec.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -49,9 +50,13 @@ class Chef
# release directory. Callback files can contain chef code (resources, etc.)
#
class Deploy < Chef::Resource
-
+
provider_base Chef::Provider::Deploy
+ identity_attr :repository
+
+ state_attrs :deploy_to, :revision
+
def initialize(name, run_context=nil)
super
@resource_name = :deploy
diff --git a/chef/lib/chef/resource/directory.rb b/chef/lib/chef/resource/directory.rb
index 729948b099..a5d5ea7366 100644
--- a/chef/lib/chef/resource/directory.rb
+++ b/chef/lib/chef/resource/directory.rb
@@ -1,6 +1,7 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Seth Chisamore (<schisamo@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008, 2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -24,6 +25,11 @@ require 'chef/mixin/securable'
class Chef
class Resource
class Directory < Chef::Resource
+
+ identity_attr :path
+
+ state_attrs :group, :mode, :owner
+
include Chef::Mixin::Securable
provides :directory, :on_platforms => :all
diff --git a/chef/lib/chef/resource/env.rb b/chef/lib/chef/resource/env.rb
index ed3442cdfb..4b5fe6cc09 100644
--- a/chef/lib/chef/resource/env.rb
+++ b/chef/lib/chef/resource/env.rb
@@ -1,5 +1,6 @@
#
# Author:: Doug MacEachern (<dougm@vmware.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2010 VMware, Inc.
# License:: Apache License, Version 2.0
#
@@ -20,6 +21,10 @@ class Chef
class Resource
class Env < Chef::Resource
+ identity_attr :key_name
+
+ state_attrs :value
+
def initialize(name, run_context=nil)
super
@resource_name = :env
diff --git a/chef/lib/chef/resource/erl_call.rb b/chef/lib/chef/resource/erl_call.rb
index 00d8fd19a1..e0e38926bb 100644
--- a/chef/lib/chef/resource/erl_call.rb
+++ b/chef/lib/chef/resource/erl_call.rb
@@ -1,5 +1,6 @@
#
# Author:: Joe Williams (<joe@joetify.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Joe Williams
# License:: Apache License, Version 2.0
#
@@ -24,6 +25,8 @@ class Chef
# erl_call : http://erlang.org/doc/man/erl_call.html
+ identity_attr :code
+
def initialize(name, run_context=nil)
super
@resource_name = :erl_call
diff --git a/chef/lib/chef/resource/execute.rb b/chef/lib/chef/resource/execute.rb
index cad3bfde4f..6c07bf9352 100644
--- a/chef/lib/chef/resource/execute.rb
+++ b/chef/lib/chef/resource/execute.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -22,6 +23,8 @@ class Chef
class Resource
class Execute < Chef::Resource
+ identity_attr :command
+
def initialize(name, run_context=nil)
super
@resource_name = :execute
diff --git a/chef/lib/chef/resource/file.rb b/chef/lib/chef/resource/file.rb
index 8abc219015..0b92f3332d 100644
--- a/chef/lib/chef/resource/file.rb
+++ b/chef/lib/chef/resource/file.rb
@@ -29,11 +29,11 @@ class Chef
identity_attr :path
- state_attrs :checksum, :owner, :group, :mode
-
- # By default, windows gets `state_attrs :rights, :deny_rights`
if Platform.windows?
- state_attrs :rights, :deny_rights
+ # Use Windows rights instead of standard *nix permissions
+ state_attrs :checksum, :rights, :deny_rights
+ else
+ state_attrs :checksum, :owner, :group, :mode
end
provides :file, :on_platforms => :all
@@ -52,7 +52,7 @@ class Chef
def content(arg=nil)
set_or_return(
- :content,
+ :content,
arg,
:kind_of => String
)
diff --git a/chef/lib/chef/resource/group.rb b/chef/lib/chef/resource/group.rb
index d5c2b3f2fb..76f3a779ae 100644
--- a/chef/lib/chef/resource/group.rb
+++ b/chef/lib/chef/resource/group.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 OpsCode, Inc.
# License:: Apache License, Version 2.0
#
@@ -20,6 +21,10 @@ class Chef
class Resource
class Group < Chef::Resource
+ identity_attr :group_name
+
+ state_attrs :members
+
def initialize(name, run_context=nil)
super
@resource_name = :group
diff --git a/chef/lib/chef/resource/http_request.rb b/chef/lib/chef/resource/http_request.rb
index c850bb72c1..d31ff0b1c9 100644
--- a/chef/lib/chef/resource/http_request.rb
+++ b/chef/lib/chef/resource/http_request.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -22,6 +23,8 @@ class Chef
class Resource
class HttpRequest < Chef::Resource
+ identity_attr :url
+
def initialize(name, run_context=nil)
super
@resource_name = :http_request
diff --git a/chef/lib/chef/resource/ifconfig.rb b/chef/lib/chef/resource/ifconfig.rb
index e738e462bc..daa8a572a0 100644
--- a/chef/lib/chef/resource/ifconfig.rb
+++ b/chef/lib/chef/resource/ifconfig.rb
@@ -1,5 +1,6 @@
#
# Author:: Jason K. Jackson (jasonjackson@gmail.com)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Jason K. Jackson
# License:: Apache License, Version 2.0
#
@@ -22,6 +23,10 @@ class Chef
class Resource
class Ifconfig < Chef::Resource
+ identity_attr :device
+
+ state_attrs :inet_addr, :mask
+
def initialize(name, run_context=nil)
super
@resource_name = :ifconfig
diff --git a/chef/lib/chef/resource/link.rb b/chef/lib/chef/resource/link.rb
index a0c5726abc..a0fab0428d 100644
--- a/chef/lib/chef/resource/link.rb
+++ b/chef/lib/chef/resource/link.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -24,7 +25,11 @@ class Chef
class Link < Chef::Resource
include Chef::Mixin::Securable
- provides :link, :on_platform => :all
+ provides :link, :on_platform => :all
+
+ identity_attr :target_file
+
+ state_attrs :to, :owner, :group
def initialize(name, run_context=nil)
super
diff --git a/chef/lib/chef/resource/log.rb b/chef/lib/chef/resource/log.rb
index 95f995298f..d1b6b5af0b 100644
--- a/chef/lib/chef/resource/log.rb
+++ b/chef/lib/chef/resource/log.rb
@@ -1,5 +1,6 @@
#
# Author:: Cary Penniman (<cary@rightscale.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -17,22 +18,24 @@
#
class Chef
class Resource
-
- # Sends a string from a recipe to a log provider
- #
- # log "some string to log" do
- # level :info # (default) also supports :warn, :debug, and :error
- # end
- #
- # === Example
- # log "your string to log"
- #
- # or
- #
- # log "a debug string" { level :debug }
- #
class Log < Chef::Resource
-
+
+ identity_attr :name
+
+ # Sends a string from a recipe to a log provider
+ #
+ # log "some string to log" do
+ # level :info # (default) also supports :warn, :debug, and :error
+ # end
+ #
+ # === Example
+ # log "your string to log"
+ #
+ # or
+ #
+ # log "a debug string" { level :debug }
+ #
+
# Initialize log resource with a name as the string to log
#
# === Parameters
@@ -54,7 +57,7 @@ class Chef
:equal_to => [ :debug, :info, :warn, :error, :fatal ]
)
end
-
+
end
end
end
diff --git a/chef/lib/chef/resource/mdadm.rb b/chef/lib/chef/resource/mdadm.rb
index 14e9c650a2..46a85b2475 100644
--- a/chef/lib/chef/resource/mdadm.rb
+++ b/chef/lib/chef/resource/mdadm.rb
@@ -1,5 +1,6 @@
#
# Author:: Joe Williams (<joe@joetify.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Joe Williams
# License:: Apache License, Version 2.0
#
@@ -22,6 +23,10 @@ class Chef
class Resource
class Mdadm < Chef::Resource
+ identity_attr :raid_device
+
+ state_attrs :devices, :level, :chunk
+
def initialize(name, run_context=nil)
super
@resource_name = :mdadm
diff --git a/chef/lib/chef/resource/mount.rb b/chef/lib/chef/resource/mount.rb
index e9b3533943..8c32bdd280 100644
--- a/chef/lib/chef/resource/mount.rb
+++ b/chef/lib/chef/resource/mount.rb
@@ -1,5 +1,6 @@
#
# Author:: Joshua Timberman (<joshua@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Opscode, Inc
# License:: Apache License, Version 2.0
#
@@ -22,6 +23,10 @@ class Chef
class Resource
class Mount < Chef::Resource
+ identity_attr :device
+
+ state_attrs :mount_point, :device_type, :fstype
+
def initialize(name, run_context=nil)
super
@resource_name = :mount
diff --git a/chef/lib/chef/resource/ohai.rb b/chef/lib/chef/resource/ohai.rb
index 91da1a4a5b..48e55e9f01 100644
--- a/chef/lib/chef/resource/ohai.rb
+++ b/chef/lib/chef/resource/ohai.rb
@@ -1,5 +1,6 @@
#
# Author:: Michael Leinartas (<mleinartas@gmail.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2010 Michael Leinartas
# License:: Apache License, Version 2.0
#
@@ -20,9 +21,14 @@ class Chef
class Resource
class Ohai < Chef::Resource
+ identity_attr :name
+
+ state_attrs :plugin
+
def initialize(name, run_context=nil)
super
@resource_name = :ohai
+ @name = name
@allowed_actions.push(:reload)
@action = :reload
@plugin = nil
@@ -35,6 +41,14 @@ class Chef
:kind_of => [ String ]
)
end
+
+ def name(arg=nil)
+ set_or_return(
+ :name,
+ arg,
+ :kind_of => [ String ]
+ )
+ end
end
end
end
diff --git a/chef/lib/chef/resource/package.rb b/chef/lib/chef/resource/package.rb
index fa863b3810..eaad3e2e58 100644
--- a/chef/lib/chef/resource/package.rb
+++ b/chef/lib/chef/resource/package.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -24,7 +25,7 @@ class Chef
identity_attr :package_name
- state_attrs :version
+ state_attrs :version, :options
def initialize(name, run_context=nil)
super
diff --git a/chef/lib/chef/resource/remote_directory.rb b/chef/lib/chef/resource/remote_directory.rb
index 20bbc883e2..490e3c6ba7 100644
--- a/chef/lib/chef/resource/remote_directory.rb
+++ b/chef/lib/chef/resource/remote_directory.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -27,6 +28,10 @@ class Chef
provides :remote_directory, :on_platforms => :all
+ identity_attr :path
+
+ state_attrs :files_owner, :files_group, :files_mode
+
def initialize(name, run_context=nil)
super
@resource_name = :remote_directory
diff --git a/chef/lib/chef/resource/route.rb b/chef/lib/chef/resource/route.rb
index 1a568dd2d0..cdd61f3a4b 100644
--- a/chef/lib/chef/resource/route.rb
+++ b/chef/lib/chef/resource/route.rb
@@ -1,5 +1,6 @@
#
# Author:: Bryan McLellan (btm@loftninjas.org)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Bryan McLellan
# License:: Apache License, Version 2.0
#
@@ -21,7 +22,11 @@ require 'chef/resource'
class Chef
class Resource
class Route < Chef::Resource
-
+
+ identity_attr :target
+
+ state_attrs :netmask, :gateway
+
def initialize(name, run_context=nil)
super
@resource_name = :route
diff --git a/chef/lib/chef/resource/ruby_block.rb b/chef/lib/chef/resource/ruby_block.rb
index b204185653..cb743819aa 100644
--- a/chef/lib/chef/resource/ruby_block.rb
+++ b/chef/lib/chef/resource/ruby_block.rb
@@ -21,11 +21,14 @@ class Chef
class Resource
class RubyBlock < Chef::Resource
+ identity_attr :block_name
+
def initialize(name, run_context=nil)
super
@resource_name = :ruby_block
@action = "create"
@allowed_actions.push(:create)
+ @block_name = name
end
def block(&block)
@@ -35,6 +38,14 @@ class Chef
@block
end
end
+
+ def block_name(arg=nil)
+ set_or_return(
+ :block_name,
+ arg,
+ :kind_of => String
+ )
+ end
end
end
end
diff --git a/chef/lib/chef/resource/scm.rb b/chef/lib/chef/resource/scm.rb
index 132dad6ede..781e09a2c9 100644
--- a/chef/lib/chef/resource/scm.rb
+++ b/chef/lib/chef/resource/scm.rb
@@ -23,6 +23,10 @@ class Chef
class Resource
class Scm < Chef::Resource
+ identity_attr :destination
+
+ state_attrs :revision
+
def initialize(name, run_context=nil)
super
@destination = name
diff --git a/chef/lib/chef/resource/script.rb b/chef/lib/chef/resource/script.rb
index e6a8e56c0d..6a7c8e0d5e 100644
--- a/chef/lib/chef/resource/script.rb
+++ b/chef/lib/chef/resource/script.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -22,6 +23,8 @@ class Chef
class Resource
class Script < Chef::Resource::Execute
+ identity_attr :command
+
def initialize(name, run_context=nil)
super
@resource_name = :script
diff --git a/chef/lib/chef/resource/service.rb b/chef/lib/chef/resource/service.rb
index fdbde350da..3ace5cbec3 100644
--- a/chef/lib/chef/resource/service.rb
+++ b/chef/lib/chef/resource/service.rb
@@ -1,5 +1,6 @@
#
# Author:: AJ Christensen (<aj@hjksolutions.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -22,6 +23,10 @@ class Chef
class Resource
class Service < Chef::Resource
+ identity_attr :service_name
+
+ state_attrs :enabled, :running
+
def initialize(name, run_context=nil)
super
@resource_name = :service
diff --git a/chef/lib/chef/resource/subversion.rb b/chef/lib/chef/resource/subversion.rb
index 97f48c3a44..e3226d8b3b 100644
--- a/chef/lib/chef/resource/subversion.rb
+++ b/chef/lib/chef/resource/subversion.rb
@@ -1,5 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@kallistec.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -21,7 +22,7 @@ require "chef/resource/scm"
class Chef
class Resource
class Subversion < Chef::Resource::Scm
-
+
def initialize(name, run_context=nil)
super
@svn_arguments = '--no-auth-cache'
diff --git a/chef/lib/chef/resource/template.rb b/chef/lib/chef/resource/template.rb
index 2ece12e52c..af51b64700 100644
--- a/chef/lib/chef/resource/template.rb
+++ b/chef/lib/chef/resource/template.rb
@@ -1,6 +1,7 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Seth Chisamore (<schisamo@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008, 2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
diff --git a/chef/lib/chef/resource/user.rb b/chef/lib/chef/resource/user.rb
index 2a8941e87f..4d8c4ac11b 100644
--- a/chef/lib/chef/resource/user.rb
+++ b/chef/lib/chef/resource/user.rb
@@ -21,6 +21,10 @@ require 'chef/resource'
class Chef
class Resource
class User < Chef::Resource
+
+ identity_attr :username
+
+ state_attrs :uid, :gid, :home
def initialize(name, run_context=nil)
super
diff --git a/chef/lib/chef/resource_reporter.rb b/chef/lib/chef/resource_reporter.rb
index f5871b8233..1c1947a274 100644
--- a/chef/lib/chef/resource_reporter.rb
+++ b/chef/lib/chef/resource_reporter.rb
@@ -58,6 +58,7 @@ class Chef
as_hash["duration"] = (elapsed_time * 1000).to_i.to_s
as_hash["delta"] = new_resource.diff if new_resource.respond_to?("diff")
as_hash["delta"] = "" if as_hash["delta"].nil?
+
# TODO: rename as "action"
as_hash["result"] = action.to_s
if success?
@@ -87,7 +88,7 @@ class Chef
attr_reader :summary_only
def initialize(rest_client)
- if Chef::Config[:enable_reporting]
+ if Chef::Config[:enable_reporting] && !Chef::Config[:why_run]
@reporting_enabled = true
else
@reporting_enabled = false
@@ -106,10 +107,9 @@ class Chef
def node_load_completed(node, expanded_run_list_with_versions, config)
@node = node
-
if reporting_enabled?
begin
- resource_history_url = "reports/nodes/#{@node.name}/runs"
+ resource_history_url = "reports/nodes/#{node.name}/runs"
server_response = @rest_client.post_rest(resource_history_url, {:action => :begin}, {'X-Chef-ReportingSummary' => 'true'})
run_uri = URI.parse(server_response["uri"])
@run_id = ::File.basename(run_uri.path)
@@ -210,6 +210,7 @@ class Chef
run_data["run_list"] = @node.run_list.to_json
run_data["total_res_count"] = @total_res_count.to_s
run_data["data"] = {}
+
if exception
exception_data = {}
exception_data["class"] = exception.inspect
diff --git a/chef/lib/chef/scan_access_control.rb b/chef/lib/chef/scan_access_control.rb
index 5b83a59695..5863a8c7c4 100644
--- a/chef/lib/chef/scan_access_control.rb
+++ b/chef/lib/chef/scan_access_control.rb
@@ -46,7 +46,7 @@ class Chef
# Modifies @current_resource, setting the current access control state.
def set_all!
- if File.exist?(new_resource.path)
+ if ::File.exist?(new_resource.path)
set_owner
set_group
set_mode
diff --git a/chef/lib/chef/version.rb b/chef/lib/chef/version.rb
index 23ec40ada1..febf30340e 100644
--- a/chef/lib/chef/version.rb
+++ b/chef/lib/chef/version.rb
@@ -17,7 +17,7 @@
class Chef
CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
- VERSION = '10.14.3'
+ VERSION = '10.14.5'
end
# NOTE: the Chef::Version class is defined in version_class.rb
diff --git a/chef/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb b/chef/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
index 400ffecb1f..e1f8f28bb9 100644
--- a/chef/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
+++ b/chef/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb
@@ -98,7 +98,7 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do
before do
Chef::Config.stub!(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ])
recipe_lines = BAD_RECIPE.split("\n").map {|l| l << "\n" }
- IO.should_receive(:readlines).with("C:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb").and_return(recipe_lines)
+ IO.should_receive(:readlines).at_least(1).times.with(/:\/opscode\/chef\/var\/cache\/cookbooks\/foo\/recipes\/default.rb/).and_return(recipe_lines)
@trace = [
"C:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb:14 in `from_file'",
"C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.14.0/lib/chef/run_context.rb:144:in `rescue in block in load_libraries'",
@@ -128,9 +128,20 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do
@inspector.add_explanation(@description)
end
- it "finds the culprit recipe name from the stacktrace" do
- @inspector.culprit_file.should == "C:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb"
- end
+
+ describe "and examining the stack trace for a recipe" do
+ it "find the culprit recipe name when the drive letter is upper case" do
+ @inspector.culprit_file.should == "C:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb"
+ end
+
+ it "find the culprit recipe name when the drive letter is lower case" do
+ @trace.each { |line| line.gsub!(/^C:/, "c:") }
+ @exception.set_backtrace(@trace)
+ @inspector = described_class.new(@path, @exception)
+ @inspector.add_explanation(@description)
+ @inspector.culprit_file.should == "c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb"
+ end
+ end
it "finds the line number of the error from the stack trace" do
@inspector.culprit_line.should == 14
diff --git a/chef/spec/unit/platform_spec.rb b/chef/spec/unit/platform_spec.rb
index b3e14f1364..e4d5df6cdd 100644
--- a/chef/spec/unit/platform_spec.rb
+++ b/chef/spec/unit/platform_spec.rb
@@ -154,19 +154,31 @@ describe Chef::Platform do
node.platform_version("8.5")
Chef::Platform.find_provider_for_node(node, kitty).should eql(Chef::Provider::Cat)
end
-
- it "returns a provider object given a Chef::Resource object which has a valid run context" do
+
+ def setup_file_resource
node = Chef::Node.new
node.platform("mac_os_x")
node.platform_version("9.2.2")
run_context = Chef::RunContext.new(node, {}, @events)
- file = Chef::Resource::File.new("whateva", run_context)
+ [ Chef::Resource::File.new("whateva", run_context), run_context ]
+ end
+
+ it "returns a provider object given a Chef::Resource object which has a valid run context and an action" do
+ file, run_context = setup_file_resource
provider = Chef::Platform.provider_for_resource(file, :foo)
provider.should be_an_instance_of(Chef::Provider::File)
provider.new_resource.should equal(file)
provider.run_context.should equal(run_context)
end
+ it "returns a provider object given a Chef::Resource object which has a valid run context without an action" do
+ file, run_context = setup_file_resource
+ provider = Chef::Platform.provider_for_resource(file)
+ provider.should be_an_instance_of(Chef::Provider::File)
+ provider.new_resource.should equal(file)
+ provider.run_context.should equal(run_context)
+ end
+
it "raises an error when trying to find the provider for a resource with no run context" do
file = Chef::Resource::File.new("whateva")
lambda {Chef::Platform.provider_for_resource(file)}.should raise_error(ArgumentError)
diff --git a/chef/spec/unit/provider/cookbook_file_spec.rb b/chef/spec/unit/provider/cookbook_file_spec.rb
index 6df58d24a1..80f878508a 100644
--- a/chef/spec/unit/provider/cookbook_file_spec.rb
+++ b/chef/spec/unit/provider/cookbook_file_spec.rb
@@ -104,6 +104,7 @@ EXPECTED
it "installs the file from the cookbook cache" do
@new_resource.path(@install_to)
@provider.should_receive(:backup_new_resource)
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create)
actual = IO.read(@install_to)
actual.should == @file_content
@@ -112,6 +113,7 @@ EXPECTED
it "installs the file for create_if_missing --> from Provider::File" do
@new_resource.path(@install_to)
@provider.should_receive(:backup_new_resource)
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create_if_missing)
actual = IO.read(@install_to)
actual.should == @file_content
@@ -121,6 +123,7 @@ EXPECTED
@new_resource.path(@install_to)
@provider.stub!(:backup_new_resource)
@provider.stub!(:set_file_access_controls)
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create)
@new_resource.should be_updated
@new_resource.should be_updated_by_last_action
diff --git a/chef/spec/unit/provider/deploy_spec.rb b/chef/spec/unit/provider/deploy_spec.rb
index 50ed0bb7d2..6bcd64fbfb 100644
--- a/chef/spec/unit/provider/deploy_spec.rb
+++ b/chef/spec/unit/provider/deploy_spec.rb
@@ -67,6 +67,7 @@ describe Chef::Provider::Deploy do
it "does not create deploy_to dir if it exists" do
::File.stub!(:directory?).and_return(true)
+ ::Dir.should_receive(:chdir).with(@expected_release_dir).exactly(4).times
FileUtils.should_not_receive(:mkdir_p).with(@resource.deploy_to)
FileUtils.should_not_receive(:mkdir_p).with(@resource.shared_path)
@provider.stub(:copy_cached_repo)
@@ -291,11 +292,32 @@ describe Chef::Provider::Deploy do
it "skips an eval callback if the file doesn't exist" do
barbaz_callback = @expected_release_dir + "/deploy/barbaz.rb"
::File.should_receive(:exist?).with(barbaz_callback).and_return(false)
+ ::Dir.should_receive(:chdir).with(@expected_release_dir).and_yield
@provider.should_not_receive(:from_file)
@provider.callback(:barbaz, nil)
@provider.converge
end
+ # CHEF-3449 #converge_by is called in #recipe_eval and must happen in sequence
+ # with the other calls to #converge_by to keep the train on the tracks
+ it "evaluates a callback file before the corresponding step" do
+ @provider.should_receive(:verify_directories_exist)
+ @provider.should_receive(:update_cached_repo)
+ @provider.should_receive(:enforce_ownership)
+ @provider.should_receive(:copy_cached_repo)
+ @provider.should_receive(:install_gems)
+ @provider.should_receive(:enforce_ownership)
+ @provider.should_receive(:converge_by).ordered # before_migrate
+ @provider.should_receive(:migrate).ordered
+ @provider.should_receive(:converge_by).ordered # before_symlink
+ @provider.should_receive(:symlink).ordered
+ @provider.should_receive(:converge_by).ordered # before_restart
+ @provider.should_receive(:restart).ordered
+ @provider.should_receive(:converge_by).ordered # after_restart
+ @provider.should_receive(:cleanup!)
+ @provider.deploy
+ end
+
it "gets a SCM provider as specified by its resource" do
@provider.scm_provider.should be_an_instance_of(Chef::Provider::Git)
@provider.scm_provider.new_resource.destination.should eql("/my/deploy/dir/shared/cached-copy")
diff --git a/chef/spec/unit/provider/directory_spec.rb b/chef/spec/unit/provider/directory_spec.rb
index a4ebb49445..4f297e0115 100644
--- a/chef/spec/unit/provider/directory_spec.rb
+++ b/chef/spec/unit/provider/directory_spec.rb
@@ -39,7 +39,7 @@ describe Chef::Provider::Directory do
cstats.stub!(:uid).and_return(500)
cstats.stub!(:gid).and_return(500)
cstats.stub!(:mode).and_return(0755)
- File.should_receive(:stat).once.and_return(cstats)
+ File.should_receive(:stat).twice.and_return(cstats)
@directory.load_current_resource
@directory.current_resource.path.should eql(@new_resource.path)
@directory.current_resource.owner.should eql(500)
@@ -48,11 +48,13 @@ describe Chef::Provider::Directory do
end
it "should create a new directory on create, setting updated to true" do
- load_mock_provider
@new_resource.path "/tmp/foo"
- File.should_receive(:exist?).twice.and_return(false)
+
+ File.should_receive(:exist?).exactly(3).and_return(false)
Dir.should_receive(:mkdir).with(@new_resource.path).once.and_return(true)
+
@directory.should_receive(:set_all_access_controls)
+ @directory.stub!(:update_new_file_state)
@directory.run_action(:create)
@directory.new_resource.should be_updated
end
@@ -64,10 +66,11 @@ describe Chef::Provider::Directory do
end
it "should create a new directory when parent directory does not exist if recursive is true and permissions are correct" do
- load_mock_provider
@new_resource.path "/path/to/dir"
@new_resource.recursive true
File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
+ File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
+
File.should_receive(:exist?).with('/path/to').ordered.and_return(false)
File.should_receive(:exist?).with('/path').ordered.and_return(true)
File.should_receive(:writable?).with('/path').ordered.and_return(true)
@@ -75,6 +78,7 @@ describe Chef::Provider::Directory do
FileUtils.should_receive(:mkdir_p).with(@new_resource.path).and_return(true)
@directory.should_receive(:set_all_access_controls)
+ @directory.stub!(:update_new_file_state)
@directory.run_action(:create)
@new_resource.should be_updated
end
@@ -84,7 +88,6 @@ describe Chef::Provider::Directory do
# end
it "should raise an error when creating a directory when parent directory is a file" do
- load_mock_provider
File.should_receive(:directory?).and_return(false)
Dir.should_not_receive(:mkdir).with(@new_resource.path)
lambda { @directory.run_action(:create) }.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist)
@@ -92,16 +95,15 @@ describe Chef::Provider::Directory do
end
it "should not create the directory if it already exists" do
- load_mock_provider
+ stub_file_cstats
@new_resource.path "/tmp/foo"
- File.should_receive(:exist?).twice.and_return(true)
+ File.should_receive(:exist?).exactly(3).and_return(true)
Dir.should_not_receive(:mkdir).with(@new_resource.path)
@directory.should_receive(:set_all_access_controls)
@directory.run_action(:create)
end
it "should delete the directory if it exists, and is writable with action_delete" do
- load_mock_provider
File.should_receive(:directory?).and_return(true)
File.should_receive(:writable?).once.and_return(true)
Dir.should_receive(:delete).with(@new_resource.path).once.and_return(true)
@@ -109,7 +111,6 @@ describe Chef::Provider::Directory do
end
it "should raise an exception if it cannot delete the directory due to bad permissions" do
- load_mock_provider
File.stub!(:exist?).and_return(true)
File.stub!(:writable?).and_return(false)
lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError)
@@ -124,25 +125,23 @@ describe Chef::Provider::Directory do
end
it "should raise an exception when deleting a directory when target directory is a file" do
- load_mock_provider
+ stub_file_cstats
@new_resource.path "/an/invalid/path"
File.stub!(:exist?).and_return(true)
File.should_receive(:directory?).and_return(false)
Dir.should_not_receive(:delete).with(@new_resource.path)
lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError)
@directory.new_resource.should_not be_updated
-
end
-
- def load_mock_provider
- File.stub!(:exist?).and_return(true)
- File.stub!(:directory?).and_return(true)
+ def stub_file_cstats
cstats = mock("stats")
cstats.stub!(:uid).and_return(500)
cstats.stub!(:gid).and_return(500)
cstats.stub!(:mode).and_return(0755)
- File.stub!(:stat).once.and_return(cstats)
- # @directory.load_current_resource
+ # File.stat is called in:
+ # - Chef::Provider::File.load_current_resource_attrs
+ # - Chef::ScanAccessControl via Chef::Provider::File.setup_acl
+ File.stub!(:stat).and_return(cstats)
end
end
diff --git a/chef/spec/unit/provider/file_spec.rb b/chef/spec/unit/provider/file_spec.rb
index c87d36c534..13b79e4bd6 100644
--- a/chef/spec/unit/provider/file_spec.rb
+++ b/chef/spec/unit/provider/file_spec.rb
@@ -29,6 +29,7 @@ describe Chef::Provider::File do
@resource = Chef::Resource::File.new("seattle")
@resource.path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates", "seattle.txt")))
+
@provider = Chef::Provider::File.new(@resource, @run_context)
end
@@ -52,6 +53,76 @@ describe Chef::Provider::File do
@provider.current_resource.content.should eql(nil)
end
+ it "should collect the current state of the file on the filesystem and populate current_resource" do
+ # test setup
+ stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
+ ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
+
+ # test execution
+ @provider.load_current_resource
+
+ # post-condition checks
+ @provider.current_resource.mode.should == 0600
+ @provider.current_resource.owner.should == 0
+ @provider.current_resource.group.should == 0
+ end
+
+ it "should NOT update the new_resource state with the current_resourse state if new_resource state is already specified" do
+ # test setup
+ stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
+ ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
+
+ @provider.new_resource.group(1)
+ @provider.new_resource.owner(1)
+ @provider.new_resource.mode(0644)
+
+ # test execution
+ @provider.load_current_resource
+
+ # post-condition checks
+ @provider.new_resource.group.should == 1
+ @provider.new_resource.owner.should == 1
+ @provider.new_resource.mode.should == 0644
+ end
+
+ it "should update the new_resource state with the current_resource state if the new_resource state is not specified." do
+ # test setup
+ stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
+ ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
+
+ @provider.new_resource.group(nil)
+ @provider.new_resource.owner(nil)
+ @provider.new_resource.mode(nil)
+
+ # test execution
+ @provider.load_current_resource
+
+ # post-condition checks
+ @provider.new_resource.group.should eql(@provider.current_resource.group)
+ @provider.new_resource.owner.should eql(@provider.current_resource.owner)
+ @provider.new_resource.mode.should eql(@provider.current_resource.mode)
+ end
+
+ it "should update the new_resource when attempting to set the new state" do
+ # test setup
+ stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
+ # called once in update_new_file_state and once in checksum
+ ::File.should_receive(:stat).twice.with(@provider.new_resource.path).and_return(stat_struct)
+ ::File.should_receive(:directory?).once.with(@provider.new_resource.path).and_return(false)
+
+ @provider.new_resource.group(nil)
+ @provider.new_resource.owner(nil)
+ @provider.new_resource.mode(nil)
+
+ # test exectution
+ @provider.update_new_file_state
+
+ # post-condition checks
+ @provider.new_resource.group.should == 0
+ @provider.new_resource.owner.should == 0
+ @provider.new_resource.mode.should == 0600
+end
+
it "should load a mostly blank current resource if the file specified in new_resource doesn't exist/isn't readable" do
resource = Chef::Resource::File.new("seattle")
resource.path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates", "woot.txt")))
@@ -114,6 +185,7 @@ describe Chef::Provider::File do
it "should create the file if it is missing, then set the attributes on action_create" do
@provider.load_current_resource
+ @provider.stub!(:update_new_file_state)
@provider.new_resource.stub!(:path).and_return(File.join(Dir.tmpdir, "monkeyfoo"))
@provider.access_controls.should_receive(:set_all)
@provider.should_receive(:diff_current_from_content).and_return("")
@@ -130,6 +202,7 @@ describe Chef::Provider::File do
@provider.new_resource.content "foobar"
@provider.new_resource.stub!(:path).and_return(File.join(Dir.tmpdir, "monkeyfoo"))
@provider.should_receive(:diff_current_from_content).and_return("")
+ @provider.stub!(:update_new_file_state)
File.should_receive(:open).with(@provider.new_resource.path, "w+").and_yield(io)
@provider.access_controls.should_receive(:set_all)
@provider.run_action(:create)
@@ -159,6 +232,7 @@ describe Chef::Provider::File do
@provider.load_current_resource
@provider.new_resource.stub!(:path).and_return(File.join(Dir.tmpdir, "monkeyfoo"))
@provider.should_receive(:diff_current_from_content).and_return("")
+ @provider.stub!(:update_new_file_state)
File.should_receive(:utime).once.and_return(1)
File.stub!(:open).and_return(1)
@provider.access_controls.should_receive(:set_all).once
@@ -267,6 +341,7 @@ describe Chef::Provider::File do
@provider = Chef::Provider::File.new(@resource, @run_context)
@provider.should_receive(:diff_current_from_content).and_return("")
::File.stub!(:exists?).with(@resource.path).and_return(false)
+ @provider.stub!(:update_new_file_state)
io = StringIO.new
File.should_receive(:open).with(@provider.new_resource.path, "w+").and_yield(io)
#@provider.should_receive(:action_create).and_return(true)
diff --git a/chef/spec/unit/provider/http_request_spec.rb b/chef/spec/unit/provider/http_request_spec.rb
index 99fa8415c5..26d73cebb4 100644
--- a/chef/spec/unit/provider/http_request_spec.rb
+++ b/chef/spec/unit/provider/http_request_spec.rb
@@ -167,6 +167,12 @@ describe Chef::Provider::HttpRequest do
@rest.should_receive(:run_request).with(:HEAD, @rest.create_url, @new_resource.headers, false, 10, false)
@provider.run_action(:head)
end
+
+ it "doesn't call converge_by if HEAD does not return modified" do
+ @rest.should_receive(:run_request).and_return(false)
+ @provider.should_not_receive(:converge_by)
+ @provider.run_action(:head)
+ end
end
end
end
diff --git a/chef/spec/unit/provider/package_spec.rb b/chef/spec/unit/provider/package_spec.rb
index c14e642923..5472d6e99f 100644
--- a/chef/spec/unit/provider/package_spec.rb
+++ b/chef/spec/unit/provider/package_spec.rb
@@ -20,6 +20,10 @@ require 'spec_helper'
describe Chef::Provider::Package do
before do
+ #Terrible, but we need to implement a pseduo-filesystem for testing
+ #to not have this line. Only affects updating state fields.
+ Chef::Provider::CookbookFile.any_instance.stub(:update_new_file_state)
+
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
diff --git a/chef/spec/unit/provider/remote_directory_spec.rb b/chef/spec/unit/provider/remote_directory_spec.rb
index 0bc1412d64..db79aa2f84 100644
--- a/chef/spec/unit/provider/remote_directory_spec.rb
+++ b/chef/spec/unit/provider/remote_directory_spec.rb
@@ -28,6 +28,10 @@ end
describe Chef::Provider::RemoteDirectory do
before do
Chef::FileAccessControl.any_instance.stub(:set_all)
+ #Terrible, but we need to implement a pseduo-filesystem for testing
+ #to not have this line. Only affects updating state fields.
+ Chef::Provider::CookbookFile.any_instance.stub(:update_new_file_state)
+
@resource = Chef::Resource::RemoteDirectory.new("/tmp/tafty")
# in CHEF_SPEC_DATA/cookbooks/openldap/files/default/remotedir
@resource.source "remotedir"
@@ -186,6 +190,7 @@ describe Chef::Provider::RemoteDirectory do
::File.open(@destination_dir + '/remotesubdir/remote_subdir_file1.txt', 'a') {|f| f.puts "blah blah blah" }
file1md5 = Digest::MD5.hexdigest(::File.read(@destination_dir + '/remote_dir_file1.txt'))
subdirfile1md5 = Digest::MD5.hexdigest(::File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt'))
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create)
file1md5.eql?(Digest::MD5.hexdigest(::File.read(@destination_dir + '/remote_dir_file1.txt'))).should be_true
subdirfile1md5.eql?(Digest::MD5.hexdigest(::File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt'))).should be_true
diff --git a/chef/spec/unit/provider/remote_file_spec.rb b/chef/spec/unit/provider/remote_file_spec.rb
index 6204a44f6b..0797ead1a5 100644
--- a/chef/spec/unit/provider/remote_file_spec.rb
+++ b/chef/spec/unit/provider/remote_file_spec.rb
@@ -119,6 +119,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
it "downloads the file" do
@resource.checksum("this hash doesn't match")
@rest.should_receive(:streaming_request).with("http://opscode.com/seattle.txt", {}).and_return(@tempfile)
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create)
end
@@ -126,6 +127,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
# i.e., the existing file is "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa"
@resource.checksum("fd012fd")
@rest.should_receive(:streaming_request).with("http://opscode.com/seattle.txt", {}).and_return(@tempfile)
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create)
end
end
@@ -199,10 +201,12 @@ describe Chef::Provider::RemoteFile, "action_create" do
it "should copy the raw file to the new resource" do
FileUtils.should_receive(:cp).with(@tempfile.path, @resource.path).and_return(true)
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create)
end
it "should set the new resource to updated" do
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create)
@resource.should be_updated
end
@@ -254,16 +258,19 @@ describe Chef::Provider::RemoteFile, "action_create" do
end
it "should backup the original file" do
+ @provider.stub!(:update_new_file_state)
@provider.should_receive(:backup).with(@resource.path).and_return(true)
@provider.run_action(:create)
end
it "should copy the raw file to the new resource" do
+ @provider.stub!(:update_new_file_state)
FileUtils.should_receive(:cp).with(@tempfile.path, @resource.path).and_return(true)
@provider.run_action(:create)
end
it "should set the new resource to updated" do
+ @provider.stub!(:update_new_file_state)
@provider.run_action(:create)
@resource.should be_updated
end
diff --git a/chef/spec/unit/resource/cookbook_file_spec.rb b/chef/spec/unit/resource/cookbook_file_spec.rb
index 7563585351..d0408c251a 100644
--- a/chef/spec/unit/resource/cookbook_file_spec.rb
+++ b/chef/spec/unit/resource/cookbook_file_spec.rb
@@ -1,7 +1,8 @@
#
# Author:: Daniel DeLeo (<dan@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
+#p License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -44,5 +45,45 @@ describe Chef::Resource::CookbookFile do
it "sets the provider to Chef::Provider::CookbookFile" do
@cookbook_file.provider.should == Chef::Provider::CookbookFile
end
+
+ describe "when it has a backup number, group, mode, owner, source, checksum, and cookbook on nix or path, rights, deny_rights, checksum on windows" do
+ before do
+ if Chef::Platform.windows?
+ @cookbook_file.path("C:/temp/origin/file.txt")
+ @cookbook_file.rights(:read, "Everyone")
+ @cookbook_file.deny_rights(:full_control, "Clumsy_Sam")
+ else
+ @cookbook_file.path("/tmp/origin/file.txt")
+ @cookbook_file.group("wheel")
+ @cookbook_file.mode("0664")
+ @cookbook_file.owner("root")
+ @cookbook_file.source("/tmp/foo.txt")
+ @cookbook_file.cookbook("/tmp/cookbooks/cooked.rb")
+ end
+ @cookbook_file.checksum("1" * 64)
+ end
+
+ it "describes the state" do
+ state = @cookbook_file.state
+ if Chef::Platform.windows?
+ puts state
+ state[:rights].should == [{:permissions => :read, :principals => "Everyone"}]
+ state[:deny_rights].should == [{:permissions => :full_control, :principals => "Clumsy_Sam"}]
+ else
+ state[:group].should == "wheel"
+ state[:mode].should == "0664"
+ state[:owner].should == "root"
+ end
+ state[:checksum].should == "1" * 64
+ end
+
+ it "returns the path as its identity" do
+ if Chef::Platform.windows?
+ @cookbook_file.identity.should == "C:/temp/origin/file.txt"
+ else
+ @cookbook_file.identity.should == "/tmp/origin/file.txt"
+ end
+ end
+ end
end
diff --git a/chef/spec/unit/resource/cron_spec.rb b/chef/spec/unit/resource/cron_spec.rb
index 59cbe684f3..403ffb009b 100644
--- a/chef/spec/unit/resource/cron_spec.rb
+++ b/chef/spec/unit/resource/cron_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Bryan McLellan (btm@loftninjas.org)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Bryan McLellan
# License:: Apache License, Version 2.0
#
@@ -151,4 +152,30 @@ describe Chef::Resource::Cron do
@resource.send(x, 5).should eql("5")
end
end
+
+ describe "when it has a time (minute, hour, day, month, weeekend) and user" do
+ before do
+ @resource.command("tackle")
+ @resource.minute("1")
+ @resource.hour("2")
+ @resource.day("3")
+ @resource.month("4")
+ @resource.weekday("5")
+ @resource.user("root")
+ end
+
+ it "describes the state" do
+ state = @resource.state
+ state[:minute].should == "1"
+ state[:hour].should == "2"
+ state[:day].should == "3"
+ state[:month].should == "4"
+ state[:weekday].should == "5"
+ state[:user].should == "root"
+ end
+
+ it "returns the command as its identity" do
+ @resource.identity.should == "tackle"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/deploy_spec.rb b/chef/spec/unit/resource/deploy_spec.rb
index 7809a4a233..98c9fa1581 100644
--- a/chef/spec/unit/resource/deploy_spec.rb
+++ b/chef/spec/unit/resource/deploy_spec.rb
@@ -229,4 +229,31 @@ describe Chef::Resource::Deploy do
@resource.keep_releases.should == 1
end
+ describe "when it has meta application root, revision, user, group,
+ scm provider, repository cache, environment, simlinks and migrate" do
+ before do
+ @resource.repository("http://uri.org")
+ @resource.deploy_to("/")
+ @resource.revision("1.2.3")
+ @resource.user("root")
+ @resource.group("pokemon")
+ @resource.scm_provider(Chef::Provider::Git)
+ @resource.repository_cache("cached-copy")
+ @resource.environment({"SUDO" => "TRUE"})
+ @resource.symlinks({"system" => "public/system"})
+ @resource.migrate(false)
+
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:deploy_to].should == "/"
+ state[:revision].should == "1.2.3"
+ end
+
+ it "returns the repository URI as its identity" do
+ @resource.identity.should == "http://uri.org"
+ end
+ end
+
end
diff --git a/chef/spec/unit/resource/directory_spec.rb b/chef/spec/unit/resource/directory_spec.rb
index e5b686a33e..9b0c8242e6 100644
--- a/chef/spec/unit/resource/directory_spec.rb
+++ b/chef/spec/unit/resource/directory_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -59,4 +60,23 @@ describe Chef::Resource::Directory do
lambda { @resource.recursive "monkey" }.should raise_error(ArgumentError)
end
+ describe "when it has group, mode, and owner" do
+ before do
+ @resource.path("/tmp/foo/bar/")
+ @resource.group("wheel")
+ @resource.mode("0664")
+ @resource.owner("root")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:group].should == "wheel"
+ state[:mode].should == "0664"
+ state[:owner].should == "root"
+ end
+
+ it "returns the directory path as its identity" do
+ @resource.identity.should == "/tmp/foo/bar/"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/env_spec.rb b/chef/spec/unit/resource/env_spec.rb
index adf71a4136..6862c669b2 100644
--- a/chef/spec/unit/resource/env_spec.rb
+++ b/chef/spec/unit/resource/env_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Doug MacEachern (<dougm@vmware.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2010 VMware, Inc.
# License:: Apache License, Version 2.0
#
@@ -63,4 +64,22 @@ describe Chef::Resource::Env do
@resource.value "bar"
@resource.value.should eql("bar")
end
+
+ describe "when it has key name and value" do
+ before do
+ @resource.key_name("charmander")
+ @resource.value("level7")
+ @resource.delim("hi")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:value].should == "level7"
+ end
+
+ it "returns the key name as its identity" do
+ @resource.identity.should == "charmander"
+ end
+ end
+
end
diff --git a/chef/spec/unit/resource/erl_call_spec.rb b/chef/spec/unit/resource/erl_call_spec.rb
index 8b5e5f52fd..ccad371723 100644
--- a/chef/spec/unit/resource/erl_call_spec.rb
+++ b/chef/spec/unit/resource/erl_call_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Joe Williams (<joe@joetify.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Joe Williams
# License:: Apache License, Version 2.0
#
@@ -66,4 +67,15 @@ describe Chef::Resource::ErlCall do
@resource.node_name.should eql("chef@erlang")
end
+ describe "when it has cookie and node_name" do
+ before do
+ @resource.code("erl-call:function()")
+ @resource.cookie("cookie")
+ @resource.node_name("raster")
+ end
+
+ it "returns the code as its identity" do
+ @resource.identity.should == "erl-call:function()"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/execute_spec.rb b/chef/spec/unit/resource/execute_spec.rb
index 52def2d629..0dcdab7409 100644
--- a/chef/spec/unit/resource/execute_spec.rb
+++ b/chef/spec/unit/resource/execute_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -105,4 +106,19 @@ describe Chef::Resource::Execute do
@resource.creates.should eql("something")
end
+ describe "when it has cwd, environment, group, path, return value, and a user" do
+ before do
+ @resource.command("grep")
+ @resource.cwd("/tmp/")
+ @resource.environment({ :one => :two })
+ @resource.group("legos")
+ @resource.path(["/var/local/"])
+ @resource.returns(1)
+ @resource.user("root")
+ end
+
+ it "returns the command as its identity" do
+ @resource.identity.should == "grep"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/group_spec.rb b/chef/spec/unit/resource/group_spec.rb
index 328bdb836b..7181750b1c 100644
--- a/chef/spec/unit/resource/group_spec.rb
+++ b/chef/spec/unit/resource/group_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: AJ Christensen (<aj@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>);
# Copyright:: Copyright (c) 2008 OpsCode, Inc.
# License:: Apache License, Version 2.0
#
@@ -128,5 +129,20 @@ describe Chef::Resource::Group, "append" do
it "should not allow a hash" do
lambda { @resource.send(:gid, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError)
end
-
+
+ describe "when it has members" do
+ before do
+ @resource.group_name("pokemon")
+ @resource.members(["blastoise", "pikachu"])
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:members].should eql(["blastoise", "pikachu"])
+ end
+
+ it "returns the group name as its identity" do
+ @resource.identity.should == "pokemon"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/http_request_spec.rb b/chef/spec/unit/resource/http_request_spec.rb
index 833c588452..924cf66fc2 100644
--- a/chef/spec/unit/resource/http_request_spec.rb
+++ b/chef/spec/unit/resource/http_request_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -42,5 +43,17 @@ describe Chef::Resource::HttpRequest do
@resource.message "monkeybars"
@resource.message.should eql("monkeybars")
end
+
+ describe "when it has a message and headers" do
+ before do
+ @resource.url("http://www.trololol.net")
+ @resource.message("Get sum post brah.")
+ @resource.headers({"head" => "tail"})
+ end
+
+ it "returns the url as its identity" do
+ @resource.identity.should == "http://www.trololol.net"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/ifconfig_spec.rb b/chef/spec/unit/resource/ifconfig_spec.rb
new file mode 100644
index 0000000000..2aac130978
--- /dev/null
+++ b/chef/spec/unit/resource/ifconfig_spec.rb
@@ -0,0 +1,46 @@
+#
+# Author:: Tyler Cloke (<tyler@opscode.com>)
+# Copyright:: Copyright (c) 2009 Joe Williams
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Resource::Ifconfig do
+
+ before(:each) do
+ @resource = Chef::Resource::Ifconfig.new("fakey_fakerton")
+ end
+
+ describe "when it has target, hardware address, inet address, and a mask" do
+ before do
+ @resource.device("charmander")
+ @resource.target("team_rocket")
+ @resource.hwaddr("11.2223.223")
+ @resource.inet_addr("434.2343.23")
+ @resource.mask("255.255.545")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:inet_addr].should == "434.2343.23"
+ state[:mask].should == "255.255.545"
+ end
+
+ it "returns the device as its identity" do
+ @resource.identity.should == "charmander"
+ end
+ end
+end
diff --git a/chef/spec/unit/resource/link_spec.rb b/chef/spec/unit/resource/link_spec.rb
index b519303f9f..279a5b4e77 100644
--- a/chef/spec/unit/resource/link_spec.rb
+++ b/chef/spec/unit/resource/link_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -94,4 +95,24 @@ describe Chef::Resource::Link do
lambda { @resource.owner "root*goo" }.should raise_error(ArgumentError)
end
+ describe "when it has to, link_type, owner, and group" do
+ before do
+ @resource.target_file("/var/target.tar")
+ @resource.to("/to/dir/file.tar")
+ @resource.link_type(:symbolic)
+ @resource.owner("root")
+ @resource.group("0664")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:to].should == "/to/dir/file.tar"
+ state[:owner].should == "root"
+ state[:group].should == "0664"
+ end
+
+ it "returns the target file as its identity" do
+ @resource.identity.should == "/var/target.tar"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/log_spec.rb b/chef/spec/unit/resource/log_spec.rb
index 65be233247..bc5ac13078 100644
--- a/chef/spec/unit/resource/log_spec.rb
+++ b/chef/spec/unit/resource/log_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Cary Penniman (<cary@rightscale.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -47,5 +48,14 @@ describe Chef::Resource::Log do
lambda { @resource.level :unsupported }.should raise_error(ArgumentError)
end
+ describe "when the identity is defined" do
+ before do
+ @resource = Chef::Resource::Log.new("ery day I'm loggin-in")
+ end
+
+ it "returns the log string as its identity" do
+ @resource.identity.should == "ery day I'm loggin-in"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/mdadm_spec.rb b/chef/spec/unit/resource/mdadm_spec.rb
index 720ecf6e80..c4e6704ceb 100644
--- a/chef/spec/unit/resource/mdadm_spec.rb
+++ b/chef/spec/unit/resource/mdadm_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Joe Williams (<joe@joetify.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Joe Williams
# License:: Apache License, Version 2.0
#
@@ -77,4 +78,25 @@ describe Chef::Resource::Mdadm do
@resource.exists true
@resource.exists.should eql(true)
end
+
+ describe "when it has devices, level, and chunk" do
+ before do
+ @resource.raid_device("raider")
+ @resource.devices(["device1", "device2"])
+ @resource.level(1)
+ @resource.chunk(42)
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:devices].should eql(["device1", "device2"])
+ state[:level].should == 1
+ state[:chunk].should == 42
+ end
+
+ it "returns the raid device as its identity" do
+ @resource.identity.should == "raider"
+ end
+ end
+
end
diff --git a/chef/spec/unit/resource/mount_spec.rb b/chef/spec/unit/resource/mount_spec.rb
index 5dfa7a54e1..498f33a7ba 100644
--- a/chef/spec/unit/resource/mount_spec.rb
+++ b/chef/spec/unit/resource/mount_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Joshua Timberman (<joshua@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2009 Opscode, Inc
# License:: Apache License, Version 2.0
#
@@ -135,4 +136,23 @@ describe Chef::Resource::Mount do
@resource.supports.should == support_hash
end
+ describe "when it has mount point, device type, and fstype" do
+ before do
+ @resource.device("charmander")
+ @resource.mount_point("123.456")
+ @resource.device_type(:device)
+ @resource.fstype("ranked")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:mount_point].should == "123.456"
+ state[:device_type].should eql(:device)
+ state[:fstype].should == "ranked"
+ end
+
+ it "returns the device as its identity" do
+ @resource.identity.should == "charmander"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/ohai_spec.rb b/chef/spec/unit/resource/ohai_spec.rb
index 7d25d411b3..82df61e509 100644
--- a/chef/spec/unit/resource/ohai_spec.rb
+++ b/chef/spec/unit/resource/ohai_spec.rb
@@ -41,4 +41,22 @@ describe Chef::Resource::Ohai do
@resource.plugin "passwd"
@resource.plugin.should eql("passwd")
end
+
+ describe "when it has a plugin value" do
+ before do
+ @resource.name("test")
+ @resource.plugin("passwd")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:plugin].should == "passwd"
+ end
+
+ it "returns the name as its identity" do
+ @resource.identity.should == "test"
+ end
+ end
+
+
end
diff --git a/chef/spec/unit/resource/package_spec.rb b/chef/spec/unit/resource/package_spec.rb
index b451b52a8a..3f9cc7a408 100644
--- a/chef/spec/unit/resource/package_spec.rb
+++ b/chef/spec/unit/resource/package_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -62,11 +63,13 @@ describe Chef::Resource::Package do
before do
@resource.package_name("tomcat")
@resource.version("10.9.8")
+ @resource.options("-al")
end
it "describes its state" do
state = @resource.state
state[:version].should == "10.9.8"
+ state[:options].should == "-al"
end
it "returns the file path as its identity" do
diff --git a/chef/spec/unit/resource/remote_directory_spec.rb b/chef/spec/unit/resource/remote_directory_spec.rb
index 9d69ca1b4b..e4fa8fc4e3 100644
--- a/chef/spec/unit/resource/remote_directory_spec.rb
+++ b/chef/spec/unit/resource/remote_directory_spec.rb
@@ -72,4 +72,26 @@ describe Chef::Resource::RemoteDirectory do
@resource.files_owner 1000
@resource.files_owner.should eql(1000)
end
+
+ describe "when it has cookbook, files owner, files mode, and source" do
+ before do
+ @resource.path("/var/path/")
+ @resource.cookbook("pokemon.rb")
+ @resource.files_owner("root")
+ @resource.files_group("supergroup")
+ @resource.files_mode("0664")
+ @resource.source("/var/source/")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:files_owner].should == "root"
+ state[:files_group].should == "supergroup"
+ state[:files_mode].should == "0664"
+ end
+
+ it "returns the path as its identity" do
+ @resource.identity.should == "/var/path/"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/remote_file_spec.rb b/chef/spec/unit/resource/remote_file_spec.rb
index 0f077201d5..a321d560e7 100644
--- a/chef/spec/unit/resource/remote_file_spec.rb
+++ b/chef/spec/unit/resource/remote_file_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -82,4 +83,43 @@ describe Chef::Resource::RemoteFile do
end
end
+ describe "when it has group, mode, owner, source, and checksum" do
+ before do
+ if Chef::Platform.windows?
+ @resource.path("C:/temp/origin/file.txt")
+ @resource.rights(:read, "Everyone")
+ @resource.deny_rights(:full_control, "Clumsy_Sam")
+ else
+ @resource.path("/this/path/")
+ @resource.group("pokemon")
+ @resource.mode("0664")
+ @resource.owner("root")
+ end
+ @resource.source("https://www.google.com/images/srpr/logo3w.png")
+ @resource.checksum("1"*26)
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ if Chef::Platform.windows?
+ puts state
+ state[:rights].should == [{:permissions => :read, :principals => "Everyone"}]
+ state[:deny_rights].should == [{:permissions => :full_control, :principals => "Clumsy_Sam"}]
+ else
+ state[:group].should == "pokemon"
+ state[:mode].should == "0664"
+ state[:owner].should == "root"
+ state[:checksum].should == "1"*26
+ end
+ end
+
+ it "returns the path as its identity" do
+ if Chef::Platform.windows?
+ @resource.identity.should == "C:/temp/origin/file.txt"
+ else
+ @resource.identity.should == "/this/path/"
+ end
+ end
+ end
+
end
diff --git a/chef/spec/unit/resource/route_spec.rb b/chef/spec/unit/resource/route_spec.rb
index 6a20c5fa57..54d5275411 100644
--- a/chef/spec/unit/resource/route_spec.rb
+++ b/chef/spec/unit/resource/route_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Bryan McLellan (btm@loftninjas.org)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Bryan McLellan
# License:: Apache License, Version 2.0
#
@@ -85,4 +86,22 @@ describe Chef::Resource::Route do
lambda { @resource.route_type "lolcat" }.should raise_error(ArgumentError)
end
+ describe "when it has netmask, gateway, and device" do
+ before do
+ @resource.target("charmander")
+ @resource.netmask("lemask")
+ @resource.gateway("111.111.111")
+ @resource.device("forcefield")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:netmask].should == "lemask"
+ state[:gateway].should == "111.111.111"
+ end
+
+ it "returns the target as its identity" do
+ @resource.identity.should == "charmander"
+ end
+ end
end
diff --git a/chef/spec/unit/resource/ruby_block_spec.rb b/chef/spec/unit/resource/ruby_block_spec.rb
index 60ef41c240..532888eb73 100644
--- a/chef/spec/unit/resource/ruby_block_spec.rb
+++ b/chef/spec/unit/resource/ruby_block_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: AJ Christensen (<aj@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -43,4 +44,14 @@ describe Chef::Resource::RubyBlock do
end.call.should eql("foo")
end
+ describe "when it has been initialized with block code" do
+ before do
+ @resource.block_name("puts 'harrrr'")
+ end
+
+ it "returns the block as its identity" do
+ @resource.identity.should == "puts 'harrrr'"
+ end
+ end
+
end
diff --git a/chef/spec/unit/resource/scm_spec.rb b/chef/spec/unit/resource/scm_spec.rb
index 1e181feeac..488d335342 100644
--- a/chef/spec/unit/resource/scm_spec.rb
+++ b/chef/spec/unit/resource/scm_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@kallistec.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -136,4 +137,23 @@ describe Chef::Resource::Scm do
@resource.ssh_wrapper.should be_nil
end
+ describe "when it has repository, revision, user, and group" do
+ before do
+ @resource.destination("hell")
+ @resource.repository("apt")
+ @resource.revision("1.2.3")
+ @resource.user("root")
+ @resource.group("super_adventure_club")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:revision].should == "1.2.3"
+ end
+
+ it "returns the destination as its identity" do
+ @resource.identity.should == "hell"
+ end
+ end
+
end
diff --git a/chef/spec/unit/resource/script_spec.rb b/chef/spec/unit/resource/script_spec.rb
index 560115970f..569602008b 100644
--- a/chef/spec/unit/resource/script_spec.rb
+++ b/chef/spec/unit/resource/script_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -52,4 +53,17 @@ describe Chef::Resource::Script do
@resource.flags.should eql("-f")
end
+ describe "when it has interpreter and flags" do
+ before do
+ @resource.command("grep")
+ @resource.interpreter("gcc")
+ @resource.flags("-al")
+ end
+
+ it "returns the command as its identity" do
+ @resource.identity.should == "grep"
+ end
+ end
+
+
end
diff --git a/chef/spec/unit/resource/service_spec.rb b/chef/spec/unit/resource/service_spec.rb
index e1bb2099a7..d7a90e8c7a 100644
--- a/chef/spec/unit/resource/service_spec.rb
+++ b/chef/spec/unit/resource/service_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: AJ Christensen (<aj@hjksolutions.com>)
+# Author:: Tyler Cloke (<tyler@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -141,4 +142,24 @@ describe Chef::Resource::Service do
@resource.supports.should == support_hash
end
end
+
+ describe "when it has pattern and supports" do
+ before do
+ @resource.service_name("superfriend")
+ @resource.enabled(true)
+ @resource.running(false)
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:enabled].should eql(true)
+ state[:running].should eql(false)
+ end
+
+ it "returns the service name as its identity" do
+ @resource.identity.should == "superfriend"
+ end
+ end
+
+
end
diff --git a/chef/spec/unit/resource/user_spec.rb b/chef/spec/unit/resource/user_spec.rb
index 7c6d30ab01..3361921173 100644
--- a/chef/spec/unit/resource/user_spec.rb
+++ b/chef/spec/unit/resource/user_spec.rb
@@ -98,4 +98,25 @@ end
lambda { @resource.send(attrib, { :woot => "i found it" }) }.should raise_error(ArgumentError)
end
end
+
+ describe "when it has uid, gid, and home" do
+ before do
+ @resource = Chef::Resource::User.new("root")
+ @resource.uid(123)
+ @resource.gid(456)
+ @resource.home("/usr/local/root/")
+ end
+
+ it "describes its state" do
+ state = @resource.state
+ state[:uid].should == 123
+ state[:gid].should == 456
+ state[:home].should == "/usr/local/root/"
+ end
+
+ it "returns the username as its identity" do
+ @resource.identity.should == "root"
+ end
+ end
+
end
diff --git a/chef/spec/unit/resource_reporter_spec.rb b/chef/spec/unit/resource_reporter_spec.rb
index 9d057e5c1c..c1e1ae114c 100644
--- a/chef/spec/unit/resource_reporter_spec.rb
+++ b/chef/spec/unit/resource_reporter_spec.rb
@@ -36,6 +36,7 @@ describe Chef::ResourceReporter do
@node = Chef::Node.new
@node.name("spitfire")
@rest_client = mock("Chef::REST (mock)")
+ @rest_client.stub!(:post_rest).and_return(true)
@resource_reporter = Chef::ResourceReporter.new(@rest_client)
@new_resource = Chef::Resource::File.new("/tmp/a-file.txt")
@new_resource.cookbook_name = "monkey"
@@ -75,7 +76,6 @@ describe Chef::ResourceReporter do
pending "refactor how node gets set."
@resource_reporter.status.should == "success"
end
-
end
context "when chef fails" do
@@ -287,7 +287,6 @@ describe Chef::ResourceReporter do
# "status" : "success"
# "data" : ""
# }
-
@resource_reporter.resource_action_start(@new_resource, :create)
@resource_reporter.resource_current_state_loaded(@new_resource, :create, @current_resource)
@resource_reporter.resource_updated(@new_resource, :create)
@@ -365,7 +364,7 @@ describe Chef::ResourceReporter do
context "for an unsuccessful run" do
before do
- @backtrace = ["foo.rb:1 in `foo!'", "bar.rb:2 in `bar!", "\n'baz.rb:3 in `baz!'"]
+ @backtrace = ["foo.rb:1 in `foo!'","bar.rb:2 in `bar!","'baz.rb:3 in `baz!'"]
@node = Chef::Node.new
@node.name("spitfire")
@exception = mock("ArgumentError")
@@ -379,7 +378,6 @@ describe Chef::ResourceReporter do
it "includes the exception type in the event data" do
@report.should have_key("data")
- @report["data"].should have_key("exception")
@report["data"]["exception"].should have_key("class")
@report["data"]["exception"]["class"].should == "Net::HTTPServerException"
end