diff options
author | Tim Smith <tsmith@chef.io> | 2020-05-22 09:49:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 09:49:19 -0700 |
commit | 134b0a4356de729c8455977f47812de969ec802e (patch) | |
tree | 6d284ce7f21ed71d08d1756138430282d3ae841d | |
parent | ded4cae92402ce8b446782c1c14bdcde96d8807e (diff) | |
parent | f707797029b0fc087bd0dd5640dac35c04f27e97 (diff) | |
download | chef-134b0a4356de729c8455977f47812de969ec802e.tar.gz |
Merge pull request #9904 from chef/backports
Multiple backports from Chef 16
-rw-r--r-- | chef-utils/README.md | 4 | ||||
-rw-r--r-- | chef-utils/lib/chef-utils/dsl/architecture.rb | 6 | ||||
-rw-r--r-- | chef-utils/spec/unit/dsl/architecture_spec.rb | 11 | ||||
-rw-r--r-- | lib/chef/formatters/error_inspectors/node_load_error_inspector.rb | 4 | ||||
-rw-r--r-- | lib/chef/formatters/error_inspectors/registration_error_inspector.rb | 14 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb | 4 | ||||
-rw-r--r-- | lib/chef/knife/core/windows_bootstrap_context.rb | 21 | ||||
-rw-r--r-- | lib/chef/resource_inspector.rb | 7 | ||||
-rw-r--r-- | spec/unit/knife/core/windows_bootstrap_context_spec.rb | 6 |
9 files changed, 56 insertions, 21 deletions
diff --git a/chef-utils/README.md b/chef-utils/README.md index b93cfe5214..c4a926e016 100644 --- a/chef-utils/README.md +++ b/chef-utils/README.md @@ -10,7 +10,7 @@ ## Getting Started -Chef Utils gem is common code and mixins for the core Chef Infra Ruby gems. This should be are "core library" or "foundations" library +Chef Utils gem contains common code and mixins for the core Chef Infra Ruby gems. This is intended to be a "core" or "foundations" library for the chef ecosystem (and external related gems) which allows the use of core code and utility functions of the chef gem without requiring all the heaviness of the chef gem. @@ -21,7 +21,7 @@ The Platform Family helpers provide an alternative to comparing values from `nod * `aix?` * `amazon?` * `arch?` - includes arch, manjaro, and antergos platforms -* `debian?` - includes debian, ubuntu, linuxmint, raspbian, and duvian platforms +* `debian?` - includes debian, ubuntu, linuxmint, raspbian, and devuan platforms * `dragonflybsd?` * `fedora?` - includes arista_eos, fedora, and pidora platforms * `freebsd?` diff --git a/chef-utils/lib/chef-utils/dsl/architecture.rb b/chef-utils/lib/chef-utils/dsl/architecture.rb index e78e80f416..1d1cd643b7 100644 --- a/chef-utils/lib/chef-utils/dsl/architecture.rb +++ b/chef-utils/lib/chef-utils/dsl/architecture.rb @@ -110,17 +110,17 @@ module ChefUtils # @return [Boolean] # def arm?(node = __getnode) - %w{armhf aarch64 arm64 arch64}.include?(node["kernel"]["machine"]) + %w{armv6l armv7l armhf aarch64 arm64 arch64}.include?(node["kernel"]["machine"]) end - # Determine if the current architecture is 32-bit ARM. + # Determine if the current architecture is 32-bit ARM hard float. # # @since 15.5 # # @return [Boolean] # def armhf?(node = __getnode) - %w{armhf}.include?(node["kernel"]["machine"]) + %w{armv6l armv7l armhf}.include?(node["kernel"]["machine"]) end # Determine if the current architecture is s390x. diff --git a/chef-utils/spec/unit/dsl/architecture_spec.rb b/chef-utils/spec/unit/dsl/architecture_spec.rb index 18045935a1..30eab27bfb 100644 --- a/chef-utils/spec/unit/dsl/architecture_spec.rb +++ b/chef-utils/spec/unit/dsl/architecture_spec.rb @@ -131,6 +131,17 @@ RSpec.describe ChefUtils::DSL::Architecture do arch_reports_true_for(:armhf?, :_32_bit?, :arm?) end + context "on armv6l" do + let(:arch) { "armv6l" } + + arch_reports_true_for(:armhf?, :_32_bit?, :arm?) + end + context "on armv7l" do + let(:arch) { "armv7l" } + + arch_reports_true_for(:armhf?, :_32_bit?, :arm?) + end + context "on s390" do let(:arch) { "s390" } diff --git a/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb b/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb index 58e6acbea9..3a3f602203 100644 --- a/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb @@ -46,7 +46,7 @@ class Chef when Chef::Exceptions::PrivateKeyMissing error_description.section("Private Key Not Found:", <<~E) Your private key could not be loaded. If the key file exists, ensure that it is - readable by #{Chef::Dist::CLIENT}. + readable by #{Chef::Dist::PRODUCT}. E error_description.section("Relevant Config Settings:", <<~E) client_key "#{api_key}" @@ -99,7 +99,7 @@ class Chef # redirect. def describe_404_error(error_description) error_description.section("Resource Not Found:", <<~E) - The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect. + The #{Chef::Dist::SERVER_PRODUCT} returned a HTTP 404. This usually indicates that your chef_server_url is incorrect. E error_description.section("Relevant Config Settings:", <<~E) chef_server_url "#{server_url}" diff --git a/lib/chef/formatters/error_inspectors/registration_error_inspector.rb b/lib/chef/formatters/error_inspectors/registration_error_inspector.rb index 388e6af20d..565ea217b8 100644 --- a/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/registration_error_inspector.rb @@ -28,7 +28,7 @@ class Chef humanize_http_exception(error_description) when Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError error_description.section("Network Error:", <<~E) - There was a network error connecting to the Chef Server: + There was a network error connecting to the #{Chef::Dist::SERVER_PRODUCT}: #{exception.message} E error_description.section("Relevant Config Settings:", <<~E) @@ -39,14 +39,14 @@ class Chef when Chef::Exceptions::PrivateKeyMissing error_description.section("Private Key Not Found:", <<~E) Your private key could not be loaded. If the key file exists, ensure that it is - readable by #{Chef::Dist::CLIENT}. + readable by #{Chef::Dist::PRODUCT}. E error_description.section("Relevant Config Settings:", <<~E) validation_key "#{api_key}" E when Chef::Exceptions::InvalidRedirect error_description.section("Invalid Redirect:", <<~E) - Change your server location in client.rb to the server's FQDN to avoid unwanted redirections. + Change your #{Chef::Dist::SERVER_PRODUCT} location in client.rb to the #{Chef::Dist::SERVER_PRODUCT}'s FQDN to avoid unwanted redirections. E when EOFError describe_eof_error(error_description) @@ -61,13 +61,13 @@ class Chef when Net::HTTPUnauthorized if clock_skew? error_description.section("Authentication Error:", <<~E) - Failed to authenticate to the chef server (http 401). + Failed to authenticate to the #{Chef::Dist::SERVER_PRODUCT} (http 401). The request failed because your clock has drifted by more than 15 minutes. Syncing your clock to an NTP Time source should resolve the issue. E else error_description.section("Authentication Error:", <<~E) - Failed to authenticate to the chef server (http 401). + Failed to authenticate to the #{Chef::Dist::SERVER_PRODUCT} (http 401). E error_description.section("Server Response:", format_rest_error) @@ -81,7 +81,7 @@ class Chef end when Net::HTTPForbidden error_description.section("Authorization Error:", <<~E) - Your validation client is not authorized to create the client for this node (HTTP 403). + Your validation client is not authorized to create the client for this node on the #{Chef::Dist::SERVER_PRODUCT} (HTTP 403). E error_description.section("Possible Causes:", <<~E) * There may already be a client named "#{config[:node_name]}" @@ -94,7 +94,7 @@ class Chef error_description.section("Server Response:", format_rest_error) when Net::HTTPNotFound error_description.section("Resource Not Found:", <<~E) - The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect. + The #{Chef::Dist::SERVER_PRODUCT} returned a HTTP 404. This usually indicates that your chef_server_url configuration is incorrect. E error_description.section("Relevant Config Settings:", <<~E) chef_server_url "#{server_url}" diff --git a/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb b/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb index 3fe397ed9e..4c8c51ee6c 100644 --- a/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +++ b/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb @@ -202,10 +202,12 @@ If !ERRORLEVEL!==0 ( ) else ( @echo Installation completed successfully del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%" - ) + ) <% end %> +@rem This line is required to separate the key_create label from the "block boundary" +@rem Removing these lines will cause the error "The system cannot find the batch label specified - key_create" :key_create @endlocal diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb index fda29a08a6..3cd4dcece0 100644 --- a/lib/chef/knife/core/windows_bootstrap_context.rb +++ b/lib/chef/knife/core/windows_bootstrap_context.rb @@ -39,6 +39,21 @@ class Chef super(config, run_list, chef_config, secret) end + # This is a duplicate of ChefConfig::PathHelper.cleanpath, however + # this presumes Windows so we can avoid changing the method definitions + # across Chef, ChefConfig, and ChefUtils for the circumstance where + # the methods are being run for a system other than the one Ruby is + # executing on. + # + # We only need to cleanpath the paths that we are passing to cmd.exe, + # anything written to a configuration file or passed as an argument + # will be interpreted by ruby later and do the right thing. + def cleanpath(path) + path = Pathname.new(path).cleanpath.to_s + path = path.gsub(File::SEPARATOR, '\\') + path + end + def validation_key if File.exist?(File.expand_path(@chef_config[:validation_key])) IO.read(File.expand_path(@chef_config[:validation_key])) @@ -158,8 +173,8 @@ class Chef def start_chef bootstrap_environment_option = bootstrap_environment.nil? ? "" : " -E #{bootstrap_environment}" - start_chef = "SET \"PATH=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;#{ChefConfig::Config.c_opscode_dir}\\#{ChefConfig::Dist::DIR_SUFFIX}\\bin;#{ChefConfig::Config.c_opscode_dir}\\#{ChefConfig::Dist::DIR_SUFFIX}\\embedded\\bin\;%PATH%\"\n" - start_chef << "chef-client -c #{ChefConfig::Config.etc_chef_dir(true)}/client.rb -j #{ChefConfig::Config.etc_chef_dir(true)}/first-boot.json#{bootstrap_environment_option}\n" + start_chef = "SET \"PATH=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;#{ChefConfig::Config.c_opscode_dir}\\bin;#{ChefConfig::Config.c_opscode_dir}\\embedded\\bin\;%PATH%\"\n" + start_chef << "#{Chef::Dist::CLIENT} -c #{ChefConfig::Config.etc_chef_dir(true)}/client.rb -j #{ChefConfig::Config.etc_chef_dir(true)}/first-boot.json#{bootstrap_environment_option}\n" end def win_wget @@ -260,7 +275,7 @@ class Chef end def bootstrap_directory - ChefConfig::Config.etc_chef_dir(true) + cleanpath(ChefConfig::Config.etc_chef_dir(true)) end def local_download_path diff --git a/lib/chef/resource_inspector.rb b/lib/chef/resource_inspector.rb index 7006bb5bd6..edc6c66510 100644 --- a/lib/chef/resource_inspector.rb +++ b/lib/chef/resource_inspector.rb @@ -68,8 +68,8 @@ module ResourceInspector dir, name = File.split(path) Chef::Cookbook::FileVendor.fetch_from_disk(path) loader = Chef::CookbookLoader.new(dir) - cookbooks = loader.load_cookbooks - resources = cookbooks[name].files_for(:resources) + cookbook = loader.load_cookbook(name) + resources = cookbook.files_for(:resources) resources.each_with_object({}) do |r, res| pth = r["full_path"] @@ -82,13 +82,14 @@ module ResourceInspector # otherwise, if we have a path then extract all the resources from the cookbook # or else do a list of built in resources # + # @param arguments [Array, String] One of more paths to a cookbook or a resource file to inspect # @param complete [TrueClass, FalseClass] Whether to show properties defined in the base Resource class # @return [String] JSON formatting of all resources def self.inspect(arguments = [], complete: false) output = if arguments.empty? ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.each_with_object({}) { |klass, acc| acc[klass.resource_name] = extract_resource(klass) } else - arguments.each_with_object({}) do |arg, acc| + Array(arguments).each_with_object({}) do |arg, acc| if File.directory?(arg) extract_cookbook(arg, complete).each { |k, v| acc[k] = v } else diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb index 14ca563a58..96ac00e1ad 100644 --- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -184,6 +184,12 @@ describe Chef::Knife::Core::WindowsBootstrapContext do end end + describe "#start_chef" do + it "returns the expected string" do + expect(bootstrap_context.start_chef).to match(%r{SET \"PATH=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;C:\/opscode\/chef\\bin;C:\/opscode\/chef\\embedded\\bin\;%PATH%\"\n}) + end + end + describe "msi_url" do context "when msi_url config option is not set" do let(:config) { { channel: "stable" } } |