chef 17.0.242-universal-mingw32 → 17.4.25-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -14
- data/Rakefile +2 -2
- data/chef.gemspec +10 -20
- data/lib/chef/action_collection.rb +6 -26
- data/lib/chef/application/base.rb +15 -0
- data/lib/chef/application.rb +4 -2
- data/lib/chef/chef_fs/file_pattern.rb +2 -2
- data/lib/chef/client.rb +7 -1
- data/lib/chef/compliance/default_attributes.rb +5 -3
- data/lib/chef/compliance/reporter/automate.rb +1 -1
- data/lib/chef/compliance/runner.rb +17 -3
- data/lib/chef/cookbook/cookbook_version_loader.rb +3 -3
- data/lib/chef/cookbook/gem_installer.rb +5 -1
- data/lib/chef/cookbook_version.rb +26 -4
- data/lib/chef/data_collector/run_end_message.rb +1 -1
- data/lib/chef/data_collector.rb +0 -1
- data/lib/chef/deprecated.rb +14 -4
- data/lib/chef/dsl/declare_resource.rb +5 -10
- data/lib/chef/dsl/render_helpers.rb +44 -0
- data/lib/chef/dsl/secret.rb +64 -0
- data/lib/chef/dsl/toml.rb +116 -0
- data/lib/chef/dsl/universal.rb +5 -0
- data/lib/chef/dsl.rb +1 -0
- data/lib/chef/event_dispatch/base.rb +2 -1
- data/lib/chef/exceptions.rb +23 -0
- data/lib/chef/formatters/doc.rb +2 -1
- data/lib/chef/formatters/error_mapper.rb +2 -2
- data/lib/chef/handler/slow_report.rb +66 -0
- data/lib/chef/handler.rb +46 -8
- data/lib/chef/json_compat.rb +1 -1
- data/lib/chef/node.rb +21 -20
- data/lib/chef/policy_builder/policyfile.rb +88 -45
- data/lib/chef/provider/directory.rb +6 -6
- data/lib/chef/provider/execute.rb +1 -1
- data/lib/chef/provider/file.rb +2 -2
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/launchd.rb +6 -6
- data/lib/chef/provider/link.rb +1 -1
- data/lib/chef/provider/lwrp_base.rb +1 -1
- data/lib/chef/provider/package/dnf/dnf_helper.py +11 -10
- data/lib/chef/provider/package/dnf/python_helper.rb +9 -8
- data/lib/chef/provider/package/habitat.rb +168 -0
- data/lib/chef/provider/package/powershell.rb +5 -0
- data/lib/chef/provider/package/yum/python_helper.rb +15 -10
- data/lib/chef/provider/package/yum/yum_helper.py +46 -62
- data/lib/chef/provider/package/yum.rb +1 -4
- data/lib/chef/provider/registry_key.rb +1 -1
- data/lib/chef/provider/service/systemd.rb +1 -1
- data/lib/chef/provider/subversion.rb +4 -4
- data/lib/chef/provider/support/yum_repo.erb +1 -1
- data/lib/chef/provider/support/zypper_repo.erb +4 -2
- data/lib/chef/provider/systemd_unit.rb +18 -17
- data/lib/chef/provider/template/content.rb +1 -1
- data/lib/chef/provider/user/mac.rb +3 -3
- data/lib/chef/provider/windows_script.rb +1 -1
- data/lib/chef/provider/yum_repository.rb +27 -43
- data/lib/chef/provider/zypper_repository.rb +30 -34
- data/lib/chef/provider.rb +26 -1
- data/lib/chef/provider_resolver.rb +8 -2
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource/alternatives.rb +5 -5
- data/lib/chef/resource/apt_preference.rb +2 -2
- data/lib/chef/resource/apt_repository.rb +2 -2
- data/lib/chef/resource/apt_update.rb +4 -4
- data/lib/chef/resource/build_essential.rb +1 -1
- data/lib/chef/resource/chef_client_config.rb +10 -5
- data/lib/chef/resource/chef_client_cron.rb +3 -3
- data/lib/chef/resource/chef_client_launchd.rb +3 -3
- data/lib/chef/resource/chef_client_scheduled_task.rb +15 -15
- data/lib/chef/resource/chef_client_systemd_timer.rb +3 -3
- data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
- data/lib/chef/resource/chef_handler.rb +2 -2
- data/lib/chef/resource/chef_sleep.rb +1 -1
- data/lib/chef/resource/chef_vault_secret.rb +2 -2
- data/lib/chef/resource/chocolatey_feature.rb +2 -2
- data/lib/chef/resource/chocolatey_source.rb +1 -1
- data/lib/chef/resource/cron/cron_d.rb +4 -6
- data/lib/chef/resource/cron_access.rb +1 -1
- data/lib/chef/resource/dmg_package.rb +1 -1
- data/lib/chef/resource/dsc_resource.rb +1 -1
- data/lib/chef/resource/execute.rb +5 -5
- data/lib/chef/resource/gem_package.rb +2 -1
- data/lib/chef/resource/group.rb +4 -4
- data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
- data/lib/chef/resource/habitat/habitat_package.rb +129 -0
- data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
- data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
- data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
- data/lib/chef/resource/habitat_config.rb +107 -0
- data/lib/chef/resource/habitat_install.rb +247 -0
- data/lib/chef/resource/habitat_service.rb +451 -0
- data/lib/chef/resource/habitat_user_toml.rb +92 -0
- data/lib/chef/resource/homebrew_cask.rb +18 -7
- data/lib/chef/resource/homebrew_package.rb +1 -1
- data/lib/chef/resource/homebrew_tap.rb +4 -3
- data/lib/chef/resource/homebrew_update.rb +2 -2
- data/lib/chef/resource/hostname.rb +49 -7
- data/lib/chef/resource/inspec_waiver_file_entry.rb +156 -0
- data/lib/chef/resource/kernel_module.rb +6 -6
- data/lib/chef/resource/launchd.rb +3 -3
- data/lib/chef/resource/locale.rb +1 -1
- data/lib/chef/resource/lwrp_base.rb +18 -3
- data/lib/chef/resource/macos_userdefaults.rb +2 -2
- data/lib/chef/resource/ohai_hint.rb +2 -6
- data/lib/chef/resource/openbsd_package.rb +17 -0
- data/lib/chef/resource/openssl_dhparam.rb +1 -2
- data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
- data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
- data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
- data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
- data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
- data/lib/chef/resource/openssl_x509_crl.rb +1 -3
- data/lib/chef/resource/openssl_x509_request.rb +1 -3
- data/lib/chef/resource/osx_profile.rb +3 -3
- data/lib/chef/resource/plist.rb +1 -1
- data/lib/chef/resource/powershell_package_source.rb +2 -4
- data/lib/chef/resource/reboot.rb +38 -9
- data/lib/chef/resource/remote_directory.rb +2 -2
- data/lib/chef/resource/remote_file.rb +3 -3
- data/lib/chef/resource/rhsm_errata.rb +0 -2
- data/lib/chef/resource/rhsm_errata_level.rb +1 -5
- data/lib/chef/resource/rhsm_repo.rb +15 -0
- data/lib/chef/resource/rhsm_subscription.rb +5 -5
- data/lib/chef/resource/ruby_block.rb +100 -0
- data/lib/chef/resource/scm/subversion.rb +1 -1
- data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
- data/lib/chef/resource/sudo.rb +2 -6
- data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
- data/lib/chef/resource/support/client.erb +8 -1
- data/lib/chef/resource/support/sup.toml.erb +179 -0
- data/lib/chef/resource/swap_file.rb +2 -6
- data/lib/chef/resource/sysctl.rb +2 -2
- data/lib/chef/resource/systemd_unit.rb +3 -3
- data/lib/chef/resource/timezone.rb +1 -1
- data/lib/chef/resource/user_ulimit.rb +2 -2
- data/lib/chef/resource/windows_ad_join.rb +2 -2
- data/lib/chef/resource/windows_audit_policy.rb +2 -2
- data/lib/chef/resource/windows_auto_run.rb +2 -2
- data/lib/chef/resource/windows_certificate.rb +1 -1
- data/lib/chef/resource/windows_defender.rb +163 -0
- data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
- data/lib/chef/resource/windows_dfs_folder.rb +2 -2
- data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
- data/lib/chef/resource/windows_dns_record.rb +2 -2
- data/lib/chef/resource/windows_dns_zone.rb +2 -2
- data/lib/chef/resource/windows_env.rb +1 -1
- data/lib/chef/resource/windows_feature.rb +3 -3
- data/lib/chef/resource/windows_feature_dism.rb +3 -5
- data/lib/chef/resource/windows_feature_powershell.rb +3 -3
- data/lib/chef/resource/windows_firewall_profile.rb +2 -2
- data/lib/chef/resource/windows_firewall_rule.rb +20 -6
- data/lib/chef/resource/windows_font.rb +2 -2
- data/lib/chef/resource/windows_pagefile.rb +104 -65
- data/lib/chef/resource/windows_path.rb +4 -4
- data/lib/chef/resource/windows_printer.rb +80 -61
- data/lib/chef/resource/windows_printer_port.rb +48 -65
- data/lib/chef/resource/windows_security_policy.rb +7 -4
- data/lib/chef/resource/windows_share.rb +2 -2
- data/lib/chef/resource/windows_shortcut.rb +1 -1
- data/lib/chef/resource/windows_task.rb +2 -2
- data/lib/chef/resource/windows_uac.rb +3 -5
- data/lib/chef/resource/windows_update_settings.rb +259 -0
- data/lib/chef/resource/windows_user_privilege.rb +2 -2
- data/lib/chef/resource/windows_workgroup.rb +2 -2
- data/lib/chef/resource/yum_package.rb +11 -15
- data/lib/chef/resource/zypper_package.rb +4 -4
- data/lib/chef/resource/zypper_repository.rb +28 -8
- data/lib/chef/resource.rb +20 -25
- data/lib/chef/resource_builder.rb +8 -2
- data/lib/chef/resource_inspector.rb +6 -2
- data/lib/chef/resource_reporter.rb +0 -1
- data/lib/chef/resources.rb +13 -1
- data/lib/chef/run_lock.rb +1 -1
- data/lib/chef/runner.rb +1 -1
- data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
- data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
- data/lib/chef/secret_fetcher/base.rb +76 -0
- data/lib/chef/secret_fetcher/example.rb +46 -0
- data/lib/chef/secret_fetcher.rb +55 -0
- data/lib/chef/shell/ext.rb +3 -3
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api.rb +9 -2
- data/spec/data/knife-home/.chef/plugins/knife/example_home_subcommand.rb +0 -0
- data/spec/data/knife-site-subcommands/plugins/knife/example_subcommand.rb +0 -0
- data/spec/data/knife_subcommand/test_explicit_category.rb +7 -0
- data/spec/data/knife_subcommand/test_name_mapping.rb +4 -0
- data/spec/data/knife_subcommand/test_yourself.rb +21 -0
- data/spec/functional/mixin/from_file_spec.rb +1 -1
- data/spec/functional/resource/dnf_package_spec.rb +857 -537
- data/spec/functional/resource/group_spec.rb +1 -1
- data/spec/functional/resource/link_spec.rb +1 -1
- data/spec/functional/resource/remote_file_spec.rb +1 -1
- data/spec/functional/resource/windows_env_spec.rb +2 -2
- data/spec/functional/resource/windows_hostname_spec.rb +91 -0
- data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
- data/spec/functional/resource/yum_package_spec.rb +495 -428
- data/spec/integration/client/client_spec.rb +0 -20
- data/spec/integration/compliance/compliance_spec.rb +1 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/resource_action_spec.rb +6 -6
- data/spec/integration/recipes/unified_mode_spec.rb +70 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/chef_helpers.rb +1 -1
- data/spec/support/shared/functional/execute_resource.rb +1 -1
- data/spec/support/shared/functional/knife.rb +37 -0
- data/spec/support/shared/integration/knife_support.rb +192 -0
- data/spec/support/shared/unit/knife_shared.rb +39 -0
- data/spec/support/shared/unit/provider/file.rb +3 -9
- data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +1 -1
- data/spec/unit/compliance/runner_spec.rb +46 -2
- data/spec/unit/cookbook_version_spec.rb +52 -0
- data/spec/unit/data_collector_spec.rb +47 -1
- data/spec/unit/dsl/render_helpers_spec.rb +102 -0
- data/spec/unit/dsl/secret_spec.rb +71 -0
- data/spec/unit/handler_spec.rb +8 -2
- data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
- data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
- data/spec/unit/provider/apt_update_spec.rb +3 -1
- data/spec/unit/provider/link_spec.rb +1 -1
- data/spec/unit/provider/mount/aix_spec.rb +1 -1
- data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -0
- data/spec/unit/provider/package/powershell_spec.rb +74 -12
- data/spec/unit/provider/package/yum/python_helper_spec.rb +1 -0
- data/spec/unit/provider/service/systemd_service_spec.rb +2 -2
- data/spec/unit/provider/systemd_unit_spec.rb +2 -2
- data/spec/unit/provider/zypper_repository_spec.rb +3 -10
- data/spec/unit/provider_spec.rb +23 -0
- data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
- data/spec/unit/resource/inspec_waiver_file_entry_spec.rb +80 -0
- data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
- data/spec/unit/resource/systemd_unit_spec.rb +1 -1
- data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
- data/spec/unit/resource/windows_defender_spec.rb +71 -0
- data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
- data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
- data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
- data/spec/unit/resource/zypper_repository_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +19 -8
- data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
- data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
- data/spec/unit/secret_fetcher_spec.rb +82 -0
- data/tasks/rspec.rb +4 -9
- metadata +65 -161
- data/lib/chef/provider/package/yum/simplejson/LICENSE.txt +0 -79
- data/lib/chef/provider/package/yum/simplejson/__init__.py +0 -318
- data/lib/chef/provider/package/yum/simplejson/__init__.pyc +0 -0
- data/lib/chef/provider/package/yum/simplejson/decoder.py +0 -354
- data/lib/chef/provider/package/yum/simplejson/decoder.pyc +0 -0
- data/lib/chef/provider/package/yum/simplejson/encoder.py +0 -440
- data/lib/chef/provider/package/yum/simplejson/encoder.pyc +0 -0
- data/lib/chef/provider/package/yum/simplejson/scanner.py +0 -65
- data/lib/chef/provider/package/yum/simplejson/scanner.pyc +0 -0
- data/lib/chef/provider/package/yum/simplejson/tool.py +0 -37
@@ -349,26 +349,6 @@ describe "chef-client" do
|
|
349
349
|
expect(result.stdout).to include("Run List is [recipe[x::default]]")
|
350
350
|
result.error!
|
351
351
|
end
|
352
|
-
|
353
|
-
it "should complete with success when using --profile-ruby and output a profile file", :not_supported_on_aix do
|
354
|
-
file "config/client.rb", <<~EOM
|
355
|
-
local_mode true
|
356
|
-
cookbook_path "#{path_to("cookbooks")}"
|
357
|
-
EOM
|
358
|
-
result = shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" -o 'x::default' -z --profile-ruby", cwd: chef_dir)
|
359
|
-
result.error!
|
360
|
-
expect(File.exist?(path_to("config/local-mode-cache/cache/graph_profile.out"))).to be true
|
361
|
-
end
|
362
|
-
|
363
|
-
it "doesn't produce a profile when --profile-ruby is not present" do
|
364
|
-
file "config/client.rb", <<~EOM
|
365
|
-
local_mode true
|
366
|
-
cookbook_path "#{path_to("cookbooks")}"
|
367
|
-
EOM
|
368
|
-
result = shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" -o 'x::default' -z", cwd: chef_dir)
|
369
|
-
result.error!
|
370
|
-
expect(File.exist?(path_to("config/local-mode-cache/cache/graph_profile.out"))).to be false
|
371
|
-
end
|
372
352
|
end
|
373
353
|
|
374
354
|
when_the_repository "has a cookbook that outputs some node attributes" do
|
@@ -9,7 +9,7 @@ class NoActionJackson < Chef::Resource
|
|
9
9
|
@foo
|
10
10
|
end
|
11
11
|
|
12
|
-
class <<self
|
12
|
+
class << self
|
13
13
|
attr_accessor :action_was
|
14
14
|
end
|
15
15
|
end
|
@@ -17,7 +17,7 @@ end
|
|
17
17
|
class WeirdActionJackson < Chef::Resource
|
18
18
|
provides :weird_action_jackson
|
19
19
|
|
20
|
-
class <<self
|
20
|
+
class << self
|
21
21
|
attr_accessor :action_was
|
22
22
|
end
|
23
23
|
|
@@ -176,7 +176,7 @@ module ResourceActionSpec
|
|
176
176
|
@blarghle
|
177
177
|
end
|
178
178
|
|
179
|
-
class <<self
|
179
|
+
class << self
|
180
180
|
attr_accessor :ran_action
|
181
181
|
attr_accessor :succeeded
|
182
182
|
attr_accessor :ruby_block_converged
|
@@ -284,7 +284,7 @@ module ResourceActionSpec
|
|
284
284
|
@bar = "#{value}alope" if value
|
285
285
|
@bar
|
286
286
|
end
|
287
|
-
class <<self
|
287
|
+
class << self
|
288
288
|
attr_accessor :load_current_resource_ran
|
289
289
|
attr_accessor :jackalope_ran
|
290
290
|
end
|
@@ -354,8 +354,8 @@ module ResourceActionSpec
|
|
354
354
|
end
|
355
355
|
|
356
356
|
it "allows overridden action to have a description separate from the action defined in the base resource" do
|
357
|
-
expect(ActionJackson.action_description(:test1)).to eql "Original description"
|
358
|
-
expect(ActionJackalope.action_description(:test1)).to eql "An old action with a new description"
|
357
|
+
expect(ActionJackson.new("ActionJackson", nil).action_description(:test1)).to eql "Original description"
|
358
|
+
expect(ActionJackalope.new("ActionJackalope", nil).action_description(:test1)).to eql "An old action with a new description"
|
359
359
|
end
|
360
360
|
|
361
361
|
it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do
|
@@ -874,4 +874,74 @@ describe "Unified Mode" do
|
|
874
874
|
result.error!
|
875
875
|
end
|
876
876
|
end
|
877
|
+
|
878
|
+
when_the_repository "has a resource that uses edit_resource to create a subresource" do
|
879
|
+
before do
|
880
|
+
directory "cookbooks/x" do
|
881
|
+
file "recipes/default.rb", <<~EOM
|
882
|
+
my_resource "doit"
|
883
|
+
EOM
|
884
|
+
|
885
|
+
file "resources/my_resource.rb", <<~EOM
|
886
|
+
unified_mode true
|
887
|
+
provides :my_resource
|
888
|
+
|
889
|
+
action :doit do
|
890
|
+
edit_resource(:log, "name") do
|
891
|
+
message "GOOD"
|
892
|
+
level :warn
|
893
|
+
end
|
894
|
+
end
|
895
|
+
EOM
|
896
|
+
end
|
897
|
+
end
|
898
|
+
|
899
|
+
it "recipes should still have a compile/converge mode" do
|
900
|
+
file "config/client.rb", <<~EOM
|
901
|
+
local_mode true
|
902
|
+
cookbook_path "#{path_to("cookbooks")}"
|
903
|
+
log_level :warn
|
904
|
+
EOM
|
905
|
+
|
906
|
+
result = shell_out("#{chef_client} -c \"#{path_to("config/client.rb")}\" --no-color -F doc -o 'x::default'", cwd: chef_dir)
|
907
|
+
# in recipe mode we should still run normally with a compile/converge mode
|
908
|
+
expect(result.stdout).to include("GOOD")
|
909
|
+
result.error!
|
910
|
+
end
|
911
|
+
end
|
912
|
+
|
913
|
+
when_the_repository "has a resource that uses find_resource to create a subresource" do
|
914
|
+
before do
|
915
|
+
directory "cookbooks/x" do
|
916
|
+
file "recipes/default.rb", <<~EOM
|
917
|
+
my_resource "doit"
|
918
|
+
EOM
|
919
|
+
|
920
|
+
file "resources/my_resource.rb", <<~EOM
|
921
|
+
unified_mode true
|
922
|
+
provides :my_resource
|
923
|
+
|
924
|
+
action :doit do
|
925
|
+
find_resource(:log, "name") do
|
926
|
+
message "GOOD"
|
927
|
+
level :warn
|
928
|
+
end
|
929
|
+
end
|
930
|
+
EOM
|
931
|
+
end
|
932
|
+
end
|
933
|
+
|
934
|
+
it "recipes should still have a compile/converge mode" do
|
935
|
+
file "config/client.rb", <<~EOM
|
936
|
+
local_mode true
|
937
|
+
cookbook_path "#{path_to("cookbooks")}"
|
938
|
+
log_level :warn
|
939
|
+
EOM
|
940
|
+
|
941
|
+
result = shell_out("#{chef_client} -c \"#{path_to("config/client.rb")}\" --no-color -F doc -o 'x::default'", cwd: chef_dir)
|
942
|
+
# in recipe mode we should still run normally with a compile/converge mode
|
943
|
+
expect(result.stdout).to include("GOOD")
|
944
|
+
result.error!
|
945
|
+
end
|
946
|
+
end
|
877
947
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -43,7 +43,7 @@ end
|
|
43
43
|
# This is a helper to canonicalize paths that we're using in the file
|
44
44
|
# tests.
|
45
45
|
def canonicalize_path(path)
|
46
|
-
windows? ? path.tr("/",
|
46
|
+
windows? ? path.tr("/", "\\") : path
|
47
47
|
end
|
48
48
|
|
49
49
|
# Makes a temp directory with a canonical path on any platform.
|
@@ -58,7 +58,7 @@ shared_context "a command that can be executed as an alternate user" do
|
|
58
58
|
include Chef::Mixin::ShellOut
|
59
59
|
|
60
60
|
before do
|
61
|
-
shell_out!("icacls \"#{script_output_dir.tr("/",
|
61
|
+
shell_out!("icacls \"#{script_output_dir.tr("/", "\\")}\" /grant \"authenticated users:(F)\"")
|
62
62
|
end
|
63
63
|
|
64
64
|
after do
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Author:: AJ Christensen (<aj@junglist.gen.nz>)
|
4
|
+
# Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
|
5
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
6
|
+
# License:: Apache License, Version 2.0
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
module SpecHelpers
|
21
|
+
module Knife
|
22
|
+
def redefine_argv(value)
|
23
|
+
Object.send(:remove_const, :ARGV)
|
24
|
+
Object.send(:const_set, :ARGV, value)
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_argv(*argv)
|
28
|
+
original_argv = ARGV
|
29
|
+
redefine_argv(argv.flatten)
|
30
|
+
begin
|
31
|
+
yield
|
32
|
+
ensure
|
33
|
+
redefine_argv(original_argv)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
#
|
2
|
+
# Author:: John Keiser (<jkeiser@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require "chef/config"
|
19
|
+
require "chef/knife"
|
20
|
+
require "chef/application/knife"
|
21
|
+
require "logger"
|
22
|
+
require "chef/log"
|
23
|
+
require "chef/chef_fs/file_system_cache"
|
24
|
+
|
25
|
+
module KnifeSupport
|
26
|
+
DEBUG = ENV["DEBUG"]
|
27
|
+
def knife(*args, input: nil, instance_filter: nil)
|
28
|
+
# Allow knife('role from file roles/blah.json') rather than requiring the
|
29
|
+
# arguments to be split like knife('role', 'from', 'file', 'roles/blah.json')
|
30
|
+
# If any argument will have actual spaces in it, the long form is required.
|
31
|
+
# (Since knife commands always start with the command name, and command
|
32
|
+
# names with spaces are always multiple args, this is safe.)
|
33
|
+
if args.length == 1
|
34
|
+
args = args[0].split(/\s+/)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Make output stable
|
38
|
+
Chef::Config[:concurrency] = 1
|
39
|
+
|
40
|
+
# Work on machines where we can't access /var
|
41
|
+
Dir.mktmpdir("checksums") do |checksums_cache_dir|
|
42
|
+
Chef::Config[:syntax_check_cache_path] = checksums_cache_dir
|
43
|
+
|
44
|
+
# This is Chef::Knife.run without load_commands--we'll load stuff
|
45
|
+
# ourselves, thank you very much
|
46
|
+
stdout = StringIO.new
|
47
|
+
stderr = StringIO.new
|
48
|
+
|
49
|
+
stdin = if input
|
50
|
+
StringIO.new(input)
|
51
|
+
else
|
52
|
+
STDIN
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
puts "knife: #{args.join(" ")}" if DEBUG
|
57
|
+
subcommand_class = Chef::Knife.subcommand_class_from(args)
|
58
|
+
subcommand_class.options = Chef::Application::Knife.options.merge(subcommand_class.options)
|
59
|
+
subcommand_class.load_deps
|
60
|
+
instance = subcommand_class.new(args)
|
61
|
+
|
62
|
+
# Load configs
|
63
|
+
instance.merge_configs
|
64
|
+
|
65
|
+
# Capture stdout/stderr
|
66
|
+
instance.ui = Chef::Knife::UI.new(stdout, stderr, stdin, instance.config.merge(disable_editing: true))
|
67
|
+
|
68
|
+
# Don't print stuff
|
69
|
+
Chef::Config[:verbosity] = ( DEBUG ? 2 : 0 )
|
70
|
+
instance.config[:config_file] = File.join(CHEF_SPEC_DATA, "null_config.rb")
|
71
|
+
|
72
|
+
# Ensure the ChefFS cache is empty
|
73
|
+
Chef::ChefFS::FileSystemCache.instance.reset!
|
74
|
+
|
75
|
+
# Configure chef with a (mostly) blank knife.rb
|
76
|
+
# We set a global and then mutate it in our stub knife.rb so we can be
|
77
|
+
# extra sure that we're not loading someone's real knife.rb and then
|
78
|
+
# running test scenarios against a real chef server. If things don't
|
79
|
+
# smell right, abort.
|
80
|
+
|
81
|
+
# To ensure that we don't pick up a user's credentials file we lie through our teeth about
|
82
|
+
# it's existence.
|
83
|
+
allow(File).to receive(:file?).and_call_original
|
84
|
+
allow(File).to receive(:file?).with(File.expand_path("~/.chef/credentials")).and_return(false)
|
85
|
+
|
86
|
+
# Set a canary that is modified by the default null_config.rb config file.
|
87
|
+
$__KNIFE_INTEGRATION_FAILSAFE_CHECK = "ole"
|
88
|
+
|
89
|
+
# Allow tweaking the knife instance before configuration.
|
90
|
+
instance_filter.call(instance) if instance_filter
|
91
|
+
|
92
|
+
instance.configure_chef
|
93
|
+
|
94
|
+
# The canary is incorrect, meaning the normal null_config.rb didn't run. Something is wrong.
|
95
|
+
unless $__KNIFE_INTEGRATION_FAILSAFE_CHECK == "ole ole"
|
96
|
+
raise Exception, "Potential misconfiguration of integration tests detected. Aborting test."
|
97
|
+
end
|
98
|
+
|
99
|
+
logger = Logger.new(stderr)
|
100
|
+
logger.formatter = proc { |severity, datetime, progname, msg| "#{severity}: #{msg}\n" }
|
101
|
+
Chef::Log.use_log_devices([logger])
|
102
|
+
Chef::Log.level = ( DEBUG ? :debug : :warn )
|
103
|
+
Chef::Log::Formatter.show_time = false
|
104
|
+
|
105
|
+
instance.run_with_pretty_exceptions(true)
|
106
|
+
|
107
|
+
exit_code = 0
|
108
|
+
|
109
|
+
# This is how rspec catches exit()
|
110
|
+
rescue SystemExit => e
|
111
|
+
exit_code = e.status
|
112
|
+
ensure
|
113
|
+
Chef::Config.delete(:syntax_check_cache_path)
|
114
|
+
Chef::Config.delete(:concurrency)
|
115
|
+
end
|
116
|
+
|
117
|
+
KnifeResult.new(stdout.string, stderr.string, exit_code)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class KnifeResult
|
122
|
+
|
123
|
+
include ::RSpec::Matchers
|
124
|
+
|
125
|
+
def initialize(stdout, stderr, exit_code)
|
126
|
+
@stdout = stdout
|
127
|
+
@stderr = stderr
|
128
|
+
@exit_code = exit_code
|
129
|
+
end
|
130
|
+
|
131
|
+
attr_reader :stdout
|
132
|
+
attr_reader :stderr
|
133
|
+
attr_reader :exit_code
|
134
|
+
|
135
|
+
def should_fail(*args)
|
136
|
+
expected = {}
|
137
|
+
args.each do |arg|
|
138
|
+
if arg.is_a?(Hash)
|
139
|
+
expected.merge!(arg)
|
140
|
+
elsif arg.is_a?(Integer)
|
141
|
+
expected[:exit_code] = arg
|
142
|
+
else
|
143
|
+
expected[:stderr] = arg
|
144
|
+
end
|
145
|
+
end
|
146
|
+
expected[:exit_code] = 1 unless expected[:exit_code]
|
147
|
+
should_result_in(expected)
|
148
|
+
end
|
149
|
+
|
150
|
+
def should_succeed(*args)
|
151
|
+
expected = {}
|
152
|
+
args.each do |arg|
|
153
|
+
if arg.is_a?(Hash)
|
154
|
+
expected.merge!(arg)
|
155
|
+
else
|
156
|
+
expected[:stdout] = arg
|
157
|
+
end
|
158
|
+
end
|
159
|
+
should_result_in(expected)
|
160
|
+
end
|
161
|
+
|
162
|
+
private
|
163
|
+
|
164
|
+
def should_result_in(expected)
|
165
|
+
expected[:stdout] = "" unless expected[:stdout]
|
166
|
+
expected[:stdout] = expected[:stdout].is_a?(String) ? expected[:stdout].gsub(/[ \t\f\v]+$/, "") : expected[:stdout]
|
167
|
+
expected[:stderr] = "" unless expected[:stderr]
|
168
|
+
expected[:stderr] = expected[:stderr].is_a?(String) ? expected[:stderr].gsub(/[ \t\f\v]+$/, "") : expected[:stderr]
|
169
|
+
expected[:exit_code] = 0 unless expected[:exit_code]
|
170
|
+
# TODO make this go away
|
171
|
+
stderr_actual = @stderr.sub(/^WARNING: No knife configuration file found\n/, "")
|
172
|
+
stderr_actual = stderr_actual.gsub(/[ \t\f\v]+$/, "")
|
173
|
+
stdout_actual = @stdout
|
174
|
+
stdout_actual = stdout_actual.gsub(/[ \t\f\v]+$/, "")
|
175
|
+
if ChefUtils.windows?
|
176
|
+
stderr_actual = stderr_actual.gsub("\r\n", "\n")
|
177
|
+
stdout_actual = stdout_actual.gsub("\r\n", "\n")
|
178
|
+
end
|
179
|
+
if expected[:stderr].is_a?(Regexp)
|
180
|
+
expect(stderr_actual).to match(expected[:stderr])
|
181
|
+
else
|
182
|
+
expect(stderr_actual).to eq(expected[:stderr])
|
183
|
+
end
|
184
|
+
expect(@exit_code).to eq(expected[:exit_code])
|
185
|
+
if expected[:stdout].is_a?(Regexp)
|
186
|
+
expect(stdout_actual).to match(expected[:stdout])
|
187
|
+
else
|
188
|
+
expect(stdout_actual).to eq(expected[:stdout])
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Tyler Cloke (<tyler@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
shared_examples_for "mandatory field missing" do
|
20
|
+
context "when field is nil" do
|
21
|
+
before do
|
22
|
+
knife.name_args = name_args
|
23
|
+
end
|
24
|
+
|
25
|
+
it "exits 1" do
|
26
|
+
expect { knife.run }.to raise_error(SystemExit)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "prints the usage" do
|
30
|
+
expect(knife).to receive(:show_usage)
|
31
|
+
expect { knife.run }.to raise_error(SystemExit)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "prints a relevant error message" do
|
35
|
+
expect { knife.run }.to raise_error(SystemExit)
|
36
|
+
expect(stderr.string).to match(/You must specify a #{fieldname}/)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|