diff options
author | Claire McQuin <claire@getchef.com> | 2014-10-16 10:14:56 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-10-16 10:14:56 -0700 |
commit | 1da210f48c60460bad494d4cc28d1385407e0806 (patch) | |
tree | a7d5ded97dca7a645491d92e41da31a21208cca8 | |
parent | 9af87953f6b4fe40c84e902d19b880138465044d (diff) | |
parent | b80ababcfe48bb53bf745100d18a55381c6a9f45 (diff) | |
download | chef-1da210f48c60460bad494d4cc28d1385407e0806.tar.gz |
Merge branch 'master' into mcquin/centos-locale-a
-rw-r--r-- | CHANGELOG.md | 46 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | RELEASE_NOTES.md | 23 | ||||
-rw-r--r-- | lib/chef/mixin/homebrew_user.rb | 2 | ||||
-rw-r--r-- | lib/chef/mixin/shell_out.rb | 4 | ||||
-rw-r--r-- | lib/chef/provider/dsc_script.rb | 5 | ||||
-rw-r--r-- | lib/chef/provider/package/homebrew.rb | 2 | ||||
-rw-r--r-- | lib/chef/util/dsc/local_configuration_manager.rb | 6 | ||||
-rw-r--r-- | lib/chef/win32/version.rb | 2 | ||||
-rw-r--r-- | spec/functional/resource/dsc_script_spec.rb | 139 | ||||
-rw-r--r-- | spec/functional/resource/file_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/package/homebrew_spec.rb | 9 | ||||
-rw-r--r-- | spec/unit/util/dsc/local_configuration_manager_spec.rb | 8 |
13 files changed, 185 insertions, 65 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b4bdcd9c0..f321120901 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,9 +80,55 @@ Fix version detection in FreeBSD pkgng provider. (PR 1980) * [**Dan Rathbone**](https://github.com/rathers): Fixed gem_package resource to be able to upgrade gems when version is not set. +* [**Jean Mertz**](https://github.com/JeanMertz): + Made Chef Client load library folder recursively. +* [**Eric Saxby**](https://github.com/sax): + Made Chef Client read the non-root crontab entries as the user specified in the resource. +* [**sawanoboly**](https://github.com/sawanoboly): + Added `--dry-run` option to `knife cookbook site share` which displays the files that are to be uploaded to Supermarket. +* [**Sander van Harmelen**](https://github.com/svanharmelen): + Fixed `Chef::HTTP` to be able to follow relative redirects. +* [**Cory Stephenson**](https://github.com/Aevin1387): + Fixed FreeBSD port package provider to interpret FreeBSD version 10 correctly. +* [**Brett Chalupa**](https://github.com/brettchalupa): + Added `source_url` and `issues_url` options to metadata to be used by Supermarket. +* [**Anshul Sharma**](https://github.com/justanshulsharma): + Fixed Chef Client to use the `:client_name` instead of `:node_name` during initial client registration. +* [**tbe**](https://github.com/tbe): + Fixed Paludis package provider to be able to interpret the package category. +* [**David Workman**](https://github.com/workmad3): + Added a more clear error message to chef-apply when no recipe is given. +* [**Joe Nuspl**](https://github.com/nvwls): + Added support for `sensitive` property to the execute resource. +* [**Nolan Davidson**](https://github.com/nsdavidson): + Added an error message to prevent unintentional running of `exec()` in recipes. +* [**wacky612**](https://github.com/wacky612): + Fixed a bug in pacman package provider that was preventing the installation of `bind` package. +* [**Ionuț Arțăriși**](https://github.com/mapleoin): + Changed the default service provider to systemd on SLES versions 12 and higher. +* [**Ionuț Arțăriși**](https://github.com/mapleoin): + Changed the default group provider to gpasswd on SLES versions 12 and higher. +* [**Noah Kantrowitz**](https://github.com/coderanger): + Implemented [RFC017 - File Specificity Overhaul](https://github.com/opscode/chef-rfc/blob/master/rfc017-file-specificity.md). +* [**James Bence**](https://github.com/jbence): + Improved the reliability of Git provider by making it to be more specific when selecting tags. +* [**Jean Mertz**](https://github.com/JeanMertz): + Changed knife upload not to validate the ruby files under files & templates directories. +* [**Alex Pop**](https://github.com/alexpop): + Made `knife cookbook create` to display the directory of the cookbook that is being created. +* [**Alex Pop**](https://github.com/alexpop): + Fixed the information debug output for the configuration file being used when running knife. +* [**Martin Smith**](https://github.com/martinb3): + Changed `knife cookbook site share` to make category an optional parameter when uploading cookbooks. + It is still required when the cookbook is being uploaded for the first time but on the consequent + uploads existing category of the cookbook will be used. +* [**Nicolas DUPEUX**](https://github.com/vaxvms): + Added JSON output to `knife status` command. `--medium` and `--long` output formatting parameters are now supported in knife status. ### Chef Contributions +* Add support for Windows 10 to version helper. +* `dsc_script` resource should honor configuration parameters when `configuration_data_script` is not set (Issue #2209) * Ruby has been updated to 2.1.3 along with rubygems update to 2.4.2 * Removed shelling out to erubis/ruby for syntax checks (>= 1.9 has been able to do this in the ruby vm itself for awhile now and we've dropped 1.8.7 which @@ -33,7 +33,7 @@ emerge, etc.): * git * C compiler, header files, etc. On Ubuntu/debian, use the `build-essential` package. -* ruby 1.8.7 or later (1.9.3+ recommended) +* ruby 1.9.3 or later * rubygems * bundler diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index a6d1a65f51..1fdc51c6e6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -118,7 +118,7 @@ homebrew_package 'vim' do end ``` -Chef will then execute the Homebrew command as that user. The `homebrew_user` attribute can only be provided to the +Chef will then execute the Homebrew command as that user. The `homebrew_user` attribute can only be provided to the `homebrew_package` resource, not the `package` resource. ## DSCL user provider now supports Mac OS X 10.7 and above. @@ -315,3 +315,24 @@ error when `client_fork false` is set. ## Interval sleep occurs before converge When running chef-client or chef-solo at intervals, the application will perform splay and interval sleep before converging chef. (In previous releases, splay sleep occurred first, then convergance, then interval sleep). + +## `--dry-run` option for knife cookbook site share +"knife cookbook site share" command now accepts a new command line option `--dry-run`. When this option is specified, command + will display the files that are about to be uploaded to the Supermarket. + +## New cookbook metadata attributes for Supermarket +Cookbook metadata now accepts `source_url` and `issues_url` that should point to the source code of the cookbook and + the issue tracker of the cookbook. These attributes are being used by Supermarket. + +## CHEF RFC-017 - File Specificity Overhaul +RFC-017 has two great advantages: +1. It makes it easy to create cookbooks by removing the need for `default/` folder when adding templates and cookbook files. +2. It enables the configuring a custom lookup logic when Chef is attempting to find cookbook files. + +You can read more about this RFC [here](https://github.com/opscode/chef-rfc/blob/master/rfc017-file-specificity.md). + +## JSON output for `knife status` +`knife status` command now supports two additional output formats: + +1. `--medium`: Includes normal attributes in the output and presents the output as JSON. +1. `--long`: Includes all attributes in the output and presents the output as JSON. diff --git a/lib/chef/mixin/homebrew_user.rb b/lib/chef/mixin/homebrew_user.rb index 854a954a90..ab6fb19563 100644 --- a/lib/chef/mixin/homebrew_user.rb +++ b/lib/chef/mixin/homebrew_user.rb @@ -36,7 +36,7 @@ class Chef # the brew executable. def find_homebrew_uid(provided_user = nil) # They could provide us a user name or a UID - unless provided_user.nil? + if provided_user return provided_user if provided_user.is_a? Integer return Etc.getpwnam(provided_user).uid end diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb index 82772b584a..5b05e788db 100644 --- a/lib/chef/mixin/shell_out.rb +++ b/lib/chef/mixin/shell_out.rb @@ -15,10 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# chef/shell_out has been deprecated in favor of mixlib/shellout -# chef/shell_out is still required here to ensure backward compatibility -require 'chef/shell_out' - require 'mixlib/shellout' class Chef diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb index b8ca54f1b8..a70f4b5048 100644 --- a/lib/chef/provider/dsc_script.rb +++ b/lib/chef/provider/dsc_script.rb @@ -62,7 +62,7 @@ class Chef def define_resource_requirements requirements.assert(:run) do |a| err = [ - 'Could not find Dsc on the system', + 'Could not find PowerShell DSC support on the system', powershell_info_str, "Powershell 4.0 or higher was not detected on your system and is required to use the dsc_script resource.", ] @@ -98,9 +98,8 @@ class Chef end def get_augmented_configuration_flags(configuration_data_path) - updated_flags = nil + updated_flags = @dsc_resource.flags.nil? ? {} : @dsc_resource.flags.dup if configuration_data_path - updated_flags = @dsc_resource.flags.nil? ? {} : @dsc_resource.flags.dup Chef::Util::PathHelper.validate_path(configuration_data_path) updated_flags[:configurationdata] = configuration_data_path end diff --git a/lib/chef/provider/package/homebrew.rb b/lib/chef/provider/package/homebrew.rb index 202e4d2533..a9aeea1415 100644 --- a/lib/chef/provider/package/homebrew.rb +++ b/lib/chef/provider/package/homebrew.rb @@ -109,7 +109,7 @@ class Chef private def get_response_from_command(command) - homebrew_uid = find_homebrew_uid(new_resource.homebrew_user) + homebrew_uid = find_homebrew_uid(new_resource.respond_to?(:homebrew_user) && new_resource.homebrew_user) homebrew_user = Etc.getpwuid(homebrew_uid) Chef::Log.debug "Executing '#{command}' as user '#{homebrew_user.name}'" diff --git a/lib/chef/util/dsc/local_configuration_manager.rb b/lib/chef/util/dsc/local_configuration_manager.rb index 4a56b6a397..7395dd5bbf 100644 --- a/lib/chef/util/dsc/local_configuration_manager.rb +++ b/lib/chef/util/dsc/local_configuration_manager.rb @@ -29,7 +29,7 @@ class Chef::Util::DSC def test_configuration(configuration_document) status = run_configuration_cmdlet(configuration_document) - handle_what_if_exception!(status.stderr) unless status.succeeded? + log_what_if_exception(status.stderr) unless status.succeeded? configuration_update_required?(status.return_value) end @@ -78,14 +78,14 @@ $ProgressPreference = 'SilentlyContinue';start-dscconfiguration -path #{@configu EOH end - def handle_what_if_exception!(what_if_exception_output) + def log_what_if_exception(what_if_exception_output) if what_if_exception_output.gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i # LCM returns an error if any of the resources do not support the opptional What-If Chef::Log::warn("Received error while testing configuration due to resource not supporting 'WhatIf'") elsif output_has_dsc_module_failure?(what_if_exception_output) Chef::Log::warn("Received error while testing configuration due to a module for an imported resource possibly not being fully installed:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") else - raise Chef::Exceptions::PowershellCmdletException, "Powershell Cmdlet failed: #{what_if_exception_output.gsub(/\s+/, ' ')}" + Chef::Log::warn("Received error while testing configuration:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") end end diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index d2138289f5..d16bd8c12f 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -48,6 +48,8 @@ class Chef public WIN_VERSIONS = { + "Windows 10" => {:major => 6, :minor => 4, :callable => lambda{ |product_type, suite_mask| product_type == VER_NT_WORKSTATION }}, + "Windows Server 10" => {:major => 6, :minor => 4, :callable => lambda {|product_type, suite_mask| product_type != VER_NT_WORKSTATION }}, "Windows 8.1" => {:major => 6, :minor => 3, :callable => lambda{ |product_type, suite_mask| product_type == VER_NT_WORKSTATION }}, "Windows Server 2012 R2" => {:major => 6, :minor => 3, :callable => lambda {|product_type, suite_mask| product_type != VER_NT_WORKSTATION }}, "Windows 8" => {:major => 6, :minor => 2, :callable => lambda{ |product_type, suite_mask| product_type == VER_NT_WORKSTATION }}, diff --git a/spec/functional/resource/dsc_script_spec.rb b/spec/functional/resource/dsc_script_spec.rb index fa13296c02..a736949c6b 100644 --- a/spec/functional/resource/dsc_script_spec.rb +++ b/spec/functional/resource/dsc_script_spec.rb @@ -81,17 +81,28 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do let(:test_registry_value) { 'Registration' } let(:test_registry_data1) { 'LL927' } let(:test_registry_data2) { 'LL928' } - let(:dsc_code) { <<-EOH + let(:reg_key_name_param_name) { 'testregkeyname' } + let(:reg_key_value_param_name) { 'testregvaluename' } + let(:registry_embedded_parameters) { "$#{reg_key_name_param_name} = '#{test_registry_key}';$#{reg_key_value_param_name} = '#{test_registry_value}'"} + let(:dsc_reg_code) { <<-EOH + #{registry_embedded_parameters} Registry "ChefRegKey" { - Key = '#{test_registry_key}' - ValueName = '#{test_registry_value}' + Key = $#{reg_key_name_param_name} + ValueName = $#{reg_key_value_param_name} ValueData = '#{test_registry_data}' Ensure = 'Present' } EOH } + let(:dsc_code) { dsc_reg_code } + let(:dsc_reg_script) { <<-EOH + param($testregkeyname, $testregvaluename) + #{dsc_reg_code} +EOH + } + let(:dsc_user_prefix) { 'dsc' } let(:dsc_user_suffix) { 'chefx' } let(:dsc_user) {"#{dsc_user_prefix}_usr_#{dsc_user_suffix}" } @@ -175,7 +186,7 @@ environment "whatsmydir" Ensure = 'Present' } EOH - } +} let(:dsc_config_name) { dsc_test_resource_base.name @@ -227,41 +238,79 @@ environment 'removethis' EOH removal_resource.run_action(:run) end - let(:dsc_code) { dsc_environment_config } - it 'should not raise an exception if the cwd is not etc' do - dsc_test_resource.cwd(dsc_environment_no_fail_not_etc_directory) - expect {dsc_test_resource.run_action(:run)}.not_to raise_error - end - it 'should raise an exception if the cwd is etc' do - dsc_test_resource.cwd(dsc_environment_fail_etc_directory) - expect {dsc_test_resource.run_action(:run)}.to raise_error(Chef::Exceptions::PowershellCmdletException) - begin - dsc_test_resource.run_action(:run) - rescue Chef::Exceptions::PowershellCmdletException => e - expect(e.message).to match(exception_message_signature) + describe 'when the DSC configuration contains code that raises an exception if cwd has a specific value' do + let(:dsc_code) { dsc_environment_config } + it 'should not raise an exception if the cwd is not etc' do + dsc_test_resource.cwd(dsc_environment_no_fail_not_etc_directory) + expect {dsc_test_resource.run_action(:run)}.not_to raise_error + end + + it 'should raise an exception if the cwd is etc' do + dsc_test_resource.cwd(dsc_environment_fail_etc_directory) + expect {dsc_test_resource.run_action(:run)}.to raise_error(Chef::Exceptions::PowershellCmdletException) + begin + dsc_test_resource.run_action(:run) + rescue Chef::Exceptions::PowershellCmdletException => e + expect(e.message).to match(exception_message_signature) + end end end end shared_examples_for 'a parameterized DSC configuration script' do - context 'when specifying environment variables in the environment attribute' do - let(:dsc_user_prefix_code) { dsc_user_prefix_env_code } - let(:dsc_user_suffix_code) { dsc_user_suffix_env_code } - it_behaves_like 'a dsc_script with configuration that uses environment variables' + let(:dsc_user_prefix_code) { dsc_user_prefix_env_code } + let(:dsc_user_suffix_code) { dsc_user_suffix_env_code } + it_behaves_like 'a dsc_script with configuration that uses environment variables' + end + + shared_examples_for 'a dsc_script without configuration data that takes parameters' do + context 'when configuration data is not specified' do + + before(:each) do + test_key_resource = Chef::Resource::RegistryKey.new(test_registry_key, dsc_test_run_context) + test_key_resource.recursive(true) + test_key_resource.run_action(:delete_key) + end + + after(:each) do + test_key_resource = Chef::Resource::RegistryKey.new(test_registry_key, dsc_test_run_context) + test_key_resource.recursive(true) + test_key_resource.run_action(:delete_key) + end + + let(:test_registry_data) { test_registry_data1 } + let(:dsc_parameterized_env_param_value) { "val" + Random::rand.to_s } + + it 'should have a default value of nil for the configuration_data attribute' do + expect(dsc_test_resource.configuration_data).to eql(nil) + end + + it 'should have a default value of nil for the configuration_data_path attribute' do + expect(dsc_test_resource.configuration_data_script).to eql(nil) + end + + let(:dsc_test_resource) { dsc_resource_from_path } + let(:registry_embedded_parameters) { '' } + let(:dsc_code) { dsc_reg_script } + + it 'should set a registry key according to parameters passed to the configuration' do + dsc_test_resource.configuration_name(config_name_value) + dsc_test_resource.flags({:"#{reg_key_name_param_name}" => test_registry_key, :"#{reg_key_value_param_name}" => test_registry_value}) + expect(dsc_test_resource.registry_key_exists?(test_registry_key)).to eq(false) + dsc_test_resource.run_action(:run) + expect(dsc_test_resource.registry_key_exists?(test_registry_key)).to eq(true) + expect(dsc_test_resource.registry_value_exists?(test_registry_key, {:name => test_registry_value, :type => :string, :data => test_registry_data})).to eq(true) + end end end shared_examples_for 'a dsc_script with configuration data' do - context 'when using the configuration_data attribute' do - let(:configuration_data_attribute) { 'configuration_data' } - it_behaves_like 'a dsc_script with configuration data set via an attribute' - end + let(:configuration_data_attribute) { 'configuration_data' } + it_behaves_like 'a dsc_script with configuration data set via an attribute' - context 'when using the configuration_data_script attribute' do - let(:configuration_data_attribute) { 'configuration_data_script' } - it_behaves_like 'a dsc_script with configuration data set via an attribute' - end + let(:configuration_data_attribute) { 'configuration_data_script' } + it_behaves_like 'a dsc_script with configuration data set via an attribute' end shared_examples_for 'a dsc_script with configuration data set via an attribute' do @@ -282,33 +331,28 @@ EOH end shared_examples_for 'a dsc_script with configuration data that takes parameters' do - context 'when script code takes parameters for configuration' do - let(:dsc_user_code) { dsc_user_param_code } - let(:config_param_section) { config_params } - let(:config_flags) {{:"#{dsc_user_prefix_param_name}" => "#{dsc_user_prefix}", :"#{dsc_user_suffix_param_name}" => "#{dsc_user_suffix}"}} - it 'does not directly contain the user name' do - configuration_script_content = ::File.open(dsc_test_resource.command) do | file | - file.read - end - expect(configuration_script_content.include?(dsc_user)).to be(false) + let(:dsc_user_code) { dsc_user_param_code } + let(:config_param_section) { config_params } + let(:config_flags) {{:"#{dsc_user_prefix_param_name}" => "#{dsc_user_prefix}", :"#{dsc_user_suffix_param_name}" => "#{dsc_user_suffix}"}} + it 'does not directly contain the user name' do + configuration_script_content = ::File.open(dsc_test_resource.command) do | file | + file.read end - it_behaves_like 'a dsc_script with configuration data' + expect(configuration_script_content.include?(dsc_user)).to be(false) end - + it_behaves_like 'a dsc_script with configuration data' end shared_examples_for 'a dsc_script with configuration data that uses environment variables' do - context 'when script code uses environment variables' do - let(:dsc_user_code) { dsc_user_env_code } + let(:dsc_user_code) { dsc_user_env_code } - it 'does not directly contain the user name' do - configuration_script_content = ::File.open(dsc_test_resource.command) do | file | - file.read - end - expect(configuration_script_content.include?(dsc_user)).to be(false) + it 'does not directly contain the user name' do + configuration_script_content = ::File.open(dsc_test_resource.command) do | file | + file.read end - it_behaves_like 'a dsc_script with configuration data' + expect(configuration_script_content.include?(dsc_user)).to be(false) end + it_behaves_like 'a dsc_script with configuration data' end context 'when supplying configuration through the configuration attribute' do @@ -333,5 +377,6 @@ EOH it_behaves_like 'a dsc_script with configuration data' it_behaves_like 'a dsc_script with configuration data that uses environment variables' it_behaves_like 'a dsc_script with configuration data that takes parameters' + it_behaves_like 'a dsc_script without configuration data that takes parameters' end end diff --git a/spec/functional/resource/file_spec.rb b/spec/functional/resource/file_spec.rb index 99966f85c8..83f051ea06 100644 --- a/spec/functional/resource/file_spec.rb +++ b/spec/functional/resource/file_spec.rb @@ -17,6 +17,7 @@ # require 'spec_helper' +require 'tmpdir' describe Chef::Resource::File do include_context Chef::Resource::File @@ -30,6 +31,7 @@ describe Chef::Resource::File do run_context = Chef::RunContext.new(node, {}, events) use_path = if opts[:use_relative_path] + Dir.chdir(Dir.tmpdir) File.basename(path) else path diff --git a/spec/unit/provider/package/homebrew_spec.rb b/spec/unit/provider/package/homebrew_spec.rb index d38458546d..dccd8edf11 100644 --- a/spec/unit/provider/package/homebrew_spec.rb +++ b/spec/unit/provider/package/homebrew_spec.rb @@ -158,6 +158,15 @@ describe Chef::Provider::Package::Homebrew do allow(provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => 'homestarrunner')) expect(provider.brew('info', 'opts', 'bananas')).to eql('homestarrunner') end + + context "when new_resource is Package" do + let(:new_resource) { Chef::Resource::Package.new('emacs') } + + it "does not try to read homebrew_user from Package, which does not have it" do + allow(provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => 'zombo')) + expect(provider.brew).to eql('zombo') + end + end end context 'when testing actions' do diff --git a/spec/unit/util/dsc/local_configuration_manager_spec.rb b/spec/unit/util/dsc/local_configuration_manager_spec.rb index fb6664bd40..c9a63bf816 100644 --- a/spec/unit/util/dsc/local_configuration_manager_spec.rb +++ b/spec/unit/util/dsc/local_configuration_manager_spec.rb @@ -105,15 +105,15 @@ EOH end end - context 'that fails due to an PowerShell cmdlet error that cannot be handled' do + context 'that fails due to an unknown PowerShell cmdlet error' do let(:lcm_standard_output) { 'some output' } let(:lcm_standard_error) { 'Abort, Retry, Fail?' } let(:lcm_cmdlet_success) { false } - it 'should raise a Chef::Exceptions::PowershellCmdletException' do - expect(Chef::Log).not_to receive(:warn) + it 'should log a warning' do + expect(Chef::Log).to receive(:warn) expect(lcm).to receive(:output_has_dsc_module_failure?).and_call_original - expect {lcm.test_configuration('config')}.to raise_error(Chef::Exceptions::PowershellCmdletException) + expect {lcm.test_configuration('config')}.not_to raise_error end end end |