summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-01 14:29:10 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-02 09:53:41 -0700
commitcd7617fcf5fa45149de934c29abc54d9e8bb4d28 (patch)
tree12d7f51240dbbbe7598d342db1823c91a4d639c7
parent4b689e63aa4ad108c66dea5235ef974f1ee8105e (diff)
downloadchef-cd7617fcf5fa45149de934c29abc54d9e8bb4d28.tar.gz
Fix up comments and default priority (when nothing matches)
-rw-r--r--lib/chef/node_map.rb8
-rw-r--r--lib/chef/provider/group/aix.rb2
-rw-r--r--lib/chef/provider/group/dscl.rb2
-rw-r--r--lib/chef/provider/group/gpasswd.rb2
-rw-r--r--lib/chef/provider/group/groupmod.rb2
-rw-r--r--lib/chef/provider/group/pw.rb2
-rw-r--r--lib/chef/provider/group/suse.rb4
-rw-r--r--lib/chef/provider/group/usermod.rb4
-rw-r--r--lib/chef/provider/group/windows.rb2
-rw-r--r--lib/chef/provider/ifconfig/redhat.rb2
-rw-r--r--lib/chef/provider/mount/solaris.rb2
-rw-r--r--lib/chef/provider/package.rb7
-rw-r--r--lib/chef/util/path_helper.rb204
-rw-r--r--spec/unit/provider_resolver_spec.rb7
-rw-r--r--spec/unit/resource/ifconfig_spec.rb12
15 files changed, 32 insertions, 230 deletions
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index fd284683bd..34f19d18b4 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -45,14 +45,18 @@ class Chef
# anything more specific (see `priority_of`) and is preferred over older
# values of the same specificity. (So all other things being equal,
# newest wins.)
- insert_at = 0
+ insert_at = nil
@map[key].each_with_index do |matcher, index|
if specificity(new_matcher) >= specificity(matcher)
insert_at = index
break
end
end
- @map[key].insert(insert_at, new_matcher)
+ if insert_at
+ @map[key].insert(insert_at, new_matcher)
+ else
+ @map[key] << new_matcher
+ end
self
end
diff --git a/lib/chef/provider/group/aix.rb b/lib/chef/provider/group/aix.rb
index 7d6735a66d..92bb8cb225 100644
--- a/lib/chef/provider/group/aix.rb
+++ b/lib/chef/provider/group/aix.rb
@@ -23,7 +23,7 @@ class Chef
class Provider
class Group
class Aix < Chef::Provider::Group::Groupadd
- provides :group, platform: %w(aix)
+ provides :group, platform: 'aix'
def required_binaries
[ "/usr/bin/mkgroup",
diff --git a/lib/chef/provider/group/dscl.rb b/lib/chef/provider/group/dscl.rb
index d7e8f2e827..9775ac8270 100644
--- a/lib/chef/provider/group/dscl.rb
+++ b/lib/chef/provider/group/dscl.rb
@@ -21,7 +21,7 @@ class Chef
class Group
class Dscl < Chef::Provider::Group
- provides :group, os: "darwin"
+ provides :group, os: 'darwin'
def dscl(*args)
host = "."
diff --git a/lib/chef/provider/group/gpasswd.rb b/lib/chef/provider/group/gpasswd.rb
index 33c594d9a0..432c524acd 100644
--- a/lib/chef/provider/group/gpasswd.rb
+++ b/lib/chef/provider/group/gpasswd.rb
@@ -22,7 +22,7 @@ class Chef
class Provider
class Group
class Gpasswd < Chef::Provider::Group::Groupadd
- provides :group, platform: %w(suse default)
+ provides :group
def load_current_resource
super
diff --git a/lib/chef/provider/group/groupmod.rb b/lib/chef/provider/group/groupmod.rb
index f9299546c8..82b68b8672 100644
--- a/lib/chef/provider/group/groupmod.rb
+++ b/lib/chef/provider/group/groupmod.rb
@@ -21,7 +21,7 @@ class Chef
class Group
class Groupmod < Chef::Provider::Group
- provides :group, os: "netbsd"
+ provides :group, os: 'netbsd'
def load_current_resource
super
diff --git a/lib/chef/provider/group/pw.rb b/lib/chef/provider/group/pw.rb
index 2758d5dea5..f877ed2424 100644
--- a/lib/chef/provider/group/pw.rb
+++ b/lib/chef/provider/group/pw.rb
@@ -20,7 +20,7 @@ class Chef
class Provider
class Group
class Pw < Chef::Provider::Group
- provides :group, platform: %w(freebsd)
+ provides :group, platform: 'freebsd'
def load_current_resource
super
diff --git a/lib/chef/provider/group/suse.rb b/lib/chef/provider/group/suse.rb
index 97acafb2a1..370cbe8492 100644
--- a/lib/chef/provider/group/suse.rb
+++ b/lib/chef/provider/group/suse.rb
@@ -22,8 +22,8 @@ class Chef
class Provider
class Group
class Suse < Chef::Provider::Group::Groupadd
- provides :group, platform: %w(opensuse)
- provides :group, platform: %w(suse), platform_version: '< 12.0'
+ provides :group, platform: 'opensuse'
+ provides :group, platform: 'suse', platform_version: '< 12.0'
def load_current_resource
super
diff --git a/lib/chef/provider/group/usermod.rb b/lib/chef/provider/group/usermod.rb
index d7f302c19b..fee97e05a4 100644
--- a/lib/chef/provider/group/usermod.rb
+++ b/lib/chef/provider/group/usermod.rb
@@ -23,9 +23,7 @@ class Chef
class Group
class Usermod < Chef::Provider::Group::Groupadd
- provides :group, os: "openbsd"
- provides :group, platform: %w(opensuse), platform_version: '>= 12.3'
- provides :group, platform: %w(openindiana opensolaris nexentacore omnios solaris2 smartos hpux)
+ provides :group, os: %w(openbsd solaris2 hpux)
def load_current_resource
super
diff --git a/lib/chef/provider/group/windows.rb b/lib/chef/provider/group/windows.rb
index 54e49b0e06..46d8afc7f6 100644
--- a/lib/chef/provider/group/windows.rb
+++ b/lib/chef/provider/group/windows.rb
@@ -26,7 +26,7 @@ class Chef
class Group
class Windows < Chef::Provider::Group
- provides :group, os: "windows"
+ provides :group, os: 'windows'
def initialize(new_resource,run_context)
super
diff --git a/lib/chef/provider/ifconfig/redhat.rb b/lib/chef/provider/ifconfig/redhat.rb
index 692c2a32bf..ee053d1e52 100644
--- a/lib/chef/provider/ifconfig/redhat.rb
+++ b/lib/chef/provider/ifconfig/redhat.rb
@@ -22,7 +22,7 @@ class Chef
class Provider
class Ifconfig
class Redhat < Chef::Provider::Ifconfig
- provides :ifconfig, platform: %w(centos fedora redhat ibm_powerkvm cloudlinux parallels)
+ provides :ifconfig, platform_family: %w(fedora rhel)
def initialize(new_resource, run_context)
super(new_resource, run_context)
diff --git a/lib/chef/provider/mount/solaris.rb b/lib/chef/provider/mount/solaris.rb
index ae671ab88a..deb04d4d7b 100644
--- a/lib/chef/provider/mount/solaris.rb
+++ b/lib/chef/provider/mount/solaris.rb
@@ -27,7 +27,7 @@ class Chef
class Mount
# Mount Solaris File systems
class Solaris < Chef::Provider::Mount
- provides :mount, platform: %w(openindiana opensolaris nexentacore omnios solaris2 solaris2 < 5.11 smartos)
+ provides :mount, platform: %w(openindiana opensolaris nexentacore omnios solaris2 smartos)
extend Forwardable
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index 469172f870..29ca3005a5 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -509,10 +509,9 @@ class Chef
Chef.set_provider_priority_array :package, [ Homebrew, Macports ], os: "darwin"
- Chef.set_provider_priority_array :package, Dpkg, os: "linux"
- Chef.set_provider_priority_array :package, Apt, platform: %w(ubuntu gcel linaro raspbian linuxmint debian)
- Chef.set_provider_priority_array :package, Yum, platform: %w(xenserver xcp centos amazon scientific fedora oracle redhat ibm_powerkvm cloudlinux parallels)
- Chef.set_provider_priority_array :package, Zypper, platform: %w(opensuse suse)
+ Chef.set_provider_priority_array :package, Apt, platform_family: "debian"
+ Chef.set_provider_priority_array :package, Yum, platform_family: %w(rhel fedora)
+ Chef.set_provider_priority_array :package, Zypper, platform_family: "suse"
Chef.set_provider_priority_array :package, Portage, platform: %w(gentoo)
Chef.set_provider_priority_array :package, Pacman, platform: %w(arch)
Chef.set_provider_priority_array :package, Ips, platform: %w(openindiana opensolaris omnios solaris2)
diff --git a/lib/chef/util/path_helper.rb b/lib/chef/util/path_helper.rb
index 1fddfed9b8..9ebc9319b8 100644
--- a/lib/chef/util/path_helper.rb
+++ b/lib/chef/util/path_helper.rb
@@ -16,208 +16,10 @@
# limitations under the License.
#
+require 'chef-config/path_helper'
+
class Chef
class Util
- class PathHelper
- # Maximum characters in a standard Windows path (260 including drive letter and NUL)
- WIN_MAX_PATH = 259
-
- def self.dirname(path)
- if Chef::Platform.windows?
- # Find the first slash, not counting trailing slashes
- end_slash = path.size
- loop do
- slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]/, end_slash - 1)
- if !slash
- return end_slash == path.size ? '.' : path_separator
- elsif slash == end_slash - 1
- end_slash = slash
- else
- return path[0..slash-1]
- end
- end
- else
- ::File.dirname(path)
- end
- end
-
- BACKSLASH = '\\'.freeze
-
- def self.path_separator
- if Chef::Platform.windows?
- File::ALT_SEPARATOR || BACKSLASH
- else
- File::SEPARATOR
- end
- end
-
- def self.join(*args)
- args.flatten.inject do |joined_path, component|
- # Joined path ends with /
- joined_path = joined_path.sub(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]+$/, '')
- component = component.sub(/^[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]+/, '')
- joined_path += "#{path_separator}#{component}"
- end
- end
-
- def self.validate_path(path)
- if Chef::Platform.windows?
- unless printable?(path)
- msg = "Path '#{path}' contains non-printable characters. Check that backslashes are escaped with another backslash (e.g. C:\\\\Windows) in double-quoted strings."
- Chef::Log.error(msg)
- raise Chef::Exceptions::ValidationFailed, msg
- end
-
- if windows_max_length_exceeded?(path)
- Chef::Log.debug("Path '#{path}' is longer than #{WIN_MAX_PATH}, prefixing with'\\\\?\\'")
- path.insert(0, "\\\\?\\")
- end
- end
-
- path
- end
-
- def self.windows_max_length_exceeded?(path)
- # Check to see if paths without the \\?\ prefix are over the maximum allowed length for the Windows API
- # http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
- unless path =~ /^\\\\?\\/
- if path.length > WIN_MAX_PATH
- return true
- end
- end
-
- false
- end
-
- def self.printable?(string)
- # returns true if string is free of non-printable characters (escape sequences)
- # this returns false for whitespace escape sequences as well, e.g. \n\t
- if string =~ /[^[:print:]]/
- false
- else
- true
- end
- end
-
- # Produces a comparable path.
- def self.canonical_path(path, add_prefix=true)
- # First remove extra separators and resolve any relative paths
- abs_path = File.absolute_path(path)
-
- if Chef::Platform.windows?
- # Add the \\?\ API prefix on Windows unless add_prefix is false
- # Downcase on Windows where paths are still case-insensitive
- abs_path.gsub!(::File::SEPARATOR, path_separator)
- if add_prefix && abs_path !~ /^\\\\?\\/
- abs_path.insert(0, "\\\\?\\")
- end
-
- abs_path.downcase!
- end
-
- abs_path
- end
-
- def self.cleanpath(path)
- path = Pathname.new(path).cleanpath.to_s
- # ensure all forward slashes are backslashes
- if Chef::Platform.windows?
- path = path.gsub(File::SEPARATOR, path_separator)
- end
- path
- end
-
- def self.paths_eql?(path1, path2)
- canonical_path(path1) == canonical_path(path2)
- end
-
- # Paths which may contain glob-reserved characters need
- # to be escaped before globbing can be done.
- # http://stackoverflow.com/questions/14127343
- def self.escape_glob(*parts)
- path = cleanpath(join(*parts))
- path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\"+x }
- end
-
- def self.relative_path_from(from, to)
- pathname = Pathname.new(Chef::Util::PathHelper.cleanpath(to)).relative_path_from(Pathname.new(Chef::Util::PathHelper.cleanpath(from)))
- end
-
- # Retrieves the "home directory" of the current user while trying to ascertain the existence
- # of said directory. The path returned uses / for all separators (the ruby standard format).
- # If the home directory doesn't exist or an error is otherwise encountered, nil is returned.
- #
- # If a set of path elements is provided, they are appended as-is to the home path if the
- # homepath exists.
- #
- # If an optional block is provided, the joined path is passed to that block if the home path is
- # valid and the result of the block is returned instead.
- #
- # Home-path discovery is performed once. If a path is discovered, that value is memoized so
- # that subsequent calls to home_dir don't bounce around.
- #
- # See self.all_homes.
- def self.home(*args)
- @@home_dir ||= self.all_homes { |p| break p }
- if @@home_dir
- path = File.join(@@home_dir, *args)
- block_given? ? (yield path) : path
- end
- end
-
- # See self.home. This method performs a similar operation except that it yields all the different
- # possible values of 'HOME' that one could have on this platform. Hence, on windows, if
- # HOMEDRIVE\HOMEPATH and USERPROFILE are different, the provided block will be called twice.
- # This method goes out and checks the existence of each location at the time of the call.
- #
- # The return is a list of all the returned values from each block invocation or a list of paths
- # if no block is provided.
- def self.all_homes(*args)
- paths = []
- if Chef::Platform.windows?
- # By default, Ruby uses the the following environment variables to determine Dir.home:
- # HOME
- # HOMEDRIVE HOMEPATH
- # USERPROFILE
- # Ruby only checks to see if the variable is specified - not if the directory actually exists.
- # On Windows, HOMEDRIVE HOMEPATH can point to a different location (such as an unavailable network mounted drive)
- # while USERPROFILE points to the location where the user application settings and profile are stored. HOME
- # is not defined as an environment variable (usually). If the home path actually uses UNC, then the prefix is
- # HOMESHARE instead of HOMEDRIVE.
- #
- # We instead walk down the following and only include paths that actually exist.
- # HOME
- # HOMEDRIVE HOMEPATH
- # HOMESHARE HOMEPATH
- # USERPROFILE
-
- paths << ENV['HOME']
- paths << ENV['HOMEDRIVE'] + ENV['HOMEPATH'] if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
- paths << ENV['HOMESHARE'] + ENV['HOMEPATH'] if ENV['HOMESHARE'] && ENV['HOMEPATH']
- paths << ENV['USERPROFILE']
- end
- paths << Dir.home if ENV['HOME']
-
- # Depending on what environment variables we're using, the slashes can go in any which way.
- # Just change them all to / to keep things consistent.
- # Note: Maybe this is a bad idea on some unixy systems where \ might be a valid character depending on
- # the particular brand of kool-aid you consume. This code assumes that \ and / are both
- # path separators on any system being used.
- paths = paths.map { |home_path| home_path.gsub(path_separator, ::File::SEPARATOR) if home_path }
-
- # Filter out duplicate paths and paths that don't exist.
- valid_paths = paths.select { |home_path| home_path && Dir.exists?(home_path) }
- valid_paths = valid_paths.uniq
-
- # Join all optional path elements at the end.
- # If a block is provided, invoke it - otherwise just return what we've got.
- joined_paths = valid_paths.map { |home_path| File.join(home_path, *args) }
- if block_given?
- joined_paths.each { |p| yield p }
- else
- joined_paths
- end
- end
- end
+ PathHelper = ChefConfig::PathHelper
end
end
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb
index 8e6698b454..90d107f2c0 100644
--- a/spec/unit/provider_resolver_spec.rb
+++ b/spec/unit/provider_resolver_spec.rb
@@ -534,13 +534,6 @@ describe Chef::ProviderResolver do
)
end
- on_platform "some_other_linux", os: "linux" do
- expect_providers(
- package: Chef::Provider::Package::Dpkg,
- dpkg_package: Chef::Provider::Package::Dpkg
- )
- end
-
on_platform "gentoo", os: "linux" do
expect_providers(
package: Chef::Provider::Package::Portage,
diff --git a/spec/unit/resource/ifconfig_spec.rb b/spec/unit/resource/ifconfig_spec.rb
index bdacaa35a4..e3e1f6daa2 100644
--- a/spec/unit/resource/ifconfig_spec.rb
+++ b/spec/unit/resource/ifconfig_spec.rb
@@ -47,8 +47,10 @@ describe Chef::Resource::Ifconfig do
end
end
- shared_examples "being a platform using the default ifconfig provider" do |platform, version|
+ shared_examples "being a platform based on an old Debian" do |platform, version|
before do
+ @node.automatic_attrs[:os] = 'linux'
+ @node.automatic_attrs[:platform_family] = 'debian'
@node.automatic_attrs[:platform] = platform
@node.automatic_attrs[:platform_version] = version
end
@@ -60,6 +62,8 @@ describe Chef::Resource::Ifconfig do
shared_examples "being a platform based on RedHat" do |platform, version|
before do
+ @node.automatic_attrs[:os] = 'linux'
+ @node.automatic_attrs[:platform_family] = 'rhel'
@node.automatic_attrs[:platform] = platform
@node.automatic_attrs[:platform_version] = version
end
@@ -71,6 +75,8 @@ describe Chef::Resource::Ifconfig do
shared_examples "being a platform based on a recent Debian" do |platform, version|
before do
+ @node.automatic_attrs[:os] = 'linux'
+ @node.automatic_attrs[:platform_family] = 'debian'
@node.automatic_attrs[:platform] = platform
@node.automatic_attrs[:platform_version] = version
end
@@ -85,7 +91,7 @@ describe Chef::Resource::Ifconfig do
end
describe "when it is an old Debian platform" do
- it_should_behave_like "being a platform using the default ifconfig provider", "debian", "6.0"
+ it_should_behave_like "being a platform based on an old Debian", "debian", "6.0"
end
describe "when it is a new Debian platform" do
@@ -93,7 +99,7 @@ describe Chef::Resource::Ifconfig do
end
describe "when it is an old Ubuntu platform" do
- it_should_behave_like "being a platform using the default ifconfig provider", "ubuntu", "11.04"
+ it_should_behave_like "being a platform based on an old Debian", "ubuntu", "11.04"
end
describe "when it is a new Ubuntu platform" do