diff options
author | Lamont Granquist <454857+lamont-granquist@users.noreply.github.com> | 2021-07-12 10:46:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-12 10:46:44 -0700 |
commit | 2df656665eb21c8ad2223e959e88598a8f272098 (patch) | |
tree | 7ad1c18d070183f9468089bcedcf0a76a2080b19 | |
parent | 4ffb10fe8fea7ece9efa08522961b5088f651368 (diff) | |
parent | 9925c5e53a87a52cc202a623e559fcfdf280fa5f (diff) | |
download | chef-2df656665eb21c8ad2223e959e88598a8f272098.tar.gz |
Merge pull request #11592 from skylerto/skylerto/knife-bootstrap-paths
5 files changed, 28 insertions, 16 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 633378d6ba..11c510f297 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -392,9 +392,21 @@ module ChefConfig # Where chef's cache files should be stored default(:file_cache_path) { PathHelper.join(cache_path, "cache") }.writes_value { |path| expand_relative_paths(path) } + # Where chef's cache files should be stored, used for bootstrap on unix filesystems + default(:unix_bootstrap_file_cache_path) { PathHelper.join("/var", ChefUtils::Dist::Infra::DIR_SUFFIX, "cache", windows: false) } + + # Where chef's cache files should be stored, used for bootstrap on windows filesystems + default(:windows_bootstrap_file_cache_path) { PathHelper.join("C:", ChefUtils::Dist::Infra::DIR_SUFFIX, "cache", windows: true) } + # Where backups of chef-managed files should go default(:file_backup_path) { PathHelper.join(cache_path, "backup") } + # Where chef's backup files should be stored, used for bootstrap on unix filesystems + default(:unix_bootstrap_file_backup_path) { PathHelper.join("/var", ChefUtils::Dist::Infra::DIR_SUFFIX, "backup", windows: false) } + + # Where chef's backup files should be stored, used for bootstrap on windows filesystems + default(:windows_bootstrap_file_backup_path) { PathHelper.join("C:", ChefUtils::Dist::Infra::DIR_SUFFIX, "backup", windows: true) } + # The chef-client (or solo) lockfile. # # If your `file_cache_path` resides on a NFS (or non-flock()-supporting diff --git a/knife/lib/chef/knife/core/bootstrap_context.rb b/knife/lib/chef/knife/core/bootstrap_context.rb index 0d71aa8dc3..d012f27dac 100644 --- a/knife/lib/chef/knife/core/bootstrap_context.rb +++ b/knife/lib/chef/knife/core/bootstrap_context.rb @@ -171,12 +171,12 @@ class Chef client_rb << "fips true\n" end - unless chef_config[:file_cache_path].nil? - client_rb << "file_cache_path \"#{chef_config[:file_cache_path]}\"\n" + unless chef_config[:unix_bootstrap_file_cache_path].nil? + client_rb << "file_cache_path \"#{chef_config[:unix_bootstrap_file_cache_path]}\"\n" end - unless chef_config[:file_backup_path].nil? - client_rb << "file_backup_path \"#{chef_config[:file_backup_path]}\"\n" + unless chef_config[:unix_bootstrap_file_backup_path].nil? + client_rb << "file_backup_path \"#{chef_config[:unix_bootstrap_file_backup_path]}\"\n" end client_rb diff --git a/knife/lib/chef/knife/core/windows_bootstrap_context.rb b/knife/lib/chef/knife/core/windows_bootstrap_context.rb index 2904a231a5..8116c50226 100644 --- a/knife/lib/chef/knife/core/windows_bootstrap_context.rb +++ b/knife/lib/chef/knife/core/windows_bootstrap_context.rb @@ -71,8 +71,8 @@ class Chef client_rb = <<~CONFIG chef_server_url "#{chef_config[:chef_server_url]}" validation_client_name "#{chef_config[:validation_client_name]}" - file_cache_path "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.var_chef_dir(windows: true))}\\\\cache" - file_backup_path "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.var_chef_dir(windows: true))}\\\\backup" + file_cache_path "#{ChefConfig::PathHelper.escapepath(chef_config[:windows_bootstrap_file_cache_path] || "")}" + file_backup_path "#{ChefConfig::PathHelper.escapepath(chef_config[:windows_bootstrap_file_backup_path] || "")}" cache_options ({:path => "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.etc_chef_dir(windows: true))}\\\\cache\\\\checksums", :skip_expires => true}) CONFIG diff --git a/knife/spec/unit/knife/core/bootstrap_context_spec.rb b/knife/spec/unit/knife/core/bootstrap_context_spec.rb index 79fddc8184..97cbc7a259 100644 --- a/knife/spec/unit/knife/core/bootstrap_context_spec.rb +++ b/knife/spec/unit/knife/core/bootstrap_context_spec.rb @@ -80,16 +80,16 @@ describe Chef::Knife::Core::BootstrapContext do end end - describe "when file_cache_path is set" do - let(:chef_config) { { file_cache_path: "/home/opscode/cache" } } - it "sets file_cache_path in the generated config file" do + describe "when unix_bootstrap_file_cache_path is set" do + let(:chef_config) { { unix_bootstrap_file_cache_path: "/home/opscode/cache" } } + it "sets unix_bootstrap_file_cache_path in the generated config file" do expect(bootstrap_context.config_content).to include("file_cache_path \"/home/opscode/cache\"") end end - describe "when file_backup_path is set" do - let(:chef_config) { { file_backup_path: "/home/opscode/backup" } } - it "sets file_backup_path in the generated config file" do + describe "when unix_bootstrap_file_backup_path is set" do + let(:chef_config) { { unix_bootstrap_file_backup_path: "/home/opscode/backup" } } + it "sets unix_bootstrap_file_backup_path in the generated config file" do expect(bootstrap_context.config_content).to include("file_backup_path \"/home/opscode/backup\"") end end diff --git a/knife/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/knife/spec/unit/knife/core/windows_bootstrap_context_spec.rb index af656facf0..ecbb500452 100644 --- a/knife/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/knife/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -154,8 +154,8 @@ describe Chef::Knife::Core::WindowsBootstrapContext do config_log_location: STDOUT, chef_server_url: "http://chef.example.com:4444", validation_client_name: "chef-validator-testing", - file_cache_path: "c:/chef/cache", - file_backup_path: "c:/chef/backup", + windows_bootstrap_file_cache_path: "c:/chef/cache", + windows_bootstrap_file_backup_path: "c:/chef/backup", cache_options: ({ path: "c:/chef/cache/checksums", skip_expires: true }) ) ) @@ -165,8 +165,8 @@ describe Chef::Knife::Core::WindowsBootstrapContext do expected = <<~EXPECTED echo.chef_server_url "http://chef.example.com:4444" echo.validation_client_name "chef-validator-testing" - echo.file_cache_path "C:\\\\chef\\\\cache" - echo.file_backup_path "C:\\\\chef\\\\backup" + echo.file_cache_path "c:/chef/cache" + echo.file_backup_path "c:/chef/backup" echo.cache_options ^({:path =^> "C:\\\\chef\\\\cache\\\\checksums", :skip_expires =^> true}^) echo.# Using default node name ^(fqdn^) echo.log_level :auto |