summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Preston <stuart@chef.io>2018-03-07 20:15:31 -0800
committerStuart Preston <stuart@chef.io>2018-03-07 20:15:31 -0800
commita8ee50ed5021e2897f5483049acdb36c1f23125c (patch)
tree5ad6510007607fdae38856d314ae20577c4c4690
parente20bbea2f4a4201c3db645f6a2d14c793682e6cc (diff)
parent27de91563e5311cf17fdb53e7542db553787ec2f (diff)
downloadchef-a8ee50ed5021e2897f5483049acdb36c1f23125c.tar.gz
Merge branch 'master' into sp/powershell_exec
Signed-off-by: <>
-rw-r--r--CHANGELOG.md22
-rw-r--r--Gemfile.lock14
-rw-r--r--VERSION2
-rwxr-xr-xbin/chef-resource-inspector26
-rw-r--r--chef-config/lib/chef-config/config.rb4
-rw-r--r--chef-config/lib/chef-config/version.rb2
-rw-r--r--kitchen-tests/cookbooks/base/recipes/packages.rb2
-rw-r--r--lib/chef/application/client.rb10
-rw-r--r--lib/chef/application/solo.rb10
-rw-r--r--lib/chef/config.rb3
-rw-r--r--lib/chef/dsl/reboot_pending.rb9
-rw-r--r--lib/chef/mixin/from_file.rb5
-rw-r--r--lib/chef/platform/query_helpers.rb12
-rw-r--r--lib/chef/policy_builder/policyfile.rb10
-rw-r--r--lib/chef/provider.rb41
-rw-r--r--lib/chef/provider/apt_repository.rb146
-rw-r--r--lib/chef/provider/package.rb2
-rw-r--r--lib/chef/provider/package/bff.rb (renamed from lib/chef/provider/package/aix.rb)4
-rw-r--r--lib/chef/provider/package/macports.rb2
-rw-r--r--lib/chef/provider/package/portage.rb2
-rw-r--r--lib/chef/provider/service/upstart.rb1
-rw-r--r--lib/chef/providers.rb2
-rw-r--r--lib/chef/resource/apt_package.rb2
-rw-r--r--lib/chef/resource/bff_package.rb4
-rw-r--r--lib/chef/resource/build_essential.rb7
-rw-r--r--lib/chef/resource/chef_gem.rb2
-rw-r--r--lib/chef/resource/cron.rb10
-rw-r--r--lib/chef/resource/dsc_resource.rb16
-rw-r--r--lib/chef/resource/dsc_script.rb35
-rw-r--r--lib/chef/resource/execute.rb82
-rw-r--r--lib/chef/resource/file.rb6
-rw-r--r--lib/chef/resource/gem_package.rb2
-rw-r--r--lib/chef/resource/git.rb15
-rw-r--r--lib/chef/resource/group.rb48
-rw-r--r--lib/chef/resource/hostname.rb15
-rw-r--r--lib/chef/resource/http_request.rb23
-rw-r--r--lib/chef/resource/ips_package.rb2
-rw-r--r--lib/chef/resource/link.rb53
-rw-r--r--lib/chef/resource/macos_userdefaults.rb27
-rw-r--r--lib/chef/resource/macosx_service.rb2
-rw-r--r--lib/chef/resource/macports_package.rb3
-rw-r--r--lib/chef/resource/mdadm.rb9
-rw-r--r--lib/chef/resource/ohai.rb6
-rw-r--r--lib/chef/resource/ohai_hint.rb12
-rw-r--r--lib/chef/resource/openssl_rsa_private_key.rb4
-rw-r--r--lib/chef/resource/osx_profile.rb15
-rw-r--r--lib/chef/resource/portage_package.rb10
-rw-r--r--lib/chef/resource/registry_key.rb28
-rw-r--r--lib/chef/resource/remote_file.rb1
-rw-r--r--lib/chef/resource/rhsm_errata.rb3
-rw-r--r--lib/chef/resource/rhsm_errata_level.rb3
-rw-r--r--lib/chef/resource/rhsm_register.rb24
-rw-r--r--lib/chef/resource/rhsm_repo.rb3
-rw-r--r--lib/chef/resource/rhsm_subscription.rb3
-rw-r--r--lib/chef/resource/ruby_block.rb15
-rw-r--r--lib/chef/resource/scm.rb58
-rw-r--r--lib/chef/resource/windows_env.rb2
-rw-r--r--lib/chef/resource/windows_feature.rb7
-rw-r--r--lib/chef/resource/windows_feature_dism.rb4
-rw-r--r--lib/chef/resource/windows_feature_powershell.rb6
-rw-r--r--lib/chef/resource/windows_pagefile.rb6
-rw-r--r--lib/chef/resource/windows_printer.rb7
-rw-r--r--lib/chef/resource/windows_printer_port.rb4
-rw-r--r--lib/chef/resource/windows_service.rb4
-rw-r--r--lib/chef/resource/zypper_package.rb2
-rw-r--r--lib/chef/resource/zypper_repository.rb12
-rw-r--r--lib/chef/resource_inspector.rb89
-rw-r--r--lib/chef/version.rb2
-rw-r--r--lib/chef/win32/eventlog.rb2
-rw-r--r--lib/chef/win32/security.rb40
-rw-r--r--lib/chef/win32/security/sid.rb3
-rw-r--r--lib/chef/win32/version.rb17
-rw-r--r--spec/data/mixin/invalid_data.rb3
-rw-r--r--spec/data/mixin/real_data.rb2
-rw-r--r--spec/functional/event_loggers/windows_eventlog_spec.rb4
-rw-r--r--spec/functional/mixin/from_file_spec.rb82
-rw-r--r--spec/functional/resource/link_spec.rb8
-rw-r--r--spec/functional/resource/powershell_script_spec.rb2
-rw-r--r--spec/functional/win32/security_spec.rb1
-rw-r--r--spec/functional/win32/versions_spec.rb16
-rw-r--r--spec/integration/client/client_spec.rb100
-rw-r--r--spec/integration/recipes/resource_action_spec.rb95
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/support/platform_helpers.rb5
-rw-r--r--spec/support/shared/functional/file_resource.rb2
-rw-r--r--spec/unit/application/client_spec.rb50
-rw-r--r--spec/unit/dsl/reboot_pending_spec.rb13
-rw-r--r--spec/unit/platform/query_helpers_spec.rb13
-rw-r--r--spec/unit/policy_builder/policyfile_spec.rb76
-rw-r--r--spec/unit/provider/apt_repository_spec.rb129
-rw-r--r--spec/unit/provider/link_spec.rb2
-rw-r--r--spec/unit/provider/package/bff_spec.rb (renamed from spec/unit/provider/package/aix_spec.rb)8
-rw-r--r--spec/unit/provider/remote_directory_spec.rb2
-rw-r--r--spec/unit/provider_resolver_spec.rb6
-rw-r--r--spec/unit/resource/portage_package_spec.rb6
-rw-r--r--spec/unit/resource/registry_key_spec.rb6
-rw-r--r--spec/unit/resource/remote_file_spec.rb2
-rw-r--r--spec/unit/resource_inspector_spec.rb60
-rw-r--r--spec/unit/resource_reporter_spec.rb2
-rw-r--r--spec/unit/win32/security_spec.rb8
100 files changed, 958 insertions, 833 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f631699eb..16d0879972 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,15 +1,31 @@
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
-<!-- latest_release 14.0.105 -->
-## [v14.0.105](https://github.com/chef/chef/tree/v14.0.105) (2018-03-03)
+<!-- latest_release 14.0.121 -->
+## [v14.0.121](https://github.com/chef/chef/tree/v14.0.121) (2018-03-07)
#### Merged Pull Requests
-- Add Ubuntu 18.04 Testing in Travis [#6937](https://github.com/chef/chef/pull/6937) ([tas50](https://github.com/tas50))
+- Rename bff provider to match its resource [#6956](https://github.com/chef/chef/pull/6956) ([tas50](https://github.com/tas50))
<!-- latest_release -->
<!-- release_rollup since=13.7.16 -->
### Changes since 13.7.16 release
#### Merged Pull Requests
+- Rename bff provider to match its resource [#6956](https://github.com/chef/chef/pull/6956) ([tas50](https://github.com/tas50)) <!-- 14.0.121 -->
+- Convert more set_or_returns to proper properties [#6950](https://github.com/chef/chef/pull/6950) ([tas50](https://github.com/tas50)) <!-- 14.0.120 -->
+- Remove explicit setting of @provider and depend on ProviderResolver [#6958](https://github.com/chef/chef/pull/6958) ([jasonwbarnett](https://github.com/jasonwbarnett)) <!-- 14.0.119 -->
+- remove deprecated property namespace collisions [#6952](https://github.com/chef/chef/pull/6952) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.0.118 -->
+- Added source_file to FromFile [#6938](https://github.com/chef/chef/pull/6938) ([zfjagann](https://github.com/zfjagann)) <!-- 14.0.117 -->
+- Avoid compile time error in apt_repository [#6953](https://github.com/chef/chef/pull/6953) ([tas50](https://github.com/tas50)) <!-- 14.0.116 -->
+- Remove support for Windows 2003 [#6923](https://github.com/chef/chef/pull/6923) ([tas50](https://github.com/tas50)) <!-- 14.0.115 -->
+- add a utility to dump info about resources [#6896](https://github.com/chef/chef/pull/6896) ([thommay](https://github.com/thommay)) <!-- 14.0.114 -->
+- Don&#39;t use supervisor process for one-shot / command-line runs [#6914](https://github.com/chef/chef/pull/6914) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.0.113 -->
+- Add attribute hoisting into core [#6927](https://github.com/chef/chef/pull/6927) ([jonlives](https://github.com/jonlives)) <!-- 14.0.112 -->
+- Add more description fields, style fixes, add missing requires [#6943](https://github.com/chef/chef/pull/6943) ([tas50](https://github.com/tas50)) <!-- 14.0.111 -->
+- registry_key: Properly limit allowed values for architecture [#6947](https://github.com/chef/chef/pull/6947) ([tas50](https://github.com/tas50)) <!-- 14.0.110 -->
+- Modernize provides in the portage_package resource [#6903](https://github.com/chef/chef/pull/6903) ([tas50](https://github.com/tas50)) <!-- 14.0.109 -->
+- Set properties in git resource using our resource DSL [#6902](https://github.com/chef/chef/pull/6902) ([tas50](https://github.com/tas50)) <!-- 14.0.108 -->
+- Use the existing helper method for package resource classes that don&#39;t support allow_downgrade [#6942](https://github.com/chef/chef/pull/6942) ([coderanger](https://github.com/coderanger)) <!-- 14.0.107 -->
+- Apt repo cleanup and testing expansion [#6498](https://github.com/chef/chef/pull/6498) ([tas50](https://github.com/tas50)) <!-- 14.0.106 -->
- Add Ubuntu 18.04 Testing in Travis [#6937](https://github.com/chef/chef/pull/6937) ([tas50](https://github.com/tas50)) <!-- 14.0.105 -->
- Update our tests based on new resources we ship [#6939](https://github.com/chef/chef/pull/6939) ([tas50](https://github.com/tas50)) <!-- 14.0.104 -->
- Allow specifying a comment for routes [#6929](https://github.com/chef/chef/pull/6929) ([tomdoherty](https://github.com/tomdoherty)) <!-- 14.0.103 -->
diff --git a/Gemfile.lock b/Gemfile.lock
index 771ce42307..7c2bf52d5b 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -8,10 +8,10 @@ GIT
GIT
remote: https://github.com/chef/ohai.git
- revision: 159c9046b14e86969d1e2373c4e28cb67ef3bc08
+ revision: 20305d8791869f36b7c54558e3c631e0c508ecc5
branch: master
specs:
- ohai (14.0.21)
+ ohai (14.0.23)
chef-config (>= 12.8, < 15)
ffi (~> 1.9)
ffi-yajl (~> 2.2)
@@ -27,10 +27,10 @@ GIT
PATH
remote: .
specs:
- chef (14.0.105)
+ chef (14.0.121)
addressable
bundler (>= 1.10)
- chef-config (= 14.0.105)
+ chef-config (= 14.0.121)
chef-zero (>= 13.0)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
@@ -57,10 +57,10 @@ PATH
specinfra (~> 2.10)
syslog-logger (~> 1.6)
uuidtools (~> 2.1.5)
- chef (14.0.105-universal-mingw32)
+ chef (14.0.121-universal-mingw32)
addressable
bundler (>= 1.10)
- chef-config (= 14.0.105)
+ chef-config (= 14.0.121)
chef-zero (>= 13.0)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
@@ -102,7 +102,7 @@ PATH
PATH
remote: chef-config
specs:
- chef-config (14.0.105)
+ chef-config (14.0.121)
addressable
fuzzyurl
mixlib-config (~> 2.0)
diff --git a/VERSION b/VERSION
index b135d0e778..71ca91d42e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-14.0.105 \ No newline at end of file
+14.0.121 \ No newline at end of file
diff --git a/bin/chef-resource-inspector b/bin/chef-resource-inspector
new file mode 100755
index 0000000000..6a7eac0c32
--- /dev/null
+++ b/bin/chef-resource-inspector
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+#
+# ./chef-resource-inspector - Find information about a resource
+#
+# Copyright:: Copyright (c) 2018, Chef Software, Inc
+# 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.
+
+Encoding.default_external = Encoding::UTF_8
+
+$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
+
+require "chef/resource_inspector"
+
+ResourceInspector.start
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index d5badcc58f..9d11ba9dc4 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -4,7 +4,7 @@
# Author:: AJ Christensen (<aj@chef.io>)
# Author:: Mark Mzyk (<mmzyk@chef.io>)
# Author:: Kyle Goodwin (<kgoodwin@primerevenue.com>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -440,7 +440,7 @@ module ChefConfig
default :splay, nil
default :why_run, false
default :color, false
- default :client_fork, true
+ default :client_fork, nil
default :ez, false
default :enable_reporting, true
default :enable_reporting_url_fatals, false
diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb
index f3a06a9ee5..94609a93c7 100644
--- a/chef-config/lib/chef-config/version.rb
+++ b/chef-config/lib/chef-config/version.rb
@@ -21,7 +21,7 @@
module ChefConfig
CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__)
- VERSION = "14.0.105"
+ VERSION = "14.0.121"
end
#
diff --git a/kitchen-tests/cookbooks/base/recipes/packages.rb b/kitchen-tests/cookbooks/base/recipes/packages.rb
index fc65a2d8f7..f8ceb342ad 100644
--- a/kitchen-tests/cookbooks/base/recipes/packages.rb
+++ b/kitchen-tests/cookbooks/base/recipes/packages.rb
@@ -15,7 +15,7 @@ pkgs.each do |pkg|
multipackage pkgs
end
-gems = %w{fpm aws-sdk}
+gems = %w{fpm community_cookbook_releaser}
gems.each do |gem|
chef_gem gem do
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index 0834e5f037..706ba93ca0 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -2,7 +2,7 @@
# Author:: AJ Christensen (<aj@chef.io)
# Author:: Christopher Brown (<cb@chef.io>)
# Author:: Mark Mzyk (mmzyk@chef.io)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -228,8 +228,7 @@ class Chef::Application::Client < Chef::Application
option :client_fork,
:short => "-f",
:long => "--[no-]fork",
- :description => "Fork client",
- :boolean => true
+ :description => "Fork client"
option :recipe_url,
:long => "--recipe-url=RECIPE_URL",
@@ -362,6 +361,11 @@ class Chef::Application::Client < Chef::Application
Chef::Config[:splay] = nil
end
+ # supervisor processes are enabled by default for interval-running processes but not for one-shot runs
+ if Chef::Config[:client_fork].nil?
+ Chef::Config[:client_fork] = !!Chef::Config[:interval]
+ end
+
if !Chef::Config[:client_fork] && Chef::Config[:interval] && !Chef::Platform.windows?
Chef::Application.fatal!(unforked_interval_error_message)
end
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index 6b4aef42b4..f8502edc38 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -1,7 +1,7 @@
#
# Author:: AJ Christensen (<aj@chef.io>)
# Author:: Mark Mzyk (mmzyk@chef.io)
-# Copyright:: Copyright 2008-2018, Chef Software, Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -175,8 +175,7 @@ class Chef::Application::Solo < Chef::Application
option :client_fork,
:short => "-f",
:long => "--[no-]fork",
- :description => "Fork client",
- :boolean => true
+ :description => "Fork client"
option :why_run,
:short => "-W",
@@ -261,6 +260,11 @@ class Chef::Application::Solo < Chef::Application
Chef::Config[:interval] ||= 1800
end
+ # supervisor processes are enabled by default for interval-running processes but not for one-shot runs
+ if Chef::Config[:client_fork].nil?
+ Chef::Config[:client_fork] = !!Chef::Config[:interval]
+ end
+
Chef::Application.fatal!(unforked_interval_error_message) if !Chef::Config[:client_fork] && Chef::Config[:interval]
if Chef::Config[:recipe_url]
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index 549872bfd7..f5466ae145 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -55,8 +55,7 @@ class Chef
default :event_loggers do
evt_loggers = []
- if ChefConfig.windows? && !(Chef::Platform.windows_server_2003? ||
- Chef::Platform.windows_nano_server?)
+ if ChefConfig.windows? && !Chef::Platform.windows_nano_server?
evt_loggers << :win_evt
end
evt_loggers
diff --git a/lib/chef/dsl/reboot_pending.rb b/lib/chef/dsl/reboot_pending.rb
index fdd0f5a62b..2ebad7e039 100644
--- a/lib/chef/dsl/reboot_pending.rb
+++ b/lib/chef/dsl/reboot_pending.rb
@@ -44,14 +44,7 @@ class Chef
registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') ||
# Vista + Server 2008 and newer may have reboots pending from CBS
- registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending') ||
-
- # The mere existence of the UpdateExeVolatile key should indicate a pending restart for certain updates
- # http://support.microsoft.com/kb/832475
- Chef::Platform.windows_server_2003? &&
- (registry_key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') &&
- !registry_get_values('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').select { |v| v[:name] == "Flags" }[0].nil? &&
- [1, 2, 3].include?(registry_get_values('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').select { |v| v[:name] == "Flags" }[0][:data]))
+ registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending')
elsif platform?("ubuntu")
# This should work for Debian as well if update-notifier-common happens to be installed. We need an API for that.
File.exists?("/var/run/reboot-required")
diff --git a/lib/chef/mixin/from_file.rb b/lib/chef/mixin/from_file.rb
index 4afea5d9f4..e19597dde8 100644
--- a/lib/chef/mixin/from_file.rb
+++ b/lib/chef/mixin/from_file.rb
@@ -21,11 +21,15 @@ class Chef
module Mixin
module FromFile
+ # Source path from which the object was loaded
+ attr_accessor :source_file
+
# Loads a given ruby file, and runs instance_eval against it in the context of the current
# object.
#
# Raises an IOError if the file cannot be found, or is not readable.
def from_file(filename)
+ self.source_file = filename
if File.exists?(filename) && File.readable?(filename)
instance_eval(IO.read(filename), filename, 1)
else
@@ -38,6 +42,7 @@ class Chef
#
# Raises an IOError if the file cannot be found, or is not readable.
def class_from_file(filename)
+ self.source_file = filename
if File.exists?(filename) && File.readable?(filename)
class_eval(IO.read(filename), filename, 1)
else
diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb
index 624dc05e9c..b49010efc0 100644
--- a/lib/chef/platform/query_helpers.rb
+++ b/lib/chef/platform/query_helpers.rb
@@ -24,18 +24,6 @@ class Chef
ChefConfig.windows?
end
- def windows_server_2003?
- # WMI startup shouldn't be performed unless we're on Windows.
- return false unless windows?
- require "wmi-lite/wmi"
-
- wmi = WmiLite::Wmi.new
- host = wmi.first_of("Win32_OperatingSystem")
- is_server_2003 = (host["version"] && host["version"].start_with?("5.2"))
-
- is_server_2003
- end
-
def windows_nano_server?
return false unless windows?
require "win32/registry"
diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb
index 545d36cb0e..e1293190f8 100644
--- a/lib/chef/policy_builder/policyfile.rb
+++ b/lib/chef/policy_builder/policyfile.rb
@@ -263,6 +263,16 @@ class Chef
def apply_policyfile_attributes
node.attributes.role_default = policy["default_attributes"]
node.attributes.role_override = policy["override_attributes"]
+ hoist_policyfile_attributes(node.policy_group) if node.policy_group
+ end
+
+ # @api private
+ #
+ # Hoists attributes from role_X[policy_group] up to the equivalent role_X level
+ def hoist_policyfile_attributes(policy_group)
+ Chef::Log.debug("Running attribute Hoist for group #{policy_group}")
+ Chef::Mixin::DeepMerge.hash_only_merge!(node.role_default, node.role_default[policy_group]) if node.role_default.include?(policy_group)
+ Chef::Mixin::DeepMerge.hash_only_merge!(node.role_override, node.role_override[policy_group]) if node.role_override.include?(policy_group)
end
# @api private
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index 7cb2301772..6971465b0a 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -342,45 +342,16 @@ class Chef
extend Forwardable
define_singleton_method(:to_s) { "forwarder module for #{provider_class}" }
define_singleton_method(:inspect) { to_s }
- # Add a delegator for each explicit property that will get the *current* value
- # of the property by default instead of the *actual* value.
- resource.class.properties.each_key do |name|
- class_eval(<<-EOM, __FILE__, __LINE__)
- def #{name}(*args, &block)
- # If no arguments were passed, we process "get" by defaulting
- # the value to current_resource, not new_resource. This helps
- # avoid issues where resources accidentally overwrite perfectly
- # valid stuff with default values.
- #
- # This magic is to make this kind of thing easy:
- #
- # FileUtils.chown new_resource.mode.nil? ? current_resource.mode : new_resource.mode, new_resource.path
- #
- # We do this in the file provider where we need to construct a new filesystem object and
- # when the new_resource is nil/default that means "preserve the current stuff" and does not
- # mean to ignore it which will wind up defaulting to changing the file to have a "root"
- # ownership if anything else changes. Its kind of overly clever and magical, and most likely
- # gets the use case wrong where someone has a property that they really mean to default to
- # some value which /should/ get set if its left as the default and where the default is
- # meant to be declarative. Instead of property_is_set? we should most likely be using
- # nil? but we're going to deprecate all of it anyway. Just type out what you really mean longhand.
- #
- if args.empty? && !block
- if !new_resource.property_is_set?(__method__) && current_resource
- Chef.deprecated(:namespace_collisions, "rename #{name} to current_resource.#{name}")
- return current_resource.public_send(__method__)
- end
- end
- Chef.deprecated(:namespace_collisions, "rename #{name} to new_resource.#{name}")
- new_resource.public_send(__method__, *args, &block)
- end
- EOM
- end
+ # this magic, stated simply, is that any instance method declared directly on
+ # the resource we are building, will be accessible from the action_class(provider)
+ # instance. methods declared on Chef::Resource and properties are not inherited.
dsl_methods =
resource.class.public_instance_methods +
resource.class.protected_instance_methods -
provider_class.instance_methods -
- resource.class.properties.keys
+ resource.class.properties.keys -
+ resource.class.properties.keys.map { |k| "#{k}=".to_sym } -
+ Chef::Resource.instance_methods
def_delegators(:new_resource, *dsl_methods)
end
include @included_resource_dsl_module
diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb
index c16f1e5767..6bbb052792 100644
--- a/lib/chef/provider/apt_repository.rb
+++ b/lib/chef/provider/apt_repository.rb
@@ -29,14 +29,15 @@ class Chef
provides :apt_repository, platform_family: "debian"
- LIST_APT_KEYS = "apt-key list".freeze
LIST_APT_KEY_FINGERPRINTS = "apt-key adv --list-public-keys --with-fingerprint --with-colons".freeze
def load_current_resource
end
action :add do
- unless new_resource.key.nil?
+ if new_resource.key.nil?
+ Chef::Log.debug "No 'key' property specified skipping key import"
+ else
new_resource.key.each do |k|
if is_key_id?(k) && !has_cookbook_file?(k)
install_key_from_keyserver(k)
@@ -56,16 +57,10 @@ class Chef
action :nothing
end
- components = if is_ppa_url?(new_resource.uri) && new_resource.components.empty?
- "main"
- else
- new_resource.components
- end
-
repo = build_repo(
new_resource.uri,
new_resource.distribution,
- components,
+ repo_components,
new_resource.trusted,
new_resource.arch,
new_resource.deb_src
@@ -96,19 +91,27 @@ class Chef
ignore_failure true
action :nothing
end
-
end
+ else
+ Chef::Log.debug("/etc/apt/sources.list.d/#{new_resource.name}.list does not exist. Nothing to do")
end
end
+ # is the provided ID a key ID from a keyserver. Looks at length and HEX only values
+ # @param [String] id the key value passed by the user that *may* be an ID
def is_key_id?(id)
id = id[2..-1] if id.start_with?("0x")
id =~ /^\h+$/ && [8, 16, 40].include?(id.length)
end
+ # run the specified command and extract the fingerprints from the output
+ # accepts a command so it can be used to extract both the current key's fingerprints
+ # and the fingerprint of the new key
+ # @param [String] cmd the command to run
+ #
+ # @return [Array] an array of fingerprints
def extract_fingerprints_from_cmd(cmd)
so = shell_out(cmd)
- so.run_command
so.stdout.split(/\n/).map do |t|
if z = t.match(/^fpr:+([0-9A-F]+):/)
z[1].split.join
@@ -116,11 +119,14 @@ class Chef
end.compact
end
- def key_is_valid?(cmd, key)
+ # validate the key against the apt keystore to see if that version is expired
+ # @param [String] key
+ #
+ # @return [Boolean] is the key valid or not
+ def key_is_valid?(key)
valid = true
- so = shell_out(cmd)
- so.run_command
+ so = shell_out("apt-key list")
so.stdout.split(/\n/).map do |t|
if t =~ %r{^\/#{key}.*\[expired: .*\]$}
Chef::Log.debug "Found expired key: #{t}"
@@ -133,14 +139,27 @@ class Chef
valid
end
+ # return the specified cookbook name or the cookbook containing the
+ # resource.
+ #
+ # @return [String] name of the cookbook
def cookbook_name
new_resource.cookbook || new_resource.cookbook_name
end
+ # determine if a cookbook file is available in the run
+ # @param [String] path the path to the cookbook file
+ #
+ # @return [Boolean] cookbook file exists or doesn't
def has_cookbook_file?(fn)
run_context.has_cookbook_file_in_cookbook?(cookbook_name, fn)
end
+ # determine if there are any new keys by comparing the fingerprints of installed
+ # keys to those of the passed file
+ # @param [String] file the keyfile of the new repository
+ #
+ # @return [Boolean] true: no new keys in the file. false: there are new keys
def no_new_keys?(file)
# Now we are using the option --with-colons that works across old os versions
# as well as the latest (16.10). This for both `apt-key` and `gpg` commands
@@ -149,37 +168,56 @@ class Chef
(installed_keys & proposed_keys).sort == proposed_keys.sort
end
+ # Given the provided key URI determine what kind of chef resource we need
+ # to fetch the key
+ # @param [String] uri the uri of the gpg key (local path or http URL)
+ #
+ # @raise [Chef::Exceptions::FileNotFound] Key isn't remote or found in the current run
+ #
+ # @return [Symbol] :remote_file or :cookbook_file
+ def key_type(uri)
+ if uri.start_with?("http")
+ :remote_file
+ elsif has_cookbook_file?(uri)
+ :cookbook_file
+ else
+ raise Chef::Exceptions::FileNotFound, "Cannot locate key file: #{uri}"
+ end
+ end
+
+ # Fetch the key using either cookbook_file or remote_file, validate it,
+ # and install it with apt-key add
+ # @param [String] key the key to install
+ #
+ # @raise [RuntimeError] Invalid key which can't verify the apt repository
+ #
+ # @return [void]
def install_key_from_uri(key)
key_name = key.gsub(/[^0-9A-Za-z\-]/, "_")
cached_keyfile = ::File.join(Chef::Config[:file_cache_path], key_name)
- type = if key.start_with?("http")
- :remote_file
- elsif has_cookbook_file?(key)
- :cookbook_file
- else
- raise Chef::Exceptions::FileNotFound, "Cannot locate key file"
- end
- declare_resource(type, cached_keyfile) do
+ declare_resource(key_type(key), cached_keyfile) do
source key
mode "0644"
sensitive new_resource.sensitive
action :create
+ verify "gpg %{path}"
end
- raise "The key #{cached_keyfile} is invalid and cannot be used to verify an apt repository." unless key_is_valid?("gpg #{cached_keyfile}", "")
-
declare_resource(:execute, "apt-key add #{cached_keyfile}") do
sensitive new_resource.sensitive
action :run
- not_if do
- no_new_keys?(cached_keyfile)
- end
+ not_if { no_new_keys?(cached_keyfile) }
notifies :run, "execute[apt-cache gencaches]", :immediately
end
end
- def install_key_from_keyserver(key, keyserver = new_resource.keyserver)
+ # build the apt-key command to install the keyserver
+ # @param [String] key the key to install
+ # @param [String] keyserver the key server to use
+ #
+ # @return [String] the full apt-key command to run
+ def keyserver_install_cmd(key, keyserver)
cmd = "apt-key adv --recv"
cmd << " --keyserver-options http-proxy=#{new_resource.key_proxy}" if new_resource.key_proxy
cmd << " --keyserver "
@@ -190,22 +228,37 @@ class Chef
end
cmd << " #{key}"
+ cmd
+ end
+ # @param [String] key
+ # @param [String] keyserver
+ #
+ # @raise [RuntimeError] Invalid key which can't verify the apt repository
+ #
+ # @return [void]
+ def install_key_from_keyserver(key, keyserver = new_resource.keyserver)
declare_resource(:execute, "install-key #{key}") do
- command cmd
+ command keyserver_install_cmd(key, keyserver)
sensitive new_resource.sensitive
not_if do
present = extract_fingerprints_from_cmd(LIST_APT_KEY_FINGERPRINTS).any? do |fp|
fp.end_with? key.upcase
end
- present && key_is_valid?(LIST_APT_KEYS, key.upcase)
+ present && key_is_valid?(key.upcase)
end
notifies :run, "execute[apt-cache gencaches]", :immediately
end
- raise "The key #{key} is invalid and cannot be used to verify an apt repository." unless key_is_valid?(LIST_APT_KEYS, key.upcase)
+ raise "The key #{key} is invalid and cannot be used to verify an apt repository." unless key_is_valid?(key.upcase)
end
+ # @param [String] owner
+ # @param [String] repo
+ #
+ # @raise [RuntimeError] Could not access the Launchpad PPA API
+ #
+ # @return [void]
def install_ppa_key(owner, repo)
url = "https://launchpad.net/api/1.0/~#{owner}/+archive/#{repo}"
key_id = Chef::HTTP::Simple.new(url).get("signing_key_fingerprint").delete('"')
@@ -214,12 +267,33 @@ class Chef
raise "Could not access Launchpad ppa API: #{e.message}"
end
+ # determine if the repository URL is a PPA
+ # @param [String] url the url of the repository
+ #
+ # @return [Boolean] is the repo URL a PPA
def is_ppa_url?(url)
url.start_with?("ppa:")
end
+ # determine the repository's components:
+ # - "components" property if defined
+ # - "main" if "components" not defined and the repo is a PPA URL
+ # - otherwise nothing
+ #
+ # @return [String] the repository component
+ def repo_components
+ if is_ppa_url?(new_resource.uri) && new_resource.components.empty?
+ "main"
+ else
+ new_resource.components
+ end
+ end
+
+ # given a PPA return a PPA URL in http://ppa.launchpad.net format
+ # @param [String] ppa the ppa URL
+ #
+ # @return [String] full PPA URL
def make_ppa_url(ppa)
- return unless is_ppa_url?(ppa)
owner, repo = ppa[4..-1].split("/")
repo ||= "ppa"
@@ -227,6 +301,14 @@ class Chef
"http://ppa.launchpad.net/#{owner}/#{repo}/ubuntu"
end
+ # build complete repo text that will be written to the config
+ # @param [String] uri
+ # @param [Array] components
+ # @param [Boolean] trusted
+ # @param [String] arch
+ # @param [Boolean] add_src
+ #
+ # @return [String] complete repo config text
def build_repo(uri, distribution, components, trusted, arch, add_src = false)
uri = make_ppa_url(uri) if is_ppa_url?(uri)
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index df3f2a46b1..9bfe94d5d0 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -480,7 +480,7 @@ class Chef
elsif current_version.nil?
Chef::Log.debug("#{new_resource} has no existing installed version. Installing install #{candidate_version}")
target_version_array.push(candidate_version)
- elsif version_compare(current_version, candidate_version) == 1 && !new_resource.allow_downgrade
+ elsif version_compare(current_version, candidate_version) == 1 && !allow_downgrade
Chef::Log.debug("#{new_resource} #{package_name} has installed version #{current_version}, which is newer than available version #{candidate_version}. Skipping...)")
target_version_array.push(nil)
else
diff --git a/lib/chef/provider/package/aix.rb b/lib/chef/provider/package/bff.rb
index b013b3d8ce..9a2ccd25b4 100644
--- a/lib/chef/provider/package/aix.rb
+++ b/lib/chef/provider/package/bff.rb
@@ -23,10 +23,10 @@ require "chef/mixin/get_source_from_package"
class Chef
class Provider
class Package
- class Aix < Chef::Provider::Package
+ class Bff < Chef::Provider::Package
provides :package, os: "aix"
- provides :bff_package, os: "aix"
+ provides :bff_package
include Chef::Mixin::GetSourceFromPackage
diff --git a/lib/chef/provider/package/macports.rb b/lib/chef/provider/package/macports.rb
index ad4be00477..514f3580d4 100644
--- a/lib/chef/provider/package/macports.rb
+++ b/lib/chef/provider/package/macports.rb
@@ -91,7 +91,7 @@ class Chef
raise Chef::Exceptions::Package, "Could not read from STDOUT on command: #{command}"
end
unless status.exitstatus == 0 || status.exitstatus == 1
- raise Chef::Exceptions::Package, "#{command} failed - #{status.insect}!"
+ raise Chef::Exceptions::Package, "#{command} failed - #{status.inspect}!"
end
output
end
diff --git a/lib/chef/provider/package/portage.rb b/lib/chef/provider/package/portage.rb
index 05a5df370e..e43e71f210 100644
--- a/lib/chef/provider/package/portage.rb
+++ b/lib/chef/provider/package/portage.rb
@@ -17,7 +17,7 @@
#
require "chef/provider/package"
-require "chef/resource/package"
+require "chef/resource/portage_package"
require "chef/util/path_helper"
class Chef
diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb
index 9783b3b3a5..2ff7de1138 100644
--- a/lib/chef/provider/service/upstart.rb
+++ b/lib/chef/provider/service/upstart.rb
@@ -34,6 +34,7 @@ class Chef
UPSTART_STATE_FORMAT = /\S+ \(?(start|stop)?\)? ?[\/ ](\w+)/
+ # Returns true if the configs for the service name has upstart variable
def self.supports?(resource, action)
Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:upstart)
end
diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb
index 8b07e1b405..1b9aa84697 100644
--- a/lib/chef/providers.rb
+++ b/lib/chef/providers.rb
@@ -81,7 +81,7 @@ require "chef/provider/package/yum"
require "chef/provider/package/zypper"
require "chef/provider/package/solaris"
require "chef/provider/package/smartos"
-require "chef/provider/package/aix"
+require "chef/provider/package/bff"
require "chef/provider/package/cab"
require "chef/provider/package/powershell"
require "chef/provider/package/msu"
diff --git a/lib/chef/resource/apt_package.rb b/lib/chef/resource/apt_package.rb
index ea0c9c6183..22680d5b44 100644
--- a/lib/chef/resource/apt_package.rb
+++ b/lib/chef/resource/apt_package.rb
@@ -23,7 +23,7 @@ class Chef
class Resource
class AptPackage < Chef::Resource::Package
resource_name :apt_package
- provides :package, os: "linux", platform_family: "debian"
+ provides :package, platform_family: "debian"
description "Use the apt_package resource to manage packages on Debian and Ubuntu platforms."
diff --git a/lib/chef/resource/bff_package.rb b/lib/chef/resource/bff_package.rb
index f67d6d253e..62838cfd60 100644
--- a/lib/chef/resource/bff_package.rb
+++ b/lib/chef/resource/bff_package.rb
@@ -17,11 +17,13 @@
#
require "chef/resource/package"
-require "chef/provider/package/aix"
class Chef
class Resource
class BffPackage < Chef::Resource::Package
+ resource_name :bff_package
+ provides :bff_package
+
description "Use the bff_package resource to manage packages for the AIX platform"\
" using the installp utility. When a package is installed from a local"\
" file, it must be added to the node using the remote_file or cookbook_file"\
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb
index 881f932b30..8977444692 100644
--- a/lib/chef/resource/build_essential.rb
+++ b/lib/chef/resource/build_essential.rb
@@ -22,7 +22,12 @@ class Chef
resource_name :build_essential
provides :build_essential
- property :compile_time, [true, false], default: false
+ description "Use the build_essential resource to install packages required for compiling C software from source"
+ introduced "14.0"
+
+ property :compile_time, [TrueClass, FalseClass],
+ description: "Install build essential packages at compile time.",
+ default: false
action :install do
case node["platform_family"]
diff --git a/lib/chef/resource/chef_gem.rb b/lib/chef/resource/chef_gem.rb
index b6bbd0e209..3304690901 100644
--- a/lib/chef/resource/chef_gem.rb
+++ b/lib/chef/resource/chef_gem.rb
@@ -40,7 +40,7 @@ class Chef
callbacks: {
"The chef_gem resource is restricted to the current gem environment, use gem_package to install to other environments." => proc { |v| v == "#{RbConfig::CONFIG['bindir']}/gem" },
}
- property :compile_time, [ true, false ], default: false, desired_state: false
+ property :compile_time, [TrueClass, FalseClass], default: false, desired_state: false
# force the resource to compile time if the compile time property has been set
def after_created
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index f6c009058c..32c47b963f 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -18,6 +18,7 @@
#
require "chef/resource"
+require "chef/provider/cron" # do not remove. we actually need this below
class Chef
class Resource
@@ -135,14 +136,7 @@ class Chef
)
end
- def time(arg = nil)
- set_or_return(
- :time,
- arg,
- :equal_to => Chef::Provider::Cron::SPECIAL_TIME_VALUES
- )
- end
-
+ property :time, Symbol, equal_to: Chef::Provider::Cron::SPECIAL_TIME_VALUES
property :mailto, String
property :path, String
property :home, String
diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb
index 95ee32c946..3f7fc17901 100644
--- a/lib/chef/resource/dsc_resource.rb
+++ b/lib/chef/resource/dsc_resource.rb
@@ -74,13 +74,7 @@ class Chef
end
end
- def module_version(arg = nil)
- set_or_return(
- :module_version,
- arg,
- :kind_of => [ String ]
- )
- end
+ property :module_version, String
def property(property_name, value = nil)
if not property_name.is_a?(Symbol)
@@ -113,13 +107,7 @@ class Chef
end
end
- def timeout(arg = nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [ Integer ]
- )
- end
+ property :timeout, Integer
private
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb
index 45372c091a..f64780e2bc 100644
--- a/lib/chef/resource/dsc_script.rb
+++ b/lib/chef/resource/dsc_script.rb
@@ -114,37 +114,10 @@ class Chef
end
end
- def flags(arg = nil)
- set_or_return(
- :flags,
- arg,
- :kind_of => [ Hash ]
- )
- end
-
- def cwd(arg = nil)
- set_or_return(
- :cwd,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def environment(arg = nil)
- set_or_return(
- :environment,
- arg,
- :kind_of => [ Hash ]
- )
- end
-
- def timeout(arg = nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [ Integer ]
- )
- end
+ property :flags, Hash
+ property :cwd, String
+ property :environment, Hash
+ property :timeout, Integer
end
end
end
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index 0c1b187ed0..f8baedd082 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -43,25 +43,8 @@ class Chef
super
@command = name
@backup = 5
- @creates = nil
- @cwd = nil
- @environment = nil
- @group = nil
- @returns = 0
- @timeout = nil
- @user = nil
- @umask = nil
@default_guard_interpreter = :execute
@is_guard_interpreter = false
- @live_stream = false
- end
-
- def umask(arg = nil)
- set_or_return(
- :umask,
- arg,
- :kind_of => [ String, Integer ]
- )
end
def command(arg = nil)
@@ -71,68 +54,19 @@ class Chef
:kind_of => [ String, Array ]
)
end
-
- def creates(arg = nil)
- set_or_return(
- :creates,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def cwd(arg = nil)
- set_or_return(
- :cwd,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def environment(arg = nil)
- set_or_return(
- :environment,
- arg,
- :kind_of => [ Hash ]
- )
- end
+ property :umask, [ String, Integer ]
+ property :creates, String
+ property :cwd, String
+ property :environment, Hash
alias :env :environment
- def group(arg = nil)
- set_or_return(
- :group,
- arg,
- :kind_of => [ String, Integer ]
- )
- end
-
- def live_stream(arg = nil)
- set_or_return(
- :live_stream,
- arg,
- :kind_of => [ TrueClass, FalseClass ])
- end
-
- def returns(arg = nil)
- set_or_return(
- :returns,
- arg,
- :kind_of => [ Integer, Array ]
- )
- end
-
- def timeout(arg = nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [ Integer, Float ]
- )
- end
-
+ property :group, [ String, Integer ]
+ property :live_stream, [ TrueClass, FalseClass ], default: false
+ property :returns, [ Integer, Array ], default: 0
+ property :timeout, [ Integer, Float ]
property :user, [ String, Integer ]
-
property :domain, String
-
property :password, String, sensitive: true
# lazy used to set default value of sensitive to true if password is set
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index 98341ff940..341b106720 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -52,13 +52,13 @@ class Chef
allowed_actions :create, :delete, :touch, :create_if_missing
property :path, String, name_property: true, identity: true
- property :atomic_update, [ true, false ], desired_state: false, default: lazy { |r| r.docker? && r.special_docker_files?(r.path) ? false : Chef::Config[:file_atomic_update] }
+ property :atomic_update, [ TrueClass, FalseClass ], desired_state: false, default: lazy { |r| r.docker? && r.special_docker_files?(r.path) ? false : Chef::Config[:file_atomic_update] }
property :backup, [ Integer, false ], desired_state: false, default: 5
property :checksum, [ /^[a-zA-Z0-9]{64}$/, nil ]
property :content, [ String, nil ], desired_state: false
property :diff, [ String, nil ], desired_state: false
- property :force_unlink, [ true, false ], desired_state: false, default: false
- property :manage_symlink_source, [ true, false ], desired_state: false
+ property :force_unlink, [ TrueClass, FalseClass ], desired_state: false, default: false
+ property :manage_symlink_source, [ TrueClass, FalseClass ], desired_state: false
property :verifications, Array, default: lazy { [] }
def verify(command = nil, opts = {}, &block)
diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb
index 1f9bae614d..ee1262cb47 100644
--- a/lib/chef/resource/gem_package.rb
+++ b/lib/chef/resource/gem_package.rb
@@ -40,7 +40,7 @@ class Chef
# FIXME? the array form of installing paths most likely does not work?
#
property :source, [ String, Array ]
- property :clear_sources, [ true, false ], default: false, desired_state: false
+ property :clear_sources, [ TrueClass, FalseClass ], default: false, desired_state: false
# Sets a custom gem_binary to run for gem commands.
property :gem_binary, String, desired_state: false
diff --git a/lib/chef/resource/git.rb b/lib/chef/resource/git.rb
index 9f1702f715..58200815d4 100644
--- a/lib/chef/resource/git.rb
+++ b/lib/chef/resource/git.rb
@@ -21,27 +21,14 @@ require "chef/resource/scm"
class Chef
class Resource
class Git < Chef::Resource::Scm
-
description "Use the git resource to manage source control resources that exist"\
" in a git repository. git version 1.6.5 (or higher) is required to"\
" use all of the functionality in the git resource."
- def initialize(name, run_context = nil)
- super
- @additional_remotes = Hash[]
- end
-
- def additional_remotes(arg = nil)
- set_or_return(
- :additional_remotes,
- arg,
- :kind_of => Hash
- )
- end
+ property :additional_remotes, Hash, default: {}
alias :branch :revision
alias :reference :revision
-
alias :repo :repository
end
end
diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb
index 79a234cb54..9298fbc150 100644
--- a/lib/chef/resource/group.rb
+++ b/lib/chef/resource/group.rb
@@ -20,7 +20,6 @@
class Chef
class Resource
class Group < Chef::Resource
- identity_attr :group_name
state_attrs :members
description "Use the group resource to manage a local group."
@@ -30,29 +29,12 @@ class Chef
def initialize(name, run_context = nil)
super
- @group_name = name
- @gid = nil
@members = []
@excluded_members = []
- @append = false
- @non_unique = false
end
- def group_name(arg = nil)
- set_or_return(
- :group_name,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def gid(arg = nil)
- set_or_return(
- :gid,
- arg,
- :kind_of => [ String, Integer ]
- )
- end
+ property :group_name, String, name_property: true, identity: true
+ property :gid, [ String, Integer ]
def members(arg = nil)
converted_members = arg.is_a?(String) ? arg.split(",") : arg
@@ -74,29 +56,9 @@ class Chef
)
end
- def append(arg = nil)
- set_or_return(
- :append,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
-
- def system(arg = nil)
- set_or_return(
- :system,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
-
- def non_unique(arg = nil)
- set_or_return(
- :non_unique,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
+ property :append, [ TrueClass, FalseClass ], default: false
+ property :system, [ TrueClass, FalseClass ], default: false
+ property :non_unique, [ TrueClass, FalseClass ], default: false
end
end
end
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb
index 16986c09a3..dfc7ee2ff0 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -9,28 +9,23 @@ class Chef
description "Sets the systems hostname, ensures that reboot will preserve the hostname, and re-runs the ohai plugin so the hostname will be available in subsequent cookbooks."
introduced "14.0"
- property :hostname,
- String,
+ property :hostname, String,
description: "The hostname if different than the resource's name",
name_property: true
- property :compile_time,
- [ TrueClass, FalseClass ],
+ property :compile_time, [ TrueClass, FalseClass ],
description: "Should the resource run at compile time or not.",
default: true
- property :ipaddress,
- String,
+ property :ipaddress, String,
description: "The ip address to use when configuring the hosts file",
default: lazy { node["ipaddress"] }
- property :aliases,
- [ Array, nil ],
+ property :aliases, [ Array, nil ],
description: "An array of hostname aliases to use when configuring the hosts file",
default: nil
- property :windows_reboot,
- [ TrueClass, FalseClass ],
+ property :windows_reboot, [ TrueClass, FalseClass ],
description: "Should Windows nodes be rebooted upon changing the name so it can take effect",
default: true
diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb
index d3b782ea12..fd9e3636b1 100644
--- a/lib/chef/resource/http_request.rb
+++ b/lib/chef/resource/http_request.rb
@@ -24,8 +24,6 @@ class Chef
class Resource
class HttpRequest < Chef::Resource
- identity_attr :url
-
description "Use the http_request resource to send an HTTP request (GET, PUT,"\
" POST, DELETE, HEAD, or OPTIONS) with an arbitrary message. This"\
" resource is often useful when custom callbacks are necessary."
@@ -33,19 +31,12 @@ class Chef
default_action :get
allowed_actions :get, :patch, :put, :post, :delete, :head, :options
+ property :url, String, identity: true
+ property :headers, Hash, default: {}
+
def initialize(name, run_context = nil)
super
@message = name
- @url = nil
- @headers = {}
- end
-
- def url(args = nil)
- set_or_return(
- :url,
- args,
- :kind_of => String
- )
end
def message(args = nil, &block)
@@ -57,14 +48,6 @@ class Chef
)
end
- def headers(args = nil)
- set_or_return(
- :headers,
- args,
- :kind_of => Hash
- )
- end
-
end
end
end
diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb
index 88a9f182d4..079cc27231 100644
--- a/lib/chef/resource/ips_package.rb
+++ b/lib/chef/resource/ips_package.rb
@@ -30,7 +30,7 @@ class Chef
allowed_actions :install, :remove, :upgrade
- property :accept_license, [ true, false ], default: false, desired_state: false
+ property :accept_license, [TrueClass, FalseClass], default: false, desired_state: false
end
end
end
diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb
index d51d42b506..b3f8819d2b 100644
--- a/lib/chef/resource/link.rb
+++ b/lib/chef/resource/link.rb
@@ -35,10 +35,9 @@ class Chef
class Link < Chef::Resource
include Chef::Mixin::Securable
resource_name :link
+ provides :link
- identity_attr :target_file
-
- state_attrs :to, :owner, :group
+ state_attrs :owner # required since it's not a property below
default_action :create
allowed_actions :create, :delete
@@ -46,51 +45,13 @@ class Chef
def initialize(name, run_context = nil)
verify_links_supported!
super
- @to = nil
- @link_type = :symbolic
- @target_file = name
- end
-
- def to(arg = nil)
- set_or_return(
- :to,
- arg,
- :kind_of => String
- )
- end
-
- def target_file(arg = nil)
- set_or_return(
- :target_file,
- arg,
- :kind_of => String
- )
end
- def link_type(arg = nil)
- real_arg = arg.kind_of?(String) ? arg.to_sym : arg
- set_or_return(
- :link_type,
- real_arg,
- :equal_to => [ :symbolic, :hard ]
- )
- end
-
- def group(arg = nil)
- set_or_return(
- :group,
- arg,
- :regex => Chef::Config[:group_valid_regex]
- )
- end
-
- def owner(arg = nil)
- set_or_return(
- :owner,
- arg,
- :regex => Chef::Config[:user_valid_regex]
- )
- end
+ property :target_file, String, name_property: true, identity: true
+ property :to, String
+ property :link_type, [String, Symbol], coerce: proc { |arg| arg.kind_of?(String) ? arg.to_sym : arg }, equal_to: [ :symbolic, :hard ], default: :symbolic
+ property :group, [String, Integer], regex: [Chef::Config[:group_valid_regex]]
+ property :user, [String, Integer], regex: [Chef::Config[:user_valid_regex]]
# make link quack like a file (XXX: not for public consumption)
def path
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb
index c0066c84b5..45be356d1b 100644
--- a/lib/chef/resource/macos_userdefaults.rb
+++ b/lib/chef/resource/macos_userdefaults.rb
@@ -25,50 +25,41 @@ class Chef
provides :mac_os_x_userdefaults
provides :macos_userdefaults
- introduced "14.0"
-
description "Use the macos_userdefaults resource to manage the macOS user defaults"\
" system. The properties to the resource are passed to the defaults command"\
" and the parameters follow convention of the macOS command. See the defaults(1)"\
" man page for details on how the tool works."
+ introduced "14.0"
- property :domain,
- String,
+ property :domain, String,
description: "The domain the defaults belong to.",
required: true
- property :global,
- [true, false],
+ property :global, [TrueClass, FalseClass],
description: "Whether the domain is global.",
default: false
- property :key,
- String,
+ property :key, String,
description: "The preference key."
- property :value,
- [Integer, Float, String, true, false, Hash, Array],
+ property :value, [Integer, Float, String, TrueClass, FalseClass, Hash, Array],
description: "The value of the key.",
coerce: proc { |v| coerce_booleans(v) },
required: true
- property :type,
- String,
+ property :type, String,
description: "Value type of the preference key.",
default: ""
- property :user,
- String,
+ property :user, String,
description: "User for which to set the default."
- property :sudo,
- [true, false],
+ property :sudo, [TrueClass, FalseClass],
description: "Set to true if the setting requires privileged access to modify.",
default: false,
desired_state: false
- property :is_set,
- [true, false],
+ property :is_set, [TrueClass, FalseClass],
description: "",
default: false,
desired_state: false
diff --git a/lib/chef/resource/macosx_service.rb b/lib/chef/resource/macosx_service.rb
index a12add2109..9a88e3bbfc 100644
--- a/lib/chef/resource/macosx_service.rb
+++ b/lib/chef/resource/macosx_service.rb
@@ -25,6 +25,8 @@ class Chef
provides :macosx_service, os: "darwin"
provides :service, os: "darwin"
+ description "Use the macosx_service resource to manage services on the macOS platform."
+
identity_attr :service_name
state_attrs :enabled, :running
diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb
index e787529f48..254d7e7c5f 100644
--- a/lib/chef/resource/macports_package.rb
+++ b/lib/chef/resource/macports_package.rb
@@ -20,9 +20,10 @@ require "chef/resource/package"
class Chef
class Resource
- # Use the macports_package resource to manage packages for the macOS platform.
class MacportsPackage < Chef::Resource::Package
resource_name :macports_package
+
+ description "Use the macports_package resource to manage packages for the macOS platform."
end
end
end
diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb
index 6d4014b110..c8752ba038 100644
--- a/lib/chef/resource/mdadm.rb
+++ b/lib/chef/resource/mdadm.rb
@@ -21,13 +21,14 @@ require "chef/resource"
class Chef
class Resource
- # Use the mdadm resource to manage RAID devices in a Linux environment using the mdadm utility. The mdadm resource
- # will create and assemble an array, but it will not create the config file that is used to persist the array upon
- # reboot. If the config file is required, it must be done by specifying a template with the correct array layout,
- # and then by using the mount provider to create a file systems table (fstab) entry.
class Mdadm < Chef::Resource
resource_name :mdadm
+ description "Use the mdadm resource to manage RAID devices in a Linux environment using the mdadm utility. The mdadm resource"\
+ " will create and assemble an array, but it will not create the config file that is used to persist the array upon"\
+ " reboot. If the config file is required, it must be done by specifying a template with the correct array layout,"\
+ " and then by using the mount provider to create a file systems table (fstab) entry."
+
default_action :create
allowed_actions :create, :assemble, :stop
diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb
index f2534413ea..b506d511ba 100644
--- a/lib/chef/resource/ohai.rb
+++ b/lib/chef/resource/ohai.rb
@@ -19,12 +19,14 @@
class Chef
class Resource
- # Use the ohai resource to reload the Ohai configuration on a node. This allows recipes that change system attributes
- # (like a recipe that adds a user) to refer to those attributes later on during the chef-client run.
class Ohai < Chef::Resource
resource_name :ohai
provides :ohai
+ description "Use the ohai resource to reload the Ohai configuration on a node."\
+ " This allows recipes that change system attributes (like a recipe"\
+ " that adds a user) to refer to those attributes later on during the chef-client run."
+
property :ohai_name, name_property: true
property :plugin, [String]
diff --git a/lib/chef/resource/ohai_hint.rb b/lib/chef/resource/ohai_hint.rb
index 26b76806d7..90755300ca 100644
--- a/lib/chef/resource/ohai_hint.rb
+++ b/lib/chef/resource/ohai_hint.rb
@@ -21,17 +21,15 @@ class Chef
resource_name :ohai_hint
provides :ohai_hint
- description "A resource to pass hint data to Ohai to aid in configuration detection."
+ description "Use the ohai_hint resource to pass hint data to Ohai to aid in configuration detection."
introduced "14.0"
- property :hint_name,
- String,
- description: "The name of hints file if different from the resource name",
+ property :hint_name, String,
+ description: "The name of hints file if different from the resource name.",
name_property: true
- property :content,
- Hash,
- description: "Values to include in the hint file"
+ property :content, Hash,
+ description: "Values to include in the hint file."
property :compile_time,
[TrueClass, FalseClass],
diff --git a/lib/chef/resource/openssl_rsa_private_key.rb b/lib/chef/resource/openssl_rsa_private_key.rb
index 729d5a585a..352d802175 100644
--- a/lib/chef/resource/openssl_rsa_private_key.rb
+++ b/lib/chef/resource/openssl_rsa_private_key.rb
@@ -27,12 +27,12 @@ class Chef
provides :openssl_rsa_private_key
provides :openssl_rsa_key # legacy cookbook resource name
- introduced "14.0"
description "Use the openssl_rsa_private_key resource to generate RSA private key files."\
" If a valid RSA key file can be opened at the specified location, no new file"\
" will be created. If the RSA key file cannot be opened, either because it does"\
" not exist or because the password to the RSA key file does not match the"\
" password in the recipe, it will be overwritten."
+ introduced "14.0"
property :path, String,
description: "The path to write the file to it's different than the resource name.",
@@ -63,7 +63,7 @@ class Chef
description: "The permission mode of all files created by the resource.",
default: "0600"
- property :force, [true, false],
+ property :force, [TrueClass, FalseClass],
description: "Force creating the key even if the existing key exists.",
default: false
diff --git a/lib/chef/resource/osx_profile.rb b/lib/chef/resource/osx_profile.rb
index 56eca90a7e..cf857cec6f 100644
--- a/lib/chef/resource/osx_profile.rb
+++ b/lib/chef/resource/osx_profile.rb
@@ -20,23 +20,20 @@ require "chef/resource"
class Chef
class Resource
- # Use the osx_profile resource to manage configuration profiles (.mobileconfig files)
- # on the macOS platform. The osx_profile resource installs profiles by using
- # the uuidgen library to generate a unique ProfileUUID, and then using the
- # profiles command to install the profile on the system.
class OsxProfile < Chef::Resource
provides :osx_profile, os: "darwin"
provides :osx_config_profile, os: "darwin"
- identity_attr :profile_name
-
- description "12.7"
+ description "Use the osx_profile resource to manage configuration profiles (.mobileconfig files)"\
+ " on the macOS platform. The osx_profile resource installs profiles by using"\
+ " the uuidgen library to generate a unique ProfileUUID, and then using the"\
+ " profiles command to install the profile on the system."
+ introduced "12.7"
default_action :install
-
allowed_actions :install, :remove
- property :profile_name, String, name_property: true
+ property :profile_name, String, name_property: true, identity: true
property :profile, [ String, Hash ]
property :identifier, String
property :path, String
diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb
index a12039b555..6936f5129f 100644
--- a/lib/chef/resource/portage_package.rb
+++ b/lib/chef/resource/portage_package.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,13 +22,9 @@ class Chef
class Resource
class PortagePackage < Chef::Resource::Package
resource_name :portage_package
- description "Use the portage_package resource to manage packages for the Gentoo platform."
-
- def initialize(name, run_context = nil)
- super
- @provider = Chef::Provider::Package::Portage
- end
+ provides :portage_package
+ description "Use the portage_package resource to manage packages for the Gentoo platform."
end
end
end
diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb
index 565ff278ea..8ca111bf33 100644
--- a/lib/chef/resource/registry_key.rb
+++ b/lib/chef/resource/registry_key.rb
@@ -15,14 +15,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require "chef/provider/registry_key"
+
require "chef/resource"
require "chef/digester"
class Chef
class Resource
- # Use the registry_key resource to create and delete registry keys in Microsoft Windows.
class RegistryKey < Chef::Resource
+ resource_name :registry_key
+ provides :registry_key
+
+ description "Use the registry_key resource to create and delete registry keys in Microsoft Windows."
+ introduced "11.0"
+
identity_attr :key
state_attrs :values
@@ -62,8 +67,6 @@ class Chef
def initialize(name, run_context = nil)
super
- @architecture = :machine
- @recursive = false
@key = name
@values, @unscrubbed_values = [], []
end
@@ -102,21 +105,8 @@ class Chef
end
end
- def recursive(arg = nil)
- set_or_return(
- :recursive,
- arg,
- :kind_of => [TrueClass, FalseClass]
- )
- end
-
- def architecture(arg = nil)
- set_or_return(
- :architecture,
- arg,
- :kind_of => Symbol
- )
- end
+ property :recursive, [TrueClass, FalseClass], default: false
+ property :architecture, Symbol, default: :machine, equal_to: [:machine, :x86_64, :i386]
private
diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb
index d2c2622524..a320fd8b47 100644
--- a/lib/chef/resource/remote_file.rb
+++ b/lib/chef/resource/remote_file.rb
@@ -37,7 +37,6 @@ class Chef
@use_last_modified = true
@ftp_active_mode = false
@headers = {}
- @provider = Chef::Provider::RemoteFile
end
# source can take any of the following as arguments
diff --git a/lib/chef/resource/rhsm_errata.rb b/lib/chef/resource/rhsm_errata.rb
index 56779909f5..ca3e71648f 100644
--- a/lib/chef/resource/rhsm_errata.rb
+++ b/lib/chef/resource/rhsm_errata.rb
@@ -27,8 +27,7 @@ class Chef
" to mitigate a single vulnerability must be installed on your hosts."
introduced "14.0"
- property :errata_id,
- String,
+ property :errata_id, String,
description: "An optional property for specifying the errata ID if not using the resource's name.",
name_property: true
diff --git a/lib/chef/resource/rhsm_errata_level.rb b/lib/chef/resource/rhsm_errata_level.rb
index 3aa289ac2e..bab4d6ef26 100644
--- a/lib/chef/resource/rhsm_errata_level.rb
+++ b/lib/chef/resource/rhsm_errata_level.rb
@@ -28,8 +28,7 @@ class Chef
" security level are installed."
introduced "14.0"
- property :errata_level,
- String,
+ property :errata_level, String,
coerce: proc { |x| x.downcase },
equal_to: %w{critical moderate important low},
description: "The errata level of packages to install.",
diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb
index 47fe67d1cf..fe2c6a2391 100644
--- a/lib/chef/resource/rhsm_register.rb
+++ b/lib/chef/resource/rhsm_register.rb
@@ -27,29 +27,23 @@ class Chef
" or a local Red Hat Satellite server."
introduced "14.0"
- property :activation_key,
- [String, Array],
+ property :activation_key, [String, Array],
coerce: proc { |x| Array(x) },
description: "A String or array of the activation keys to use when registering. You must also specify the organization property if using activation_key."
- property :satellite_host,
- String,
+ property :satellite_host, String,
description: "The FQDN of the Satellite host to register with. If not specified, the host will be registered with Red Hat's public RHSM service."
- property :organization,
- String,
+ property :organization, String,
description: "The organization to use when registering, required when using an activation key"
- property :environment,
- String,
+ property :environment, String,
description: "The environment to use when registering, required when using username and password"
- property :username,
- String,
+ property :username, String,
description: "The username to use when registering. Not applicable if using an activation key. If specified, password and environment are also required."
- property :password,
- String,
+ property :password, String,
description: "The password to use when registering. Not applicable if using an activation key. If specified, username and environment are also required."
property :auto_attach,
@@ -57,13 +51,11 @@ class Chef
description: "If true, RHSM will attempt to automatically attach the host to applicable subscriptions. It is generally better to use an activation key with the subscriptions pre-defined.",
default: false
- property :install_katello_agent,
- [TrueClass, FalseClass],
+ property :install_katello_agent, [TrueClass, FalseClass],
description: "If true, the 'katello-agent' RPM will be installed.",
default: true
- property :force,
- [TrueClass, FalseClass],
+ property :force, [TrueClass, FalseClass],
description: "If true, the system will be registered even if it is already registered. Normally, any register operations will fail if the machine is has already registered.",
default: false
diff --git a/lib/chef/resource/rhsm_repo.rb b/lib/chef/resource/rhsm_repo.rb
index aef4dd43d6..689874a774 100644
--- a/lib/chef/resource/rhsm_repo.rb
+++ b/lib/chef/resource/rhsm_repo.rb
@@ -26,8 +26,7 @@ class Chef
" repositories that are made available via attached subscriptions."
introduced "14.0"
- property :repo_name,
- String,
+ property :repo_name, String,
description: "An optional property for specifying the repository name if not using the resource's name.",
name_property: true
diff --git a/lib/chef/resource/rhsm_subscription.rb b/lib/chef/resource/rhsm_subscription.rb
index 41dd398cd5..21ee539dda 100644
--- a/lib/chef/resource/rhsm_subscription.rb
+++ b/lib/chef/resource/rhsm_subscription.rb
@@ -27,8 +27,7 @@ class Chef
" does not attach all necessary subscriptions to your host."
introduced "14.0"
- property :pool_id,
- String,
+ property :pool_id, String,
description: "An optional property for specifying the Pool ID if not using the resource's name.",
name_property: true
diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb
index 89b90ae70b..a3cb9e56e5 100644
--- a/lib/chef/resource/ruby_block.rb
+++ b/lib/chef/resource/ruby_block.rb
@@ -29,13 +29,6 @@ class Chef
default_action :run
allowed_actions :create, :run
- identity_attr :block_name
-
- def initialize(name, run_context = nil)
- super
- @block_name = name
- end
-
def block(&block)
if block_given? && block
@block = block
@@ -44,13 +37,7 @@ class Chef
end
end
- def block_name(arg = nil)
- set_or_return(
- :block_name,
- arg,
- :kind_of => String
- )
- end
+ property :block_name, String, name_property: true, identity: true
end
end
end
diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb
index 533723c2c4..178dcca640 100644
--- a/lib/chef/resource/scm.rb
+++ b/lib/chef/resource/scm.rb
@@ -21,8 +21,6 @@ require "chef/resource"
class Chef
class Resource
class Scm < Chef::Resource
- identity_attr :destination
-
state_attrs :revision
default_action :sync
@@ -30,10 +28,8 @@ class Chef
def initialize(name, run_context = nil)
super
- @destination = name
@enable_submodules = false
@enable_checkout = true
- @revision = "HEAD"
@remote = "origin"
@ssh_wrapper = nil
@depth = nil
@@ -41,54 +37,12 @@ class Chef
@environment = nil
end
- def destination(arg = nil)
- set_or_return(
- :destination,
- arg,
- :kind_of => String
- )
- end
-
- def repository(arg = nil)
- set_or_return(
- :repository,
- arg,
- :kind_of => String
- )
- end
-
- def revision(arg = nil)
- set_or_return(
- :revision,
- arg,
- :kind_of => String
- )
- end
-
- def user(arg = nil)
- set_or_return(
- :user,
- arg,
- :kind_of => [String, Integer]
- )
- end
-
- def group(arg = nil)
- set_or_return(
- :group,
- arg,
- :kind_of => [String, Integer]
- )
- end
-
- def svn_username(arg = nil)
- set_or_return(
- :svn_username,
- arg,
- :kind_of => String
- )
- end
-
+ property :destination, String, name_property: true, identity: true
+ property :repository, String
+ property :revision, String, default: "HEAD"
+ property :user, [String, Integer]
+ property :group, [String, Integer]
+ property :svn_username, String
property :svn_password, String, sensitive: true, desired_state: false
def svn_arguments(arg = nil)
diff --git a/lib/chef/resource/windows_env.rb b/lib/chef/resource/windows_env.rb
index f5f0bd126d..b970a397aa 100644
--- a/lib/chef/resource/windows_env.rb
+++ b/lib/chef/resource/windows_env.rb
@@ -17,6 +17,8 @@
# limitations under the License.
#
+require "chef/resource"
+
class Chef
class Resource
class WindowsEnv < Chef::Resource
diff --git a/lib/chef/resource/windows_feature.rb b/lib/chef/resource/windows_feature.rb
index 42f5524cc1..84778e2bcb 100644
--- a/lib/chef/resource/windows_feature.rb
+++ b/lib/chef/resource/windows_feature.rb
@@ -15,6 +15,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+require "chef/resource"
+
class Chef
class Resource
class WindowsFeature < Chef::Resource
@@ -33,11 +36,11 @@ class Chef
property :source, String,
description: "Use a local repository for the feature install."
- property :all, [true, false],
+ property :all, [TrueClass, FalseClass],
description: "Install all sub features.",
default: false
- property :management_tools, [true, false],
+ property :management_tools, [TrueClass, FalseClass],
description: "Install all applicable management tools of the roles, role services, or features (PowerShell only).",
default: false
diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb
index 6ffaf318d5..00fc7f71ca 100644
--- a/lib/chef/resource/windows_feature_dism.rb
+++ b/lib/chef/resource/windows_feature_dism.rb
@@ -16,6 +16,8 @@
# limitations under the License.
#
+require "chef/resource"
+
class Chef
class Resource
class WindowsFeatureDism < Chef::Resource
@@ -34,7 +36,7 @@ class Chef
property :source, String,
description: "Use a local repository for the feature install."
- property :all, [true, false],
+ property :all, [TrueClass, FalseClass],
description: "Install all sub features. This is the equivalent of specifying the /All switch to dism.exe",
default: false
diff --git a/lib/chef/resource/windows_feature_powershell.rb b/lib/chef/resource/windows_feature_powershell.rb
index 30f8f6da83..7e7fb6c160 100644
--- a/lib/chef/resource/windows_feature_powershell.rb
+++ b/lib/chef/resource/windows_feature_powershell.rb
@@ -16,6 +16,8 @@
# limitations under the License.
#
+require "chef/resource"
+
class Chef
class Resource
class WindowsFeaturePowershell < Chef::Resource
@@ -37,7 +39,7 @@ class Chef
property :source, String,
description: "Use a local repository for the feature install."
- property :all, [true, false],
+ property :all, [TrueClass, FalseClass],
description: "Install all sub features. This is equivalent to using the"\
" -InstallAllSubFeatures switch with Add-WindowsFeature.",
default: false
@@ -46,7 +48,7 @@ class Chef
description: "Specifies a timeout (in seconds) for feature install.",
default: 600
- property :management_tools, [true, false],
+ property :management_tools, [TrueClass, FalseClass],
description: "",
default: false
diff --git a/lib/chef/resource/windows_pagefile.rb b/lib/chef/resource/windows_pagefile.rb
index 069e76107c..b87134171b 100644
--- a/lib/chef/resource/windows_pagefile.rb
+++ b/lib/chef/resource/windows_pagefile.rb
@@ -15,6 +15,8 @@
# limitations under the License.
#
+require "chef/resource"
+
class Chef
class Resource
class WindowsPagefile < Chef::Resource
@@ -29,10 +31,10 @@ class Chef
description: "The path to the pagefile if different from the resource name.",
name_property: true
- property :system_managed, [true, false],
+ property :system_managed, [TrueClass, FalseClass],
description: "Configures whether the system manages the pagefile size."
- property :automatic_managed, [true, false],
+ property :automatic_managed, [TrueClass, FalseClass],
description: "Enable automatic management of pagefile initial and maximum size. Setting this to true ignores 'initial_size' and 'maximum_size' properties.",
default: false
diff --git a/lib/chef/resource/windows_printer.rb b/lib/chef/resource/windows_printer.rb
index c134e27bf7..3ad12e35c7 100644
--- a/lib/chef/resource/windows_printer.rb
+++ b/lib/chef/resource/windows_printer.rb
@@ -39,7 +39,7 @@ class Chef
property :comment, String,
description: "Optional descriptor for the printer queue."
- property :default, [true, false],
+ property :default, [TrueClass, FalseClass],
description: "Should this be the system's default printer.",
default: false
@@ -50,7 +50,7 @@ class Chef
property :location, String,
description: "Printer location, e.g. 'Fifth floor copy room'."
- property :shared, [true, false],
+ property :shared, [TrueClass, FalseClass],
description: "Should the printer be shared.",
default: false
@@ -62,7 +62,8 @@ class Chef
validation_message: "The ipv4_address property must be in the IPv4 format of WWW.XXX.YYY.ZZZ",
regex: Resolv::IPv4::Regex
- property :exists, [true, false], desired_state: true
+ property :exists, [TrueClass, FalseClass],
+ desired_state: true
PRINTERS_REG_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\\'.freeze unless defined?(PRINTERS_REG_KEY)
diff --git a/lib/chef/resource/windows_printer_port.rb b/lib/chef/resource/windows_printer_port.rb
index 9da43948f6..6d2b293e9f 100644
--- a/lib/chef/resource/windows_printer_port.rb
+++ b/lib/chef/resource/windows_printer_port.rb
@@ -46,7 +46,7 @@ class Chef
property :port_description, String,
description: "The description of the port."
- property :snmp_enabled, [true, false],
+ property :snmp_enabled, [TrueClass, FalseClass],
description: "Should SNMP be enabled on the port.",
default: false
@@ -55,7 +55,7 @@ class Chef
validation_message: "port_protocol must be either 1 for RAW or 2 for LPR!",
default: 1, equal_to: [1, 2]
- property :exists, [true, false],
+ property :exists, [TrueClass, FalseClass],
desired_state: true
PORTS_REG_KEY = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\\'.freeze unless defined?(PORTS_REG_KEY)
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb
index 8a76a716aa..aaa21aa6a7 100644
--- a/lib/chef/resource/windows_service.rb
+++ b/lib/chef/resource/windows_service.rb
@@ -41,11 +41,9 @@ class Chef
allowed_actions :configure_startup, :create, :delete, :configure
- identity_attr :service_name
-
state_attrs :enabled, :running
- property :service_name, name_property: true
+ property :service_name, name_property: true, identity: true
# The display name to be used by user interface programs to identify the
# service. This string has a maximum length of 256 characters.
diff --git a/lib/chef/resource/zypper_package.rb b/lib/chef/resource/zypper_package.rb
index 2e48caef55..23b8779f25 100644
--- a/lib/chef/resource/zypper_package.rb
+++ b/lib/chef/resource/zypper_package.rb
@@ -29,7 +29,7 @@ class Chef
" packages with Zypper for the SUSE Enterprise and OpenSUSE platforms."
property :gpg_check, [ TrueClass, FalseClass ], default: lazy { Chef::Config[:zypper_check_gpg] }
- property :allow_downgrade, [ true, false ], default: false
+ property :allow_downgrade, [ TrueClass, FalseClass ], default: false
end
end
end
diff --git a/lib/chef/resource/zypper_repository.rb b/lib/chef/resource/zypper_repository.rb
index 298373b87d..776c7a407f 100644
--- a/lib/chef/resource/zypper_repository.rb
+++ b/lib/chef/resource/zypper_repository.rb
@@ -33,20 +33,20 @@ class Chef
property :repo_name, String, name_property: true
property :description, String
property :type, String, default: "NONE"
- property :enabled, [true, false], default: true
- property :autorefresh, [true, false], default: true
- property :gpgcheck, [true, false], default: true
+ property :enabled, [TrueClass, FalseClass], default: true
+ property :autorefresh, [TrueClass, FalseClass], default: true
+ property :gpgcheck, [TrueClass, FalseClass], default: true
property :gpgkey, String
property :baseurl, String
property :mirrorlist, String
property :path, String
property :priority, Integer, default: 99
- property :keeppackages, [true, false], default: false
+ property :keeppackages, [TrueClass, FalseClass], default: false
property :mode, default: "0644"
- property :refresh_cache, [true, false], default: true
+ property :refresh_cache, [TrueClass, FalseClass], default: true
property :source, String
property :cookbook, String
- property :gpgautoimportkeys, [true, false], default: true
+ property :gpgautoimportkeys, [TrueClass, FalseClass], default: true
default_action :create
allowed_actions :create, :remove, :add, :refresh
diff --git a/lib/chef/resource_inspector.rb b/lib/chef/resource_inspector.rb
new file mode 100644
index 0000000000..0f4f718c72
--- /dev/null
+++ b/lib/chef/resource_inspector.rb
@@ -0,0 +1,89 @@
+# Copyright:: Copyright 2018, Chef Software, Inc
+# 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 "chef/cookbook_loader"
+require "chef/cookbook/file_vendor"
+require "chef/cookbook/file_system_file_vendor"
+require "chef/resource/lwrp_base"
+require "chef/run_context"
+require "chef/node"
+require "chef/resources"
+require "chef/json_compat"
+
+module ResourceInspector
+ def self.extract_resource(resource, complete = false)
+ data = {}
+ data[:description] = resource.description
+ # data[:deprecated] = resource.deprecated || false
+ data[:actions] = resource.allowed_actions
+ data[:examples] = resource.examples
+ data[:introduced] = resource.introduced
+
+ properties = unless complete
+ resource.properties.reject { |_, k| k.options[:declared_in] == Chef::Resource }
+ else
+ resource.properties
+ end
+
+ data[:properties] = properties.each_with_object([]) do |(n, k), acc|
+ opts = k.options
+ acc << { name: n, description: opts[:description], introduced: opts[:introduced], is: opts[:is], deprecated: opts[:deprecated] || false }
+ end
+ data
+ end
+
+ def self.extract_cookbook(path, complete)
+ path = File.expand_path(path)
+ dir, name = File.split(path)
+ Chef::Cookbook::FileVendor.fetch_from_disk(path)
+ loader = Chef::CookbookLoader.new(dir)
+ cookbooks = loader.load_cookbooks
+ resources = cookbooks[name].files_for(:resources)
+
+ resources.each_with_object({}) do |r, res|
+ pth = r["full_path"]
+ cur = Chef::Resource::LWRPBase.build_from_file(name, pth, Chef::RunContext.new(Chef::Node.new, nil, nil))
+ res[cur.resource_name] = extract_resource(cur, complete)
+ end
+ end
+
+ # If we're given no resources, dump all of Chef's built ins
+ # otherwise, if we have a path then extract all the resources from the cookbook
+ # or else do a list of built in resources
+ #
+ # @param complete [TrueClass, FalseClass] Whether to show properties defined in the base Resource class
+ def self.inspect(arguments = [], complete: false)
+ output = if arguments.empty?
+ ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.each_with_object({}) { |klass, acc| acc[klass.resource_name] = extract_resource(klass) }
+ else
+ arguments.each_with_object({}) do |arg, acc|
+ if File.directory?(arg)
+ extract_cookbook(arg, complete).each { |k, v| acc[k] = v }
+ else
+ r = Chef::ResourceResolver.resolve(arg.to_sym, canonical: nil)
+ acc[r.resource_name] = extract_resource(r, complete)
+ end
+ end
+ end
+
+ puts Chef::JSONCompat.to_json_pretty(output)
+ end
+
+ def self.start
+ inspect(ARGV, complete: true)
+ end
+
+end
diff --git a/lib/chef/version.rb b/lib/chef/version.rb
index 7bb86374ca..c7dc5c0b67 100644
--- a/lib/chef/version.rb
+++ b/lib/chef/version.rb
@@ -23,7 +23,7 @@ require "chef/version_string"
class Chef
CHEF_ROOT = File.expand_path("../..", __FILE__)
- VERSION = Chef::VersionString.new("14.0.105")
+ VERSION = Chef::VersionString.new("14.0.121")
end
#
diff --git a/lib/chef/win32/eventlog.rb b/lib/chef/win32/eventlog.rb
index eae0ae4abf..418d72e65e 100644
--- a/lib/chef/win32/eventlog.rb
+++ b/lib/chef/win32/eventlog.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-if Chef::Platform.windows? && (not Chef::Platform.windows_server_2003?)
+if Chef::Platform.windows?
if !defined? Chef::Win32EventLogLoaded
if defined? Windows::Constants
[:INFINITE, :WAIT_FAILED, :FORMAT_MESSAGE_IGNORE_INSERTS, :ERROR_INSUFFICIENT_BUFFER].each do |c|
diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb
index 63b626b1d7..821d81ef81 100644
--- a/lib/chef/win32/security.rb
+++ b/lib/chef/win32/security.rb
@@ -643,32 +643,26 @@ class Chef
# Checks if the caller has the admin privileges in their
# security token
def self.has_admin_privileges?
- if Chef::Platform.windows_server_2003?
- # Admin privileges do not exist on Windows Server 2003
-
- true
- else
- # a regular user doesn't have privileges to call Chef::ReservedNames::Win32::Security.OpenProcessToken
- # hence we return false if the open_current_process_token fails with `Access is denied.` error message.
- begin
- process_token = open_current_process_token(TOKEN_READ)
- rescue Exception => run_error
- return false if run_error.message =~ /Access is denied/
- Chef::ReservedNames::Win32::Error.raise!
- end
+ # a regular user doesn't have privileges to call Chef::ReservedNames::Win32::Security.OpenProcessToken
+ # hence we return false if the open_current_process_token fails with `Access is denied.` error message.
+ begin
+ process_token = open_current_process_token(TOKEN_READ)
+ rescue Exception => run_error
+ return false if run_error.message =~ /Access is denied/
+ Chef::ReservedNames::Win32::Error.raise!
+ end
- # display token elevation details
- token_elevation_type = get_token_information_elevation_type(process_token)
- Chef::Log.debug("Token Elevation Type: #{token_elevation_type}")
+ # display token elevation details
+ token_elevation_type = get_token_information_elevation_type(process_token)
+ Chef::Log.debug("Token Elevation Type: #{token_elevation_type}")
- elevation_result = FFI::Buffer.new(:ulong)
- elevation_result_size = FFI::MemoryPointer.new(:uint32)
- success = GetTokenInformation(process_token.handle.handle, :TokenElevation, elevation_result, 4, elevation_result_size)
+ elevation_result = FFI::Buffer.new(:ulong)
+ elevation_result_size = FFI::MemoryPointer.new(:uint32)
+ success = GetTokenInformation(process_token.handle.handle, :TokenElevation, elevation_result, 4, elevation_result_size)
- # Assume process is not elevated if the call fails.
- # Process is elevated if the result is different than 0.
- success && (elevation_result.read_ulong != 0)
- end
+ # Assume process is not elevated if the call fails.
+ # Process is elevated if the result is different than 0.
+ success && (elevation_result.read_ulong != 0)
end
def self.logon_user(username, domain, password, logon_type, logon_provider)
diff --git a/lib/chef/win32/security/sid.rb b/lib/chef/win32/security/sid.rb
index c77616853c..b551cbd2e3 100644
--- a/lib/chef/win32/security/sid.rb
+++ b/lib/chef/win32/security/sid.rb
@@ -248,8 +248,7 @@ class Chef
# See https://technet.microsoft.com/en-us/library/cc961992.aspx
# In practice, this is SID.Administrators if the current_user is an admin (even if not
- # running elevated), and is current_user otherwise. On win2k3, it technically can be
- # current_user in all cases if a certain group policy is set.
+ # running elevated), and is current_user otherwise.
def self.default_security_object_owner
token = Chef::ReservedNames::Win32::Security.open_current_process_token
Chef::ReservedNames::Win32::Security.get_token_information_owner(token)
diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb
index f8228d40b3..944cb207f5 100644
--- a/lib/chef/win32/version.rb
+++ b/lib/chef/win32/version.rb
@@ -76,15 +76,8 @@ class Chef
@sp_minor_version = ver_info[:w_service_pack_minor]
# Obtain sku information for the purpose of identifying
- # datacenter, cluster, and core skus, the latter 2 only
- # exist in releases after Windows Server 2003
- if ! Chef::Platform.windows_server_2003?
- @sku = get_product_info(@major_version, @minor_version, @sp_major_version, @sp_minor_version)
- else
- # The get_product_info API is not supported on Win2k3,
- # use an alternative to identify datacenter skus
- @sku = get_datacenter_product_info_windows_server_2003(ver_info)
- end
+ # datacenter, cluster, and core skus
+ @sku = get_product_info(@major_version, @minor_version, @sp_major_version, @sp_minor_version)
end
marketing_names = Array.new
@@ -153,12 +146,6 @@ class Chef
out.get_uint(0)
end
- def get_datacenter_product_info_windows_server_2003(ver_info)
- # The intent is not to get the actual sku, just identify
- # Windows Server 2003 datacenter
- sku = (ver_info[:w_suite_mask] & VER_SUITE_DATACENTER) ? PRODUCT_DATACENTER_SERVER : 0
- end
-
end
end
end
diff --git a/spec/data/mixin/invalid_data.rb b/spec/data/mixin/invalid_data.rb
new file mode 100644
index 0000000000..e6f6c3a783
--- /dev/null
+++ b/spec/data/mixin/invalid_data.rb
@@ -0,0 +1,3 @@
+# For spec/functional/mixin/from_file_spec.rb
+a :foo
+c :bar
diff --git a/spec/data/mixin/real_data.rb b/spec/data/mixin/real_data.rb
new file mode 100644
index 0000000000..e15b86fc68
--- /dev/null
+++ b/spec/data/mixin/real_data.rb
@@ -0,0 +1,2 @@
+# For spec/functional/mixin/from_file_spec.rb
+a :foo
diff --git a/spec/functional/event_loggers/windows_eventlog_spec.rb b/spec/functional/event_loggers/windows_eventlog_spec.rb
index 019595ea8d..8a9475680d 100644
--- a/spec/functional/event_loggers/windows_eventlog_spec.rb
+++ b/spec/functional/event_loggers/windows_eventlog_spec.rb
@@ -19,12 +19,12 @@
require "spec_helper"
require "securerandom"
require "chef/event_loggers/windows_eventlog"
-if Chef::Platform.windows? && (not Chef::Platform.windows_server_2003?)
+if Chef::Platform.windows?
require "win32/eventlog"
include Win32
end
-describe Chef::EventLoggers::WindowsEventLogger, :windows_only, :not_supported_on_win2k3 do
+describe Chef::EventLoggers::WindowsEventLogger, :windows_only do
def rand
random.rand(1 << 32).to_s
end
diff --git a/spec/functional/mixin/from_file_spec.rb b/spec/functional/mixin/from_file_spec.rb
new file mode 100644
index 0000000000..a279f48790
--- /dev/null
+++ b/spec/functional/mixin/from_file_spec.rb
@@ -0,0 +1,82 @@
+#
+# Copyright:: Copyright 2014-2018, Chef Software, Inc.
+# 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::Mixin::FromFile do
+ REAL_DATA = File.join(CHEF_SPEC_DATA, "mixin", "real_data.rb")
+ INVALID_DATA = File.join(CHEF_SPEC_DATA, "mixin", "invalid_data.rb")
+ NO_DATA = File.join(CHEF_SPEC_DATA, "mixin", "non_existant_data.rb")
+
+ class TestData
+ include Chef::Mixin::FromFile
+
+ def a(a = nil)
+ @a = a if a
+ @a
+ end
+ end
+
+ class ClassTestData
+ class <<self
+ include Chef::Mixin::FromFile
+
+ def a(a = nil)
+ @a = a if a
+ @a
+ end
+ end
+ end
+
+ describe "from_file" do
+ it "should load data" do
+ datum = TestData.new
+ datum.from_file(REAL_DATA)
+ expect(datum.a).to eq(:foo)
+ end
+
+ it "should load class data" do
+ datum = ClassTestData
+ datum.class_from_file(REAL_DATA)
+ expect(datum.a).to eq(:foo)
+ end
+
+ it "should set source_file" do
+ datum = TestData.new
+ datum.from_file(REAL_DATA)
+ expect(datum.source_file).to eq(REAL_DATA)
+ end
+
+ it "should set class source_file" do
+ datum = ClassTestData
+ datum.class_from_file(REAL_DATA)
+ expect(datum.source_file).to eq(REAL_DATA)
+ end
+
+ it "should fail on invalid data" do
+ datum = TestData.new
+ expect do
+ datum.from_file(INVALID_DATA)
+ end.to raise_error(NoMethodError)
+ end
+
+ it "should fail on nonexistant data" do
+ datum = TestData.new
+ expect { datum.from_file(NO_DATA) }.to raise_error(IOError)
+ end
+ end
+end
diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb
index e8a95436f7..8073bbc92e 100644
--- a/spec/functional/resource/link_spec.rb
+++ b/spec/functional/resource/link_spec.rb
@@ -172,7 +172,7 @@ describe Chef::Resource::Link do
create_resource
end
- describe "when supported on platform", :not_supported_on_win2k3 do
+ describe "when supported on platform" do
shared_examples_for "delete errors out" do
it "delete errors out" do
expect { resource.run_action(:delete) }.to raise_error(Chef::Exceptions::Link)
@@ -694,10 +694,4 @@ describe Chef::Resource::Link do
end
end
end
-
- describe "when not supported on platform", :win2k3_only do
- it "raises error" do
- expect { resource }.to raise_error(Chef::Exceptions::Win32APIFunctionNotImplemented)
- end
- end
end
diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb
index af345b0ea4..bbd304fd06 100644
--- a/spec/functional/resource/powershell_script_spec.rb
+++ b/spec/functional/resource/powershell_script_spec.rb
@@ -36,8 +36,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
let(:cmdlet_exit_code_success_content) { "get-item ." }
let(:windows_process_exit_code_success_content) { "#{ENV['SystemRoot']}\\system32\\attrib.exe $env:systemroot" }
let(:windows_process_exit_code_not_found_content) { "findstr /notavalidswitch" }
- # Note that process exit codes on 32-bit Win2k3 cannot
- # exceed maximum value of signed integer
let(:arbitrary_nonzero_process_exit_code) { 4193 }
let(:arbitrary_nonzero_process_exit_code_content) { "exit #{arbitrary_nonzero_process_exit_code}" }
let(:invalid_powershell_interpreter_flag) { "/thisflagisinvalid" }
diff --git a/spec/functional/win32/security_spec.rb b/spec/functional/win32/security_spec.rb
index 6c24cbec08..22c749b609 100644
--- a/spec/functional/win32/security_spec.rb
+++ b/spec/functional/win32/security_spec.rb
@@ -42,7 +42,6 @@ describe "Chef::Win32::Security", :windows_only do
before do
allow_any_instance_of(Chef::Mixin::UserContext).to receive(:node).and_return({ "platform_family" => "windows" })
- allow(Chef::Platform).to receive(:windows_server_2003?).and_return(false)
add_user = Mixlib::ShellOut.new("net user #{user} #{password} /ADD")
add_user.run_command
add_user.error!
diff --git a/spec/functional/win32/versions_spec.rb b/spec/functional/win32/versions_spec.rb
index d6e840ed7f..19bd0e3875 100644
--- a/spec/functional/win32/versions_spec.rb
+++ b/spec/functional/win32/versions_spec.rb
@@ -21,7 +21,7 @@ if Chef::Platform.windows?
require "chef/win32/version"
end
-describe "Chef::ReservedNames::Win32::Version", :windows_only, :not_supported_on_win2k3 do
+describe "Chef::ReservedNames::Win32::Version", :windows_only do
before do
wmi = WmiLite::Wmi.new
@@ -31,14 +31,12 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only, :not_supported_on
# On Win2k8R2 and later, we can dynamically obtain marketing
# names for comparison from WMI so the test should not
# need to be modified when new Windows releases arise.
- # For Win2k3 and Win2k8, we use static names in this test
- # based on the version number information from WMI. The names
- # from WMI contain extended characters such as registered
- # trademark on Win2k8 and Win2k3 that we're not using in our
- # library, so we have to set the expectation statically.
- if Chef::Platform.windows_server_2003?
- @current_os_version = "Windows Server 2003 R2"
- elsif is_windows_server_2008?(host)
+ # For Win2k8 we use static names in this test based on the
+ # version number information from WMI. The names from WMI
+ # contain extended characters such as registered trademark
+ # on Win2k8 that we're not using in our library, so we have
+ # to set the expectation statically.
+ if is_windows_server_2008?(host)
@current_os_version = "Windows Server 2008"
else
# The name from WMI is actually what we want in Win2k8R2+.
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb
index de12b8ba8e..77008524c8 100644
--- a/spec/integration/client/client_spec.rb
+++ b/spec/integration/client/client_spec.rb
@@ -46,7 +46,7 @@ describe "chef-client" do
# we're running `chef-client` from the source tree and not the external one.
# cf. CHEF-4914
let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" }
- let(:chef_solo) { "ruby '#{chef_dir}/chef-solo' --minimal-ohai" }
+ let(:chef_solo) { "ruby '#{chef_dir}/chef-solo' --legacy-mode --minimal-ohai" }
let(:critical_env_vars) { %w{_ORIGINAL_GEM_PATH GEM_PATH GEM_HOME GEM_ROOT BUNDLE_BIN_PATH BUNDLE_GEMFILE RUBYLIB RUBYOPT RUBY_ENGINE RUBY_ROOT RUBY_VERSION PATH}.map { |o| "#{o}=#{ENV[o]}" } .join(" ") }
@@ -624,4 +624,102 @@ EOM
expect(command.stdout).not_to include("INFO")
end
end
+
+ when_the_repository "has a cookbook that knows if we're running forked" do
+ before do
+ file "cookbooks/x/recipes/default.rb", <<~EOM
+ puts Chef::Config[:client_fork] ? "WITHFORK" : "NOFORK"
+EOM
+ file "config/client.rb", <<EOM
+local_mode true
+cookbook_path "#{path_to('cookbooks')}"
+EOM
+ end
+
+ it "chef-client runs by default with no supervisor" do
+ command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("NOFORK")
+ end
+
+ it "chef-solo runs by default with no supervisor" do
+ command = shell_out("#{chef_solo} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("NOFORK")
+ end
+
+ it "chef-client --no-fork does not fork" do
+ command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("NOFORK")
+ end
+
+ it "chef-solo --no-fork does not fork" do
+ command = shell_out("#{chef_solo} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("NOFORK")
+ end
+
+ it "chef-client with --fork uses a supervisor" do
+ command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --fork", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("WITHFORK")
+ end
+
+ it "chef-solo with --fork uses a supervisor" do
+ command = shell_out("#{chef_solo} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --fork", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("WITHFORK")
+ end
+ end
+
+ when_the_repository "has a cookbook that knows if we're running forked, and configures forking in config.rb" do
+ before do
+ file "cookbooks/x/recipes/default.rb", <<~EOM
+ puts Chef::Config[:client_fork] ? "WITHFORK" : "NOFORK"
+EOM
+ file "config/client.rb", <<EOM
+local_mode true
+cookbook_path "#{path_to('cookbooks')}"
+client_fork true
+EOM
+ end
+
+ it "chef-client uses a supervisor" do
+ command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("WITHFORK")
+ end
+
+ it "chef-solo uses a supervisor" do
+ command = shell_out("#{chef_solo} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("WITHFORK")
+ end
+ end
+
+ when_the_repository "has a cookbook that knows if we're running forked, and configures no-forking in config.rb" do
+ before do
+ file "cookbooks/x/recipes/default.rb", <<~EOM
+ puts Chef::Config[:client_fork] ? "WITHFORK" : "NOFORK"
+EOM
+ file "config/client.rb", <<EOM
+local_mode true
+cookbook_path "#{path_to('cookbooks')}"
+client_fork false
+EOM
+ end
+
+ it "chef-client uses a supervisor" do
+ command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("NOFORK")
+ end
+
+ it "chef-solo uses a supervisor" do
+ command = shell_out("#{chef_solo} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir)
+ command.error!
+ expect(command.stdout).to include("NOFORK")
+ end
+ end
end
diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb
index d6ea4347c4..149b17fcad 100644
--- a/spec/integration/recipes/resource_action_spec.rb
+++ b/spec/integration/recipes/resource_action_spec.rb
@@ -378,94 +378,6 @@ module ResourceActionSpec
end
end
- context "With a resource with property x" do
- class ResourceActionSpecWithX < Chef::Resource
- resource_name :resource_action_spec_with_x
- property :x, default: 20
- action :set do
- # Access x during converge to ensure that we emit no warnings there
- x
- end
- end
-
- context "And another resource with a property x and an action that sets property x to its value" do
- class ResourceActionSpecAlsoWithX < Chef::Resource
- resource_name :resource_action_spec_also_with_x
- property :x
- action :set_x_to_x do
- resource_action_spec_with_x "hi" do
- x x
- end
- end
- def self.x_warning_line
- __LINE__ - 4
- end
- action :set_x_to_x_in_non_initializer do
- r = resource_action_spec_with_x "hi" do
- x 10
- end
- x_times_2 = r.x * 2
- end
- action :set_x_to_10 do
- resource_action_spec_with_x "hi" do
- x 10
- end
- end
- end
-
- attr_reader :x_warning_line
-
- it "Using the enclosing resource to set x to x emits a warning that you're using the wrong x" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- recipe = converge do
- resource_action_spec_also_with_x "hi" do
- x 1
- action :set_x_to_x
- end
- end
- warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
- expect(warnings.size).to eq 2
- expect(warnings[0]).to match(/property x is declared in both resource_action_spec_with_x\[hi\] and resource_action_spec_also_with_x\[hi\] action :set_x_to_x. Use new_resource.x instead. At #{__FILE__}:#{ResourceActionSpecAlsoWithX.x_warning_line}/)
- end
-
- it "Using the enclosing resource to set x to x outside the initializer emits no warning" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- recipe = converge do
- resource_action_spec_also_with_x "hi" do
- x 1
- action :set_x_to_x_in_non_initializer
- end
- end
- warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
- expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one
- end
-
- it "Using the enclosing resource to set x to 10 emits no warning" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- recipe = converge do
- resource_action_spec_also_with_x "hi" do
- x 1
- action :set_x_to_10
- end
- end
- warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
- expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one
- end
-
- it "Using the enclosing resource to set x to 10 emits no warning" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- recipe = converge do
- r = resource_action_spec_also_with_x "hi"
- r.x 1
- r.action :set_x_to_10
- end
- warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
- expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one
- end
- end
-
- end
-
context "With a resource with a set_or_return property named group (same name as a resource)" do
class ResourceActionSpecWithGroupAction < Chef::Resource
resource_name :resource_action_spec_set_group_to_nil
@@ -504,13 +416,6 @@ module ResourceActionSpec
end
end
end
-
- it "Raises an error when attempting to use a template in the action" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- expect_converge do
- has_property_named_template "hi"
- end.to raise_error(/Property `template` of `has_property_named_template\[hi\]` was incorrectly passed a block. Possible property-resource collision. To call a resource named `template` either rename the property or else use `declare_resource\(:template, ...\)`/)
- end
end
context "When a resource declares methods in action_class" do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index dbefbf29e4..78f8da7b51 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -146,11 +146,9 @@ RSpec.configure do |config|
config.filter_run_excluding :not_supported_on_mac_osx_106 => true if mac_osx_106?
config.filter_run_excluding :not_supported_on_mac_osx => true if mac_osx?
config.filter_run_excluding :mac_osx_only => true if !mac_osx?
- config.filter_run_excluding :not_supported_on_win2k3 => true if windows_win2k3?
config.filter_run_excluding :not_supported_on_solaris => true if solaris?
config.filter_run_excluding :not_supported_on_gce => true if gce?
config.filter_run_excluding :not_supported_on_nano => true if windows_nano_server?
- config.filter_run_excluding :win2k3_only => true unless windows_win2k3?
config.filter_run_excluding :win2012r2_only => true unless windows_2012r2?
config.filter_run_excluding :windows_2008r2_or_later => true unless windows_2008r2_or_later?
config.filter_run_excluding :windows64_only => true unless windows64?
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index 3cc8778f7a..f015a6cd50 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -51,11 +51,6 @@ def windows_domain_joined?
computer_system["partofdomain"]
end
-def windows_win2k3?
- return false unless windows?
- (host_version && host_version.start_with?("5.2"))
-end
-
def windows_2008r2_or_later?
return false unless windows?
return false unless host_version
diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb
index eb7a378db9..d025a0806d 100644
--- a/spec/support/shared/functional/file_resource.rb
+++ b/spec/support/shared/functional/file_resource.rb
@@ -399,7 +399,7 @@ shared_examples_for "a configured file resource" do
content
end
- context "when the target file is a symlink", :not_supported_on_win2k3 do
+ context "when the target file is a symlink" do
let(:symlink_target) do
File.join(CHEF_SPEC_DATA, "file-test-target")
end
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index 3f803f2033..0cd3cb3995 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -107,6 +107,7 @@ describe Chef::Application::Client, "reconfigure" do
shared_examples "sets the configuration" do |cli_arguments, expected_config|
describe cli_arguments do
before do
+ cli_arguments ||= ""
ARGV.replace(cli_arguments.split)
app.reconfigure
end
@@ -144,6 +145,36 @@ describe Chef::Application::Client, "reconfigure" do
end
end
+ describe "--[no]-fork" do
+ before do
+ Chef::Config[:interval] = nil # FIXME: we're overriding the before block setting this
+ end
+
+ context "by default" do
+ it_behaves_like "sets the configuration", "", client_fork: false
+ end
+
+ context "with --fork" do
+ it_behaves_like "sets the configuration", "--fork", client_fork: true
+ end
+
+ context "with --no-fork" do
+ it_behaves_like "sets the configuration", "--no-fork", client_fork: false
+ end
+
+ context "with an interval" do
+ it_behaves_like "sets the configuration", "--interval 1800", client_fork: true
+ end
+
+ context "with once" do
+ it_behaves_like "sets the configuration", "--once", client_fork: false
+ end
+
+ context "with daemonize", :unix_only do
+ it_behaves_like "sets the configuration", "--daemonize", client_fork: true
+ end
+ end
+
describe "--config-option" do
context "with a single value" do
it_behaves_like "sets the configuration", "--config-option chef_server_url=http://example",
@@ -186,21 +217,16 @@ describe Chef::Application::Client, "reconfigure" do
Chef::Config[:splay] = nil
end
- context "when interval is given" do
- before do
- Chef::Config[:interval] = 600
- allow(ChefConfig).to receive(:windows?).and_return(false)
- end
-
- it "should terminate with message" do
- expect(Chef::Application).to receive(:fatal!).with(
-"Unforked chef-client interval runs are disabled in Chef 12.
+ it "should terminal with message when interval is given" do
+ Chef::Config[:interval] = 600
+ allow(ChefConfig).to receive(:windows?).and_return(false)
+ expect(Chef::Application).to receive(:fatal!).with(
+ "Unforked chef-client interval runs are disabled in Chef 12.
Configuration settings:
interval = 600 seconds
Enable chef-client interval runs by setting `:client_fork = true` in your config file or adding `--fork` to your command line options."
- )
- app.reconfigure
- end
+ )
+ app.reconfigure
end
context "when interval is given on windows" do
diff --git a/spec/unit/dsl/reboot_pending_spec.rb b/spec/unit/dsl/reboot_pending_spec.rb
index 5cd7c7794f..2a12e27610 100644
--- a/spec/unit/dsl/reboot_pending_spec.rb
+++ b/spec/unit/dsl/reboot_pending_spec.rb
@@ -49,19 +49,6 @@ describe Chef::DSL::RebootPending do
allow(recipe).to receive(:registry_key_exists?).with('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending').and_return(true)
expect(recipe.reboot_pending?).to be_truthy
end
-
- context "version is server 2003" do
- before do
- allow(Chef::Platform).to receive(:windows_server_2003?).and_return(true)
- end
-
- it 'should return true if value "HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile" contains specific data on 2k3' do
- allow(recipe).to receive(:registry_key_exists?).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(true)
- allow(recipe).to receive(:registry_get_values).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(
- [{ :name => "Flags", :type => :dword, :data => 3 }])
- expect(recipe.reboot_pending?).to be_truthy
- end
- end
end
context "platform is ubuntu" do
diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb
index aa2b3c1f11..ac5158e913 100644
--- a/spec/unit/platform/query_helpers_spec.rb
+++ b/spec/unit/platform/query_helpers_spec.rb
@@ -18,19 +18,6 @@
require "spec_helper"
-describe "Chef::Platform#windows_server_2003?" do
- it "returns false early when not on windows" do
- allow(ChefConfig).to receive(:windows?).and_return(false)
- expect(Chef::Platform).not_to receive(:require)
- expect(Chef::Platform.windows_server_2003?).to be_falsey
- end
-
- # CHEF-4888: Need to call WIN32OLE.ole_initialize in new threads
- it "does not raise an exception" do
- expect { Thread.fork { Chef::Platform.windows_server_2003? }.join }.not_to raise_error
- end
-end
-
describe "Chef::Platform#windows_nano_server?" do
include_context "Win32"
diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb
index 466d0f970b..b8cf56750d 100644
--- a/spec/unit/policy_builder/policyfile_spec.rb
+++ b/spec/unit/policy_builder/policyfile_spec.rb
@@ -70,8 +70,44 @@ describe Chef::PolicyBuilder::Policyfile do
}
end
- let(:policyfile_default_attributes) { { "policyfile_default_attr" => "policyfile_default_value" } }
- let(:policyfile_override_attributes) { { "policyfile_override_attr" => "policyfile_override_value" } }
+ let(:policyfile_default_attributes) do
+ {
+ "policyfile_default_attr" => "policyfile_default_value",
+ "top_level_attr" => "hat",
+ "baseline_attr" => {
+ "one" => 1,
+ "two" => 2,
+ "deep" => {
+ "three" => 3,
+ "four" => [4],
+ "five" => [5],
+ },
+ },
+ "policy_group_value" => {
+ "baseline_attr" => {
+ "one" => 111,
+ },
+ },
+ }
+ end
+
+ let(:policyfile_override_attributes) do
+ {
+ "policyfile_override_attr" => "policyfile_override_value",
+ "baseline_attr" => {
+ "deep" => {
+ "three" => 333 },
+ },
+ "policy_group_value" => {
+ "top_level_attr" => "cat",
+ "baseline_attr" => {
+ "deep" => {
+ "four" => [444],
+ },
+ },
+ },
+ }
+ end
let(:policyfile_run_list) { ["recipe[example1::default]", "recipe[example2::server]"] }
@@ -636,6 +672,42 @@ describe Chef::PolicyBuilder::Policyfile do
end
end
+
+ describe "hoisting attribute values" do
+ context "with no policy group set" do
+ it "does not hoist policy_group specific attributes" do
+ expect( node["top_level_attr"] ).to eql("hat")
+ expect( node["baseline_attr"]["one"] ).to eql(1)
+ expect( node["baseline_attr"]["two"] ).to eql(2)
+ expect( node["baseline_attr"]["deep"]["three"] ).to eql(333)
+ expect( node["baseline_attr"]["deep"]["four"] ).to eql([4])
+ expect( node["baseline_attr"]["deep"]["five"] ).to eql([5])
+ end
+ end
+
+ context "with a policy group set" do
+ before do
+ Chef::Config[:policy_group] = "policy_group_value"
+ policy_builder.finish_load_node(node)
+ policy_builder.build_node
+ end
+
+ it "hoists default attributes" do
+ expect( node["top_level_attr"] ).to eql("cat")
+ expect( node["baseline_attr"]["one"]).to eql(111)
+ expect( node["baseline_attr"]["two"] ).to eql(2)
+ expect( node["baseline_attr"]["deep"]["five"] ).to eql([5])
+ end
+
+ it "hoists override attributes" do
+ expect( node["top_level_attr"] ).to eql("cat")
+ expect( node["baseline_attr"]["two"] ).to eql(2)
+ expect( node["baseline_attr"]["deep"]["three"] ).to eql(333)
+ expect( node["baseline_attr"]["deep"]["four"] ).to eql([444])
+ expect( node["baseline_attr"]["deep"]["five"] ).to eql([5])
+ end
+ end
+ end
end
describe "fetching the desired cookbook set" do
diff --git a/spec/unit/provider/apt_repository_spec.rb b/spec/unit/provider/apt_repository_spec.rb
index cabf6551c9..d881d01124 100644
--- a/spec/unit/provider/apt_repository_spec.rb
+++ b/spec/unit/provider/apt_repository_spec.rb
@@ -47,7 +47,6 @@ EOF
describe Chef::Provider::AptRepository do
let(:new_resource) { Chef::Resource::AptRepository.new("multiverse") }
- let(:shellout_env) { { env: { "LANG" => "en_US", "LANGUAGE" => "en_US" } } }
let(:provider) do
node = Chef::Node.new
events = Chef::EventDispatch::Dispatcher.new
@@ -60,15 +59,22 @@ describe Chef::Provider::AptRepository do
end
let(:apt_key_finger) do
- r = double("Mixlib::ShellOut", stdout: APT_KEY_FINGER, exitstatus: 0, live_stream: true)
- allow(r).to receive(:run_command)
- r
+ double("shell_out", stdout: APT_KEY_FINGER, exitstatus: 0, error?: false)
end
let(:gpg_finger) do
- r = double("Mixlib::ShellOut", stdout: GPG_FINGER, exitstatus: 0, live_stream: true)
- allow(r).to receive(:run_command)
- r
+ double("shell_out", stdout: GPG_FINGER, exitstatus: 0, error?: false)
+ end
+
+ let(:gpg_shell_out_success) do
+ double("shell_out", :stdout => "pub 2048R/7BD9BF62 2011-08-19 nginx signing key <signing-key@nginx.com>",
+ :exitstatus => 0, :error? => false)
+ end
+
+ let(:gpg_shell_out_failure) do
+ double("shell_out", :stderr => "gpg: no valid OpenPGP data found.\n
+ gpg: processing message failed: eof",
+ :exitstatus => 1, :error? => true)
end
let(:apt_fingerprints) do
@@ -83,35 +89,39 @@ C5986B4F1257FFA86632CBA746181433FBB75451
end
describe "#is_key_id?" do
- it "should detect a key" do
+ it "detects a key" do
expect(provider.is_key_id?("A4FF2279")).to be_truthy
end
- it "should detect a key with a hex signifier" do
+ it "detects a key with a hex signifier" do
expect(provider.is_key_id?("0xA4FF2279")).to be_truthy
end
- it "should reject a key with the wrong length" do
+ it "rejects a key with the wrong length" do
expect(provider.is_key_id?("4FF2279")).to be_falsey
end
- it "should reject a key with non-hex characters" do
+ it "rejects a key with non-hex characters" do
expect(provider.is_key_id?("A4KF2279")).to be_falsey
end
end
describe "#extract_fingerprints_from_cmd" do
- before do
- expect(Mixlib::ShellOut).to receive(:new).and_return(apt_key_finger)
- end
-
- it "should run the desired command" do
- expect(apt_key_finger).to receive(:run_command)
+ it "runs the desired command" do
+ expect(provider).to receive(:shell_out).and_return(apt_key_finger)
provider.extract_fingerprints_from_cmd(apt_key_finger_cmd)
end
- it "should return a list of key fingerprints" do
+ it "returns a list of key fingerprints" do
+ expect(provider).to receive(:shell_out).and_return(apt_key_finger)
expect(provider.extract_fingerprints_from_cmd(apt_key_finger_cmd)).to eql(apt_fingerprints)
end
end
+ describe "#cookbook_name" do
+ it "returns 'test' when the cookbook property is set" do
+ new_resource.cookbook("test")
+ expect(provider.cookbook_name).to eq("test")
+ end
+ end
+
describe "#no_new_keys?" do
before do
allow(provider).to receive(:extract_fingerprints_from_cmd).with(apt_key_finger_cmd).and_return(apt_fingerprints)
@@ -119,14 +129,14 @@ C5986B4F1257FFA86632CBA746181433FBB75451
let(:file) { "/tmp/remote-gpg-keyfile" }
- it "should match a set of keys" do
+ it "matches a set of keys" do
allow(provider).to receive(:extract_fingerprints_from_cmd)
.with("gpg --with-fingerprint --with-colons #{file}")
.and_return(Array(apt_fingerprints.first))
expect(provider.no_new_keys?(file)).to be_truthy
end
- it "should notice missing keys" do
+ it "notices missing keys" do
allow(provider).to receive(:extract_fingerprints_from_cmd)
.with("gpg --with-fingerprint --with-colons #{file}")
.and_return(%w{ F36A89E33CC1BD0F71079007327574EE02A818DD })
@@ -134,11 +144,71 @@ C5986B4F1257FFA86632CBA746181433FBB75451
end
end
+ describe "#key_type" do
+ it "returns :remote_file with an http URL" do
+ expect(provider.key_type("https://www.chef.io/key")).to eq(:remote_file)
+ end
+
+ it "returns :cookbook_file with a chef managed file" do
+ expect(provider).to receive(:has_cookbook_file?).and_return(true)
+ expect(provider.key_type("/foo/bar.key")).to eq(:cookbook_file)
+ end
+
+ it "throws exception if an unknown file specified" do
+ expect(provider).to receive(:has_cookbook_file?).and_return(false)
+ expect { provider.key_type("/foo/bar.key") }.to raise_error(Chef::Exceptions::FileNotFound)
+ end
+ end
+
+ describe "#keyserver_install_cmd" do
+ it "returns keyserver install command" do
+ expect(provider.keyserver_install_cmd("ABC", "gpg.mit.edu")).to eq("apt-key adv --recv --keyserver hkp://gpg.mit.edu:80 ABC")
+ end
+
+ it "uses proxy if key_proxy property is set" do
+ new_resource.key_proxy("proxy.mycorp.dmz:3128")
+ expect(provider.keyserver_install_cmd("ABC", "gpg.mit.edu")).to eq("apt-key adv --recv --keyserver-options http-proxy=proxy.mycorp.dmz:3128 --keyserver hkp://gpg.mit.edu:80 ABC")
+ end
+
+ it "properly handles keyservers passed with hkp:// URIs" do
+ expect(provider.keyserver_install_cmd("ABC", "hkp://gpg.mit.edu")).to eq("apt-key adv --recv --keyserver hkp://gpg.mit.edu ABC")
+ end
+ end
+
+ describe "#is_ppa_url" do
+ it "returns true if the URL starts with ppa:" do
+ expect(provider.is_ppa_url?("ppa://example.com")).to be_truthy
+ end
+
+ it "returns false if the URL does not start with ppa:" do
+ expect(provider.is_ppa_url?("example.com")).to be_falsey
+ end
+ end
+
+ describe "#repo_components" do
+ it "returns 'main' if a PPA and components property not set" do
+ expect(provider).to receive(:is_ppa_url?).and_return(true)
+ expect(provider.repo_components).to eq("main")
+ end
+
+ it "returns components property if a PPA and components is set" do
+ new_resource.components(["foo"])
+ expect(provider).to receive(:is_ppa_url?).and_return(true)
+ expect(provider.repo_components).to eq(["foo"])
+ end
+
+ it "returns components property if not a PPA" do
+ new_resource.components(["foo"])
+ expect(provider).to receive(:is_ppa_url?).and_return(false)
+ expect(provider.repo_components).to eq(["foo"])
+ end
+ end
+
describe "#install_ppa_key" do
let(:url) { "https://launchpad.net/api/1.0/~chef/+archive/main" }
let(:key) { "C5986B4F1257FFA86632CBA746181433FBB75451" }
- it "should get a key" do
+ it "gets a key" do
simples = double("HTTP")
allow(simples).to receive(:get).and_return("\"#{key}\"")
expect(Chef::HTTP::Simple).to receive(:new).with(url).and_return(simples)
@@ -148,42 +218,37 @@ C5986B4F1257FFA86632CBA746181433FBB75451
end
describe "#make_ppa_url" do
- it "should ignore non-ppa repositories" do
- expect(provider.make_ppa_url("some_string")).to be_nil
- end
-
- it "should create a URL" do
+ it "creates a URL" do
expect(provider).to receive(:install_ppa_key).with("chef", "main").and_return(true)
expect(provider.make_ppa_url("ppa:chef/main")).to eql("http://ppa.launchpad.net/chef/main/ubuntu")
end
end
describe "#build_repo" do
- it "should create a repository string" do
+ it "creates a repository string" do
target = %Q{deb "http://test/uri" unstable main\n}
expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil)).to eql(target)
end
- it "should create a repository string with no distribution" do
+ it "creates a repository string with no distribution" do
target = %Q{deb "http://test/uri" main\n}
expect(provider.build_repo("http://test/uri", nil, "main", false, nil)).to eql(target)
end
- it "should create a repository string with source" do
+ it "creates a repository string with source" do
target = %Q{deb "http://test/uri" unstable main\ndeb-src "http://test/uri" unstable main\n}
expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil, true)).to eql(target)
end
- it "should create a repository string with options" do
+ it "creates a repository string with options" do
target = %Q{deb [trusted=yes] "http://test/uri" unstable main\n}
expect(provider.build_repo("http://test/uri", "unstable", "main", true, nil)).to eql(target)
end
- it "should handle a ppa repo" do
+ it "handles a ppa repo" do
target = %Q{deb "http://ppa.launchpad.net/chef/main/ubuntu" unstable main\n}
expect(provider).to receive(:make_ppa_url).with("ppa:chef/main").and_return("http://ppa.launchpad.net/chef/main/ubuntu")
expect(provider.build_repo("ppa:chef/main", "unstable", "main", false, nil)).to eql(target)
end
end
-
end
diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb
index 9426cf41dc..b233fac72b 100644
--- a/spec/unit/provider/link_spec.rb
+++ b/spec/unit/provider/link_spec.rb
@@ -25,7 +25,7 @@ if Chef::Platform.windows?
require "chef/win32/file" #probably need this in spec_helper
end
-describe Chef::Resource::Link, :not_supported_on_win2k3 do
+describe Chef::Resource::Link do
let(:provider) do
node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/bff_spec.rb
index 3c54c6a80c..1018f2d3e9 100644
--- a/spec/unit/provider/package/aix_spec.rb
+++ b/spec/unit/provider/package/bff_spec.rb
@@ -18,7 +18,7 @@
#
require "spec_helper"
-describe Chef::Provider::Package::Aix do
+describe Chef::Provider::Package::Bff do
before(:each) do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@@ -27,7 +27,7 @@ describe Chef::Provider::Package::Aix do
@new_resource = Chef::Resource::Package.new("samba.base")
@new_resource.source("/tmp/samba.base")
- @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context)
+ @provider = Chef::Provider::Package::Bff.new(@new_resource, @run_context)
allow(::File).to receive(:exist?).with(@new_resource.source).and_return(true)
end
@@ -99,7 +99,7 @@ describe Chef::Provider::Package::Aix do
it "should raise an exception if the source is not set but we are installing" do
status = double("Status", :stdout => "", :exitstatus => 1, :format_for_exception => "")
@new_resource = Chef::Resource::Package.new("samba.base")
- @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context)
+ @provider = Chef::Provider::Package::Bff.new(@new_resource, @run_context)
allow(@provider).to receive(:shell_out).and_return(status)
expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
end
@@ -156,7 +156,7 @@ describe Chef::Provider::Package::Aix do
it "should run installp -aYF -d when the package is a path to install" do
@new_resource = Chef::Resource::Package.new("/tmp/samba.base")
- @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context)
+ @provider = Chef::Provider::Package::Bff.new(@new_resource, @run_context)
expect(@new_resource.source).to eq("/tmp/samba.base")
expect(@provider).to receive(:shell_out!).with("installp", "-aYF", "-d", "/tmp/samba.base", "/tmp/samba.base", timeout: 900)
@provider.install_package("/tmp/samba.base", "3.3.12.0")
diff --git a/spec/unit/provider/remote_directory_spec.rb b/spec/unit/provider/remote_directory_spec.rb
index cb1b6e3cd8..d391da3010 100644
--- a/spec/unit/provider/remote_directory_spec.rb
+++ b/spec/unit/provider/remote_directory_spec.rb
@@ -193,7 +193,7 @@ describe Chef::Provider::RemoteDirectory do
expect(::File.exist?(@destination_dir + "/a/multiply/nested/directory/qux.txt")).to be_falsey
end
- it "removes directory symlinks properly", :not_supported_on_win2k3 do
+ it "removes directory symlinks properly" do
symlinked_dir_path = @destination_dir + "/symlinked_dir"
@provider.action = :create
@provider.run_action
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb
index ac641de43a..6fa05c936a 100644
--- a/spec/unit/provider_resolver_spec.rb
+++ b/spec/unit/provider_resolver_spec.rb
@@ -554,6 +554,7 @@ describe Chef::ProviderResolver do
PROVIDERS =
{
bash: [ Chef::Resource::Bash, Chef::Provider::Script ],
+ bff_package: [ Chef::Resource::BffPackage, Chef::Provider::Package::Bff ],
breakpoint: [ Chef::Resource::Breakpoint, Chef::Resource::Breakpoint.action_class ],
chef_gem: [ Chef::Resource::ChefGem, Chef::Provider::Package::Rubygems ],
cookbook_file: [ Chef::Resource::CookbookFile, Chef::Provider::CookbookFile ],
@@ -592,7 +593,6 @@ describe Chef::ProviderResolver do
# We want to check that these are unsupported:
apt_package: nil,
- bff_package: nil,
dpkg_package: nil,
dsc_script: nil,
ips_package: nil,
@@ -781,13 +781,11 @@ describe Chef::ProviderResolver do
},
"aix" => {
- bff_package: [ Chef::Resource::BffPackage, Chef::Provider::Package::Aix ],
cron: [ Chef::Resource::Cron, Chef::Provider::Cron::Aix ],
group: [ Chef::Resource::Group, Chef::Provider::Group::Aix ],
ifconfig: [ Chef::Resource::Ifconfig, Chef::Provider::Ifconfig::Aix ],
mount: [ Chef::Resource::Mount, Chef::Provider::Mount::Aix ],
- # TODO should be Chef::Resource::BffPackage
- package: [ Chef::Resource::Package, Chef::Provider::Package::Aix ],
+ package: [ Chef::Resource::Package, Chef::Provider::Package::Bff ],
rpm_package: [ Chef::Resource::RpmPackage, Chef::Provider::Package::Rpm ],
user: [ Chef::Resource::User::AixUser, Chef::Provider::User::Aix ],
# service: [ Chef::Resource::AixService, Chef::Provider::Service::Aix ],
diff --git a/spec/unit/resource/portage_package_spec.rb b/spec/unit/resource/portage_package_spec.rb
index 02a7aef39a..a37cfd6e41 100644
--- a/spec/unit/resource/portage_package_spec.rb
+++ b/spec/unit/resource/portage_package_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,8 +29,4 @@ describe Chef::Resource::PortagePackage, "initialize" do
it "sets the resource_name to :portage_package" do
expect(resource.resource_name).to eql(:portage_package)
end
-
- it "sets the provider to Chef::Provider::Package::Portage" do
- expect(resource.provider).to eql(Chef::Provider::Package::Portage)
- end
end
diff --git a/spec/unit/resource/registry_key_spec.rb b/spec/unit/resource/registry_key_spec.rb
index 07ad4f820b..d8eea74ed4 100644
--- a/spec/unit/resource/registry_key_spec.rb
+++ b/spec/unit/resource/registry_key_spec.rb
@@ -25,7 +25,7 @@ describe Chef::Resource::RegistryKey, "initialize" do
expect(resource.resource_name).to eql(:registry_key)
end
- it "sets the key equal to the argument to initialize" do
+ it "sets the key property to the resource name" do
expect(resource.key).to eql('HKCU\Software\Raxicoricofallapatorius')
end
@@ -159,6 +159,10 @@ describe Chef::Resource::RegistryKey, "architecture" do
end
end
+ it "does not allow other symbols" do
+ expect { resource.architecture(:nope) }.to raise_error(ArgumentError)
+ end
+
it "does not allow a hash" do
expect { resource.architecture({ :sonic => :screwdriver }) }.to raise_error(ArgumentError)
end
diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb
index 3e9ba1904c..691c55219c 100644
--- a/spec/unit/resource/remote_file_spec.rb
+++ b/spec/unit/resource/remote_file_spec.rb
@@ -31,13 +31,11 @@ describe Chef::Resource::RemoteFile do
it "says its provider is RemoteFile when the source is an absolute URI" do
resource.source("http://www.google.com/robots.txt")
- expect(resource.provider).to eq(Chef::Provider::RemoteFile)
expect(resource.provider_for_action(:create)).to be_kind_of(Chef::Provider::RemoteFile)
end
it "says its provider is RemoteFile when the source is a network share" do
resource.source("\\\\fakey\\fakerton\\fake.txt")
- expect(resource.provider).to eq(Chef::Provider::RemoteFile)
expect(resource.provider_for_action(:create)).to be_kind_of(Chef::Provider::RemoteFile)
end
diff --git a/spec/unit/resource_inspector_spec.rb b/spec/unit/resource_inspector_spec.rb
new file mode 100644
index 0000000000..2cb9c0bb65
--- /dev/null
+++ b/spec/unit/resource_inspector_spec.rb
@@ -0,0 +1,60 @@
+# Copyright:: Copyright 2018, Chef Software, Inc
+# 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"
+require "chef/resource_inspector"
+
+class DummyResource < Chef::Resource
+ resource_name :dummy
+ description "A dummy resource"
+ examples <<~EOH
+ dummy "foo" do
+ first "yes"
+ end
+ EOH
+ introduced "14.0"
+ property :first, String, description: "My First Property", introduced: "14.0"
+
+ action :dummy do
+ return true
+ end
+end
+
+describe ResourceInspector do
+ describe "inspecting a resource" do
+ subject { ResourceInspector.extract_resource(DummyResource, false) }
+
+ it "returns a hash with required data" do
+ expect(subject[:description]).to eq "A dummy resource"
+ expect(subject[:actions]).to match_array [:nothing, :dummy]
+ end
+
+ context "excluding built in properties" do
+ it "returns a single property" do
+ expect(subject[:properties].count).to eq 1
+ expect(subject[:properties].first[:name]).to eq :first
+ end
+ end
+
+ context "including built in properties" do
+ subject { ResourceInspector.extract_resource(DummyResource, true) }
+ it "returns many properties" do
+ expect(subject[:properties].count).to be > 1
+ expect(subject[:properties].map { |n| n[:name] }).to include(:name, :first, :sensitive)
+ end
+ end
+ end
+end
diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb
index 4fcfb01233..0ea704084c 100644
--- a/spec/unit/resource_reporter_spec.rb
+++ b/spec/unit/resource_reporter_spec.rb
@@ -285,7 +285,7 @@ describe Chef::ResourceReporter do
end
it "resource_command in prepared_run_data should be blank" do
- expect(@first_update_report["after"]).to eq({ :command => "sensitive-resource", :user => nil })
+ expect(@first_update_report["after"]).to eq({ :command => "sensitive-resource" })
end
end
diff --git a/spec/unit/win32/security_spec.rb b/spec/unit/win32/security_spec.rb
index 6e4441a482..9d98ccdf49 100644
--- a/spec/unit/win32/security_spec.rb
+++ b/spec/unit/win32/security_spec.rb
@@ -65,14 +65,8 @@ describe "Chef::Win32::Security", :windows_only do
end
describe "self.has_admin_privileges?" do
- it "returns true for windows server 2003" do
- allow(Chef::Platform).to receive(:windows_server_2003?).and_return(true)
- expect(Chef::ReservedNames::Win32::Security.has_admin_privileges?).to be true
- end
-
context "when the user doesn't have admin privileges" do
it "returns false" do
- allow(Chef::Platform).to receive(:windows_server_2003?).and_return(false)
allow(Chef::ReservedNames::Win32::Security).to receive(:open_current_process_token).and_raise("Access is denied.")
expect(Chef::ReservedNames::Win32::Security.has_admin_privileges?).to be false
end
@@ -80,7 +74,6 @@ describe "Chef::Win32::Security", :windows_only do
context "when open_current_process_token fails with some other error than `Access is Denied`" do
it "raises error" do
- allow(Chef::Platform).to receive(:windows_server_2003?).and_return(false)
allow(Chef::ReservedNames::Win32::Security).to receive(:open_current_process_token).and_raise("boom")
expect { Chef::ReservedNames::Win32::Security.has_admin_privileges? }.to raise_error(Chef::Exceptions::Win32APIError)
end
@@ -88,7 +81,6 @@ describe "Chef::Win32::Security", :windows_only do
context "when the user has admin privileges" do
it "returns true" do
- allow(Chef::Platform).to receive(:windows_server_2003?).and_return(false)
allow(Chef::ReservedNames::Win32::Security).to receive(:open_current_process_token)
token = Chef::ReservedNames::Win32::Security.open_current_process_token
allow(token).to receive_message_chain(:handle, :handle)