From 37a72ed07c6d7ecfbecc71203cc3ac7e3fb69352 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Thu, 5 Sep 2019 14:20:52 -0700 Subject: checkpoint Signed-off-by: Lamont Granquist --- .expeditor/config.yml | 1 + .expeditor/update_version.sh | 3 +- .gitignore | 6 + Gemfile | 1 + Gemfile.lock | 15 +- Rakefile | 8 +- chef-config/chef-config.gemspec | 1 + chef-config/lib/chef-config/config.rb | 12 +- chef-config/lib/chef-config/exceptions.rb | 2 +- chef-config/lib/chef-config/fips.rb | 6 +- chef-config/lib/chef-config/path_helper.rb | 16 +- chef-config/lib/chef-config/version.rb | 17 +- chef-config/lib/chef-config/windows.rb | 12 +- .../lib/chef-config/workstation_config_loader.rb | 4 +- chef-config/spec/spec_helper.rb | 6 +- chef-config/spec/unit/config_spec.rb | 4 +- chef-config/spec/unit/fips_spec.rb | 6 +- chef-config/spec/unit/path_helper_spec.rb | 12 +- .../spec/unit/workstation_config_loader_spec.rb | 6 +- chef-helpers/.rspec | 2 + chef-helpers/Gemfile | 3 + chef-helpers/LICENSE | 201 +++++++++++++++ chef-helpers/Rakefile | 13 + chef-helpers/chef-helpers.gemspec | 31 +++ chef-helpers/lib/chef-helpers.rb | 43 ++++ chef-helpers/lib/chef-helpers/architecture.rb | 112 ++++++++ chef-helpers/lib/chef-helpers/internal.rb | 39 +++ chef-helpers/lib/chef-helpers/introspection.rb | 80 ++++++ chef-helpers/lib/chef-helpers/os.rb | 49 ++++ chef-helpers/lib/chef-helpers/path_sanity.rb | 54 ++++ chef-helpers/lib/chef-helpers/platform.rb | 286 +++++++++++++++++++++ chef-helpers/lib/chef-helpers/platform_family.rb | 170 ++++++++++++ chef-helpers/lib/chef-helpers/service.rb | 63 +++++ chef-helpers/lib/chef-helpers/version.rb | 19 ++ chef-helpers/lib/chef-helpers/which.rb | 47 ++++ chef-helpers/spec/spec_helper.rb | 75 ++++++ chef.gemspec | 1 + habitat/plan.sh | 4 + lib/chef/action_collection.rb | 0 lib/chef/application.rb | 4 +- lib/chef/application/client.rb | 8 +- lib/chef/application/solo.rb | 4 +- lib/chef/audit/runner.rb | 2 +- lib/chef/chef_class.rb | 7 +- lib/chef/chef_fs.rb | 2 +- lib/chef/chef_fs/file_pattern.rb | 2 +- .../chef_server/cookbook_artifacts_dir.rb | 2 +- .../chef_server/versioned_cookbooks_dir.rb | 2 +- .../chef_repository_file_system_root_dir.rb | 4 +- .../chef_fs/file_system/repository/nodes_dir.rb | 4 +- lib/chef/chef_fs/path_utils.rb | 4 +- lib/chef/client.rb | 8 +- lib/chef/config.rb | 5 +- lib/chef/data_collector.rb | 4 +- lib/chef/dsl/core.rb | 2 +- lib/chef/dsl/platform_introspection.rb | 25 +- lib/chef/dsl/recipe.rb | 3 +- lib/chef/event_loggers/windows_eventlog.rb | 2 +- lib/chef/file_content_management/deploy.rb | 4 +- .../file_content_management/deploy/mv_windows.rb | 2 +- lib/chef/file_content_management/tempfile.rb | 2 +- .../error_inspectors/resource_failure_inspector.rb | 2 +- lib/chef/http.rb | 2 +- lib/chef/knife.rb | 2 +- lib/chef/local_mode.rb | 2 +- lib/chef/mixin/file_class.rb | 2 +- lib/chef/mixin/lazy_module_include.rb | 4 +- lib/chef/mixin/path_sanity.rb | 42 +-- lib/chef/mixin/securable.rb | 2 +- lib/chef/mixin/shell_out.rb | 7 +- lib/chef/mixin/template.rb | 2 +- lib/chef/mixin/user_context.rb | 4 +- lib/chef/mixin/which.rb | 4 +- lib/chef/mixin/windows_architecture_helper.rb | 10 +- lib/chef/mixin/windows_env_helper.rb | 8 +- lib/chef/node.rb | 3 +- lib/chef/node_map.rb | 21 +- lib/chef/platform/query_helpers.rb | 10 +- lib/chef/platform/rebooter.rb | 2 +- lib/chef/platform/service_helpers.rb | 96 +------ lib/chef/provider.rb | 2 + lib/chef/provider/file.rb | 2 +- lib/chef/provider/ifconfig/redhat.rb | 2 +- lib/chef/provider/link.rb | 6 +- lib/chef/provider/mount/solaris.rb | 2 +- lib/chef/provider/package/yum.rb | 2 +- lib/chef/provider/registry_key.rb | 2 +- lib/chef/provider/remote_directory.rb | 6 +- lib/chef/provider/remote_file/fetcher.rb | 2 +- lib/chef/provider/remote_file/local_file.rb | 2 +- lib/chef/provider/script.rb | 4 +- lib/chef/provider/service.rb | 7 +- lib/chef/provider/service/arch.rb | 2 +- lib/chef/provider/service/debian.rb | 8 +- lib/chef/provider/service/init.rb | 2 +- lib/chef/provider/service/insserv.rb | 8 +- lib/chef/provider/service/invokercd.rb | 8 +- lib/chef/provider/service/redhat.rb | 8 +- lib/chef/provider/service/systemd.rb | 6 +- lib/chef/provider/service/upstart.rb | 6 +- lib/chef/provider/subversion.rb | 2 +- lib/chef/provider/windows_path.rb | 4 +- lib/chef/provider/windows_task.rb | 4 +- lib/chef/resource.rb | 1 + lib/chef/resource/build_essential.rb | 4 +- lib/chef/resource/execute.rb | 4 +- lib/chef/resource/file.rb | 6 +- lib/chef/resource/link.rb | 2 +- lib/chef/resource/msu_package.rb | 4 +- lib/chef/resource/remote_directory.rb | 4 +- lib/chef/resource/service.rb | 7 +- lib/chef/resource/solaris_package.rb | 2 +- lib/chef/resource/yum_package.rb | 2 +- lib/chef/run_lock.rb | 8 +- lib/chef/util/powershell/ps_credential.rb | 2 +- lib/chef/util/windows/logon_session.rb | 2 +- lib/chef/win32/eventlog.rb | 2 +- omnibus/Gemfile.lock | 110 ++++---- omnibus/config/projects/chef.rb | 2 +- .../event_loggers/windows_eventlog_spec.rb | 2 +- spec/functional/mixin/user_context_spec.rb | 4 +- spec/functional/rebooter_spec.rb | 2 +- spec/functional/resource/cookbook_file_spec.rb | 4 +- spec/functional/resource/template_spec.rb | 2 +- spec/functional/win32/crypto_spec.rb | 2 +- spec/functional/win32/security_spec.rb | 2 +- spec/functional/win32/service_manager_spec.rb | 2 +- spec/functional/win32/sid_spec.rb | 4 +- spec/functional/win32/version_info_spec.rb | 2 +- spec/functional/win32/versions_spec.rb | 2 +- spec/integration/client/client_spec.rb | 2 +- spec/integration/knife/config_get_profile_spec.rb | 4 +- spec/integration/knife/config_get_spec.rb | 4 +- .../integration/knife/config_list_profiles_spec.rb | 4 +- spec/integration/knife/config_use_profile_spec.rb | 4 +- spec/integration/knife/list_spec.rb | 4 +- spec/integration/solo/solo_spec.rb | 2 +- spec/support/matchers/leak.rb | 2 +- spec/support/mock/platform.rb | 2 +- spec/support/platform_helpers.rb | 2 + .../shared/integration/integration_helper.rb | 2 +- spec/support/shared/integration/knife_support.rb | 2 +- spec/support/shared/unit/provider/file.rb | 8 +- spec/unit/application/client_spec.rb | 4 +- spec/unit/application_spec.rb | 2 +- spec/unit/chef_fs/file_pattern_spec.rb | 4 +- spec/unit/chef_fs/path_util_spec.rb | 6 +- spec/unit/client_spec.rb | 6 +- spec/unit/cookbook/cookbook_version_loader_spec.rb | 4 +- spec/unit/cookbook/syntax_check_spec.rb | 4 +- spec/unit/cookbook_loader_spec.rb | 2 +- spec/unit/data_bag_spec.rb | 4 +- spec/unit/dsl/platform_introspection_spec.rb | 32 ++- .../deploy/mv_windows_spec.rb | 2 +- .../compile_error_inspector_spec.rb | 2 +- spec/unit/knife/bootstrap_spec.rb | 2 +- spec/unit/knife/core/gem_glob_loader_spec.rb | 2 +- spec/unit/knife/core/hashed_command_loader_spec.rb | 2 +- spec/unit/knife/core/subcommand_loader_spec.rb | 2 +- spec/unit/knife/core/ui_spec.rb | 4 +- spec/unit/knife/data_bag_from_file_spec.rb | 4 +- spec/unit/knife/environment_from_file_spec.rb | 4 +- spec/unit/knife/supermarket_install_spec.rb | 2 +- spec/unit/mixin/path_sanity_spec.rb | 6 +- spec/unit/mixin/shell_out_spec.rb | 2 +- spec/unit/mixin/template_spec.rb | 8 +- spec/unit/mixin/user_context_spec.rb | 6 +- spec/unit/node_map_spec.rb | 24 +- spec/unit/platform/query_helpers_spec.rb | 18 +- spec/unit/provider/execute_spec.rb | 2 +- spec/unit/provider/link_spec.rb | 10 +- spec/unit/provider/package/windows/exe_spec.rb | 2 +- spec/unit/provider/package/windows_spec.rb | 4 +- spec/unit/provider/remote_file/fetcher_spec.rb | 4 +- spec/unit/provider/remote_file/local_file_spec.rb | 2 +- .../unit/provider/remote_file/network_file_spec.rb | 2 +- spec/unit/provider/script_spec.rb | 4 +- spec/unit/provider/subversion_spec.rb | 6 +- spec/unit/provider/user/dscl_spec.rb | 4 +- spec/unit/provider_resolver_spec.rb | 103 +++----- spec/unit/resource/cookbook_file_spec.rb | 6 +- spec/unit/resource/remote_file_spec.rb | 6 +- spec/unit/role_spec.rb | 4 +- spec/unit/shell_spec.rb | 2 +- spec/unit/win32/error_spec.rb | 2 +- spec/unit/win32/link_spec.rb | 2 +- spec/unit/win32/security_spec.rb | 2 +- spec/unit/windows_service_spec.rb | 2 +- tasks/rspec.rb | 14 +- 189 files changed, 1825 insertions(+), 602 deletions(-) create mode 100644 chef-helpers/.rspec create mode 100644 chef-helpers/Gemfile create mode 100644 chef-helpers/LICENSE create mode 100644 chef-helpers/Rakefile create mode 100644 chef-helpers/chef-helpers.gemspec create mode 100644 chef-helpers/lib/chef-helpers.rb create mode 100644 chef-helpers/lib/chef-helpers/architecture.rb create mode 100644 chef-helpers/lib/chef-helpers/internal.rb create mode 100644 chef-helpers/lib/chef-helpers/introspection.rb create mode 100644 chef-helpers/lib/chef-helpers/os.rb create mode 100644 chef-helpers/lib/chef-helpers/path_sanity.rb create mode 100644 chef-helpers/lib/chef-helpers/platform.rb create mode 100644 chef-helpers/lib/chef-helpers/platform_family.rb create mode 100644 chef-helpers/lib/chef-helpers/service.rb create mode 100644 chef-helpers/lib/chef-helpers/version.rb create mode 100644 chef-helpers/lib/chef-helpers/which.rb create mode 100644 chef-helpers/spec/spec_helper.rb create mode 100644 lib/chef/action_collection.rb diff --git a/.expeditor/config.yml b/.expeditor/config.yml index c90235d03f..d25121bd59 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -14,6 +14,7 @@ slack: rubygems: - chef - chef-config + - chef-helpers docker_images: - chef diff --git a/.expeditor/update_version.sh b/.expeditor/update_version.sh index 222ae5cf27..61ea24a01d 100755 --- a/.expeditor/update_version.sh +++ b/.expeditor/update_version.sh @@ -12,10 +12,11 @@ set -evx sed -i -r "s/^(\s*)VERSION = \".+\"/\1VERSION = \"$(cat VERSION)\"/" chef-config/lib/chef-config/version.rb +sed -i -r "s/^(\s*)VERSION = \".+\"/\1VERSION = \"$(cat VERSION)\"/" chef-helpers/lib/chef-helpers/version.rb sed -i -r "s/VersionString\.new\(\".+\"\)/VersionString.new(\"$(cat VERSION)\")/" lib/chef/version.rb # Update the version inside Gemfile.lock -bundle update chef chef-config --jobs=7 +bundle update chef chef-config chef-helpers --jobs=7 # Once Expeditor finshes executing this script, it will commit the changes and push # the commit as a new tag corresponding to the value in the VERSION file. diff --git a/.gitignore b/.gitignore index ac14a13e8e..670b8e9015 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,9 @@ nodes/ # chef-config chef-config/.bundle chef-config/Gemfile.lock +chef-config/pkg/* + +# chef-helpers +chef-helpers/.bundle +chef-helpers/Gemfile.lock +chef-helpers/pkg/* diff --git a/Gemfile b/Gemfile index f04116d177..5df1ee6d7c 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ source "https://rubygems.org" gem "chef", path: "." gem "chef-config", path: File.expand_path("../chef-config", __FILE__) if File.exist?(File.expand_path("../chef-config", __FILE__)) +gem "chef-helpers", path: File.expand_path("../chef-helpers", __FILE__) if File.exist?(File.expand_path("../chef-helpers", __FILE__)) gem "cheffish", "~> 14" group(:omnibus_package) do diff --git a/Gemfile.lock b/Gemfile.lock index fe71594622..df272fed35 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,6 +13,7 @@ PATH addressable bundler (>= 1.10) chef-config (= 14.4.56) + chef-helpers (= 14.4.56) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -44,6 +45,7 @@ PATH addressable bundler (>= 1.10) chef-config (= 14.4.56) + chef-helpers (= 14.4.56) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -88,11 +90,17 @@ PATH specs: chef-config (14.4.56) addressable + chef-helpers (= 14.4.56) fuzzyurl mixlib-config (>= 2.2.12, < 3.0) mixlib-shellout (~> 2.0) tomlrb (~> 1.2) +PATH + remote: chef-helpers + specs: + chef-helpers (14.4.56) + GEM remote: https://rubygems.org/ specs: @@ -101,7 +109,7 @@ GEM mixlib-cli (~> 1.4) mixlib-shellout (~> 2.0) ast (2.4.0) - backports (3.11.3) + backports (3.11.4) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) builder (3.2.3) @@ -175,7 +183,7 @@ GEM addressable (~> 2.3) libyajl2 (1.2.0) method_source (0.9.0) - mixlib-archive (0.4.13) + mixlib-archive (0.4.16) mixlib-log mixlib-authentication (2.1.1) mixlib-cli (1.7.0) @@ -356,6 +364,7 @@ DEPENDENCIES appbundler chef! chef-config! + chef-helpers! chef-vault cheffish (~> 14) chefstyle! @@ -377,4 +386,4 @@ DEPENDENCIES yard BUNDLED WITH - 1.16.4 + 1.16.1 diff --git a/Rakefile b/Rakefile index e42832c365..cacaee860d 100644 --- a/Rakefile +++ b/Rakefile @@ -25,9 +25,11 @@ require_relative "tasks/announce" # hack the chef-config install to run before the traditional install task task :super_install do - chef_config_path = ::File.join(::File.dirname(__FILE__), "chef-config") - Dir.chdir(chef_config_path) - sh("rake install") + %w{chef-helpers chef-config}.each do |gem| + path = ::File.join(::File.dirname(__FILE__), gem) + Dir.chdir(path) + sh("rake install") + end end task install: :super_install diff --git a/chef-config/chef-config.gemspec b/chef-config/chef-config.gemspec index 547735bb55..8ca76a5def 100644 --- a/chef-config/chef-config.gemspec +++ b/chef-config/chef-config.gemspec @@ -15,6 +15,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] + spec.add_dependency "chef-helpers", "= #{ChefConfig::VERSION}" spec.add_dependency "mixlib-shellout", "~> 2.0" spec.add_dependency "mixlib-config", ">= 2.2.12", "< 3.0" spec.add_dependency "fuzzyurl" diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 0046d25f78..8eceef605e 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -24,7 +24,7 @@ require "pathname" require "chef-config/fips" require "chef-config/logger" -require "chef-config/windows" +require "chef-helpers" require "chef-config/path_helper" require "chef-config/mixin/fuzzy_hostname_matcher" @@ -60,7 +60,7 @@ module ChefConfig # @return [String] a platform specific path def self.platform_specific_path(path) path = PathHelper.cleanpath(path) - if ChefConfig.windows? + if ChefHelpers.windows? # turns \etc\chef\client.rb and \var\chef\client.rb into C:/chef/client.rb # Some installations will be on different drives so use the drive that # the expanded path to __FILE__ is found. @@ -78,7 +78,7 @@ module ChefConfig # # @return [String] the drive letter def self.windows_installation_drive - if ChefConfig.windows? + if ChefHelpers.windows? drive = File.expand_path(__FILE__).split("/", 2)[0] drive = ENV["SYSTEMDRIVE"] if drive.to_s == "" drive @@ -540,7 +540,7 @@ module ChefConfig # Path to the default CA bundle files. default :ssl_ca_path, nil default(:ssl_ca_file) do - if ChefConfig.windows? && embedded_dir + if ChefHelpers.windows? && embedded_dir cacert_path = File.join(embedded_dir, "ssl/certs/cacert.pem") cacert_path if File.exist?(cacert_path) else @@ -799,7 +799,7 @@ module ChefConfig # Those lists of regular expressions define what chef considers a # valid user and group name - if ChefConfig.windows? + if ChefHelpers.windows? set_defaults_for_windows else set_defaults_for_nix @@ -1082,7 +1082,7 @@ module ChefConfig end end rescue - if ChefConfig.windows? + if ChefHelpers.windows? ChefConfig.logger.trace "Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else." else ChefConfig.logger.trace "No usable locale -a command found, assuming you have en_US.UTF-8 installed." diff --git a/chef-config/lib/chef-config/exceptions.rb b/chef-config/lib/chef-config/exceptions.rb index 23fd28f9c8..c11b47b609 100644 --- a/chef-config/lib/chef-config/exceptions.rb +++ b/chef-config/lib/chef-config/exceptions.rb @@ -15,7 +15,7 @@ # limitations under the License. # -require "chef-config/windows" +require "chef-helpers" require "chef-config/logger" module ChefConfig diff --git a/chef-config/lib/chef-config/fips.rb b/chef-config/lib/chef-config/fips.rb index 623ce87686..5afedea015 100644 --- a/chef-config/lib/chef-config/fips.rb +++ b/chef-config/lib/chef-config/fips.rb @@ -1,6 +1,6 @@ # # Author:: Matt Wrock () -# Copyright:: Copyright (c) 2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2016-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,10 +16,12 @@ # limitations under the License. # +require 'chef-helpers' + module ChefConfig def self.fips? - if ChefConfig.windows? + if ChefHelpers.windows? begin require "win32/registry" rescue LoadError diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb index 84217b9591..24d57399f2 100644 --- a/chef-config/lib/chef-config/path_helper.rb +++ b/chef-config/lib/chef-config/path_helper.rb @@ -1,6 +1,6 @@ # # Author:: Bryan McLellan -# Copyright:: Copyright 2014-2018, Chef Software, Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +16,7 @@ # limitations under the License. # -require "chef-config/windows" +require "chef-helpers" require "chef-config/logger" require "chef-config/exceptions" @@ -26,7 +26,7 @@ module ChefConfig WIN_MAX_PATH = 259 def self.dirname(path) - if ChefConfig.windows? + if ChefHelpers.windows? # Find the first slash, not counting trailing slashes end_slash = path.size loop do @@ -47,7 +47,7 @@ module ChefConfig BACKSLASH = '\\'.freeze def self.path_separator - if ChefConfig.windows? + if ChefHelpers.windows? File::ALT_SEPARATOR || BACKSLASH else File::SEPARATOR @@ -71,7 +71,7 @@ module ChefConfig end def self.validate_path(path) - if ChefConfig.windows? + if ChefHelpers.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." ChefConfig.logger.error(msg) @@ -114,7 +114,7 @@ module ChefConfig # First remove extra separators and resolve any relative paths abs_path = File.absolute_path(path) - if ChefConfig.windows? + if ChefHelpers.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) @@ -142,7 +142,7 @@ module ChefConfig def self.cleanpath(path) path = Pathname.new(path).cleanpath.to_s # ensure all forward slashes are backslashes - if ChefConfig.windows? + if ChefHelpers.windows? path = path.gsub(File::SEPARATOR, path_separator) end path @@ -219,7 +219,7 @@ module ChefConfig paths = [] paths << ENV[@@per_tool_home_environment] if defined?(@@per_tool_home_environment) && @@per_tool_home_environment && ENV[@@per_tool_home_environment] paths << ENV["CHEF_HOME"] if ENV["CHEF_HOME"] - if ChefConfig.windows? + if ChefHelpers.windows? # By default, Ruby uses the the following environment variables to determine Dir.home: # HOME # HOMEDRIVE HOMEPATH diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index cd86802b1b..9bb1c348f1 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -1,4 +1,4 @@ -# Copyright:: Copyright 2010-2016, Chef Software, Inc. +# Copyright:: Copyright 2010-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,22 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -# NOTE: This file is generated by running `rake version` in the top level of -# this repo. Do not edit this manually. Edit the VERSION file and run the rake -# task instead. -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - module ChefConfig CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__) VERSION = "14.4.56".freeze end - -# -# NOTE: the Chef::Version class is defined in version_class.rb -# -# NOTE: DO NOT Use the Chef::Version class on ChefConfig::VERSIONs. The -# Chef::Version class is for _cookbooks_ only, and cannot handle -# pre-release versions like "10.14.0.rc.2". Please use Rubygem's -# Gem::Version class instead. -# diff --git a/chef-config/lib/chef-config/windows.rb b/chef-config/lib/chef-config/windows.rb index 9c606110a4..411d9d3bf7 100644 --- a/chef-config/lib/chef-config/windows.rb +++ b/chef-config/lib/chef-config/windows.rb @@ -1,5 +1,5 @@ # -# Copyright:: Copyright 2015-2016, Chef Software, Inc. +# Copyright:: Copyright 2015-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,14 +15,10 @@ # limitations under the License. # -module ChefConfig +require 'chef-helpers' +module ChefConfig def self.windows? - if RUBY_PLATFORM =~ /mswin|mingw|windows/ - true - else - false - end + ChefHelpers.windows? end - end diff --git a/chef-config/lib/chef-config/workstation_config_loader.rb b/chef-config/lib/chef-config/workstation_config_loader.rb index af0c438ca1..c2baad9d17 100644 --- a/chef-config/lib/chef-config/workstation_config_loader.rb +++ b/chef-config/lib/chef-config/workstation_config_loader.rb @@ -20,7 +20,7 @@ require "chef-config/config" require "chef-config/exceptions" require "chef-config/logger" require "chef-config/path_helper" -require "chef-config/windows" +require "chef-helpers" require "chef-config/mixin/dot_d" require "chef-config/mixin/credentials" @@ -139,7 +139,7 @@ module ChefConfig end def working_directory - a = if ChefConfig.windows? + a = if ChefHelpers.windows? env["CD"] else env["PWD"] diff --git a/chef-config/spec/spec_helper.rb b/chef-config/spec/spec_helper.rb index 6a324474e1..8206283a56 100644 --- a/chef-config/spec/spec_helper.rb +++ b/chef-config/spec/spec_helper.rb @@ -1,4 +1,4 @@ -require "chef-config/windows" +require "chef-helpers" # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| @@ -32,8 +32,8 @@ RSpec.configure do |config| config.filter_run :focus config.run_all_when_everything_filtered = true - config.filter_run_excluding windows_only: true unless ChefConfig.windows? - config.filter_run_excluding unix_only: true if ChefConfig.windows? + config.filter_run_excluding windows_only: true unless ChefHelpers.windows? + config.filter_run_excluding unix_only: true if ChefHelpers.windows? # Limits the available syntax to the non-monkey patched syntax that is # recommended. For more details, see: diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb index 7e32a1e742..10f6e4c551 100644 --- a/chef-config/spec/unit/config_spec.rb +++ b/chef-config/spec/unit/config_spec.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Kyle Goodwin () -# 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"); @@ -201,7 +201,7 @@ RSpec.describe ChefConfig::Config do end before :each do - allow(ChefConfig).to receive(:windows?).and_return(is_windows) + allow(ChefHelpers).to receive(:windows?).and_return(is_windows) end describe "class method: windows_installation_drive" do before do diff --git a/chef-config/spec/unit/fips_spec.rb b/chef-config/spec/unit/fips_spec.rb index d53096cead..0b52ddb7fc 100644 --- a/chef-config/spec/unit/fips_spec.rb +++ b/chef-config/spec/unit/fips_spec.rb @@ -1,6 +1,6 @@ # # Author:: Matt Wrock () -# Copyright:: Copyright (c) 2016-2017, Chef Software Inc. +# Copyright:: Copyright (c) 2016-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,7 +32,7 @@ RSpec.describe "ChefConfig.fips?" do let(:fips_path) { "/proc/sys/crypto/fips_enabled" } before(:each) do - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) allow(::File).to receive(:exist?).with(fips_path).and_return(true) allow(::File).to receive(:read).with(fips_path).and_return(enabled) end @@ -69,7 +69,7 @@ RSpec.describe "ChefConfig.fips?" do let(:win_reg_entry) { { "Enabled" => enabled } } before(:each) do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with(fips_key, arch).and_yield(win_reg_entry) end diff --git a/chef-config/spec/unit/path_helper_spec.rb b/chef-config/spec/unit/path_helper_spec.rb index 399b3dc965..303fb2e91d 100644 --- a/chef-config/spec/unit/path_helper_spec.rb +++ b/chef-config/spec/unit/path_helper_spec.rb @@ -1,6 +1,6 @@ # # Author:: Bryan McLellan -# Copyright:: Copyright 2014-2016, Chef Software, Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -58,7 +58,7 @@ RSpec.describe ChefConfig::PathHelper do context "on windows" do before(:each) do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) end include_examples("common_functionality") @@ -106,7 +106,7 @@ RSpec.describe ChefConfig::PathHelper do context "on unix" do before(:each) do - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) end include_examples("common_functionality") @@ -144,7 +144,7 @@ RSpec.describe ChefConfig::PathHelper do context "on windows" do before(:each) do # pass by default - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(path_helper).to receive(:printable?).and_return(true) allow(path_helper).to receive(:windows_max_length_exceeded?).and_return(false) end @@ -254,7 +254,7 @@ RSpec.describe ChefConfig::PathHelper do context "when given more than one argument" do it "joins, cleanpaths, and escapes characters reserved by glob" do args = ["this/*path", "[needs]", "escaping?"] - escaped_path = if ChefConfig.windows? + escaped_path = if ChefHelpers.windows? "this\\\\\\*path\\\\\\[needs\\]\\\\escaping\\?" else "this/\\*path/\\[needs\\]/escaping\\?" @@ -286,7 +286,7 @@ RSpec.describe ChefConfig::PathHelper do describe "all_homes" do before do stub_const("ENV", env) - allow(ChefConfig).to receive(:windows?).and_return(is_windows) + allow(ChefHelpers).to receive(:windows?).and_return(is_windows) end context "on windows" do diff --git a/chef-config/spec/unit/workstation_config_loader_spec.rb b/chef-config/spec/unit/workstation_config_loader_spec.rb index 28fbdf63dd..3f47b4f5eb 100644 --- a/chef-config/spec/unit/workstation_config_loader_spec.rb +++ b/chef-config/spec/unit/workstation_config_loader_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" require "tempfile" require "chef-config/exceptions" -require "chef-config/windows" +require "chef-helpers" require "chef-config/workstation_config_loader" RSpec.describe ChefConfig::WorkstationConfigLoader do @@ -98,7 +98,7 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do let(:env_pwd) { "/path/to/cwd" } before do - if ChefConfig.windows? + if ChefHelpers.windows? env["CD"] = env_pwd else env["PWD"] = env_pwd @@ -430,7 +430,7 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do end describe "when loading a credentials file" do - if ChefConfig.windows? + if ChefHelpers.windows? let(:home) { "C:/Users/example.user" } else let(:home) { "/Users/example.user" } diff --git a/chef-helpers/.rspec b/chef-helpers/.rspec new file mode 100644 index 0000000000..eb3ef03653 --- /dev/null +++ b/chef-helpers/.rspec @@ -0,0 +1,2 @@ +--color +-fd diff --git a/chef-helpers/Gemfile b/chef-helpers/Gemfile new file mode 100644 index 0000000000..b4e2a20bb6 --- /dev/null +++ b/chef-helpers/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gemspec diff --git a/chef-helpers/LICENSE b/chef-helpers/LICENSE new file mode 100644 index 0000000000..11069edd79 --- /dev/null +++ b/chef-helpers/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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. diff --git a/chef-helpers/Rakefile b/chef-helpers/Rakefile new file mode 100644 index 0000000000..df2f59e298 --- /dev/null +++ b/chef-helpers/Rakefile @@ -0,0 +1,13 @@ +require "bundler/gem_tasks" + +task default: :spec + +begin + require "rspec/core/rake_task" + desc "Run standard specs" + RSpec::Core::RakeTask.new(:spec) do |t| + t.pattern = FileList["spec/**/*_spec.rb"] + end +rescue LoadError + STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n" +end diff --git a/chef-helpers/chef-helpers.gemspec b/chef-helpers/chef-helpers.gemspec new file mode 100644 index 0000000000..f1cbc6f17a --- /dev/null +++ b/chef-helpers/chef-helpers.gemspec @@ -0,0 +1,31 @@ +# coding: utf-8 +lib = File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require "chef-helpers/version" + +Gem::Specification.new do |spec| + spec.name = "chef-helpers" + spec.version = ChefHelpers::VERSION + spec.authors = ["Adam Jacob"] + spec.email = ["adam@chef.io"] + + spec.summary = %q{Basic helpers for Core Chef development} + spec.homepage = "https://github.com/chef/chef" + spec.license = "Apache-2.0" + + spec.require_paths = ["lib"] + + # FIXME: helpful screaming at people to not add deps to any other chef-ecosystem gems + + spec.add_development_dependency "rake" + + %w{rspec-core rspec-expectations rspec-mocks}.each do |rspec| + spec.add_development_dependency(rspec, "~> 3.2") + end + + spec.files = %w{Rakefile LICENSE} + Dir.glob("*.gemspec") + + Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } + + spec.bindir = "bin" + spec.executables = [] +end diff --git a/chef-helpers/lib/chef-helpers.rb b/chef-helpers/lib/chef-helpers.rb new file mode 100644 index 0000000000..5a3163f606 --- /dev/null +++ b/chef-helpers/lib/chef-helpers.rb @@ -0,0 +1,43 @@ +# +# Copyright:: Copyright 2015-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-helpers/architecture' +require 'chef-helpers/os' +require 'chef-helpers/platform_family' +require 'chef-helpers/platform' +require 'chef-helpers/introspection' +require 'chef-helpers/service' +require 'chef-helpers/which' +require 'chef-helpers/path_sanity' + +module ChefHelpers + # FIXME: we need a policy around when we can add methods here and should probably be careful + # since this is likely to become breaking changes by injecting methods everywhere. + extend ChefHelpers::Architecture + extend ChefHelpers::OS + extend ChefHelpers::PlatformFamily + extend ChefHelpers::Platform + extend ChefHelpers::Introspection + extend ChefHelpers::Which + include ChefHelpers::Architecture + include ChefHelpers::OS + include ChefHelpers::PlatformFamily + include ChefHelpers::Platform + include ChefHelpers::Introspection + include ChefHelpers::Which + # ChefHelpers::Service is deliberately excluded +end diff --git a/chef-helpers/lib/chef-helpers/architecture.rb b/chef-helpers/lib/chef-helpers/architecture.rb new file mode 100644 index 0000000000..47e8197116 --- /dev/null +++ b/chef-helpers/lib/chef-helpers/architecture.rb @@ -0,0 +1,112 @@ +# +# Copyright:: Copyright 2018-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. +# + +module ChefHelpers + module Architecture + extend self + + # Determine if the current architecture is 64-bit + # + # @return [Boolean] + # + def _64_bit?(node = Internal.getnode) + %w{amd64 x86_64 ppc64 ppc64le s390x ia64 sparc64 aarch64 arch64 arm64 sun4v sun4u} + .include?(node["kernel"]["machine"]) + end + + # Determine if the current architecture is 32-bit + # + # @return [Boolean] + # + def _32_bit?(node = Internal.getnode) + !_64_bit?(node) + end + + # Determine if the current architecture is i386 + # + # @return [Boolean] + # + def i386?(node = Internal.getnode) + _32_bit?(node) && intel?(node) + end + + # Determine if the current architecture is Intel. + # + # @return [Boolean] + # + def intel?(node = Internal.getnode) + %w{i86pc i386 x86_64 amd64 i686}.include?(node["kernel"]["machine"]) + end + + # Determine if the current architecture is SPARC. + # + # @return [Boolean] + # + def sparc?(node = Internal.getnode) + %w{sun4u sun4v}.include?(node["kernel"]["machine"]) + end + + # Determine if the current architecture is Powerpc64 Big Endian + # + # @return [Boolean] + # + def ppc64?(node = Internal.getnode) + %w{ppc64}.include?(node["kernel"]["machine"]) + end + + # Determine if the current architecture is Powerpc64 Little Endian + # + # @return [Boolean] + # + def ppc64le?(node = Internal.getnode) + %w{ppc64le}.include?(node["kernel"]["machine"]) + end + + # Determine if the current architecture is PowerPC. + # + # @return [Boolean] + # + def powerpc?(node = Internal.getnode) + %w{powerpc}.include?(node["kernel"]["machine"]) + end + + # Determine if the current architecture is 32-bit ARM + # + # @return [Boolean] + # + def armhf?(node = Internal.getnode) + %w{armhf}.include?(node["kernel"]["machine"]) + end + + # Determine if the current architecture is s390x + # + # @return [Boolean] + # + def s390x?(node = Internal.getnode) + %w{s390x}.include?(node["kernel"]["machine"]) + end + + # Determine if the current architecture is s390 + # + # @return [Boolean] + # + def s390?(node = Internal.getnode) + %w{s390}.include?(node["kernel"]["machine"]) + end + + end +end diff --git a/chef-helpers/lib/chef-helpers/internal.rb b/chef-helpers/lib/chef-helpers/internal.rb new file mode 100644 index 0000000000..7e2762b8d3 --- /dev/null +++ b/chef-helpers/lib/chef-helpers/internal.rb @@ -0,0 +1,39 @@ +# +# Copyright:: Copyright 2018-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. +# + +module ChefHelpers + module Internal + class << self + + # @api private + def env + ENV + end + + # @api private + def env_path + env['PATH'] + end + + # @api private + def getnode + return node if respond_to?(:node) + run_context&.node if respond_to?(:run_context) + end + end + end +end diff --git a/chef-helpers/lib/chef-helpers/introspection.rb b/chef-helpers/lib/chef-helpers/introspection.rb new file mode 100644 index 0000000000..85941bc878 --- /dev/null +++ b/chef-helpers/lib/chef-helpers/introspection.rb @@ -0,0 +1,80 @@ +# +# Copyright:: Copyright 2018-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. +# + + +module ChefHelpers + # This is for "introspection" helpers in the sense that we are inspecting the + # actual server or image under management to determine running state (duck-typing the system). + # The helpers here may use the node object state from ohai, but typically not the big 5: platform, + # platform_family, platform_version, arch, os. The helpers here should infer somewhat + # higher level facts about the system. + # + module Introspection + # Returns whether the node is a docker container. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def docker?(node = Internal.getnode) + # Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad, + # and that makes us sad too. + !!(node && node.read("virtualization", "systems", "docker") == "guest") + end + + # @param [Chef::Node] node + # + # @return [Boolean] + # + def systemd?(node = Internal.getnode) + ::File.exist?("/proc/1/comm") && ::File.open("/proc/1/comm").gets.chomp == "systemd" + end + + # @param [Chef::Node] node + # + # @return [Boolean] + # + def kitchen?(node = Internal.getnode) + ENV.key?('TEST_KITCHEN') + end + + # @param [Chef::Node] node + # + # @return [Boolean] + # + def ci?(node = Internal.getnode) + ENV.key?('CI') + end + + class << self + def has_systemd_service_unit?(svc_name) + %w{ /etc /usr/lib /lib /run }.any? do |load_path| + ::File.exist?( + "#{load_path}/systemd/system/#{svc_name.gsub(/@.*$/, '@')}.service" + ) + end + end + + def has_systemd_unit?(svc_name) + # TODO: stop supporting non-service units with service resource + %w{ /etc /usr/lib /lib /run }.any? do |load_path| + ::File.exist?("#{load_path}/systemd/system/#{svc_name}") + end + end + end + end +end diff --git a/chef-helpers/lib/chef-helpers/os.rb b/chef-helpers/lib/chef-helpers/os.rb new file mode 100644 index 0000000000..85611f7ed9 --- /dev/null +++ b/chef-helpers/lib/chef-helpers/os.rb @@ -0,0 +1,49 @@ +# +# Copyright:: Copyright 2018-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. +# + +module ChefHelpers + module OS + extend self + + # + # NOTE CAREFULLY: Most node['os'] values should not appear in this file at all. + # + # For cases where node['os'] == node['platform_family'] == node['platform'] then + # only the platform helper should be added. + # + + # Determine if the current node is linux. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def linux?(node = Internal.getnode) + node["os"] == "linux" + end + + # Determine if the current node is darwin. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def darwin?(node = Internal.getnode) + node["os"] == "darwin" + end + end +end diff --git a/chef-helpers/lib/chef-helpers/path_sanity.rb b/chef-helpers/lib/chef-helpers/path_sanity.rb new file mode 100644 index 0000000000..db414bb5f6 --- /dev/null +++ b/chef-helpers/lib/chef-helpers/path_sanity.rb @@ -0,0 +1,54 @@ +# +# Copyright:: Copyright 2018-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-helpers/internal' +require 'chef-helpers/platform_family' + +module ChefHelpers + module PathSanity + extend self + + def sanitized_path + env_path = Internal.env_path.nil? ? "" : Internal.env_path.dup + path_separator = PlatformFamily.windows? ? ";" : ":" + # ensure the Ruby and Gem bindirs are included + # mainly for 'full-stack' Chef installs + new_paths = env_path.split(path_separator) + [ ruby_bindir, gem_bindir ].compact.each do |path| + new_paths = [ path ] + new_paths unless new_paths.include?(path) + end + sane_paths.each do |path| + new_paths << path unless new_paths.include?(path) + end + new_paths.join(path_separator).scrub + end + + class << self + def sane_paths + PlatformFamily.windows? ? %w{} : %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin} + end + + def ruby_bindir + RbConfig::CONFIG["bindir"] + end + + def gem_bindir + Gem.bindir + end + end + end +end diff --git a/chef-helpers/lib/chef-helpers/platform.rb b/chef-helpers/lib/chef-helpers/platform.rb new file mode 100644 index 0000000000..a3bc3d4859 --- /dev/null +++ b/chef-helpers/lib/chef-helpers/platform.rb @@ -0,0 +1,286 @@ +# +# Copyright:: Copyright 2018-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. +# + +module ChefHelpers + module Platform + extend self + + # Determine if the current node is arch linux. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def arch?(node) + node["platform"] == "arch" + end + alias_method :arch_linux?, :arch? + + # + # Determine if the current node is linux mint. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def linuxmint?(node = Internal.getnode) + node["platform"] == "linuxmint" + end + # chef-sugar backcompat methods + alias_method :mint?, :linuxmint? + alias_method :linux_mint?, :linuxmint? + + # + # Determine if the current node is ubuntu. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def ubuntu?(node = Internal.getnode) + node["platform"] == "ubuntu" + end + + # + # Determine if the current node is amazon linux. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def amazon?(node = Internal.getnode) + node["platform"] == "amazon" + end + # chef-sugar backcompat methods + alias_method :amazon_linux?, :amazon? + + # + # Determine if the current node is centos. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def centos?(node = Internal.getnode) + node["platform"] == "centos" + end + + # + # Determine if the current node is oracle linux. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def oracle?(node = Internal.getnode) + node["platform"] == "oracle" + end + # chef-sugar backcompat methods + alias_method :oracle_linux?, :oracle? + + # + # Determine if the current node is scientific linux. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def scientific?(node = Internal.getnode) + node["platform"] == "scientific" + end + # chef-sugar backcompat methods + alias_method :scientific_linux?, :scientific? + + # + # Determine if the current node is redhat enterprise. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def redhat?(node = Internal.getnode) + node["platform"] == "redhat" + end + # chef-sugar backcompat methods + alias_method :redhat_enterprise?, :redhat? + alias_method :redhat_enterprise_linux?, :redhat? + + # Determine if the current node is solaris2 + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def solaris2?(node = Internal.getnode) + node["platform"] == "solaris2" + end + # chef-sugar backcompat methods + alias_method :solaris?, :solaris2? + + # Determine if the current node is smartos + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def smartos?(node = Internal.getnode) + node["platform"] == "smartos" + end + + # Determine if the current node is omnios + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def omnios?(node = Internal.getnode) + node["platform"] == "omnios" + end + + # Determine if the current node is openindiana + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def openindiana?(node = Internal.getnode) + node["platform"] == "openindiana" + end + + # Determine if the current node is opensolaris + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def opensolaris?(node = Internal.getnode) + node["platform"] == "opensolaris" + end + + # Determine if the current node is nexentacore + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def nexentacore?(node = Internal.getnode) + node["platform"] == "nexentacore" + end + + # Determine if the current node is aix + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def aix?(node = Internal.getnode) + node["platform"] == "aix" + end + + # Determine if the current node is freebsd + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def freebsd?(node) + node["platform"] == "freebsd" + end + + # Determine if the current node is openbsd + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def openbsd?(node) + node["platform"] == "openbsd" + end + + # Determine if the current node is netbsd + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def netbsd?(node) + node["platform"] == "netbsd" + end + + # Determine if the current node is dragonflybsd + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def dragonflybsd?(node) + node["platform"] == "dragonflybsd" + end + + # Determine if the current node is MacOS. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def mac_os_x?(node) + node["platform"] == "mac_os_x" + end + + # Determine if the current node is MacOS. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def mac_os_x_server?(node) + node["platform"] == "mac_os_x_server" + end + + # Determine if the current node is gentoo + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def gentoo?(node) + node["platform"] == "gentoo" + end + + # Determine if the current node is slackware. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def slackware?(node) + node["platform"] == "slackware" + end + + # Determine if the current node is SuSE. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def suse?(node) + node["platform"] == "suse" + end + + # FIXME FIXME FIXME: all the rest of the platforms + end +end diff --git a/chef-helpers/lib/chef-helpers/platform_family.rb b/chef-helpers/lib/chef-helpers/platform_family.rb new file mode 100644 index 0000000000..65a658b9c3 --- /dev/null +++ b/chef-helpers/lib/chef-helpers/platform_family.rb @@ -0,0 +1,170 @@ +# +# Copyright:: Copyright 2018-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-helpers/internal' + +module ChefHelpers + module PlatformFamily + + extend self + + # + # NOTE CAREFULLY: Most node['platform_family'] values should not appear in this file at all. + # + # For cases where node['os'] == node['platform_family'] == node['platform'] then + # only the platform helper should be added. + # + # For cases where there are more than one platform in the platform family, but the platform_family + # name duplicates one of the platform names, then it should be added here with the _family? suffix. + # (e.g. fedora_platform?, debian_platform?, etc). + # + + # Determine if the current node is a member of the debian family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def debian_platform?(node) + node["platform_family"] == "debian" + end + # NOTE: debian? matches only the exact platform + + # Determine if the current node is a member of the fedora family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def fedora_platform?(node) + node["platform_family"] == "fedora" + end + # NOTE: fedora? matches only the exact platform + + # Determine if the current node is a member of the OSX family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def mac_os_x_family?(node) + node["platform_family"] == "mac_os_x" + end + alias_method :osx?, :mac_os_x_family? + alias_method :mac?, :mac_os_x_family? + # NOTE: mac_os_x? matches only the exact platform + + # Determine if the current node is a member of the redhat family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def rhel?(node) + node["platform_family"] == "rhel" + end + alias_method :el?, :rhel? + + # Determine if the current node is a member of the suse family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def suse_family?(node) + node["platform_family"] == "suse" + end + # NOTE: suse? matches only the exact platform + + # Determine if the current node is a member of the windows family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def windows?(node = Internal.getnode) + # we prefer to use the node object so that chef-sugar can stub the node data with fauxhai, but + # for contexts where there is no node (e.g. class parsing time) we use RUBY_PLATFORM. + node ? node["platform_family"] == "windows" : RUBY_PLATFORM =~ /mswin|mingw32|windows/ + end + + # + # Platform-Family-like Helpers + # + # These are meta-helpers which address the issue that platform_family is single valued and cannot + # be an array while a tree-like Taxonomy is what is called for in some cases. + # + + # If it uses RPM, it goes in here (rhel, fedora, amazon, suse platform_families). Deliberately does not + # include AIX because bff is AIX's primary package manager and adding it here would make this substantially + # less useful since in no way can AIX trace its lineage back to old redhat distros. This is most useful for + # "smells like redhat, including SuSE". + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def rpm_based?(node = Internal.getnode) + fedora_derived?(node) || node["platform_family"] == "suse" + end + + # RPM-based distros which are not SuSE and are very loosely similar to fedora, using yum or dnf. The historical + # lineage of the distro should have forked off from old redhat fedora distros at some point. Currently rhel, + # fedora and amazon. This is most useful for "smells like redhat, but isn't SuSE". + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def fedora_derived?(node = Internal.getnode) + redhat_based?(node) || node["platform_family"] == "amazon" + end + + # RedHat distros -- fedora and rhel platform_families, nothing else. This is most likely not as useful as the + # "fedora_dervied?" helper. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def redhat_based?(node = Internal.getnode) + %w{rhel fedora}.include?(node["platform_family"]) + end + + # All of the Solaris-lineage. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def solaris_based?(node = Internal.getnode) + %w{solaris2 smartos omnios openindiana opensolaris nexentacore}.include?(node["platform"]) + end + + # All of the BSD-lineage. + # + # Note that MacOSX is not included since Mac deviates so significantly from BSD that including it would not be useful. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def bsd_based?(node = Internal.getnode) + %w{netbsd freebsd openbsd dragonflybsd}.include?(node["platform"]) + end + end +end diff --git a/chef-helpers/lib/chef-helpers/service.rb b/chef-helpers/lib/chef-helpers/service.rb new file mode 100644 index 0000000000..0d865fe00a --- /dev/null +++ b/chef-helpers/lib/chef-helpers/service.rb @@ -0,0 +1,63 @@ +# +# Copyright:: Copyright 2018-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. +# + +module ChefHelpers + # NOTE: these are mixed into the service resource+providers specifically and deliberately not + # injected into the global namespace + module Service + extend self + + def debianrcd?(node = Internal.getnode) + ::File.exist?("/usr/sbin/update-rc.d") + end + + def invokercd?(node = Internal.getnode) + ::File.exist?("/usr/sbin/invoke-rc.d") + end + + def upstart?(node = Internal.getnode) + ::File.exist?("/sbin/initctl") + end + + def insserv?(node = Internal.getnode) + ::File.exist?("/sbin/insserv") + end + + def redhatrcd?(node = Internal.getnode) + ::File.exist?("/sbin/chkconfig") + end + + def service_script_exist?(type, script) + case type + when :initd + ::File.exist?("/etc/init.d/#{script}") + when :upstart + ::File.exist?("/etc/init/#{script}.conf") + when :xinetd + ::File.exist?("/etc/xinetd.d/#{script}") + when :etc_rcd + ::File.exist?("/etc/rc.d/#{script}") + when :systemd + ::File.exist?("/etc/init.d/#{script}") || + ChefHelpers::Introspection.has_systemd_service_unit?(script) || + ChefHelpers::Introspection.has_systemd_unit?(script) + else + raise ArgumentError, "type of service must be one of :initd, :upstart, :xinetd, :etc_rcd, or :systemd" + end + end + end +end diff --git a/chef-helpers/lib/chef-helpers/version.rb b/chef-helpers/lib/chef-helpers/version.rb new file mode 100644 index 0000000000..a543865510 --- /dev/null +++ b/chef-helpers/lib/chef-helpers/version.rb @@ -0,0 +1,19 @@ +# Copyright:: Copyright 2010-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. + +module ChefHelpers + CHEFHELPERS_ROOT = File.expand_path("../..", __FILE__) + VERSION = "14.4.56".freeze +end diff --git a/chef-helpers/lib/chef-helpers/which.rb b/chef-helpers/lib/chef-helpers/which.rb new file mode 100644 index 0000000000..e0a48f564c --- /dev/null +++ b/chef-helpers/lib/chef-helpers/which.rb @@ -0,0 +1,47 @@ +# +# Copyright:: Copyright 2018-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-helpers/internal' +require 'chef-helpers/which' + +module ChefHelpers + module Which + extend self + + def which(*cmds, extra_path: nil, &block) + where(*cmds, extra_path: extra_path, &block).first || false + end + + def where(*cmds, extra_path: nil, &block) + extra_path ||= PathSanity.sanitized_path + paths = Internal.env_path.split(::File::PATH_SEPARATOR) + Array(extra_path) + cmds.map do |cmd| + paths.map do |path| + filename = ::File.join(path, cmd) + filename if Which.valid_executable?(filename, &block) + end.compact + end.flatten + end + + class << self + def valid_executable?(filename, &block) + return false unless ::File.executable?(filename) && !::File.directory?(filename) + block ? yield(filename) : true + end + end + end +end diff --git a/chef-helpers/spec/spec_helper.rb b/chef-helpers/spec/spec_helper.rb new file mode 100644 index 0000000000..8206283a56 --- /dev/null +++ b/chef-helpers/spec/spec_helper.rb @@ -0,0 +1,75 @@ +require "chef-helpers" + +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + config.filter_run_excluding windows_only: true unless ChefHelpers.windows? + config.filter_run_excluding unix_only: true if ChefHelpers.windows? + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + # config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +end diff --git a/chef.gemspec b/chef.gemspec index 6cbbe4b7fc..8d39c9bcef 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -16,6 +16,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.4.0" s.add_dependency "chef-config", "= #{Chef::VERSION}" + s.add_dependency "chef-helpers", "= #{Chef::VERSION}" s.add_dependency "mixlib-cli", "~> 1.7" s.add_dependency "mixlib-log", "~> 2.0", ">= 2.0.3" diff --git a/habitat/plan.sh b/habitat/plan.sh index 26fcd5dad6..0169a8ff58 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -56,6 +56,10 @@ do_build() { bundle config --local silence_root_warning 1 + pushd chef-helpers > /dev/null + _bundle_install "${pkg_prefix}/bundle" + popd > /dev/null + pushd chef-config > /dev/null _bundle_install "${pkg_prefix}/bundle" popd > /dev/null diff --git a/lib/chef/action_collection.rb b/lib/chef/action_collection.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/chef/application.rb b/lib/chef/application.rb index 81637eabb8..ecc8578937 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -75,7 +75,7 @@ class Chef Chef::Application.fatal!("SIGTERM received, stopping", Chef::Exceptions::SigTerm.new) end - unless Chef::Platform.windows? + unless ChefHelpers.windows? trap("QUIT") do logger.info("SIGQUIT received, call stack:\n " + caller.join("\n ")) end @@ -288,7 +288,7 @@ class Chef # win32-process gem exposes some form of :fork for Process # class. So we are separately ensuring that the platform we're # running on is not windows before forking. - chef_config[:client_fork] && Process.respond_to?(:fork) && !Chef::Platform.windows? + chef_config[:client_fork] && Process.respond_to?(:fork) && !ChefHelpers.windows? end # Run chef-client once and then exit. If TERM signal is received, ignores the diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 0e5584ded3..3b2de4e7e5 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -113,7 +113,7 @@ class Chef::Application::Client < Chef::Application description: "Group to set privilege to", proc: nil - unless Chef::Platform.windows? + unless ChefHelpers.windows? option :daemonize, short: "-d [WAIT]", long: "--daemonize [WAIT]", @@ -264,7 +264,7 @@ class Chef::Application::Client < Chef::Application description: "Set maximum duration to wait for another client run to finish, default is indefinitely.", proc: lambda { |s| s.to_i } - if Chef::Platform.windows? + if ChefHelpers.windows? option :fatal_windows_admin_check, short: "-A", long: "--fatal-windows-admin-check", @@ -366,7 +366,7 @@ class Chef::Application::Client < Chef::Application Chef::Config[:client_fork] = !!Chef::Config[:interval] end - if !Chef::Config[:client_fork] && Chef::Config[:interval] && !Chef::Platform.windows? + if !Chef::Config[:client_fork] && Chef::Config[:interval] && !ChefHelpers.windows? Chef::Application.fatal!(unforked_interval_error_message) end @@ -412,7 +412,7 @@ class Chef::Application::Client < Chef::Application def setup_signal_handlers super - unless Chef::Platform.windows? + unless ChefHelpers.windows? SELF_PIPE.replace IO.pipe trap("USR1") do diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb index ee7d1530ed..bb4550a90e 100644 --- a/lib/chef/application/solo.rb +++ b/lib/chef/application/solo.rb @@ -75,7 +75,7 @@ class Chef::Application::Solo < Chef::Application option :color, long: "--[no-]color", boolean: true, - default: !Chef::Platform.windows?, + default: !ChefHelpers.windows?, description: "Use colored output, defaults to enabled" option :log_level, @@ -111,7 +111,7 @@ class Chef::Application::Solo < Chef::Application description: "Group to set privilege to", proc: nil - unless Chef::Platform.windows? + unless ChefHelpers.windows? option :daemonize, short: "-d", long: "--daemonize", diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb index 847d5efbd5..96de022a23 100644 --- a/lib/chef/audit/runner.rb +++ b/lib/chef/audit/runner.rb @@ -146,7 +146,7 @@ class Chef # Set up the backend for Specinfra/Serverspec. :exec is the local system; on Windows, it is :cmd def configure_specinfra - if Chef::Platform.windows? + if ChefHelpers.windows? Specinfra.configuration.backend = :cmd Specinfra.configuration.os = { family: "windows" } else diff --git a/lib/chef/chef_class.rb b/lib/chef/chef_class.rb index 95b03f1c5c..dec9542d72 100644 --- a/lib/chef/chef_class.rb +++ b/lib/chef/chef_class.rb @@ -1,6 +1,6 @@ # # Author:: Lamont Granquist () -# Copyright:: Copyright 2015-2016, Chef Software, Inc. +# Copyright:: Copyright 2015-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -239,10 +239,5 @@ class Chef end end - # @api private Only for test dependency injection; not evenly implemented as yet. - def self.path_to(path) - path - end - reset! end diff --git a/lib/chef/chef_fs.rb b/lib/chef/chef_fs.rb index 43a9efd5e2..31400895fc 100644 --- a/lib/chef/chef_fs.rb +++ b/lib/chef/chef_fs.rb @@ -53,7 +53,7 @@ require "chef/platform" class Chef module ChefFS def self.windows? - Chef::Platform.windows? + ChefHelpers.windows? end end end diff --git a/lib/chef/chef_fs/file_pattern.rb b/lib/chef/chef_fs/file_pattern.rb index 835e06eab7..41becca99e 100644 --- a/lib/chef/chef_fs/file_pattern.rb +++ b/lib/chef/chef_fs/file_pattern.rb @@ -239,7 +239,7 @@ class Chef end def self.pattern_special_characters - if Chef::ChefFS.windows? + if ChefHelpers.windows? @pattern_special_characters ||= /(\*\*|\*|\?|[\*\?\.\|\(\)\[\]\{\}\+\\\\\^\$])/ else # Unix also supports character regexes and backslashes diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb index e4df7858a7..2eef494ba7 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb @@ -86,7 +86,7 @@ class Chef # the symlink without removing the original contents if we # are running on windows # - if Chef::Platform.windows? + if ChefHelpers.windows? Dir.rmdir proxy_cookbook_path end end diff --git a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb index 94c1a5b695..24dce29cf7 100644 --- a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb @@ -91,7 +91,7 @@ class Chef # the symlink without removing the original contents if we # are running on windows # - if Chef::Platform.windows? + if ChefHelpers.windows? Dir.rmdir proxy_cookbook_path end end diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb index e07a73a118..26244e7fe4 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb @@ -44,7 +44,7 @@ require "chef/chef_fs/data_handler/role_data_handler" require "chef/chef_fs/data_handler/user_data_handler" require "chef/chef_fs/data_handler/group_data_handler" require "chef/chef_fs/data_handler/container_data_handler" -require "chef/win32/security" if Chef::Platform.windows? +require "chef/win32/security" if ChefHelpers.windows? class Chef module ChefFS @@ -111,7 +111,7 @@ class Chef child_paths[name].each do |path| begin Dir.mkdir(path, 0700) - if Chef::Platform.windows? + if ChefHelpers.windows? all_mask = Chef::ReservedNames::Win32::API::Security::GENERIC_ALL administrators = Chef::ReservedNames::Win32::Security::SID.Administrators owner = Chef::ReservedNames::Win32::Security::SID.default_security_object_owner diff --git a/lib/chef/chef_fs/file_system/repository/nodes_dir.rb b/lib/chef/chef_fs/file_system/repository/nodes_dir.rb index a0dd0c9e51..41604f2de6 100644 --- a/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/nodes_dir.rb @@ -20,7 +20,7 @@ require "chef/chef_fs/file_system/repository/node" require "chef/chef_fs/file_system/repository/directory" require "chef/chef_fs/file_system/exceptions" -require "chef/win32/security" if Chef::Platform.windows? +require "chef/win32/security" if ChefHelpers.windows? class Chef module ChefFS @@ -35,7 +35,7 @@ class Chef def create_child(child_name, file_contents = nil) child = super File.chmod(0600, child.file_path) - if Chef::Platform.windows? + if ChefHelpers.windows? read_mask = Chef::ReservedNames::Win32::API::Security::GENERIC_READ write_mask = Chef::ReservedNames::Win32::API::Security::GENERIC_WRITE administrators = Chef::ReservedNames::Win32::Security::SID.Administrators diff --git a/lib/chef/chef_fs/path_utils.rb b/lib/chef/chef_fs/path_utils.rb index 4de23f8266..3a76311586 100644 --- a/lib/chef/chef_fs/path_utils.rb +++ b/lib/chef/chef_fs/path_utils.rb @@ -57,7 +57,7 @@ class Chef end def self.regexp_path_separator - Chef::ChefFS.windows? ? '[\/\\\\]' : "/" + ChefHelpers.windows? ? '[\/\\\\]' : "/" end # Given a server path, determines if it is absolute. @@ -101,7 +101,7 @@ class Chef # Compares two path fragments according to the case-sentitivity of the host platform. def self.os_path_eq?(left, right) - Chef::ChefFS.windows? ? left.casecmp(right) == 0 : left == right + ChefHelpers.windows? ? left.casecmp(right) == 0 : left == right end # Given two general OS-dependent file paths, determines the relative path of the diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 33d625c54e..5fd3a11562 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -20,7 +20,6 @@ require "chef/config" require "chef/mixin/params_validate" -require "chef/mixin/path_sanity" require "chef/log" require "chef/deprecated" require "chef/server_api" @@ -53,6 +52,7 @@ require "chef/policy_builder" require "chef/request_id" require "chef/platform/rebooter" require "chef/mixin/deprecation" +require "chef-helpers" require "ohai" require "rbconfig" @@ -61,8 +61,6 @@ class Chef # The main object in a Chef run. Preps a Chef::Node and Chef::RunContext, # syncs cookbooks if necessary, and triggers convergence. class Client - include Chef::Mixin::PathSanity - extend Chef::Mixin::Deprecation # @@ -256,7 +254,7 @@ class Chef logger.info("Platform: #{RUBY_PLATFORM}") logger.info "Chef-client pid: #{Process.pid}" logger.debug("Chef-client request_id: #{request_id}") - enforce_path_sanity + ENV['PATH'] = ChefHelpers::PathSanity.sanitized_path if Chef::Config[:enforce_path_sanity] run_ohai generate_guid @@ -825,7 +823,7 @@ class Chef # @api private # def do_windows_admin_check - if Chef::Platform.windows? + if ChefHelpers.windows? logger.trace("Checking for administrator privileges....") if !has_admin_privileges? diff --git a/lib/chef/config.rb b/lib/chef/config.rb index f5466ae145..d2d79b9266 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -4,7 +4,7 @@ # Author:: AJ Christensen () # Author:: Mark Mzyk () # Author:: Kyle Goodwin () -# 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"); @@ -28,6 +28,7 @@ require "chef-config/logger" ChefConfig.logger = Chef::Log require "chef-config/config" +require "chef-helpers" require "chef/platform/query_helpers" # Ohai::Config defines its own log_level and log_location. When loaded, it will @@ -55,7 +56,7 @@ class Chef default :event_loggers do evt_loggers = [] - if ChefConfig.windows? && !Chef::Platform.windows_nano_server? + if ChefHelpers.windows? && !Chef::Platform.windows_nano_server? evt_loggers << :win_evt end evt_loggers diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb index 5cc92a34e4..04238afa89 100644 --- a/lib/chef/data_collector.rb +++ b/lib/chef/data_collector.rb @@ -2,7 +2,7 @@ # Author:: Adam Leff () # Author:: Ryan Cragun () # -# Copyright:: Copyright 2012-2017, Chef Software Inc. +# Copyright:: Copyright 2012-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -132,7 +132,7 @@ class Chef def run_started(current_run_status) update_run_status(current_run_status) - message = Chef::DataCollector::Messages.run_start_message(current_run_status) + message = Chef::DataCollector::Messages.construct_message(current_run_status) disable_reporter_on_error do send_to_data_collector(message) end diff --git a/lib/chef/dsl/core.rb b/lib/chef/dsl/core.rb index d7c5b6a006..77f9b567c9 100644 --- a/lib/chef/dsl/core.rb +++ b/lib/chef/dsl/core.rb @@ -1,7 +1,7 @@ #-- # Author:: Adam Jacob () # Author:: Christopher Walters () -# Copyright:: Copyright 2008-2016 Chef Software, Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb index e7f0c60f0d..7bd0fb0361 100644 --- a/lib/chef/dsl/platform_introspection.rb +++ b/lib/chef/dsl/platform_introspection.rb @@ -16,13 +16,15 @@ # limitations under the License. # +require 'chef-helpers' + class Chef module DSL - # == Chef::DSL::PlatformIntrospection # Provides the DSL for platform-dependent switch logic, such as # #value_for_platform. module PlatformIntrospection + include ChefHelpers # Implementation class for determining platform dependent values class PlatformDependentValue @@ -243,27 +245,16 @@ class Chef end end - # Shamelessly stolen from https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/docker.rb - # Given a node object, returns whether the node is a docker container. - # - # === Parameters - # node:: [Chef::Node] The node to check. - # - # === Returns - # true:: if the current node is a docker container - # false:: if the current node is not a docker container - def docker?(node = run_context.nil? ? nil : run_context.node) - # Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad, - # and that makes us sad too. - !!(node && node[:virtualization] && node[:virtualization][:systems] && - node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest") - end - # a simple helper to determine if we're on a windows release pre-2012 / 8 # @return [Boolean] Is the system older than Windows 8 / 2012 def older_than_win_2012_or_8?(node = run_context.nil? ? nil : run_context.node) node["platform_version"].to_f < 6.2 end + + # ^^^^^^ NOTE: PLEASE DO NOT CONTINUE TO ADD THESE KINDS OF PLATFORM_VERSION APIS WITHOUT ^^^^^^^ + # ^^^^^^ GOING THROUGH THE COMMUNITY RFC PROCESS AND ADDRESS THE EXISTING CHEF-SUGAR ONES ^^^^^^^ + # ^^^^^^ DO "THE HARD RIGHT THING" AND ADDRESS THE BROADER PROBLEM AND FIX IT ALL. ^^^^^^^ + end end end diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb index 9da812cec0..b00502c186 100644 --- a/lib/chef/dsl/recipe.rb +++ b/lib/chef/dsl/recipe.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Christopher Walters () -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ require "chef/dsl/reboot_pending" require "chef/dsl/audit" require "chef/dsl/powershell" require "chef/dsl/core" +require "chef/dsl/universal" require "chef/mixin/lazy_module_include" class Chef diff --git a/lib/chef/event_loggers/windows_eventlog.rb b/lib/chef/event_loggers/windows_eventlog.rb index 950477556a..0ed16997a4 100644 --- a/lib/chef/event_loggers/windows_eventlog.rb +++ b/lib/chef/event_loggers/windows_eventlog.rb @@ -38,7 +38,7 @@ class Chef SOURCE = "Chef".freeze def self.available? - Chef::Platform.windows? + ChefHelpers.windows? end def initialize diff --git a/lib/chef/file_content_management/deploy.rb b/lib/chef/file_content_management/deploy.rb index 1e3ae55c21..751ca76b6b 100644 --- a/lib/chef/file_content_management/deploy.rb +++ b/lib/chef/file_content_management/deploy.rb @@ -18,7 +18,7 @@ require "chef/file_content_management/deploy/cp" require "chef/file_content_management/deploy/mv_unix" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/file_content_management/deploy/mv_windows" end @@ -27,7 +27,7 @@ class Chef class Deploy def self.strategy(atomic_update) if atomic_update - Chef::Platform.windows? ? MvWindows.new() : MvUnix.new() + ChefHelpers.windows? ? MvWindows.new() : MvUnix.new() else Cp.new() end diff --git a/lib/chef/file_content_management/deploy/mv_windows.rb b/lib/chef/file_content_management/deploy/mv_windows.rb index 210400bc08..6e534c1ff0 100644 --- a/lib/chef/file_content_management/deploy/mv_windows.rb +++ b/lib/chef/file_content_management/deploy/mv_windows.rb @@ -22,7 +22,7 @@ # require "chef/platform/query_helpers" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/security" end diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb index c3bf07d92b..4aa8add8e6 100644 --- a/lib/chef/file_content_management/tempfile.rb +++ b/lib/chef/file_content_management/tempfile.rb @@ -67,7 +67,7 @@ class Chef basename = ::File.basename(@new_resource.path, tempfile_extension) # the leading "[.]chef-" here should be considered a public API and should not be changed basename.insert 0, "chef-" - basename.insert 0, "." unless Chef::Platform.windows? # dotfile if we're not on windows + basename.insert 0, "." unless ChefHelpers.windows? # dotfile if we're not on windows basename.scrub end diff --git a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb index 1cc147db7a..1cce0538d6 100644 --- a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +++ b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb @@ -51,7 +51,7 @@ class Chef error_description.section("Template Context:", "#{exception.source_location}\n#{exception.source_listing}") end - if Chef::Platform.windows? + if ChefHelpers.windows? require "chef/win32/security" if !Chef::ReservedNames::Win32::Security.has_admin_privileges? diff --git a/lib/chef/http.rb b/lib/chef/http.rb index 3f815b9eff..c6e1530707 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -514,7 +514,7 @@ class Chef content_length = response["Content-Length"] if tf.nil? tf = Tempfile.open("chef-rest") - if Chef::Platform.windows? + if ChefHelpers.windows? tf.binmode # required for binary files on Windows platforms end end diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 6e525bdf3d..13c397b180 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -440,7 +440,7 @@ class Chef unless respond_to?(:run) ui.error "You need to add a #run method to your knife command before you can use it" end - enforce_path_sanity + ENV['PATH'] = ChefHelpers::PathSanity.sanitized_path if Chef::Config[:enforce_path_sanity] maybe_setup_fips Chef::LocalMode.with_server_connectivity do run diff --git a/lib/chef/local_mode.rb b/lib/chef/local_mode.rb index 5630a54335..72d40d8c81 100644 --- a/lib/chef/local_mode.rb +++ b/lib/chef/local_mode.rb @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. require "chef/config" -if Chef::Platform.windows? +if ChefHelpers.windows? if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1") require "chef/monkey_patches/webrick-utils" end diff --git a/lib/chef/mixin/file_class.rb b/lib/chef/mixin/file_class.rb index 166dd5796a..d27116014d 100644 --- a/lib/chef/mixin/file_class.rb +++ b/lib/chef/mixin/file_class.rb @@ -23,7 +23,7 @@ class Chef module FileClass def file_class - @host_os_file ||= if Chef::Platform.windows? + @host_os_file ||= if ChefHelpers.windows? require "chef/win32/file" Chef::ReservedNames::Win32::File else diff --git a/lib/chef/mixin/lazy_module_include.rb b/lib/chef/mixin/lazy_module_include.rb index 34e1fce4f1..6705758c4b 100644 --- a/lib/chef/mixin/lazy_module_include.rb +++ b/lib/chef/mixin/lazy_module_include.rb @@ -1,5 +1,5 @@ # -# Copyright:: Copyright 2011-2016, Chef Software Inc. +# Copyright:: Copyright 2011-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -52,6 +52,7 @@ class Chef infector = Module.new do define_method(:included) do |subklass| super(subklass) + puts "infecting #{subclass}" subklass.extend(infector) parent_klass.descendants.push(subklass) end @@ -68,6 +69,7 @@ class Chef super classes.each do |klass| descendants.each do |descendant| + puts "recursively including #{klass} into #{descendant}" descendant.send(:include, klass) end end diff --git a/lib/chef/mixin/path_sanity.rb b/lib/chef/mixin/path_sanity.rb index c441d0770a..51f0595b4f 100644 --- a/lib/chef/mixin/path_sanity.rb +++ b/lib/chef/mixin/path_sanity.rb @@ -1,6 +1,6 @@ # # Author:: Seth Chisamore () -# Copyright:: Copyright 2011-2017, Chef Software Inc. +# Copyright:: Copyright 2011-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,48 +19,12 @@ class Chef module Mixin module PathSanity - + # FIXME: deprecatad def enforce_path_sanity(env = ENV) if Chef::Config[:enforce_path_sanity] - env["PATH"] = sanitized_path(env) - end - end - - def sanitized_path(env = ENV) - env_path = env["PATH"].nil? ? "" : env["PATH"].dup - path_separator = Chef::Platform.windows? ? ";" : ":" - # ensure the Ruby and Gem bindirs are included - # mainly for 'full-stack' Chef installs - new_paths = env_path.split(path_separator) - [ ruby_bindir, gem_bindir ].compact.each do |path| - new_paths = [ path ] + new_paths unless new_paths.include?(path) - end - sane_paths.each do |path| - new_paths << path unless new_paths.include?(path) - end - new_paths.join(path_separator).encode("utf-8", invalid: :replace, undef: :replace) - end - - private - - def sane_paths - @sane_paths ||= begin - if Chef::Platform.windows? - %w{} - else - %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin} - end + env["PATH"] = ChefHelpers::PathSanity.sanitized_path(env) end end - - def ruby_bindir - RbConfig::CONFIG["bindir"] - end - - def gem_bindir - Gem.bindir - end - end end end diff --git a/lib/chef/mixin/securable.rb b/lib/chef/mixin/securable.rb index eb59f184d1..a94cbc8056 100644 --- a/lib/chef/mixin/securable.rb +++ b/lib/chef/mixin/securable.rb @@ -49,7 +49,7 @@ class Chef end # Windows does not support the sticky or setuid bits - if Chef::Platform.windows? + if ChefHelpers.windows? Integer(m) <= 0777 && Integer(m) >= 0 else Integer(m) <= 07777 && Integer(m) >= 0 diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb index 25a8ee989c..169dbda1fc 100644 --- a/lib/chef/mixin/shell_out.rb +++ b/lib/chef/mixin/shell_out.rb @@ -16,12 +16,11 @@ # limitations under the License. require "mixlib/shellout" -require "chef/mixin/path_sanity" +require "chef-helpers/path_sanity" class Chef module Mixin module ShellOut - extend Chef::Mixin::PathSanity # PREFERRED APIS: # @@ -162,7 +161,7 @@ class Chef "LC_ALL" => Chef::Config[:internal_locale], "LANGUAGE" => Chef::Config[:internal_locale], "LANG" => Chef::Config[:internal_locale], - env_path => sanitized_path, + env_path => ChefHelpers::PathSanity.sanitized_path, }.update(options[env_key] || {}) end options @@ -244,7 +243,7 @@ class Chef end def self.env_path - if Chef::Platform.windows? + if ChefHelpers.windows? "Path" else "PATH" diff --git a/lib/chef/mixin/template.rb b/lib/chef/mixin/template.rb index bb811aa758..812d1b3025 100644 --- a/lib/chef/mixin/template.rb +++ b/lib/chef/mixin/template.rb @@ -173,7 +173,7 @@ class Chef # potential issues for the applications that will consume # this template. - if Chef::Platform.windows? + if ChefHelpers.windows? output = output.gsub(/\r?\n/, "\r\n") end diff --git a/lib/chef/mixin/user_context.rb b/lib/chef/mixin/user_context.rb index f5c2da1389..92003937c5 100644 --- a/lib/chef/mixin/user_context.rb +++ b/lib/chef/mixin/user_context.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require "chef/util/windows/logon_session" if Chef::Platform.windows? +require "chef/util/windows/logon_session" if ChefHelpers.windows? class Chef module Mixin @@ -26,7 +26,7 @@ class Chef # When authentication = :local, we use the credentials to create a logon session against the local system, and then try to access the files. # When authentication = :remote, we continue with the current user but pass the provided credentials to the remote system. def with_user_context(user, password, domain = nil, authentication = :remote, &block) - unless Chef::Platform.windows? + unless ChefHelpers.windows? raise Exceptions::UnsupportedPlatform, "User context impersonation is supported only on the Windows platform" end diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb index 8a825f55c9..ae8f38eaf0 100644 --- a/lib/chef/mixin/which.rb +++ b/lib/chef/mixin/which.rb @@ -1,6 +1,6 @@ #-- # Author:: Lamont Granquist -# Copyright:: Copyright 2010-2017, Chef Software Inc. +# Copyright:: Copyright 2010-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +28,7 @@ class Chef paths = env_path.split(File::PATH_SEPARATOR) + Array(extra_path) cmds.map do |cmd| paths.map do |path| - filename = Chef.path_to(File.join(path, cmd)) + filename = File.join(path, cmd) filename if valid_executable?(filename, &block) end.compact end.flatten diff --git a/lib/chef/mixin/windows_architecture_helper.rb b/lib/chef/mixin/windows_architecture_helper.rb index 67c34a85a1..f2906d110a 100644 --- a/lib/chef/mixin/windows_architecture_helper.rb +++ b/lib/chef/mixin/windows_architecture_helper.rb @@ -18,8 +18,8 @@ require "chef/exceptions" require "chef/platform/query_helpers" -require "chef/win32/process" if Chef::Platform.windows? -require "chef/win32/system" if Chef::Platform.windows? +require "chef/win32/process" if ChefHelpers.windows? +require "chef/win32/system" if ChefHelpers.windows? class Chef module Mixin @@ -89,7 +89,7 @@ class Chef end def is_i386_process_on_x86_64_windows? - if Chef::Platform.windows? + if ChefHelpers.windows? Chef::ReservedNames::Win32::Process.is_wow64_process else false @@ -97,13 +97,13 @@ class Chef end def disable_wow64_file_redirection( node ) - if ( node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows? + if ( node_windows_architecture(node) == :x86_64) && ::ChefHelpers.windows? Chef::ReservedNames::Win32::System.wow64_disable_wow64_fs_redirection end end def restore_wow64_file_redirection( node, original_redirection_state ) - if (node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows? + if (node_windows_architecture(node) == :x86_64) && ::ChefHelpers.windows? Chef::ReservedNames::Win32::System.wow64_revert_wow64_fs_redirection(original_redirection_state) end end diff --git a/lib/chef/mixin/windows_env_helper.rb b/lib/chef/mixin/windows_env_helper.rb index 610c0cd075..756ecd25e7 100644 --- a/lib/chef/mixin/windows_env_helper.rb +++ b/lib/chef/mixin/windows_env_helper.rb @@ -19,16 +19,16 @@ require "chef/exceptions" require "chef/mixin/wide_string" require "chef/platform/query_helpers" -require "chef/win32/error" if Chef::Platform.windows? -require "chef/win32/api/system" if Chef::Platform.windows? -require "chef/win32/api/unicode" if Chef::Platform.windows? +require "chef/win32/error" if ChefHelpers.windows? +require "chef/win32/api/system" if ChefHelpers.windows? +require "chef/win32/api/unicode" if ChefHelpers.windows? class Chef module Mixin module WindowsEnvHelper include Chef::Mixin::WideString - if Chef::Platform.windows? + if ChefHelpers.windows? include Chef::ReservedNames::Win32::API::System end diff --git a/lib/chef/node.rb b/lib/chef/node.rb index c31fc99279..635acb44fb 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -2,7 +2,7 @@ # Author:: Christopher Brown () # Author:: Christopher Walters () # Author:: Tim Hinderliter () -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -88,7 +88,6 @@ class Chef # after the run_context has been set on the node, go through the cookbook_collection # and setup the node[:cookbooks] attribute so that it is published in the node object def set_cookbook_attribute - return unless run_context.cookbook_collection run_context.cookbook_collection.each do |cookbook_name, cookbook| automatic_attrs[:cookbooks][cookbook_name][:version] = cookbook.version end diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb index a4891234f5..875f6f9687 100644 --- a/lib/chef/node_map.rb +++ b/lib/chef/node_map.rb @@ -240,6 +240,11 @@ EOH private + def platform_family_query_helper?(node, m) + method = "#{m}?".to_sym + ChefHelpers::PlatformFamily.respond_to?(method) && ChefHelpers::PlatformFamily.send(method, node) + end + # # Succeeds if: # - no negative matches (!value) @@ -255,11 +260,19 @@ EOH # Split the blacklist and whitelist blacklist, whitelist = filter_values.partition { |v| v.is_a?(String) && v.start_with?("!") } - # If any blacklist value matches, we don't match - return false if blacklist.any? { |v| v[1..-1] == value } + if attribute == :platform_family + # If any blacklist value matches, we don't match + return false if blacklist.any? { |v| v[1..-1] == value || platform_family_query_helper?(node, v[1..-1]) } - # If the whitelist is empty, or anything matches, we match. - whitelist.empty? || whitelist.any? { |v| v == :all || v == value } + # If the whitelist is empty, or anything matches, we match. + whitelist.empty? || whitelist.any? { |v| v == :all || v == value || platform_family_query_helper?(node, v) } + else + # If any blacklist value matches, we don't match + return false if blacklist.any? { |v| v[1..-1] == value } + + # If the whitelist is empty, or anything matches, we match. + whitelist.empty? || whitelist.any? { |v| v == :all || v == value } + end end def matches_version_list?(node, filters, attribute) diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb index b49010efc0..a8cadbde4a 100644 --- a/lib/chef/platform/query_helpers.rb +++ b/lib/chef/platform/query_helpers.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# 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"); @@ -16,16 +16,18 @@ # limitations under the License. # +require 'chef-helpers' + class Chef class Platform class << self def windows? - ChefConfig.windows? + ChefHelpers.windows? end def windows_nano_server? - return false unless windows? + return false unless ChefHelpers.windows? require "win32/registry" # This method may be called before ohai runs (e.g., it may be used to @@ -47,7 +49,7 @@ class Chef end def supports_msi? - return false unless windows? + return false unless ChefHelpers.windows? require "win32/registry" key = "System\\CurrentControlSet\\Services\\msiserver" diff --git a/lib/chef/platform/rebooter.rb b/lib/chef/platform/rebooter.rb index 430d175869..358507c5c8 100644 --- a/lib/chef/platform/rebooter.rb +++ b/lib/chef/platform/rebooter.rb @@ -34,7 +34,7 @@ class Chef reboot_info = node.run_context.reboot_info cmd = case - when Chef::Platform.windows? + when ChefHelpers.windows? # should this do /f as well? do we then need a minimum delay to let apps quit? # Use explicit path to shutdown.exe, to protect against https://github.com/chef/chef/issues/5594 windows_shutdown_path = "#{ENV['SYSTEMROOT']}/System32/shutdown.exe" diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb index 02d293449c..4f6810b3d9 100644 --- a/lib/chef/platform/service_helpers.rb +++ b/lib/chef/platform/service_helpers.rb @@ -1,6 +1,6 @@ # # Author:: Lamont Granquist () -# Copyright:: Copyright 2014-2016, Chef Software, Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,50 +17,22 @@ # require "chef/chef_class" +require "chef-helpers" class Chef class Platform + # FIXME: deprecated, use ChefHelpers::Service instead class ServiceHelpers class << self - # This helper is mostly used to sort out the mess of different - # linux mechanisms that can be used to start services. It does - # not necessarily need to linux-specific, but currently all our - # other service providers are narrowly platform-specific with no - # alternatives. - # - # NOTE: if a system has (for example) chkconfig installed then we - # should report that chkconfig is installed. The fact that a system - # may also have systemd installed does not mean that we do not - # report that systemd is also installed. This module is purely for - # discovery of all the alternatives, handling the priority of the - # different services is NOT a design concern of this module. - # def service_resource_providers providers = [] - if ::File.exist?(Chef.path_to("/usr/sbin/update-rc.d")) - providers << :debian - end - - if ::File.exist?(Chef.path_to("/usr/sbin/invoke-rc.d")) - providers << :invokercd - end - - if ::File.exist?(Chef.path_to("/sbin/initctl")) - providers << :upstart - end - - if ::File.exist?(Chef.path_to("/sbin/insserv")) - providers << :insserv - end - - if systemd_is_init? - providers << :systemd - end - - if ::File.exist?(Chef.path_to("/sbin/chkconfig")) - providers << :redhat - end + providers << :debian if ChefHelpers::Service.debianrcd? + providers << :invokercd if ChefHelpers::Service.invokercd? + providers << :upstart if ChefHelpers::Service.upstart? + providers << :insserv if ChefHelpers::Service.insserv? + providers << :systemd if ChefHelpers.systemd? + providers << :redhat if ChefHelpers::Service.redhatrcd? providers end @@ -68,54 +40,14 @@ class Chef def config_for_service(service_name) configs = [] - if ::File.exist?(Chef.path_to("/etc/init.d/#{service_name}")) - configs += [ :initd, :systemd ] - end - - if ::File.exist?(Chef.path_to("/etc/init/#{service_name}.conf")) - configs << :upstart - end - - if ::File.exist?(Chef.path_to("/etc/xinetd.d/#{service_name}")) - configs << :xinetd - end - - if ::File.exist?(Chef.path_to("/etc/rc.d/#{service_name}")) - configs << :etc_rcd - end - - if ::File.exist?(Chef.path_to("/usr/local/etc/rc.d/#{service_name}")) - configs << :usr_local_etc_rcd - end - - if has_systemd_service_unit?(service_name) || has_systemd_unit?(service_name) - configs << :systemd - end + configs << :initd if ChefHelpers::Service.service_script_exist?(:initd, service_name) + configs << :upstart if ChefHelpers::Service.service_script_exist?(:upstart, service_name) + configs << :xinetd if ChefHelpers::Service.service_script_exist?(:xinetd, service_name) + configs << :systemd if ChefHelpers::Service.service_script_exist?(:systemd, service_name) + configs << :etc_rcd if ChefHelpers::Service.service_script_exist?(:etc_rcd, service_name) configs end - - private - - def systemd_is_init? - ::File.exist?(Chef.path_to("/proc/1/comm")) && - ::File.open(Chef.path_to("/proc/1/comm")).gets.chomp == "systemd" - end - - def has_systemd_service_unit?(svc_name) - %w{ /etc /usr/lib /lib /run }.any? do |load_path| - ::File.exist?( - Chef.path_to("#{load_path}/systemd/system/#{svc_name.gsub(/@.*$/, '@')}.service") - ) - end - end - - def has_systemd_unit?(svc_name) - # TODO: stop supporting non-service units with service resource - %w{ /etc /usr/lib /lib /run }.any? do |load_path| - ::File.exist?(Chef.path_to("#{load_path}/systemd/system/#{svc_name}")) - end - end end end end diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb index 1751c35129..f1dded4112 100644 --- a/lib/chef/provider.rb +++ b/lib/chef/provider.rb @@ -46,6 +46,8 @@ class Chef # includes the "core" DSL and not the "recipe" DSL by design include Chef::DSL::Core + # the class only gets the Universal DSL (no resource_collection at class parsing time) + extend Chef::DSL::Universal # supports the given resource and action (late binding) def self.supports?(resource, action) diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb index 05522f1eb8..e7793a04aa 100644 --- a/lib/chef/provider/file.rb +++ b/lib/chef/provider/file.rb @@ -451,7 +451,7 @@ class Chef end def load_resource_attributes_from_file(resource) - if Chef::Platform.windows? + if ChefHelpers.windows? # This is a work around for CHEF-3554. # OC-6534: is tracking the real fix for this workaround. # Add support for Windows equivalent, or implicit resource diff --git a/lib/chef/provider/ifconfig/redhat.rb b/lib/chef/provider/ifconfig/redhat.rb index 70d78bcfe9..275207665b 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_family: %w{fedora rhel amazon} + provides :ifconfig, platform_family: "fedora_derived" def initialize(new_resource, run_context) super(new_resource, run_context) diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb index 783d52d09a..b2ab2515d7 100644 --- a/lib/chef/provider/link.rb +++ b/lib/chef/provider/link.rb @@ -82,7 +82,7 @@ class Chef end def canonicalize(path) - Chef::Platform.windows? ? path.tr("/", '\\') : path + ChefHelpers.windows? ? path.tr("/", '\\') : path end def action_create @@ -101,7 +101,7 @@ class Chef # However if the new symlink will point to a file and the current symlink is pointing at a # directory we want to throw an exception and calling ::File.unlink on the directory symlink # will throw the correct ones. - if Chef::Platform.windows? && ::File.directory?(new_resource.to) && + if ChefHelpers.windows? && ::File.directory?(new_resource.to) && ::File.directory?(current_resource.target_file) converge_by("unlink existing windows symlink to dir at #{new_resource.target_file}") do ::Dir.unlink(new_resource.target_file) @@ -143,7 +143,7 @@ class Chef def action_delete if current_resource.to # Exists - if Chef::Platform.windows? && ::File.directory?(current_resource.target_file) + if ChefHelpers.windows? && ::File.directory?(current_resource.target_file) converge_by("delete link to dir at #{new_resource.target_file}") do ::Dir.delete(new_resource.target_file) logger.info("#{new_resource} deleted") diff --git a/lib/chef/provider/mount/solaris.rb b/lib/chef/provider/mount/solaris.rb index 48936c8057..8f8aa77b11 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 smartos} + provides :mount, platform_family: "solaris_based" extend Forwardable diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index e991e4541e..4dd3cb69f4 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -37,7 +37,7 @@ class Chef use_multipackage_api use_package_name_for_source - provides :package, platform_family: %w{fedora amazon rhel} + provides :package, platform_family: "fedora_derived" provides :yum_package diff --git a/lib/chef/provider/registry_key.rb b/lib/chef/provider/registry_key.rb index 7c7b190b95..e6412858ce 100644 --- a/lib/chef/provider/registry_key.rb +++ b/lib/chef/provider/registry_key.rb @@ -36,7 +36,7 @@ class Chef include Chef::Mixin::Checksum def running_on_windows! - unless Chef::Platform.windows? + unless ChefHelpers.windows? raise Chef::Exceptions::Win32NotWindows, "Attempt to manipulate the windows registry on a non-windows node" end end diff --git a/lib/chef/provider/remote_directory.rb b/lib/chef/provider/remote_directory.rb index 94de68c557..7485a4bcbd 100644 --- a/lib/chef/provider/remote_directory.rb +++ b/lib/chef/provider/remote_directory.rb @@ -111,7 +111,7 @@ class Chef next if managed_files.include?(file) if ::File.directory?(file) - if !Chef::Platform.windows? && file_class.symlink?(file.dup) + if !ChefHelpers.windows? && file_class.symlink?(file.dup) # Unix treats dir symlinks as files purge_file(file) else @@ -208,7 +208,7 @@ class Chef # Set the sensitivity level res.sensitive(new_resource.sensitive) res.source(::File.join(source, relative_source_path)) - if Chef::Platform.windows? && files_rights + if ChefHelpers.windows? && files_rights files_rights.each_pair do |permission, *args| res.rights(permission, *args) end @@ -244,7 +244,7 @@ class Chef def directory_resource(dir) res = Chef::Resource::Directory.new(dir, run_context) res.cookbook_name = resource_cookbook - if Chef::Platform.windows? && rights + if ChefHelpers.windows? && rights # rights are only meant to be applied to the toppest-level directory; # Windows will handle inheritance. if dir == path diff --git a/lib/chef/provider/remote_file/fetcher.rb b/lib/chef/provider/remote_file/fetcher.rb index 3011dd80a0..5b3e256d24 100644 --- a/lib/chef/provider/remote_file/fetcher.rb +++ b/lib/chef/provider/remote_file/fetcher.rb @@ -24,7 +24,7 @@ class Chef def self.for_resource(uri, new_resource, current_resource) if network_share?(uri) - if !Chef::Platform.windows? + if !ChefHelpers.windows? raise Exceptions::UnsupportedPlatform, "Fetching the file on a network share is supported only on the Windows platform. Please change your source: #{uri}" end Chef::Provider::RemoteFile::NetworkFile.new(uri, new_resource, current_resource) diff --git a/lib/chef/provider/remote_file/local_file.rb b/lib/chef/provider/remote_file/local_file.rb index 0719e5dbf7..e8a521763d 100644 --- a/lib/chef/provider/remote_file/local_file.rb +++ b/lib/chef/provider/remote_file/local_file.rb @@ -41,7 +41,7 @@ class Chef def source_path @source_path ||= begin path = URI.unescape(uri.path) - Chef::Platform.windows? ? fix_windows_path(path) : path + ChefHelpers.windows? ? fix_windows_path(path) : path end end diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb index c5966370f7..3c0431e928 100644 --- a/lib/chef/provider/script.rb +++ b/lib/chef/provider/script.rb @@ -18,7 +18,7 @@ require "tempfile" require "chef/provider/execute" -require "chef/win32/security" if Chef::Platform.windows? +require "chef/win32/security" if ChefHelpers.windows? require "forwardable" class Chef @@ -67,7 +67,7 @@ class Chef end def set_owner_and_group - if Chef::Platform.windows? + if ChefHelpers.windows? # And on Windows also this is a no-op if there is no user specified. grant_alternate_user_read_access else diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb index c116d321f1..4d3d640866 100644 --- a/lib/chef/provider/service.rb +++ b/lib/chef/provider/service.rb @@ -1,7 +1,7 @@ # # Author:: AJ Christensen () # Author:: Davide Cavalca () -# 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"); @@ -18,10 +18,13 @@ # require "chef/provider" +require "chef-helpers" class Chef class Provider class Service < Chef::Provider + include ChefHelpers::Service + extend ChefHelpers::Service def supports @supports ||= new_resource.supports.dup @@ -245,7 +248,7 @@ class Chef Chef.set_provider_priority_array :service, [ Systemd, Arch ], platform_family: "arch" Chef.set_provider_priority_array :service, [ Systemd, Gentoo ], platform_family: "gentoo" Chef.set_provider_priority_array :service, [ Systemd, Upstart, Insserv, Debian, Invokercd ], platform_family: "debian" - Chef.set_provider_priority_array :service, [ Systemd, Insserv, Redhat ], platform_family: %w{rhel fedora suse amazon} + Chef.set_provider_priority_array :service, [ Systemd, Insserv, Redhat ], platform_family: "rpm_based" end end end diff --git a/lib/chef/provider/service/arch.rb b/lib/chef/provider/service/arch.rb index e34227036a..da1c71ba8b 100644 --- a/lib/chef/provider/service/arch.rb +++ b/lib/chef/provider/service/arch.rb @@ -23,7 +23,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init provides :service, platform_family: "arch" def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:etc_rcd) + service_script_exist?(:etc_rcd, resource.service_name) end def initialize(new_resource, run_context) diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index 351075111b..61cae7421b 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -1,6 +1,6 @@ # # Author:: AJ Christensen () -# 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"); @@ -22,15 +22,15 @@ class Chef class Provider class Service class Debian < Chef::Provider::Service::Init - provides :service, platform_family: "debian" do |node| - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian) + provides :service, platform_family: "debian" do + debianrcd? end UPDATE_RC_D_ENABLED_MATCHES = /\/rc[\dS].d\/S|not installed/i UPDATE_RC_D_PRIORITIES = /\/rc([\dS]).d\/([SK])(\d\d)/i def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) + service_script_exist?(:initd, resource.service_name) end def load_current_resource diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb index 6d150513cc..55f2d7d509 100644 --- a/lib/chef/provider/service/init.rb +++ b/lib/chef/provider/service/init.rb @@ -29,7 +29,7 @@ class Chef provides :service, os: "!windows" def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) + service_script_exist?(:initd, resource.service_name) end def initialize(new_resource, run_context) diff --git a/lib/chef/provider/service/insserv.rb b/lib/chef/provider/service/insserv.rb index a8e841f8b3..2ea9dbd340 100644 --- a/lib/chef/provider/service/insserv.rb +++ b/lib/chef/provider/service/insserv.rb @@ -1,6 +1,6 @@ # # Author:: Bryan McLellan -# Copyright:: Copyright 2011-2017, Chef Software Inc. +# Copyright:: Copyright 2011-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,12 +24,12 @@ class Chef class Service class Insserv < Chef::Provider::Service::Init - provides :service, platform_family: %w{debian rhel fedora suse amazon} do |node| - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:insserv) + provides :service, platform_family: %w{debian rhel fedora suse amazon} do + insserv? end def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) + service_script_exist?(:initd, resource.service_name) end def load_current_resource diff --git a/lib/chef/provider/service/invokercd.rb b/lib/chef/provider/service/invokercd.rb index 9477afec48..08c9f0ebc3 100644 --- a/lib/chef/provider/service/invokercd.rb +++ b/lib/chef/provider/service/invokercd.rb @@ -1,6 +1,6 @@ # # Author:: AJ Christensen () -# 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"); @@ -23,12 +23,12 @@ class Chef class Service class Invokercd < Chef::Provider::Service::Init - provides :service, platform_family: "debian", override: true do |node| - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:invokercd) + provides :service, platform_family: "debian", override: true do + invokercd? end def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) + service_script_exist?(:initd, resource.service_name) end def initialize(new_resource, run_context) diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb index 18ef245083..77b83aae1f 100644 --- a/lib/chef/provider/service/redhat.rb +++ b/lib/chef/provider/service/redhat.rb @@ -1,6 +1,6 @@ # # Author:: AJ Christensen () -# 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"); @@ -28,15 +28,15 @@ class Chef # @api private attr_accessor :current_run_levels - provides :service, platform_family: %w{rhel fedora suse amazon} do |node| - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) + provides :service, platform_family: "rpm_based" do + redhatrcd? end CHKCONFIG_ON = /\d:on/ CHKCONFIG_MISSING = /No such/ def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) + service_script_exist?(:initd, resource.service_name) end def initialize(new_resource, run_context) diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb index 6d5bc338c7..fac4686c4f 100644 --- a/lib/chef/provider/service/systemd.rb +++ b/lib/chef/provider/service/systemd.rb @@ -26,14 +26,14 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple include Chef::Mixin::Which - provides :service, os: "linux" do |node| - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) + provides :service, os: "linux" do + systemd? end attr_accessor :status_check_success def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:systemd) + service_script_exist?(:systemd, resource.service_name) end def load_current_resource diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index 68f97d1ff2..f2ff182aa9 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -28,15 +28,15 @@ class Chef # to maintain a local state of service across restart's internal calls attr_accessor :upstart_service_running - provides :service, platform_family: "debian", override: true do |node| - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) + provides :service, platform_family: "debian", override: true do + upstart? end 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) + service_script_exist?(:upstart, resource.service_name) end # Upstart does more than start or stop a service, creating multiple 'states' [1] that a service can be in. diff --git a/lib/chef/provider/subversion.rb b/lib/chef/provider/subversion.rb index dec9e06f87..99886961a9 100644 --- a/lib/chef/provider/subversion.rb +++ b/lib/chef/provider/subversion.rb @@ -212,7 +212,7 @@ class Chef def svn_binary new_resource.svn_binary || - (Chef::Platform.windows? ? "svn.exe" : "svn") + (ChefHelpers.windows? ? "svn.exe" : "svn") end def assert_target_directory_valid! diff --git a/lib/chef/provider/windows_path.rb b/lib/chef/provider/windows_path.rb index 1c78e20606..33b37804ed 100644 --- a/lib/chef/provider/windows_path.rb +++ b/lib/chef/provider/windows_path.rb @@ -16,14 +16,14 @@ # limitations under the License. # -require "chef/mixin/windows_env_helper" if Chef::Platform.windows? +require "chef/mixin/windows_env_helper" if ChefHelpers.windows? require "chef/mixin/wide_string" require "chef/exceptions" class Chef class Provider class WindowsPath < Chef::Provider - include Chef::Mixin::WindowsEnvHelper if Chef::Platform.windows? + include Chef::Mixin::WindowsEnvHelper if ChefHelpers.windows? provides :windows_path diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index 98dd8795fa..eb0404f55e 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -22,7 +22,7 @@ require "iso8601" require "chef/mixin/powershell_out" require "chef/provider" require "chef/util/path_helper" -require "win32/taskscheduler" if Chef::Platform.windows? +require "win32/taskscheduler" if ChefHelpers.windows? class Chef class Provider @@ -30,7 +30,7 @@ class Chef include Chef::Mixin::ShellOut include Chef::Mixin::PowershellOut - if Chef::Platform.windows? + if ChefHelpers.windows? include Win32 provides :windows_task diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 1440b2eb61..17133e0cdb 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -59,6 +59,7 @@ class Chef extend Chef::Mixin::Provides include Chef::DSL::Universal + extend Chef::DSL::Universal # Bring in `property` and `property_type` include Chef::Mixin::Properties diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb index 7c549fb236..fc76dcb676 100644 --- a/lib/chef/resource/build_essential.rb +++ b/lib/chef/resource/build_essential.rb @@ -1,5 +1,5 @@ # -# Copyright:: 2008-2018, Chef Software, Inc. +# Copyright:: 2008-2018, Chef Software Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ class Chef case node["platform_family"] when "debian" declare_resource(:package, %w{ autoconf binutils-doc bison build-essential flex gettext ncurses-dev }) - when "amazon", "fedora", "rhel" + when fedora_derived? declare_resource(:package, %w{ autoconf bison flex gcc gcc-c++ gettext kernel-devel make m4 ncurses-devel patch }) # Ensure GCC 4 is available on older pre-6 EL diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb index 93f8063d5d..3bfdc8a07e 100644 --- a/lib/chef/resource/execute.rb +++ b/lib/chef/resource/execute.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Tyler Cloke () -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -98,7 +98,7 @@ class Chef description: "Windows only: The password of the user specified by the user property. This property is mandatory if user is specified on Windows and may only be specified if user is specified. The sensitive property for this resource will automatically be set to true if password is specified." # lazy used to set default value of sensitive to true if password is set - property :sensitive, [ TrueClass, FalseClass ], default: lazy { |r| r.password ? true : false } + property :sensitive, [ TrueClass, FalseClass ], default: lazy { password ? true : false } property :elevated, [ TrueClass, FalseClass ], default: false, introduced: "13.3" diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb index cac20f2356..48c4e79cbb 100644 --- a/lib/chef/resource/file.rb +++ b/lib/chef/resource/file.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Seth Chisamore () -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,7 +30,7 @@ class Chef description "Use the file resource to manage files directly on a node." - if Platform.windows? + if ChefHelpers.windows? # Use Windows rights instead of standard *nix permissions state_attrs :checksum, :rights, :deny_rights else @@ -54,7 +54,7 @@ class Chef property :path, String, name_property: true, identity: true, description: "The full path to the file, including the file name and its extension. For example: /files/file.txt. Default value: the name of the resource block. Microsoft Windows: A path that begins with a forward slash (/) will point to the root of the current working directory of the chef-client process. This path can vary from system to system. Therefore, using a path that begins with a forward slash (/) is not recommended." - 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 :atomic_update, [ TrueClass, FalseClass ], desired_state: false, default: lazy { docker? && special_docker_files?(path) ? false : Chef::Config[:file_atomic_update] }, description: "Perform atomic file updates on a per-resource basis. Set to true for atomic file updates. Set to false for non-atomic file updates. This setting overrides file_atomic_update, which is a global setting found in the client.rb file." property :backup, [ Integer, FalseClass ], desired_state: false, default: 5, diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb index 00ce69dddd..ddad945cce 100644 --- a/lib/chef/resource/link.rb +++ b/lib/chef/resource/link.rb @@ -78,7 +78,7 @@ class Chef # On certain versions of windows links are not supported. Make # sure we are not on such a platform. - if Chef::Platform.windows? + if ChefHelpers.windows? require "chef/win32/file" begin Chef::ReservedNames::Win32::File.verify_links_supported! diff --git a/lib/chef/resource/msu_package.rb b/lib/chef/resource/msu_package.rb index 85ab170ee0..f52cd15196 100644 --- a/lib/chef/resource/msu_package.rb +++ b/lib/chef/resource/msu_package.rb @@ -1,6 +1,6 @@ # # Author:: Nimisha Sharad () -# Copyright:: Copyright 2008-2016, Chef Software, Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +39,7 @@ class Chef uri_scheme?(s) ? s : Chef::Util::PathHelper.canonical_path(s, false) end end), - default: lazy { |r| r.package_name } + default: lazy { package_name } property :checksum, String, desired_state: false end end diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb index f03b13ef02..4786dc7502 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/lib/chef/resource/remote_directory.rb @@ -45,10 +45,10 @@ class Chef @recursive = true @files_owner = nil @files_group = nil - @files_mode = 0644 unless Chef::Platform.windows? + @files_mode = 0644 unless ChefHelpers.windows? end - if Chef::Platform.windows? + if ChefHelpers.windows? # create a second instance of the 'rights' attribute rights_attribute(:files_rights) end diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index c5197d5f06..004eff8054 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -1,7 +1,7 @@ # # Author:: AJ Christensen () # Author:: Tyler Cloke () -# 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"); @@ -18,11 +18,14 @@ # require "chef/resource" -require "shellwords" +require "chef-helpers" class Chef class Resource class Service < Chef::Resource + include ChefHelpers::Service + extend ChefHelpers::Service + identity_attr :service_name state_attrs :enabled, :running, :masked diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb index 435a6ecc44..0a8e932b35 100644 --- a/lib/chef/resource/solaris_package.rb +++ b/lib/chef/resource/solaris_package.rb @@ -1,7 +1,7 @@ # # Author:: Toomas Pelberg () # Author:: Prabhu Das () -# Copyright:: Copyright 2013-2016, Chef Software Inc. +# Copyright:: Copyright 2013-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb index 905cacc477..61487bbf8d 100644 --- a/lib/chef/resource/yum_package.rb +++ b/lib/chef/resource/yum_package.rb @@ -22,7 +22,7 @@ class Chef class Resource class YumPackage < Chef::Resource::Package resource_name :yum_package - provides :package, platform_family: %w{rhel fedora amazon} + provides :package, platform_family: "fedora_derived" description "Use the yum_package resource to install, upgrade, and remove packages with Yum"\ " for the Red Hat and CentOS platforms. The yum_package resource is able to resolve"\ diff --git a/lib/chef/run_lock.rb b/lib/chef/run_lock.rb index 08d58fd164..c6afa01c0c 100644 --- a/lib/chef/run_lock.rb +++ b/lib/chef/run_lock.rb @@ -17,7 +17,7 @@ require "chef/mixin/create_path" require "fcntl" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/mutex" end require "chef/config" @@ -96,7 +96,7 @@ class Chef # def wait Chef::Log.warn("Chef client #{runpid} is running, will wait for it to finish and then run.") - if Chef::Platform.windows? + if ChefHelpers.windows? mutex.wait else runlock.flock(File::LOCK_EX) @@ -115,7 +115,7 @@ class Chef # Release the system-wide lock. def release if runlock - if Chef::Platform.windows? + if ChefHelpers.windows? mutex.release else runlock.flock(File::LOCK_UN) @@ -137,7 +137,7 @@ class Chef # @api private solely for race condition tests def acquire_lock - if Chef::Platform.windows? + if ChefHelpers.windows? acquire_win32_mutex else # If we support FD_CLOEXEC, then use it. diff --git a/lib/chef/util/powershell/ps_credential.rb b/lib/chef/util/powershell/ps_credential.rb index 32810b98a6..97c94c6d93 100644 --- a/lib/chef/util/powershell/ps_credential.rb +++ b/lib/chef/util/powershell/ps_credential.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require "chef/win32/crypto" if Chef::Platform.windows? +require "chef/win32/crypto" if ChefHelpers.windows? class Chef::Util::Powershell class PSCredential diff --git a/lib/chef/util/windows/logon_session.rb b/lib/chef/util/windows/logon_session.rb index afe58ae4f9..f70a2205b2 100644 --- a/lib/chef/util/windows/logon_session.rb +++ b/lib/chef/util/windows/logon_session.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require "chef/win32/api/security" if Chef::Platform.windows? +require "chef/win32/api/security" if ChefHelpers.windows? require "chef/mixin/wide_string" class Chef diff --git a/lib/chef/win32/eventlog.rb b/lib/chef/win32/eventlog.rb index e8c63bf13a..308c1f6b33 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? +if ChefHelpers.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/omnibus/Gemfile.lock b/omnibus/Gemfile.lock index 0f30245639..464c9898ca 100644 --- a/omnibus/Gemfile.lock +++ b/omnibus/Gemfile.lock @@ -1,24 +1,24 @@ GIT remote: https://github.com/chef/omnibus - revision: 386cd17f6a6365bd4585761a2738b4561fbaea97 + revision: af75fc2b244de04e76961c02b30db504d5b1a8f4 branch: master specs: - omnibus (6.0.1) - aws-sdk (~> 2) + omnibus (6.0.25) + aws-sdk-s3 (~> 1) chef-sugar (>= 3.3) cleanroom (~> 1.0) ffi-yajl (~> 2.2) license_scout (~> 1.0) - mixlib-shellout (~> 2.0) + mixlib-shellout (>= 2.0, < 4.0) mixlib-versioning - ohai (>= 13, < 15) + ohai (>= 13, < 16) pedump ruby-progressbar (~> 1.7) thor (~> 0.18) GIT remote: https://github.com/chef/omnibus-software - revision: 56ae031dc36c9c060eb94709dd30f13ac50bc3f2 + revision: 0dc67ede1784d56a975cb4a7aea47ad2349bf24a branch: master specs: omnibus-software (4.0.0) @@ -31,14 +31,22 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) awesome_print (1.8.0) - aws-sdk (2.11.115) - aws-sdk-resources (= 2.11.115) - aws-sdk-core (2.11.115) - aws-sigv4 (~> 1.0) + aws-eventstream (1.0.2) + aws-partitions (1.150.0) + aws-sdk-core (3.48.3) + aws-eventstream (~> 1.0, >= 1.0.2) + aws-partitions (~> 1.0) + aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-resources (2.11.115) - aws-sdk-core (= 2.11.115) - aws-sigv4 (1.0.3) + aws-sdk-kms (1.16.0) + aws-sdk-core (~> 3, >= 3.48.2) + aws-sigv4 (~> 1.1) + aws-sdk-s3 (1.36.0) + aws-sdk-core (~> 3, >= 3.48.2) + aws-sdk-kms (~> 1) + aws-sigv4 (~> 1.0) + aws-sigv4 (1.1.0) + aws-eventstream (~> 1.0, >= 1.0.2) berkshelf (4.3.5) addressable (~> 2.3, >= 2.3.4) berkshelf-api-client (~> 2.0, >= 2.0.2) @@ -72,19 +80,19 @@ GEM buff-shell_out (0.2.0) buff-ruby_engine (~> 0.1.0) builder (3.2.3) - byebug (10.0.2) + byebug (11.0.1) celluloid (0.16.0) timers (~> 4.0.0) celluloid-io (0.16.2) celluloid (>= 0.16.0) nio4r (>= 1.1.0) - chef-config (13.10.4) + chef-config (13.12.14) addressable fuzzyurl mixlib-config (>= 2.2.12, < 3.0) mixlib-shellout (~> 2.0) tomlrb (~> 1.2) - chef-sugar (4.1.0) + chef-sugar (5.0.1) citrus (3.0.2) cleanroom (1.0.0) coderay (1.1.2) @@ -92,9 +100,9 @@ GEM erubis (2.7.0) faraday (0.9.2) multipart-post (>= 1.2, < 3) - ffi (1.9.25) - ffi (1.9.25-x64-mingw32) - ffi (1.9.25-x86-mingw32) + ffi (1.10.0) + ffi (1.10.0-x64-mingw32) + ffi (1.10.0-x86-mingw32) ffi-yajl (2.3.1) libyajl2 (~> 1.2) fuzzyurl (0.9.0) @@ -103,18 +111,18 @@ GEM gyoku (1.3.1) builder (>= 2.1.2) hashie (3.6.0) - hitimes (1.3.0) - hitimes (1.3.0-x64-mingw32) - hitimes (1.3.0-x86-mingw32) + hitimes (1.3.1) + hitimes (1.3.1-x64-mingw32) + hitimes (1.3.1-x86-mingw32) httpclient (2.7.2) iostruct (0.0.4) ipaddress (0.8.3) jmespath (1.4.0) - json (2.1.0) - kitchen-vagrant (1.3.3) + json (2.2.0) + kitchen-vagrant (1.3.6) test-kitchen (~> 1.4) libyajl2 (1.2.0) - license_scout (1.0.15) + license_scout (1.0.24) ffi-yajl (~> 2.2) mixlib-shellout (~> 2.2) toml-rb (~> 1.0) @@ -122,24 +130,26 @@ GEM logging (2.2.2) little-plugger (~> 1.1) multi_json (~> 1.10) - method_source (0.9.0) - minitar (0.6.1) - mixlib-archive (0.4.13) + method_source (0.9.2) + minitar (0.8) + mixlib-archive (0.4.20) + mixlib-log + mixlib-archive (0.4.20-universal-mingw32) mixlib-log mixlib-authentication (2.1.1) mixlib-cli (1.7.0) - mixlib-config (2.2.13) + mixlib-config (2.2.18) tomlrb - mixlib-install (3.11.5) + mixlib-install (3.11.12) mixlib-shellout mixlib-versioning thor mixlib-log (1.7.1) - mixlib-shellout (2.4.0) - mixlib-shellout (2.4.0-universal-mingw32) + mixlib-shellout (2.4.4) + mixlib-shellout (2.4.4-universal-mingw32) win32-process (~> 0.8.2) wmi-lite (~> 1.0) - mixlib-versioning (1.2.2) + mixlib-versioning (1.2.7) molinillo (0.4.5) multi_json (1.13.1) multipart-post (2.0.0) @@ -150,14 +160,14 @@ GEM net-ssh (>= 2.6.5) nio4r (2.3.1) nori (2.6.0) - octokit (4.10.0) + octokit (4.14.0) sawyer (~> 0.8.0, >= 0.5.3) - ohai (13.10.0) + ohai (13.12.6) chef-config (>= 12.5.0.alpha.1, < 14) ffi (~> 1.9) ffi-yajl (~> 2.2) ipaddress - mixlib-cli + mixlib-cli (< 2.0) mixlib-config (~> 2.0) mixlib-log (>= 1.7.1, < 2.0) mixlib-shellout (~> 2.0) @@ -170,15 +180,15 @@ GEM multipart-post (~> 2.0.0) progressbar zhexdump (>= 0.0.2) - plist (3.4.0) + plist (3.5.0) progressbar (1.10.0) - pry (0.11.3) + pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) - pry-byebug (3.6.0) - byebug (~> 10.0) + pry-byebug (3.7.0) + byebug (~> 11.0) pry (~> 0.10) - pry-stack_explorer (0.4.9.2) + pry-stack_explorer (0.4.9.3) binding_of_caller (>= 0.7) pry (>= 0.9.11) public_suffix (3.0.3) @@ -203,7 +213,7 @@ GEM varia_model (~> 0.4.0) ruby-progressbar (1.10.0) rubyntlm (0.6.2) - rubyzip (1.2.1) + rubyzip (1.2.2) sawyer (0.8.1) addressable (>= 2.3.5, < 2.6) faraday (~> 0.8, < 1.0) @@ -212,7 +222,7 @@ GEM molinillo (~> 0.4.2) semverse (~> 1.1) systemu (2.6.5) - test-kitchen (1.23.2) + test-kitchen (1.24.0) mixlib-install (~> 3.6) mixlib-shellout (>= 1.2, < 3.0) net-scp (~> 1.1) @@ -222,18 +232,18 @@ GEM winrm (~> 2.0) winrm-elevated (~> 1.0) winrm-fs (~> 1.1) - thor (0.20.0) + thor (0.20.3) timers (4.0.4) hitimes toml-rb (1.1.2) citrus (~> 3.0, > 3.0) - tomlrb (1.2.7) + tomlrb (1.2.8) varia_model (0.4.1) buff-extensions (~> 1.0) hashie (>= 2.0.2, < 4.0.0) win32-process (0.8.3) ffi (>= 1.0.0) - winrm (2.2.3) + winrm (2.3.1) builder (>= 2.1.2) erubis (~> 2.7) gssapi (~> 1.2) @@ -242,15 +252,15 @@ GEM logging (>= 1.6.1, < 3.0) nori (~> 2.0) rubyntlm (~> 0.6.0, >= 0.6.1) - winrm-elevated (1.1.0) + winrm-elevated (1.1.1) winrm (~> 2.0) winrm-fs (~> 1.0) - winrm-fs (1.2.1) + winrm-fs (1.3.2) erubis (~> 2.7) logging (>= 1.6.1, < 3.0) rubyzip (~> 1.1) winrm (~> 2.0) - wmi-lite (1.0.0) + wmi-lite (1.0.2) zhexdump (0.0.2) PLATFORMS @@ -272,4 +282,4 @@ DEPENDENCIES winrm-fs (~> 1.0) BUNDLED WITH - 1.16.4 + 1.17.3 diff --git a/omnibus/config/projects/chef.rb b/omnibus/config/projects/chef.rb index 7c90725d95..fa54a951c4 100644 --- a/omnibus/config/projects/chef.rb +++ b/omnibus/config/projects/chef.rb @@ -79,7 +79,7 @@ package :deb do compression_type :xz end -proj_to_work_around_cleanroom = self +proj_to_work_around_cleanroom = self # wat voodoo hackery is this? package :pkg do identifier "com.getchef.pkg.#{proj_to_work_around_cleanroom.name}" signing_identity "Developer ID Installer: Chef Software, Inc. (EU3VF8YLX2)" diff --git a/spec/functional/event_loggers/windows_eventlog_spec.rb b/spec/functional/event_loggers/windows_eventlog_spec.rb index 8a9475680d..06aac89c6a 100644 --- a/spec/functional/event_loggers/windows_eventlog_spec.rb +++ b/spec/functional/event_loggers/windows_eventlog_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" require "securerandom" require "chef/event_loggers/windows_eventlog" -if Chef::Platform.windows? +if ChefHelpers.windows? require "win32/eventlog" include Win32 end diff --git a/spec/functional/mixin/user_context_spec.rb b/spec/functional/mixin/user_context_spec.rb index 802b1db9f1..909555d997 100644 --- a/spec/functional/mixin/user_context_spec.rb +++ b/spec/functional/mixin/user_context_spec.rb @@ -17,8 +17,8 @@ require "spec_helper" -require "chef/win32/api" if Chef::Platform.windows? -require "chef/win32/api/error" if Chef::Platform.windows? +require "chef/win32/api" if ChefHelpers.windows? +require "chef/win32/api/error" if ChefHelpers.windows? require "chef/mixin/user_context" describe Chef::Mixin::UserContext, windows_only: true do diff --git a/spec/functional/rebooter_spec.rb b/spec/functional/rebooter_spec.rb index 8e5b23f86b..1e2c2ab2b8 100644 --- a/spec/functional/rebooter_spec.rb +++ b/spec/functional/rebooter_spec.rb @@ -72,7 +72,7 @@ describe Chef::Platform::Rebooter do shared_context "test a reboot method" do def test_rebooter_method(method_sym, is_windows, is_solaris, expected_reboot_str) - allow(ChefConfig).to receive(:windows?).and_return(is_windows) + allow(ChefHelpers).to receive(:windows?).and_return(is_windows) node.automatic["os"] = node.automatic["platform"] = node.automatic["platform_family"] = "solaris2" if is_solaris expect(rebooter).to receive(:shell_out!).once.with(expected_reboot_str) expect(rebooter).to receive(:raise).with(Chef::Exceptions::Reboot) diff --git a/spec/functional/resource/cookbook_file_spec.rb b/spec/functional/resource/cookbook_file_spec.rb index d127413c73..826c5ac094 100644 --- a/spec/functional/resource/cookbook_file_spec.rb +++ b/spec/functional/resource/cookbook_file_spec.rb @@ -70,11 +70,11 @@ describe Chef::Resource::CookbookFile do let(:path) { File.join(windows_non_temp_dir, make_tmpname(file_base)) } before do - FileUtils.mkdir_p(windows_non_temp_dir) if Chef::Platform.windows? + FileUtils.mkdir_p(windows_non_temp_dir) if ChefHelpers.windows? end after do - FileUtils.rm_r(windows_non_temp_dir) if Chef::Platform.windows? && File.exists?(windows_non_temp_dir) + FileUtils.rm_r(windows_non_temp_dir) if ChefHelpers.windows? && File.exists?(windows_non_temp_dir) end end diff --git a/spec/functional/resource/template_spec.rb b/spec/functional/resource/template_spec.rb index 679ffe661a..5d66c13ab8 100644 --- a/spec/functional/resource/template_spec.rb +++ b/spec/functional/resource/template_spec.rb @@ -203,7 +203,7 @@ describe Chef::Resource::Template do it "output should contain platform's line endings" do resource.run_action(:create) binread(path).each_line do |line| - expect(line).to end_with(Chef::Platform.windows? ? "\r\n" : "\n") + expect(line).to end_with(ChefHelpers.windows? ? "\r\n" : "\n") end end end diff --git a/spec/functional/win32/crypto_spec.rb b/spec/functional/win32/crypto_spec.rb index 5fcbca02b6..634151799a 100644 --- a/spec/functional/win32/crypto_spec.rb +++ b/spec/functional/win32/crypto_spec.rb @@ -17,7 +17,7 @@ # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/crypto" end diff --git a/spec/functional/win32/security_spec.rb b/spec/functional/win32/security_spec.rb index b3fe2afb31..8a43ea762f 100644 --- a/spec/functional/win32/security_spec.rb +++ b/spec/functional/win32/security_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" require "mixlib/shellout" require "chef/mixin/user_context" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/security" end diff --git a/spec/functional/win32/service_manager_spec.rb b/spec/functional/win32/service_manager_spec.rb index 8fff73396e..79d656ce46 100644 --- a/spec/functional/win32/service_manager_spec.rb +++ b/spec/functional/win32/service_manager_spec.rb @@ -17,7 +17,7 @@ # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/application/windows_service_manager" end diff --git a/spec/functional/win32/sid_spec.rb b/spec/functional/win32/sid_spec.rb index eac62d88b6..847336b596 100644 --- a/spec/functional/win32/sid_spec.rb +++ b/spec/functional/win32/sid_spec.rb @@ -17,12 +17,12 @@ # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/security" end describe "Chef::ReservedNames::Win32::SID", :windows_only do - if Chef::Platform.windows? + if ChefHelpers.windows? SID ||= Chef::ReservedNames::Win32::Security::SID end diff --git a/spec/functional/win32/version_info_spec.rb b/spec/functional/win32/version_info_spec.rb index b5570732a0..2de70f6c56 100644 --- a/spec/functional/win32/version_info_spec.rb +++ b/spec/functional/win32/version_info_spec.rb @@ -17,7 +17,7 @@ # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/file/version_info" end diff --git a/spec/functional/win32/versions_spec.rb b/spec/functional/win32/versions_spec.rb index 19bd0e3875..b5097cef20 100644 --- a/spec/functional/win32/versions_spec.rb +++ b/spec/functional/win32/versions_spec.rb @@ -17,7 +17,7 @@ # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/version" end diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index 4408c00b23..fb71396d1a 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -62,7 +62,7 @@ EOM shell_out!("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", cwd: chef_dir) end - it "should complete successfully with no other environment variables", skip: (Chef::Platform.windows?) do + it "should complete successfully with no other environment variables", skip: (ChefHelpers.windows?) do file "config/client.rb", <<~EOM local_mode true cookbook_path "#{path_to('cookbooks')}" diff --git a/spec/integration/knife/config_get_profile_spec.rb b/spec/integration/knife/config_get_profile_spec.rb index e97b24b869..1ead66d2dd 100644 --- a/spec/integration/knife/config_get_profile_spec.rb +++ b/spec/integration/knife/config_get_profile_spec.rb @@ -50,7 +50,7 @@ describe "knife config get-profile", :workstation do ENV["KNIFE_HOME"] = old_knife_home ENV["HOME"] = old_home Dir.chdir(old_wd) - ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd + ENV[ChefHelpers.windows? ? "CD" : "PWD"] = Dir.pwd ChefConfig::PathHelper.per_tool_home_environment = nil end end @@ -60,7 +60,7 @@ describe "knife config get-profile", :workstation do # because it has to run after the before set in the "with a chef repo" shared context. directory("repo") Dir.chdir(path_to("repo")) - ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd + ENV[ChefHelpers.windows? ? "CD" : "PWD"] = Dir.pwd ENV["HOME"] = path_to(".") end diff --git a/spec/integration/knife/config_get_spec.rb b/spec/integration/knife/config_get_spec.rb index f34d096051..c18b9156b0 100644 --- a/spec/integration/knife/config_get_spec.rb +++ b/spec/integration/knife/config_get_spec.rb @@ -54,7 +54,7 @@ describe "knife config get", :workstation do ENV["KNIFE_HOME"] = old_knife_home ENV["HOME"] = old_home Dir.chdir(old_wd) - ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd + ENV[ChefHelpers.windows? ? "CD" : "PWD"] = Dir.pwd ChefConfig::PathHelper.per_tool_home_environment = nil end end @@ -64,7 +64,7 @@ describe "knife config get", :workstation do # because it has to run after the before set in the "with a chef repo" shared context. directory("repo") Dir.chdir(path_to("repo")) - ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd + ENV[ChefHelpers.windows? ? "CD" : "PWD"] = Dir.pwd ENV["HOME"] = path_to(".") end diff --git a/spec/integration/knife/config_list_profiles_spec.rb b/spec/integration/knife/config_list_profiles_spec.rb index 32846f9999..b8a20c9e3b 100644 --- a/spec/integration/knife/config_list_profiles_spec.rb +++ b/spec/integration/knife/config_list_profiles_spec.rb @@ -44,7 +44,7 @@ describe "knife config list-profiles", :workstation do ensure ENV["HOME"] = old_home Dir.chdir(old_wd) - ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd + ENV[ChefHelpers.windows? ? "CD" : "PWD"] = Dir.pwd end end @@ -53,7 +53,7 @@ describe "knife config list-profiles", :workstation do # because it has to run after the before set in the "with a chef repo" shared context. directory("repo") Dir.chdir(path_to("repo")) - ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd + ENV[ChefHelpers.windows? ? "CD" : "PWD"] = Dir.pwd ENV["HOME"] = path_to(".") end diff --git a/spec/integration/knife/config_use_profile_spec.rb b/spec/integration/knife/config_use_profile_spec.rb index a021dbbe6f..caf1e8b3da 100644 --- a/spec/integration/knife/config_use_profile_spec.rb +++ b/spec/integration/knife/config_use_profile_spec.rb @@ -51,7 +51,7 @@ describe "knife config use-profile", :workstation do ENV["KNIFE_HOME"] = old_knife_home ENV["HOME"] = old_home Dir.chdir(old_wd) - ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd + ENV[ChefHelpers.windows? ? "CD" : "PWD"] = Dir.pwd ChefConfig::PathHelper.per_tool_home_environment = nil end end @@ -61,7 +61,7 @@ describe "knife config use-profile", :workstation do # because it has to run after the before set in the "with a chef repo" shared context. directory("repo") Dir.chdir(path_to("repo")) - ENV[ChefConfig.windows? ? "CD" : "PWD"] = Dir.pwd + ENV[ChefHelpers.windows? ? "CD" : "PWD"] = Dir.pwd ENV["HOME"] = path_to(".") end diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb index 39a3f77fc5..0eaff01b00 100644 --- a/spec/integration/knife/list_spec.rb +++ b/spec/integration/knife/list_spec.rb @@ -466,7 +466,7 @@ EOM end end - when_the_repository "has a cookbooks directory and a symlinked cookbooks directory", skip: (Chef::Platform.windows?) do + when_the_repository "has a cookbooks directory and a symlinked cookbooks directory", skip: (ChefHelpers.windows?) do before do directory "cookbooks" symlink "symlinked", "cookbooks" @@ -503,7 +503,7 @@ EOM end end - when_the_repository "has a real_cookbooks directory and a cookbooks symlink to it", skip: (Chef::Platform.windows?) do + when_the_repository "has a real_cookbooks directory and a cookbooks symlink to it", skip: (ChefHelpers.windows?) do before do directory "real_cookbooks" symlink "cookbooks", "real_cookbooks" diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb index 58314473e7..7964d37f9c 100644 --- a/spec/integration/solo/solo_spec.rb +++ b/spec/integration/solo/solo_spec.rb @@ -4,7 +4,7 @@ require "chef/run_lock" require "chef/config" require "timeout" require "fileutils" -require "chef/win32/security" if Chef::Platform.windows? +require "chef/win32/security" if ChefHelpers.windows? describe "chef-solo" do include IntegrationSupport diff --git a/spec/support/matchers/leak.rb b/spec/support/matchers/leak.rb index 5f22c1c151..4c6ca66d06 100644 --- a/spec/support/matchers/leak.rb +++ b/spec/support/matchers/leak.rb @@ -60,7 +60,7 @@ module Matchers def profiler @profiler ||= begin - if Chef::Platform.windows? + if ChefHelpers.windows? require File.join(File.dirname(__FILE__), "..", "platforms", "prof", "win32") RSpec::Prof::Win32::Profiler.new else diff --git a/spec/support/mock/platform.rb b/spec/support/mock/platform.rb index c6670827f9..1795c5a7ba 100644 --- a/spec/support/mock/platform.rb +++ b/spec/support/mock/platform.rb @@ -6,7 +6,7 @@ # testing code that mixes in platform specific modules like +Chef::Mixin::Securable+ # or +Chef::FileAccessControl+ def platform_mock(platform = :unix) - allow(ChefConfig).to receive(:windows?).and_return(platform == :windows ? true : false) + allow(ChefHelpers).to receive(:windows?).and_return(platform == :windows ? true : false) ENV["SYSTEMDRIVE"] = (platform == :windows ? "C:" : nil) if platform == :windows diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb index 6ae052ba1d..b930002710 100644 --- a/spec/support/platform_helpers.rb +++ b/spec/support/platform_helpers.rb @@ -34,6 +34,8 @@ def ruby_32bit? end def windows? + # NOTE this deliberately does not use ChefHelpers.windows? because otherwise it would + # pick up the node out of tests, while this tests the hosts running the specs. !!(RUBY_PLATFORM =~ /mswin|mingw|windows/) end diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb index 5fc9de4de7..e2019306b2 100644 --- a/spec/support/shared/integration/integration_helper.rb +++ b/spec/support/shared/integration/integration_helper.rb @@ -128,7 +128,7 @@ module IntegrationSupport # TODO: "force" actually means "silence all exceptions". this # silences a weird permissions error on Windows that we should track # down, but for now there's no reason for it to blow up our CI. - FileUtils.remove_entry_secure(@repository_dir, force = Chef::Platform.windows?) + FileUtils.remove_entry_secure(@repository_dir, force = ChefHelpers.windows?) ensure @repository_dir = nil end diff --git a/spec/support/shared/integration/knife_support.rb b/spec/support/shared/integration/knife_support.rb index 87ce1bc0b0..37ca78ba46 100644 --- a/spec/support/shared/integration/knife_support.rb +++ b/spec/support/shared/integration/knife_support.rb @@ -181,7 +181,7 @@ module KnifeSupport expect(stderr_actual).to eq(expected[:stderr]) end stdout_actual = @stdout - if Chef::Platform.windows? + if ChefHelpers.windows? stderr_actual = stderr_actual.gsub("\r\n", "\n") stdout_actual = stdout_actual.gsub("\r\n", "\n") end diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index a7c7af92f6..482a22b952 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -1,6 +1,6 @@ # # Author:: Lamont Granquist () -# Copyright:: Copyright 2013-2016, Chef Software, Inc. +# Copyright:: Copyright 2013-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -255,7 +255,7 @@ shared_examples_for Chef::Provider::File do context "examining file security metadata on Unix with a file that exists" do before do # fake that we're on unix even if we're on windows - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) # mock up the filesystem to behave like unix setup_normal_file stat_struct = double("::File.stat", mode: 0600, uid: 0, gid: 0, mtime: 10000) @@ -331,7 +331,7 @@ shared_examples_for Chef::Provider::File do context "examining file security metadata on Unix with a file that does not exist" do before do # fake that we're on unix even if we're on windows - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) setup_missing_file end @@ -380,7 +380,7 @@ shared_examples_for Chef::Provider::File do before do # fake that we're on unix even if we're on windows - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) # mock up the filesystem to behave like unix setup_normal_file stat_struct = double("::File.stat", mode: 0600, uid: 0, gid: 0, mtime: 10000) diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb index 40f690abb1..d57205ba28 100644 --- a/spec/unit/application/client_spec.rb +++ b/spec/unit/application/client_spec.rb @@ -219,7 +219,7 @@ describe Chef::Application::Client, "reconfigure" do it "should terminal with message when interval is given" do Chef::Config[:interval] = 600 - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).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: @@ -232,7 +232,7 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config context "when interval is given on windows" do before do Chef::Config[:interval] = 600 - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) end it "should not terminate" do diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index b8d7242466..423b7da1dd 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -270,7 +270,7 @@ describe Chef::Application do end end - if Chef::Platform.windows? + if ChefHelpers.windows? it_behaves_like "sets log_location", :win_evt, Chef::Log::WinEvt it_behaves_like "sets log_location", "win_evt", Chef::Log::WinEvt else diff --git a/spec/unit/chef_fs/file_pattern_spec.rb b/spec/unit/chef_fs/file_pattern_spec.rb index 58cdbb28c2..a06468c1e2 100644 --- a/spec/unit/chef_fs/file_pattern_spec.rb +++ b/spec/unit/chef_fs/file_pattern_spec.rb @@ -157,7 +157,7 @@ describe Chef::ChefFS::FilePattern do end end - context 'with simple pattern "a\*\b"', skip: (Chef::Platform.windows?) do + context 'with simple pattern "a\*\b"', skip: (ChefHelpers.windows?) do let(:pattern) { Chef::ChefFS::FilePattern.new('a\*\b') } it "match?" do expect(pattern.match?("a*b")).to be_truthy @@ -264,7 +264,7 @@ describe Chef::ChefFS::FilePattern do end end - context 'with star pattern "/abc/d[a-z][0-9]f/ghi"', skip: (Chef::Platform.windows?) do + context 'with star pattern "/abc/d[a-z][0-9]f/ghi"', skip: (ChefHelpers.windows?) do let(:pattern) { Chef::ChefFS::FilePattern.new("/abc/d[a-z][0-9]f/ghi") } it "match?" do expect(pattern.match?("/abc/de1f/ghi")).to be_truthy diff --git a/spec/unit/chef_fs/path_util_spec.rb b/spec/unit/chef_fs/path_util_spec.rb index 93205a1815..1140fe6054 100644 --- a/spec/unit/chef_fs/path_util_spec.rb +++ b/spec/unit/chef_fs/path_util_spec.rb @@ -1,6 +1,6 @@ # # Author:: Kartik Null Cating-Subramanian () -# Copyright:: Copyright 2015-2016, Chef Software Inc. +# Copyright:: Copyright 2015-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -81,7 +81,7 @@ describe Chef::ChefFS::PathUtils do end it "handles root correctly" do - if Chef::Platform.windows? + if ChefHelpers.windows? expect(Chef::ChefFS::PathUtils.realest_path("C:/")).to eq("C:/") else expect(Chef::ChefFS::PathUtils.realest_path("/")).to eq("/") @@ -91,7 +91,7 @@ describe Chef::ChefFS::PathUtils do context "invoking descendant_path" do it "handles paths with various casing on windows" do - allow(Chef::ChefFS).to receive(:windows?) { true } + allow(ChefHelpers).to receive(:windows?) { true } expect(Chef::ChefFS::PathUtils.descendant_path("C:/ab/b/c", "C:/AB/B")).to eq("c") expect(Chef::ChefFS::PathUtils.descendant_path("C:/ab/b/c", "c:/ab/B")).to eq("c") end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 4f9d66d776..ec291e670f 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -2,7 +2,7 @@ # Author:: Adam Jacob () # Author:: Tim Hinderliter () # Author:: Christopher Walters () -# 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"); @@ -457,7 +457,7 @@ EOM describe "windows_admin_check" do context "platform is not windows" do before do - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) end it "shouldn't be called" do @@ -468,7 +468,7 @@ EOM context "platform is windows" do before do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) end it "should be called" do diff --git a/spec/unit/cookbook/cookbook_version_loader_spec.rb b/spec/unit/cookbook/cookbook_version_loader_spec.rb index 40a054abee..993d414c9c 100644 --- a/spec/unit/cookbook/cookbook_version_loader_spec.rb +++ b/spec/unit/cookbook/cookbook_version_loader_spec.rb @@ -1,6 +1,6 @@ # # Author:: Daniel DeLeo () -# Copyright:: Copyright 2014-2016, Chef Software, Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::Cookbook::CookbookVersionLoader do before do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } end describe "loading a cookbook" do diff --git a/spec/unit/cookbook/syntax_check_spec.rb b/spec/unit/cookbook/syntax_check_spec.rb index a24fa3ab2a..da45311b4e 100644 --- a/spec/unit/cookbook/syntax_check_spec.rb +++ b/spec/unit/cookbook/syntax_check_spec.rb @@ -1,6 +1,6 @@ # # Author:: Daniel DeLeo () -# Copyright:: Copyright 2010-2016, Chef Software Inc. +# Copyright:: Copyright 2010-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ require "chef/cookbook/syntax_check" describe Chef::Cookbook::SyntaxCheck do before do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } end let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "cookbooks", "openldap") } diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index 6553dad433..73e539d746 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::CookbookLoader do before do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } end let(:repo_paths) do [ diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index f20148de72..66854fd23b 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# 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,7 +22,7 @@ require "chef/data_bag" describe Chef::DataBag do before(:each) do @data_bag = Chef::DataBag.new - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } end describe "initialize" do diff --git a/spec/unit/dsl/platform_introspection_spec.rb b/spec/unit/dsl/platform_introspection_spec.rb index 51123ba930..fb8e2a219e 100644 --- a/spec/unit/dsl/platform_introspection_spec.rb +++ b/spec/unit/dsl/platform_introspection_spec.rb @@ -1,6 +1,6 @@ # # Author:: Seth Falcon () -# Copyright:: Copyright 2010-2016, Chef Software Inc. +# Copyright:: Copyright 2010-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -127,3 +127,33 @@ describe Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue do end end + +describe "ChefHelper functions mixed into classes" do + METHODS = [ :windows?, :fedora_derived?, :bsd_based?, :rhel?, :aix?, :gentoo? ] + + METHODS.each do |method| + it "mixes #{method} into Chef::Resource instances" do + expect(Chef::Resource.instance_methods.include?(method)).to be true + end + + it "mixes #{method} into Chef::Resource classes (provides lines, etc)" do + expect(Chef::Resource.respond_to?(method)).to be true + end + + it "mixes #{method} into Chef::Provider instances (actions)" do + expect(Chef::Provider.instance_methods.include?(method)).to be true + end + + it "mixes #{method} into Chef::Provider classes (provides lines, etc)" do + expect(Chef::Provider.respond_to?(method)).to be true + end + + it "mixes #{method} into Chef::Recipe instances (recipe files)" do + expect(Chef::Recipe.instance_methods.include?(method)).to be true + end + + it "mixes #{method} into Chef::Node instances (attribute files)" do + expect(Chef::Recipe.instance_methods.include?(method)).to be true + end + end +end diff --git a/spec/unit/file_content_management/deploy/mv_windows_spec.rb b/spec/unit/file_content_management/deploy/mv_windows_spec.rb index 80155f131c..25046dc91d 100644 --- a/spec/unit/file_content_management/deploy/mv_windows_spec.rb +++ b/spec/unit/file_content_management/deploy/mv_windows_spec.rb @@ -18,7 +18,7 @@ require "spec_helper" -unless Chef::Platform.windows? +unless ChefHelpers.windows? class Chef module ReservedNames module Win32 diff --git a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb index 209d987e78..22ff5515f0 100644 --- a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb @@ -1,6 +1,6 @@ # # Author:: Daniel DeLeo () -# Copyright:: Copyright 2012-2016, Chef Software Inc. +# Copyright:: Copyright 2012-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 624261fb8b..8dbf5060c2 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -23,7 +23,7 @@ require "net/ssh" describe Chef::Knife::Bootstrap do before do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } end let(:knife) do Chef::Log.logger = Logger.new(StringIO.new) diff --git a/spec/unit/knife/core/gem_glob_loader_spec.rb b/spec/unit/knife/core/gem_glob_loader_spec.rb index 689426de1b..56a212f846 100644 --- a/spec/unit/knife/core/gem_glob_loader_spec.rb +++ b/spec/unit/knife/core/gem_glob_loader_spec.rb @@ -23,7 +23,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do let(:plugin_dir) { File.join(home, ".chef", "plugins", "knife") } before do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } Chef::Util::PathHelper.class_variable_set(:@@home_dir, home) end diff --git a/spec/unit/knife/core/hashed_command_loader_spec.rb b/spec/unit/knife/core/hashed_command_loader_spec.rb index e866f13a9c..2a1959c394 100644 --- a/spec/unit/knife/core/hashed_command_loader_spec.rb +++ b/spec/unit/knife/core/hashed_command_loader_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Chef::Knife::SubcommandLoader::HashedCommandLoader do before do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } end let(:plugin_manifest) do diff --git a/spec/unit/knife/core/subcommand_loader_spec.rb b/spec/unit/knife/core/subcommand_loader_spec.rb index 5db0bb73e5..40b3fc3caf 100644 --- a/spec/unit/knife/core/subcommand_loader_spec.rb +++ b/spec/unit/knife/core/subcommand_loader_spec.rb @@ -23,7 +23,7 @@ describe Chef::Knife::SubcommandLoader do let(:plugin_dir) { File.join(home, ".chef", "plugins", "knife") } before do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } Chef::Util::PathHelper.class_variable_set(:@@home_dir, home) end diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index 025c1ecd91..bf0a3d1534 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -3,7 +3,7 @@ # Author:: Tim Hinderliter () # Author:: Daniel DeLeo () # Author:: John Keiser () -# 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"); @@ -482,7 +482,7 @@ EOM before(:each) do stdout = double("StringIO", tty?: true) allow(@ui).to receive(:stdout).and_return(stdout) - allow(ChefConfig).to receive(:windows?) { true } + allow(ChefHelpers).to receive(:windows?) { true } Chef::Config.reset end diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb index 3bea392ae2..373a110f57 100644 --- a/spec/unit/knife/data_bag_from_file_spec.rb +++ b/spec/unit/knife/data_bag_from_file_spec.rb @@ -1,6 +1,6 @@ # # Author:: Seth Falcon () -# Copyright:: Copyright 2010-2016, Chef Software Inc. +# Copyright:: Copyright 2010-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,7 @@ Chef::Knife::DataBagFromFile.load_deps describe Chef::Knife::DataBagFromFile do before :each do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } Chef::Config[:node_name] = "webmonkey.example.com" FileUtils.mkdir_p([db_folder, db_folder2]) db_file.write(Chef::JSONCompat.to_json(plain_data)) diff --git a/spec/unit/knife/environment_from_file_spec.rb b/spec/unit/knife/environment_from_file_spec.rb index 11e05cb922..17cc5b2ba4 100644 --- a/spec/unit/knife/environment_from_file_spec.rb +++ b/spec/unit/knife/environment_from_file_spec.rb @@ -1,7 +1,7 @@ # # Author:: Stephen Delano () # Author:: Seth Falcon () -# Copyright:: Copyright 2010-2016, Chef Software Inc. +# Copyright:: Copyright 2010-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ Chef::Knife::EnvironmentFromFile.load_deps describe Chef::Knife::EnvironmentFromFile do before(:each) do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } @knife = Chef::Knife::EnvironmentFromFile.new @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) diff --git a/spec/unit/knife/supermarket_install_spec.rb b/spec/unit/knife/supermarket_install_spec.rb index 68c8af1028..bb33bea516 100644 --- a/spec/unit/knife/supermarket_install_spec.rb +++ b/spec/unit/knife/supermarket_install_spec.rb @@ -30,7 +30,7 @@ describe Chef::Knife::SupermarketInstall do prepare_to_import: true, finalize_updates_to: true, merge_updates_from: true) end let(:install_path) do - if Chef::Platform.windows? + if ChefHelpers.windows? "C:/tmp/chef" else "/var/tmp/chef" diff --git a/spec/unit/mixin/path_sanity_spec.rb b/spec/unit/mixin/path_sanity_spec.rb index c9ed4e2595..417a5c74bd 100644 --- a/spec/unit/mixin/path_sanity_spec.rb +++ b/spec/unit/mixin/path_sanity_spec.rb @@ -1,6 +1,6 @@ # # Author:: Seth Chisamore () -# Copyright:: Copyright 2011-2017, Chef Software Inc. +# Copyright:: Copyright 2011-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,7 +35,7 @@ describe Chef::Mixin::PathSanity do @gem_bindir = "/some/gem/bin" allow(Gem).to receive(:bindir).and_return(@gem_bindir) allow(RbConfig::CONFIG).to receive(:[]).with("bindir").and_return(@ruby_bindir) - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) end it "adds all useful PATHs even if environment is an empty hash" do @@ -83,7 +83,7 @@ describe Chef::Mixin::PathSanity do gem_bindir = 'C:\gems\bin' allow(Gem).to receive(:bindir).and_return(gem_bindir) allow(RbConfig::CONFIG).to receive(:[]).with("bindir").and_return(ruby_bindir) - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) env = { "PATH" => 'C:\Windows\system32;C:\mr\softie' } @sanity.enforce_path_sanity(env) expect(env["PATH"]).to eq("#{gem_bindir};#{ruby_bindir};C:\\Windows\\system32;C:\\mr\\softie") diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index 7f6021d911..9c10813eb0 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -30,7 +30,7 @@ describe Chef::Mixin::ShellOut do subject(:shell_out_obj) { shell_out_class.new } def env_path - if Chef::Platform.windows? + if ChefHelpers.windows? "Path" else "PATH" diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb index ab7ed5bc5a..bd50afdaf9 100644 --- a/spec/unit/mixin/template_spec.rb +++ b/spec/unit/mixin/template_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# 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"); @@ -21,7 +21,7 @@ require "spec_helper" require "cgi" describe Chef::Mixin::Template, "render_template" do - let(:sep) { Chef::Platform.windows? ? "\r\n" : "\n" } + let(:sep) { ChefHelpers.windows? ? "\r\n" : "\n" } before :each do @context = Chef::Mixin::Template::TemplateContext.new({}) @@ -39,7 +39,7 @@ describe Chef::Mixin::Template, "render_template" do describe "when running on windows" do before do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) end it "should render the templates with windows line endings" do @@ -54,7 +54,7 @@ describe Chef::Mixin::Template, "render_template" do describe "when running on unix" do before do - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) end it "should render the templates with unix line endings" do diff --git a/spec/unit/mixin/user_context_spec.rb b/spec/unit/mixin/user_context_spec.rb index 896241f173..2271d80990 100644 --- a/spec/unit/mixin/user_context_spec.rb +++ b/spec/unit/mixin/user_context_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Edwards () -# Copyright:: Copyright (c) 2015 Chef Software, Inc. +# Copyright:: Copyright (c) 2015-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +39,7 @@ describe "a class that mixes in user_context" do context "when running on Windows" do before do - allow(::Chef::Platform).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(::Chef::Util::Windows::LogonSession).to receive(:new).and_return(logon_session) end @@ -98,7 +98,7 @@ describe "a class that mixes in user_context" do context "when not running on Windows" do before do - allow(::Chef::Platform).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) end it "raises a ::Chef::Exceptions::UnsupportedPlatform exception" do diff --git a/spec/unit/node_map_spec.rb b/spec/unit/node_map_spec.rb index df70ad380a..c2dfe518d0 100644 --- a/spec/unit/node_map_spec.rb +++ b/spec/unit/node_map_spec.rb @@ -104,8 +104,8 @@ describe Chef::NodeMap do end it "returns nil when the platform_family does not match" do - allow(node).to receive(:[]).with(:os).and_return("linux") - allow(node).to receive(:[]).with(:platform_family).and_return("debian") + node.automatic["os"] = "linux" + node.automatic["platform_family"] = "debian" expect(node_map.get(node, :thing)).to eql(nil) end end @@ -174,26 +174,26 @@ describe Chef::NodeMap do end it "returns the value when the node matches" do - allow(node).to receive(:[]).with(:platform_family).and_return("rhel") - allow(node).to receive(:[]).with(:platform_version).and_return("7.0") + node.automatic["platform_family"] = "rhel" + node.automatic["platform_version"] = "7.0" expect(node_map.get(node, :thing)).to eql(:foo) end it "returns nil when the block does not match" do - allow(node).to receive(:[]).with(:platform_family).and_return("rhel") - allow(node).to receive(:[]).with(:platform_version).and_return("6.4") + node.automatic["platform_family"] = "rhel" + node.automatic["platform_version"] = "6.4" expect(node_map.get(node, :thing)).to eql(nil) end it "returns nil when the platform_family filter does not match" do - allow(node).to receive(:[]).with(:platform_family).and_return("debian") - allow(node).to receive(:[]).with(:platform_version).and_return("7.0") + node.automatic["platform_family"] = "debian" + node.automatic["platform_version"] = "7.0" expect(node_map.get(node, :thing)).to eql(nil) end it "returns nil when both do not match" do - allow(node).to receive(:[]).with(:platform_family).and_return("debian") - allow(node).to receive(:[]).with(:platform_version).and_return("6.0") + node.automatic["platform_family"] = "debian" + node.automatic["platform_version"] = "6.0" expect(node_map.get(node, :thing)).to eql(nil) end @@ -203,8 +203,8 @@ describe Chef::NodeMap do end it "returns the value when the node matches" do - allow(node).to receive(:[]).with(:platform_family).and_return("rhel") - allow(node).to receive(:[]).with(:platform_version).and_return("7.0") + node.automatic["platform_family"] = "rhel" + node.automatic["platform_version"] = "7.0" expect(node_map.get(node, :thing)).to eql(:foo) end end diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb index 82ed4de9c6..e6e155c0d8 100644 --- a/spec/unit/platform/query_helpers_spec.rb +++ b/spec/unit/platform/query_helpers_spec.rb @@ -1,6 +1,6 @@ # # Author:: Bryan McLellan -# Copyright:: Copyright 2014-2016, Chef Software, Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,13 +43,13 @@ describe "Chef::Platform#windows_nano_server?" do end it "returns false early when not on windows" do - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) expect(Chef::Platform).to_not receive(:require) expect(Chef::Platform.windows_nano_server?).to be false end it "returns true when the registry value is 1" do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) .with(key, access) @@ -59,7 +59,7 @@ describe "Chef::Platform#windows_nano_server?" do end it "returns false when the registry value is not 1" do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) .with(key, access) @@ -69,7 +69,7 @@ describe "Chef::Platform#windows_nano_server?" do end it "returns false when the registry value does not exist" do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) .with(key, access) @@ -80,7 +80,7 @@ describe "Chef::Platform#windows_nano_server?" do end it "returns false when the registry key does not exist" do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) .with(key, access) @@ -114,13 +114,13 @@ describe "Chef::Platform#supports_msi?" do end it "returns false early when not on windows" do - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) expect(Chef::Platform).to_not receive(:require) expect(Chef::Platform.supports_msi?).to be false end it "returns true when the registry key exists" do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) .with(key, access) @@ -129,7 +129,7 @@ describe "Chef::Platform#supports_msi?" do end it "returns false when the registry key does not exist" do - allow(ChefConfig).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) .with(key, access) diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb index 9718a012da..42685883fc 100644 --- a/spec/unit/provider/execute_spec.rb +++ b/spec/unit/provider/execute_spec.rb @@ -42,7 +42,7 @@ describe Chef::Provider::Execute do before do allow(Chef::EventDispatch::EventsOutputStream).to receive(:new) { @live_stream } - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } @original_log_level = Chef::Log.level Chef::Log.level = :info allow(STDOUT).to receive(:tty?).and_return(false) diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb index 027b318c7e..5cb0250c7e 100644 --- a/spec/unit/provider/link_spec.rb +++ b/spec/unit/provider/link_spec.rb @@ -1,7 +1,7 @@ # # Author:: AJ Christensen () # Author:: John Keiser () -# 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"); @@ -21,7 +21,7 @@ require "ostruct" require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/file" # probably need this in spec_helper end @@ -41,7 +41,7 @@ describe Chef::Resource::Link do end def canonicalize(path) - Chef::Platform.windows? ? path.tr("/", '\\') : path + ChefHelpers.windows? ? path.tr("/", '\\') : path end describe "when the target is a symlink" do @@ -348,7 +348,7 @@ describe Chef::Resource::Link do allow(Chef::Resource::Link).to receive(:new).with( provider.new_resource.name).and_return(resource_link) allow(resource_link).to receive(:verify_links_supported!) - allow(Chef::Platform).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) end context "soft links" do @@ -378,7 +378,7 @@ describe Chef::Resource::Link do context "on Linux platform" do before(:each) do - allow(Chef::Platform).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) end context "soft links" do diff --git a/spec/unit/provider/package/windows/exe_spec.rb b/spec/unit/provider/package/windows/exe_spec.rb index 4f6a6121bd..7c525d771c 100644 --- a/spec/unit/provider/package/windows/exe_spec.rb +++ b/spec/unit/provider/package/windows/exe_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" require "chef/provider/package/windows/exe" -unless Chef::Platform.windows? +unless ChefHelpers.windows? class Chef module ReservedNames::Win32 class File diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb index 6b85013f3d..3062a475f1 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -1,6 +1,6 @@ # # Author:: Bryan McLellan -# Copyright:: Copyright 2014-2017, Chef Software Inc. +# Copyright:: Copyright 2014-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ require "chef/provider/package/windows/msi" describe Chef::Provider::Package::Windows, :windows_only do before(:each) do - allow(Chef::Util::PathHelper).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) allow(Chef::FileCache).to receive(:create_cache_path).with("package/").and_return(cache_path) end diff --git a/spec/unit/provider/remote_file/fetcher_spec.rb b/spec/unit/provider/remote_file/fetcher_spec.rb index b110e2c03a..a3ae60d6b0 100644 --- a/spec/unit/provider/remote_file/fetcher_spec.rb +++ b/spec/unit/provider/remote_file/fetcher_spec.rb @@ -1,6 +1,6 @@ # # Author:: Lamont Granquist () -# Copyright:: Copyright 2013-2016, Chef Software Inc. +# Copyright:: Copyright 2013-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,7 @@ describe Chef::Provider::RemoteFile::Fetcher do describe "when passed a network share" do before do expect(Chef::Provider::RemoteFile::NetworkFile).to receive(:new).and_return(fetcher_instance) - allow(Chef::Platform).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) end context "when host is a name" do diff --git a/spec/unit/provider/remote_file/local_file_spec.rb b/spec/unit/provider/remote_file/local_file_spec.rb index 6dad6a57f2..43f38a0e00 100644 --- a/spec/unit/provider/remote_file/local_file_spec.rb +++ b/spec/unit/provider/remote_file/local_file_spec.rb @@ -31,7 +31,7 @@ describe Chef::Provider::RemoteFile::LocalFile do context "when parsing source path on windows" do before do - allow(Chef::Platform).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) end describe "when given local unix path" do diff --git a/spec/unit/provider/remote_file/network_file_spec.rb b/spec/unit/provider/remote_file/network_file_spec.rb index 1c2bcc5911..07d8a402ca 100644 --- a/spec/unit/provider/remote_file/network_file_spec.rb +++ b/spec/unit/provider/remote_file/network_file_spec.rb @@ -33,7 +33,7 @@ describe Chef::Provider::RemoteFile::NetworkFile do let(:source_file) { double("::File", read: nil) } before do - allow(Chef::Platform).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) end it "stages the local file to a temporary file" do diff --git a/spec/unit/provider/script_spec.rb b/spec/unit/provider/script_spec.rb index 08b19730a7..036d742717 100644 --- a/spec/unit/provider/script_spec.rb +++ b/spec/unit/provider/script_spec.rb @@ -59,7 +59,7 @@ describe Chef::Provider::Script, "action_run" do context "when configuring the script file's security" do context "when not running on Windows" do before do - allow(::Chef::Platform).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) end context "#set_owner_and_group" do it "sets the owner and group for the script file" do @@ -73,7 +73,7 @@ describe Chef::Provider::Script, "action_run" do context "when running on Windows" do before do - allow(::Chef::Platform).to receive(:windows?).and_return(true) + allow(ChefHelpers).to receive(:windows?).and_return(true) expect(new_resource.user).to eq(nil) stub_const("Chef::ReservedNames::Win32::API::Security::GENERIC_READ", 1) stub_const("Chef::ReservedNames::Win32::API::Security::GENERIC_EXECUTE", 4) diff --git a/spec/unit/provider/subversion_spec.rb b/spec/unit/provider/subversion_spec.rb index d3c5073b7e..68fc7b6cfa 100644 --- a/spec/unit/provider/subversion_spec.rb +++ b/spec/unit/provider/subversion_spec.rb @@ -1,6 +1,6 @@ # # Author:: Daniel DeLeo () -# 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"); @@ -274,7 +274,7 @@ describe Chef::Provider::Subversion do it "selects 'svn' as the binary by default" do @resource.svn_binary nil - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } expect(@provider).to receive(:svn_binary).and_return("svn") expect(@provider.export_command).to eql( "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") @@ -282,7 +282,7 @@ describe Chef::Provider::Subversion do it "selects an svn binary with an exe extension on windows" do @resource.svn_binary nil - allow(ChefConfig).to receive(:windows?) { true } + allow(ChefHelpers).to receive(:windows?) { true } expect(@provider).to receive(:svn_binary).and_return("svn.exe") expect(@provider.export_command).to eql( "svn.exe export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index c93a1eb4a8..ebcc491ab0 100644 --- a/spec/unit/provider/user/dscl_spec.rb +++ b/spec/unit/provider/user/dscl_spec.rb @@ -1,6 +1,6 @@ # # Author:: Dreamcat4 () -# Copyright:: Copyright 2009-2016, Chef Software Inc. +# Copyright:: Copyright 2009-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ require "ostruct" describe Chef::Provider::User::Dscl do before do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } end let(:shellcmdresult) do Struct.new(:stdout, :stderr, :exitstatus) diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb index a3f2801adf..5c6b30906b 100644 --- a/spec/unit/provider_resolver_spec.rb +++ b/spec/unit/provider_resolver_spec.rb @@ -34,10 +34,6 @@ describe Chef::ProviderResolver do # Root the filesystem under a temp directory so Chef.path_to will point at it when_the_repository "is empty" do - before do - allow(Chef).to receive(:path_to) { |path| File.join(path_to(""), path) } - end - let(:resource_name) { :service } let(:provider) { nil } let(:action) { :start } @@ -145,51 +141,36 @@ describe Chef::ProviderResolver do describe "resolving service resource" do def stub_service_providers(*services) - services.each do |service| - case service - when :debian - file "usr/sbin/update-rc.d", "" - when :invokercd - file "usr/sbin/invoke-rc.d", "" - when :insserv - file "sbin/insserv", "" - when :upstart - file "sbin/initctl", "" - when :redhat - file "sbin/chkconfig", "" - when :systemd - file "proc/1/comm", "systemd\n" - else - raise ArgumentError, service - end + allowed = [:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd] + + (allowed - services).each do |api| + allow(Chef::Provider::Service).to receive(:"#{api}?").and_return(false) + end + + raise ArgumentError unless (services - allowed).empty? + + services.each do |api| + allow(Chef::Provider::Service).to receive(:"#{api}?").and_return(true) end end def stub_service_configs(*configs) - configs.each do |config| - case config - when :initd - file "etc/init.d/#{service_name}", "" - when :upstart - file "etc/init/#{service_name}.conf", "" - when :xinetd - file "etc/xinetd.d/#{service_name}", "" - when :etc_rcd - file "etc/rc.d/#{service_name}", "" - when :usr_local_etc_rcd - file "usr/local/etc/rc.d/#{service_name}", "" - when :systemd - file "proc/1/comm", "systemd\n" - file "etc/systemd/system/#{service_name}.service", "" - else - raise ArgumentError, config - end + allowed = [:initd, :upstart, :xinetd, :systemd, :etc_rcd] + + (allowed - configs).each do |type| + allow(Chef::Provider::Service).to receive(:service_script_exist?).with(type, service_name).and_return(false) + end + + raise ArgumentError unless (configs - allowed).empty? + + configs.each do |type| + allow(Chef::Provider::Service).to receive(:service_script_exist?).with(type, service_name).and_return(true) end end shared_examples_for "an ubuntu platform with upstart, update-rc.d and systemd" do before do - stub_service_providers(:debian, :invokercd, :upstart, :systemd) + stub_service_providers(:debianrcd, :invokercd, :upstart, :systemd) end it "when both the SysV init and Systemd script exists, it returns a Service::Debian provider" do @@ -213,12 +194,12 @@ describe Chef::ProviderResolver do end it "when only the SysV init script exists, it returns a Service::Systemd provider" do - stub_service_configs(:initd) + stub_service_configs(:initd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Systemd) end it "when both SysV and Upstart scripts exist, it returns a Service::Systemd provider" do - stub_service_configs(:initd, :upstart) + stub_service_configs(:initd, :systemd, :upstart) expect(resolved_provider).to eql(Chef::Provider::Service::Systemd) end @@ -235,7 +216,7 @@ describe Chef::ProviderResolver do shared_examples_for "an ubuntu platform with upstart and update-rc.d" do before do - stub_service_providers(:debian, :invokercd, :upstart) + stub_service_providers(:debianrcd, :invokercd, :upstart) end # needs to be handled by the highest priority init.d handler @@ -362,7 +343,7 @@ describe Chef::ProviderResolver do shared_examples_for "a debian platform using the insserv provider" do context "with a default install" do before do - stub_service_providers(:debian, :invokercd, :insserv) + stub_service_providers(:debianrcd, :invokercd, :insserv) end it "uses the Service::Insserv Provider to manage sysv init scripts" do @@ -378,7 +359,7 @@ describe Chef::ProviderResolver do context "when the user has installed upstart" do before do - stub_service_providers(:debian, :invokercd, :insserv, :upstart) + stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart) end it "when only the SysV init script exists, it returns an Insserv provider" do @@ -407,8 +388,8 @@ describe Chef::ProviderResolver do it_behaves_like "an ubuntu platform with upstart, update-rc.d and systemd" it "when the unit-files are missing and system-ctl list-unit-files returns an error" do - stub_service_providers(:debian, :invokercd, :upstart, :systemd) - stub_service_configs(:initd, :upstart) + stub_service_providers(:debianrcd, :invokercd, :upstart, :systemd) + stub_service_configs(:initd, :upstart, :systemd) mock_shellout_command("/bin/systemctl list-unit-files", exitstatus: 1) expect(resolved_provider).to eql(Chef::Provider::Service::Systemd) end @@ -445,8 +426,8 @@ describe Chef::ProviderResolver do it "always returns a Solaris provider" do # no matter what we stub on the next two lines we should get a Solaris provider - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd) + stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd) + stub_service_configs(:initd, :upstart, :xinetd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Solaris) end end @@ -460,8 +441,8 @@ describe Chef::ProviderResolver do it "always returns a Windows provider" do # no matter what we stub on the next two lines we should get a Windows provider - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd) + stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd) + stub_service_configs(:initd, :upstart, :xinetd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Windows) end end @@ -475,8 +456,8 @@ describe Chef::ProviderResolver do it "always returns a Macosx provider" do # no matter what we stub on the next two lines we should get a Macosx provider - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd) + stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd) + stub_service_configs(:initd, :upstart, :xinetd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Macosx) end end @@ -484,7 +465,6 @@ describe Chef::ProviderResolver do on_platform "freebsd", os: "freebsd", platform_version: "10.3" do it "returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do stub_service_providers - stub_service_configs(:usr_local_etc_rcd) expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) end @@ -495,15 +475,14 @@ describe Chef::ProviderResolver do end it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do - # should only care about :usr_local_etc_rcd stub in the service configs - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:usr_local_etc_rcd, :initd, :upstart, :xinetd, :systemd) + stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd) + stub_service_configs(:initd, :upstart, :xinetd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) end it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do # should only care about :etc_rcd stub in the service configs - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) + stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd) stub_service_configs(:etc_rcd, :initd, :upstart, :xinetd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) end @@ -518,7 +497,6 @@ describe Chef::ProviderResolver do on_platform "netbsd", os: "netbsd", platform_version: "7.0.1" do it "returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do stub_service_providers - stub_service_configs(:usr_local_etc_rcd) expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) end @@ -529,15 +507,14 @@ describe Chef::ProviderResolver do end it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do - # should only care about :usr_local_etc_rcd stub in the service configs - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:usr_local_etc_rcd, :initd, :upstart, :xinetd, :systemd) + stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd) + stub_service_configs(:initd, :upstart, :xinetd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) end it "always returns a Freebsd provider if it finds the /usr/local/etc/rc.d initscript" do # should only care about :etc_rcd stub in the service configs - stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) + stub_service_providers(:debianrcd, :invokercd, :insserv, :upstart, :redhatrcd, :systemd) stub_service_configs(:etc_rcd, :initd, :upstart, :xinetd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Freebsd) end diff --git a/spec/unit/resource/cookbook_file_spec.rb b/spec/unit/resource/cookbook_file_spec.rb index b35233649d..da3c80a729 100644 --- a/spec/unit/resource/cookbook_file_spec.rb +++ b/spec/unit/resource/cookbook_file_spec.rb @@ -53,7 +53,7 @@ describe Chef::Resource::CookbookFile do describe "when it has a backup number, group, mode, owner, source, checksum, and cookbook on nix or path, rights, deny_rights, checksum on windows" do before do - if Chef::Platform.windows? + if ChefHelpers.windows? resource.path("C:/temp/origin/file.txt") resource.rights(:read, "Everyone") resource.deny_rights(:full_control, "Clumsy_Sam") @@ -70,7 +70,7 @@ describe Chef::Resource::CookbookFile do it "describes the state" do state = resource.state_for_resource_reporter - if Chef::Platform.windows? + if ChefHelpers.windows? puts state expect(state[:rights]).to eq([{ permissions: :read, principals: "Everyone" }]) expect(state[:deny_rights]).to eq([{ permissions: :full_control, principals: "Clumsy_Sam" }]) @@ -83,7 +83,7 @@ describe Chef::Resource::CookbookFile do end it "returns the path as its identity" do - if Chef::Platform.windows? + if ChefHelpers.windows? expect(resource.identity).to eq("C:/temp/origin/file.txt") else expect(resource.identity).to eq("/tmp/origin/file.txt") diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb index 39d34d9a96..dff6e0f70b 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/spec/unit/resource/remote_file_spec.rb @@ -181,7 +181,7 @@ describe Chef::Resource::RemoteFile do describe "when it has group, mode, owner, source, and checksum" do before do - if Chef::Platform.windows? + if ChefHelpers.windows? resource.path("C:/temp/origin/file.txt") resource.rights(:read, "Everyone") resource.deny_rights(:full_control, "Clumsy_Sam") @@ -197,7 +197,7 @@ describe Chef::Resource::RemoteFile do it "describes its state" do state = resource.state_for_resource_reporter - if Chef::Platform.windows? + if ChefHelpers.windows? puts state expect(state[:rights]).to eq([{ permissions: :read, principals: "Everyone" }]) expect(state[:deny_rights]).to eq([{ permissions: :full_control, principals: "Clumsy_Sam" }]) @@ -210,7 +210,7 @@ describe Chef::Resource::RemoteFile do end it "returns the path as its identity" do - if Chef::Platform.windows? + if ChefHelpers.windows? expect(resource.identity).to eq("C:/temp/origin/file.txt") else expect(resource.identity).to eq("/this/path/") diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb index 57f1d5c6ba..7d4d6dc881 100644 --- a/spec/unit/role_spec.rb +++ b/spec/unit/role_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# 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"); @@ -21,7 +21,7 @@ require "chef/role" describe Chef::Role do before(:each) do - allow(ChefConfig).to receive(:windows?) { false } + allow(ChefHelpers).to receive(:windows?) { false } @role = Chef::Role.new @role.name("ops_master") end diff --git a/spec/unit/shell_spec.rb b/spec/unit/shell_spec.rb index 8ba1afa72a..c915bb5798 100644 --- a/spec/unit/shell_spec.rb +++ b/spec/unit/shell_spec.rb @@ -43,7 +43,7 @@ describe Shell do before do Shell.irb_conf = {} allow(Shell::ShellSession.instance).to receive(:reset!) - allow(ChefConfig).to receive(:windows?).and_return(false) + allow(ChefHelpers).to receive(:windows?).and_return(false) allow(Chef::Util::PathHelper).to receive(:home).and_return("/home/foo") end diff --git a/spec/unit/win32/error_spec.rb b/spec/unit/win32/error_spec.rb index 316303ab4f..9991b149bd 100644 --- a/spec/unit/win32/error_spec.rb +++ b/spec/unit/win32/error_spec.rb @@ -17,7 +17,7 @@ # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/error" require "chef/win32/api/error" end diff --git a/spec/unit/win32/link_spec.rb b/spec/unit/win32/link_spec.rb index 5f749c034e..08d5580518 100644 --- a/spec/unit/win32/link_spec.rb +++ b/spec/unit/win32/link_spec.rb @@ -16,7 +16,7 @@ # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/api/file" require "chef/win32/file" require "chef/win32/version" diff --git a/spec/unit/win32/security_spec.rb b/spec/unit/win32/security_spec.rb index b5e441f2a0..88c4bb8670 100644 --- a/spec/unit/win32/security_spec.rb +++ b/spec/unit/win32/security_spec.rb @@ -17,7 +17,7 @@ # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/win32/error" require "chef/win32/security" require "chef/win32/api/error" diff --git a/spec/unit/windows_service_spec.rb b/spec/unit/windows_service_spec.rb index 45af0f9d9f..9850bbd7c5 100644 --- a/spec/unit/windows_service_spec.rb +++ b/spec/unit/windows_service_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # require "spec_helper" -if Chef::Platform.windows? +if ChefHelpers.windows? require "chef/application/windows_service" end diff --git a/tasks/rspec.rb b/tasks/rspec.rb index afd7d12705..61e7b551b9 100644 --- a/tasks/rspec.rb +++ b/tasks/rspec.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Daniel DeLeo () -# 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"); @@ -25,12 +25,14 @@ CHEF_ROOT = File.join(File.dirname(__FILE__), "..") begin require "rspec/core/rake_task" - desc "Run specs for Chef's Components (chef-config)" + desc "Run specs for Chef's Components" task :component_specs do - Dir.chdir("chef-config") do - Bundler.with_clean_env do - sh("bundle install") - sh("bundle exec rake spec") + %w{chef-helpers chef-config}.each do |gem| + Dir.chdir(gem) do + Bundler.with_clean_env do + sh("bundle install") + sh("bundle exec rake spec") + end end end end -- cgit v1.2.1