chef 12.5.0.alpha.1 → 12.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +21 -25
- data/Gemfile +46 -0
- data/README.md +4 -4
- data/Rakefile +5 -110
- data/distro/common/html/knife_cookbook_site.html +18 -18
- data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
- data/lib/chef/application.rb +1 -1
- data/lib/chef/application/apply.rb +19 -1
- data/lib/chef/application/client.rb +11 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/windows_service_manager.rb +9 -7
- data/lib/chef/chef_class.rb +39 -0
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
- data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
- data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
- data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
- data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
- data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
- data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
- data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
- data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
- data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
- data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
- data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
- data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
- data/lib/chef/client.rb +2 -3
- data/lib/chef/config.rb +34 -2
- data/lib/chef/cookbook/metadata.rb +25 -3
- data/lib/chef/cookbook/synchronizer.rb +1 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
- data/lib/chef/cookbook_version.rb +3 -3
- data/lib/chef/deprecation/mixin/template.rb +1 -2
- data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
- data/lib/chef/deprecation/provider/file.rb +1 -1
- data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
- data/lib/chef/deprecation/provider/remote_file.rb +1 -2
- data/lib/chef/deprecation/provider/template.rb +1 -1
- data/lib/chef/deprecation/warnings.rb +3 -4
- data/lib/chef/dsl/reboot_pending.rb +3 -2
- data/lib/chef/dsl/recipe.rb +6 -5
- data/lib/chef/dsl/resources.rb +2 -2
- data/lib/chef/event_dispatch/base.rb +12 -7
- data/lib/chef/event_dispatch/dispatcher.rb +21 -6
- data/lib/chef/exceptions.rb +22 -0
- data/lib/chef/file_content_management/tempfile.rb +1 -1
- data/lib/chef/formatters/base.rb +3 -0
- data/lib/chef/formatters/doc.rb +53 -5
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
- data/lib/chef/formatters/minimal.rb +2 -2
- data/lib/chef/knife.rb +35 -55
- data/lib/chef/knife/bootstrap.rb +41 -0
- data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
- data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
- data/lib/chef/knife/bootstrap/templates/README.md +3 -4
- data/lib/chef/knife/cookbook_create.rb +1 -1
- data/lib/chef/knife/cookbook_site_download.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +6 -6
- data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
- data/lib/chef/knife/core/bootstrap_context.rb +12 -4
- data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
- data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
- data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
- data/lib/chef/knife/core/node_presenter.rb +24 -1
- data/lib/chef/knife/core/object_loader.rb +1 -0
- data/lib/chef/knife/core/subcommand_loader.rb +131 -146
- data/lib/chef/knife/node_run_list_remove.rb +12 -1
- data/lib/chef/knife/null.rb +10 -0
- data/lib/chef/knife/rehash.rb +62 -0
- data/lib/chef/knife/search.rb +3 -3
- data/lib/chef/knife/ssh.rb +52 -30
- data/lib/chef/local_mode.rb +5 -0
- data/lib/chef/log.rb +5 -1
- data/lib/chef/mixin/deprecation.rb +8 -8
- data/lib/chef/mixin/params_validate.rb +2 -2
- data/lib/chef/mixin/template.rb +48 -0
- data/lib/chef/mixin/which.rb +1 -1
- data/lib/chef/mixin/wide_string.rb +72 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
- data/lib/chef/mixin/windows_env_helper.rb +4 -1
- data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
- data/lib/chef/monkey_patches/win32/registry.rb +72 -0
- data/lib/chef/node.rb +97 -3
- data/lib/chef/node_map.rb +2 -2
- data/lib/chef/platform/provider_mapping.rb +5 -6
- data/lib/chef/platform/query_helpers.rb +46 -4
- data/lib/chef/platform/service_helpers.rb +30 -32
- data/lib/chef/policy_builder.rb +1 -8
- data/lib/chef/policy_builder/dynamic.rb +186 -0
- data/lib/chef/policy_builder/expand_node_object.rb +30 -15
- data/lib/chef/policy_builder/policyfile.rb +155 -18
- data/lib/chef/property.rb +38 -9
- data/lib/chef/provider.rb +104 -12
- data/lib/chef/provider/batch.rb +8 -0
- data/lib/chef/provider/deploy.rb +2 -2
- data/lib/chef/provider/directory.rb +14 -2
- data/lib/chef/provider/dsc_resource.rb +5 -9
- data/lib/chef/provider/group/pw.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -2
- data/lib/chef/provider/mount.rb +7 -3
- data/lib/chef/provider/package/dpkg.rb +5 -11
- data/lib/chef/provider/package/rpm.rb +2 -2
- data/lib/chef/provider/package/rubygems.rb +1 -1
- data/lib/chef/provider/package/windows/msi.rb +2 -2
- data/lib/chef/provider/package/yum.rb +17 -5
- data/lib/chef/provider/powershell_script.rb +27 -4
- data/lib/chef/provider/remote_directory.rb +190 -102
- data/lib/chef/provider/service.rb +12 -2
- data/lib/chef/provider/service/aix.rb +1 -1
- data/lib/chef/provider/service/debian.rb +3 -5
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/gentoo.rb +3 -3
- data/lib/chef/provider/service/init.rb +3 -3
- data/lib/chef/provider/service/insserv.rb +2 -4
- data/lib/chef/provider/service/invokercd.rb +2 -4
- data/lib/chef/provider/service/openbsd.rb +2 -1
- data/lib/chef/provider/service/redhat.rb +52 -16
- data/lib/chef/provider/service/simple.rb +2 -2
- data/lib/chef/provider/service/systemd.rb +3 -5
- data/lib/chef/provider/service/upstart.rb +4 -6
- data/lib/chef/provider/subversion.rb +13 -7
- data/lib/chef/provider/template/content.rb +16 -6
- data/lib/chef/provider/user/solaris.rb +32 -4
- data/lib/chef/provider/windows_script.rb +3 -5
- data/lib/chef/provider_resolver.rb +2 -2
- data/lib/chef/resource.rb +85 -27
- data/lib/chef/resource/action_class.rb +83 -0
- data/lib/chef/resource/chef_gem.rb +3 -3
- data/lib/chef/resource/deploy.rb +8 -2
- data/lib/chef/resource/dsc_script.rb +2 -0
- data/lib/chef/resource/file/verification.rb +1 -1
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/service.rb +10 -2
- data/lib/chef/resource/subversion.rb +5 -0
- data/lib/chef/resource/windows_script.rb +6 -2
- data/lib/chef/resource/yum_package.rb +10 -1
- data/lib/chef/resource_resolver.rb +3 -3
- data/lib/chef/run_context.rb +6 -8
- data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
- data/lib/chef/run_lock.rb +30 -21
- data/lib/chef/util/powershell/ps_credential.rb +4 -0
- data/lib/chef/util/windows.rb +0 -32
- data/lib/chef/util/windows/net_group.rb +85 -106
- data/lib/chef/util/windows/net_use.rb +35 -71
- data/lib/chef/util/windows/net_user.rb +0 -1
- data/lib/chef/util/windows/volume.rb +19 -19
- data/lib/chef/version.rb +3 -3
- data/lib/chef/win32/api.rb +1 -0
- data/lib/chef/win32/api/file.rb +20 -0
- data/lib/chef/win32/api/net.rb +163 -43
- data/lib/chef/win32/api/registry.rb +51 -0
- data/lib/chef/win32/api/system.rb +23 -0
- data/lib/chef/win32/api/unicode.rb +0 -43
- data/lib/chef/win32/crypto.rb +2 -1
- data/lib/chef/win32/file.rb +28 -3
- data/lib/chef/win32/mutex.rb +1 -2
- data/lib/chef/win32/net.rb +162 -8
- data/lib/chef/win32/process.rb +13 -0
- data/lib/chef/win32/registry.rb +25 -28
- data/lib/chef/win32/security.rb +1 -1
- data/lib/chef/win32/security/token.rb +1 -1
- data/lib/chef/win32/system.rb +62 -0
- data/lib/chef/win32/unicode.rb +7 -2
- data/lib/chef/win32/version.rb +0 -4
- data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
- data/spec/data/dsc_lcm.pfx +0 -0
- data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
- data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
- data/spec/functional/knife/ssh_spec.rb +16 -0
- data/spec/functional/resource/deploy_revision_spec.rb +1 -1
- data/spec/functional/resource/dsc_resource_spec.rb +2 -0
- data/spec/functional/resource/dsc_script_spec.rb +91 -2
- data/spec/functional/resource/group_spec.rb +67 -44
- data/spec/functional/resource/powershell_script_spec.rb +104 -15
- data/spec/functional/resource/windows_service_spec.rb +1 -1
- data/spec/functional/run_lock_spec.rb +368 -189
- data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
- data/spec/integration/client/client_spec.rb +51 -0
- data/spec/integration/knife/download_spec.rb +4 -0
- data/spec/integration/knife/list_spec.rb +8 -0
- data/spec/integration/knife/upload_spec.rb +1 -1
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/remote_directory.rb +74 -0
- data/spec/integration/recipes/resource_action_spec.rb +42 -22
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
- data/spec/integration/recipes/resource_load_spec.rb +206 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/platform_helpers.rb +13 -0
- data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
- data/spec/support/shared/functional/windows_script.rb +63 -26
- data/spec/support/shared/unit/mock_shellout.rb +46 -0
- data/spec/support/shared/unit/provider/file.rb +10 -4
- data/spec/unit/application/client_spec.rb +16 -3
- data/spec/unit/application/knife_spec.rb +2 -2
- data/spec/unit/chef_class_spec.rb +0 -4
- data/spec/unit/client_spec.rb +6 -1
- data/spec/unit/config_spec.rb +31 -0
- data/spec/unit/cookbook/metadata_spec.rb +23 -3
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
- data/spec/unit/deprecation_spec.rb +3 -6
- data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
- data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
- data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
- data/spec/unit/formatters/doc_spec.rb +32 -0
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
- data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
- data/spec/unit/knife/bootstrap_spec.rb +55 -3
- data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
- data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
- data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
- data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
- data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
- data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
- data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
- data/spec/unit/mixin/template_spec.rb +5 -1
- data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
- data/spec/unit/node_spec.rb +213 -0
- data/spec/unit/platform/query_helpers_spec.rb +146 -3
- data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
- data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
- data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
- data/spec/unit/property/validation_spec.rb +5 -0
- data/spec/unit/property_spec.rb +152 -26
- data/spec/unit/provider/deploy_spec.rb +5 -5
- data/spec/unit/provider/directory_spec.rb +35 -0
- data/spec/unit/provider/dsc_resource_spec.rb +3 -10
- data/spec/unit/provider/ifconfig_spec.rb +22 -2
- data/spec/unit/provider/mount/aix_spec.rb +2 -1
- data/spec/unit/provider/mount/mount_spec.rb +6 -0
- data/spec/unit/provider/mount/windows_spec.rb +14 -0
- data/spec/unit/provider/mount_spec.rb +12 -1
- data/spec/unit/provider/package/dpkg_spec.rb +8 -1
- data/spec/unit/provider/package/rpm_spec.rb +18 -1
- data/spec/unit/provider/package/rubygems_spec.rb +18 -0
- data/spec/unit/provider/package/yum_spec.rb +97 -24
- data/spec/unit/provider/powershell_script_spec.rb +52 -26
- data/spec/unit/provider/remote_directory_spec.rb +1 -2
- data/spec/unit/provider/service/aix_service_spec.rb +3 -3
- data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
- data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
- data/spec/unit/provider/service/redhat_spec.rb +88 -8
- data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
- data/spec/unit/provider/service/windows_spec.rb +211 -200
- data/spec/unit/provider/subversion_spec.rb +50 -31
- data/spec/unit/provider/template/content_spec.rb +93 -2
- data/spec/unit/provider/user/solaris_spec.rb +66 -9
- data/spec/unit/provider_resolver_spec.rb +707 -650
- data/spec/unit/resource/deploy_spec.rb +7 -1
- data/spec/unit/resource/dsc_script_spec.rb +4 -0
- data/spec/unit/resource/file/verification_spec.rb +1 -1
- data/spec/unit/resource/powershell_script_spec.rb +17 -13
- data/spec/unit/resource/service_spec.rb +4 -4
- data/spec/unit/resource/subversion_spec.rb +4 -0
- data/spec/unit/resource/yum_package_spec.rb +10 -1
- data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
- data/spec/unit/win32/registry_spec.rb +394 -0
- data/tasks/external_tests.rb +47 -23
- data/tasks/maintainers.rb +155 -14
- metadata +51 -26
- data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
- data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
- data/spec/unit/registry_helper_spec.rb +0 -390
@@ -21,7 +21,7 @@ require 'spec_helper'
|
|
21
21
|
describe "Chef::Platform#windows_server_2003?" do
|
22
22
|
it "returns false early when not on windows" do
|
23
23
|
allow(ChefConfig).to receive(:windows?).and_return(false)
|
24
|
-
expect(Chef::Platform).not_to receive(:require)
|
24
|
+
expect(Chef::Platform).not_to receive(:require)
|
25
25
|
expect(Chef::Platform.windows_server_2003?).to be_falsey
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,127 @@ describe "Chef::Platform#windows_server_2003?" do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
34
|
+
describe "Chef::Platform#windows_nano_server?" do
|
35
|
+
include_context "Win32"
|
36
|
+
|
37
|
+
let(:key) { "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Server\\ServerLevels" }
|
38
|
+
let(:key_query_value) { 0x0001 }
|
39
|
+
let(:access) { key_query_value | 0x0100 }
|
40
|
+
let(:hive) { double("Win32::Registry::HKEY_LOCAL_MACHINE") }
|
41
|
+
let(:registry) { double("Win32::Registry") }
|
42
|
+
|
43
|
+
before(:all) do
|
44
|
+
Win32::Registry = Class.new
|
45
|
+
Win32::Registry::Error = Class.new(RuntimeError)
|
46
|
+
end
|
47
|
+
|
48
|
+
before do
|
49
|
+
Win32::Registry::HKEY_LOCAL_MACHINE = hive
|
50
|
+
Win32::Registry::KEY_QUERY_VALUE = key_query_value
|
51
|
+
end
|
52
|
+
|
53
|
+
after do
|
54
|
+
Win32::Registry.send(:remove_const, 'HKEY_LOCAL_MACHINE') if defined?(Win32::Registry::HKEY_LOCAL_MACHINE)
|
55
|
+
Win32::Registry.send(:remove_const, 'KEY_QUERY_VALUE') if defined?(Win32::Registry::KEY_QUERY_VALUE)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns false early when not on windows" do
|
59
|
+
allow(ChefConfig).to receive(:windows?).and_return(false)
|
60
|
+
expect(Chef::Platform).to_not receive(:require)
|
61
|
+
expect(Chef::Platform.windows_nano_server?).to be false
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns true when the registry value is 1" do
|
65
|
+
allow(ChefConfig).to receive(:windows?).and_return(true)
|
66
|
+
allow(Chef::Platform).to receive(:require).with('win32/registry')
|
67
|
+
expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
|
68
|
+
with(key, access).
|
69
|
+
and_yield(registry)
|
70
|
+
expect(registry).to receive(:[]).with("NanoServer").and_return(1)
|
71
|
+
expect(Chef::Platform.windows_nano_server?).to be true
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns false when the registry value is not 1" do
|
75
|
+
allow(ChefConfig).to receive(:windows?).and_return(true)
|
76
|
+
allow(Chef::Platform).to receive(:require).with('win32/registry')
|
77
|
+
expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
|
78
|
+
with(key, access).
|
79
|
+
and_yield(registry)
|
80
|
+
expect(registry).to receive(:[]).with("NanoServer").and_return(0)
|
81
|
+
expect(Chef::Platform.windows_nano_server?).to be false
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns false when the registry value does not exist" do
|
85
|
+
allow(ChefConfig).to receive(:windows?).and_return(true)
|
86
|
+
allow(Chef::Platform).to receive(:require).with('win32/registry')
|
87
|
+
expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
|
88
|
+
with(key, access).
|
89
|
+
and_yield(registry)
|
90
|
+
expect(registry).to receive(:[]).with("NanoServer").
|
91
|
+
and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
|
92
|
+
expect(Chef::Platform.windows_nano_server?).to be false
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns false when the registry key does not exist" do
|
96
|
+
allow(ChefConfig).to receive(:windows?).and_return(true)
|
97
|
+
allow(Chef::Platform).to receive(:require).with('win32/registry')
|
98
|
+
expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
|
99
|
+
with(key, access).
|
100
|
+
and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
|
101
|
+
expect(Chef::Platform.windows_nano_server?).to be false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "Chef::Platform#supports_msi?" do
|
106
|
+
include_context "Win32" # clear and restore Win32:: namespace
|
107
|
+
|
108
|
+
let(:key) { "System\\CurrentControlSet\\Services\\msiserver" }
|
109
|
+
let(:key_query_value) { 0x0001 }
|
110
|
+
let(:access) { key_query_value }
|
111
|
+
let(:hive) { double("Win32::Registry::HKEY_LOCAL_MACHINE") }
|
112
|
+
let(:registry) { double("Win32::Registry") }
|
113
|
+
|
114
|
+
before(:all) do
|
115
|
+
Win32::Registry = Class.new
|
116
|
+
Win32::Registry::Error = Class.new(RuntimeError)
|
117
|
+
end
|
118
|
+
|
119
|
+
before do
|
120
|
+
Win32::Registry::HKEY_LOCAL_MACHINE = hive
|
121
|
+
Win32::Registry::KEY_QUERY_VALUE = key_query_value
|
122
|
+
end
|
123
|
+
|
124
|
+
after do
|
125
|
+
Win32::Registry.send(:remove_const, 'HKEY_LOCAL_MACHINE') if defined?(Win32::Registry::HKEY_LOCAL_MACHINE)
|
126
|
+
Win32::Registry.send(:remove_const, 'KEY_QUERY_VALUE') if defined?(Win32::Registry::KEY_QUERY_VALUE)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "returns false early when not on windows" do
|
130
|
+
allow(ChefConfig).to receive(:windows?).and_return(false)
|
131
|
+
expect(Chef::Platform).to_not receive(:require)
|
132
|
+
expect(Chef::Platform.supports_msi?).to be false
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns true when the registry key exists" do
|
136
|
+
allow(ChefConfig).to receive(:windows?).and_return(true)
|
137
|
+
allow(Chef::Platform).to receive(:require).with('win32/registry')
|
138
|
+
expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
|
139
|
+
with(key, access).
|
140
|
+
and_yield(registry)
|
141
|
+
expect(Chef::Platform.supports_msi?).to be true
|
142
|
+
end
|
143
|
+
|
144
|
+
it "returns false when the registry key does not exist" do
|
145
|
+
allow(ChefConfig).to receive(:windows?).and_return(true)
|
146
|
+
allow(Chef::Platform).to receive(:require).with('win32/registry')
|
147
|
+
expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
|
148
|
+
with(key, access).
|
149
|
+
and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
|
150
|
+
expect(Chef::Platform.supports_msi?).to be false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'Chef::Platform#supports_dsc?' do
|
35
155
|
it 'returns false if powershell is not present' do
|
36
156
|
node = Chef::Node.new
|
37
157
|
expect(Chef::Platform.supports_dsc?(node)).to be_falsey
|
@@ -54,7 +174,7 @@ describe 'Chef::Platform#supports_dsc?' do
|
|
54
174
|
end
|
55
175
|
end
|
56
176
|
|
57
|
-
describe 'Chef::Platform#supports_dsc_invoke_resource?' do
|
177
|
+
describe 'Chef::Platform#supports_dsc_invoke_resource?' do
|
58
178
|
it 'returns false if powershell is not present' do
|
59
179
|
node = Chef::Node.new
|
60
180
|
expect(Chef::Platform.supports_dsc_invoke_resource?(node)).to be_falsey
|
@@ -75,3 +195,26 @@ describe 'Chef::Platform#supports_dsc_invoke_resource?' do
|
|
75
195
|
end
|
76
196
|
end
|
77
197
|
|
198
|
+
describe 'Chef::Platform#dsc_refresh_mode_disabled?' do
|
199
|
+
let(:node) { instance_double('Chef::Node') }
|
200
|
+
let(:cmdlet) { instance_double('Chef::Util::Powershell::Cmdlet') }
|
201
|
+
let(:cmdlet_result) { instance_double('Chef::Util::Powershell::CmdletResult')}
|
202
|
+
|
203
|
+
it "returns true when RefreshMode is Disabled" do
|
204
|
+
expect(Chef::Util::Powershell::Cmdlet).to receive(:new).
|
205
|
+
with(node, "Get-DscLocalConfigurationManager", :object).
|
206
|
+
and_return(cmdlet)
|
207
|
+
expect(cmdlet).to receive(:run!).and_return(cmdlet_result)
|
208
|
+
expect(cmdlet_result).to receive(:return_value).and_return({ 'RefreshMode' => 'Disabled' })
|
209
|
+
expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be true
|
210
|
+
end
|
211
|
+
|
212
|
+
it "returns false when RefreshMode is not Disabled" do
|
213
|
+
expect(Chef::Util::Powershell::Cmdlet).to receive(:new).
|
214
|
+
with(node, "Get-DscLocalConfigurationManager", :object).
|
215
|
+
and_return(cmdlet)
|
216
|
+
expect(cmdlet).to receive(:run!).and_return(cmdlet_result)
|
217
|
+
expect(cmdlet_result).to receive(:return_value).and_return({ 'RefreshMode' => 'LaLaLa' })
|
218
|
+
expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be false
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@getchef.com>)
|
3
|
+
# Copyright:: Copyright 2014 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
|
+
require 'spec_helper'
|
20
|
+
require 'chef/policy_builder'
|
21
|
+
|
22
|
+
describe Chef::PolicyBuilder::Dynamic do
|
23
|
+
|
24
|
+
let(:node_name) { "joe_node" }
|
25
|
+
let(:ohai_data) { {"platform" => "ubuntu", "platform_version" => "13.04", "fqdn" => "joenode.example.com"} }
|
26
|
+
let(:json_attribs) { {"custom_attr" => "custom_attr_value"} }
|
27
|
+
let(:override_runlist) { nil }
|
28
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
29
|
+
|
30
|
+
let(:err_namespace) { Chef::PolicyBuilder::Policyfile }
|
31
|
+
|
32
|
+
let(:base_node) do
|
33
|
+
node = Chef::Node.new
|
34
|
+
node.name(node_name)
|
35
|
+
node
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:node) { base_node }
|
39
|
+
|
40
|
+
subject(:policy_builder) { Chef::PolicyBuilder::Dynamic.new(node_name, ohai_data, json_attribs, override_runlist, events) }
|
41
|
+
|
42
|
+
describe "loading policy data" do
|
43
|
+
|
44
|
+
describe "delegating PolicyBuilder API to the correct implementation" do
|
45
|
+
|
46
|
+
let(:implementation) { instance_double("Chef::PolicyBuilder::Policyfile") }
|
47
|
+
|
48
|
+
before do
|
49
|
+
allow(policy_builder).to receive(:implementation).and_return(implementation)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Dynamic should load_node, figure out the correct backend, then forward
|
53
|
+
# messages to it after. That behavior is tested below.
|
54
|
+
it "responds to #load_node" do
|
55
|
+
expect(policy_builder).to respond_to(:load_node)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "forwards #original_runlist" do
|
59
|
+
expect(implementation).to receive(:original_runlist)
|
60
|
+
policy_builder.original_runlist
|
61
|
+
end
|
62
|
+
|
63
|
+
it "forwards #run_context" do
|
64
|
+
expect(implementation).to receive(:run_context)
|
65
|
+
policy_builder.run_context
|
66
|
+
end
|
67
|
+
|
68
|
+
it "forwards #run_list_expansion" do
|
69
|
+
expect(implementation).to receive(:run_list_expansion)
|
70
|
+
policy_builder.run_list_expansion
|
71
|
+
end
|
72
|
+
|
73
|
+
it "forwards #build_node to the implementation object" do
|
74
|
+
expect(implementation).to receive(:build_node)
|
75
|
+
policy_builder.build_node
|
76
|
+
end
|
77
|
+
|
78
|
+
it "forwards #setup_run_context to the implementation object" do
|
79
|
+
expect(implementation).to receive(:setup_run_context)
|
80
|
+
policy_builder.setup_run_context
|
81
|
+
|
82
|
+
arg = Object.new
|
83
|
+
|
84
|
+
expect(implementation).to receive(:setup_run_context).with(arg)
|
85
|
+
policy_builder.setup_run_context(arg)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "forwards #expand_run_list to the implementation object" do
|
89
|
+
expect(implementation).to receive(:expand_run_list)
|
90
|
+
policy_builder.expand_run_list
|
91
|
+
end
|
92
|
+
|
93
|
+
it "forwards #sync_cookbooks to the implementation object" do
|
94
|
+
expect(implementation).to receive(:sync_cookbooks)
|
95
|
+
policy_builder.sync_cookbooks
|
96
|
+
end
|
97
|
+
|
98
|
+
it "forwards #temporary_policy? to the implementation object" do
|
99
|
+
expect(implementation).to receive(:temporary_policy?)
|
100
|
+
policy_builder.temporary_policy?
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "selecting a backend implementation" do
|
106
|
+
|
107
|
+
let(:implementation) do
|
108
|
+
policy_builder.select_implementation(node)
|
109
|
+
policy_builder.implementation
|
110
|
+
end
|
111
|
+
|
112
|
+
context "when no policyfile attributes are present on the node" do
|
113
|
+
|
114
|
+
context "and json_attribs are not given" do
|
115
|
+
|
116
|
+
let(:json_attribs) { {} }
|
117
|
+
|
118
|
+
it "uses the ExpandNodeObject implementation" do
|
119
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::ExpandNodeObject)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
context "and no policyfile attributes are present in json_attribs" do
|
125
|
+
|
126
|
+
let(:json_attribs) { {"foo" => "bar"} }
|
127
|
+
|
128
|
+
it "uses the ExpandNodeObject implementation" do
|
129
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::ExpandNodeObject)
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
context "and :use_policyfile is set in Chef::Config" do
|
135
|
+
|
136
|
+
before do
|
137
|
+
Chef::Config[:use_policyfile] = true
|
138
|
+
end
|
139
|
+
|
140
|
+
it "uses the Policyfile implementation" do
|
141
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
context "and policy_name and policy_group are set on Chef::Config" do
|
147
|
+
|
148
|
+
before do
|
149
|
+
Chef::Config[:policy_name] = "example-policy"
|
150
|
+
Chef::Config[:policy_group] = "testing"
|
151
|
+
end
|
152
|
+
|
153
|
+
it "uses the Policyfile implementation" do
|
154
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
context "and deployment_group and policy_document_native_api are set on Chef::Config" do
|
160
|
+
|
161
|
+
before do
|
162
|
+
Chef::Config[:deployment_group] = "example-policy-staging"
|
163
|
+
Chef::Config[:policy_document_native_api] = false
|
164
|
+
end
|
165
|
+
|
166
|
+
it "uses the Policyfile implementation" do
|
167
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
context "and policyfile attributes are present in json_attribs" do
|
173
|
+
|
174
|
+
let(:json_attribs) { {"policy_name" => "example-policy", "policy_group" => "testing"} }
|
175
|
+
|
176
|
+
it "uses the Policyfile implementation" do
|
177
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when policyfile attributes are present on the node" do
|
185
|
+
|
186
|
+
let(:node) do
|
187
|
+
base_node.policy_name = "example-policy"
|
188
|
+
base_node.policy_group = "staging"
|
189
|
+
base_node
|
190
|
+
end
|
191
|
+
|
192
|
+
it "uses the Policyfile implementation" do
|
193
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "loading a node" do
|
201
|
+
|
202
|
+
let(:implementation) { instance_double("Chef::PolicyBuilder::Policyfile") }
|
203
|
+
|
204
|
+
before do
|
205
|
+
allow(policy_builder).to receive(:implementation).and_return(implementation)
|
206
|
+
end
|
207
|
+
|
208
|
+
context "when not running chef solo" do
|
209
|
+
|
210
|
+
|
211
|
+
context "when successful" do
|
212
|
+
|
213
|
+
before do
|
214
|
+
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
215
|
+
expect(policy_builder).to receive(:select_implementation).with(node)
|
216
|
+
expect(implementation).to receive(:finish_load_node).with(node)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "selects the backend implementation and continues node loading" do
|
220
|
+
policy_builder.load_node
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
context "when an error occurs finding the node" do
|
226
|
+
|
227
|
+
before do
|
228
|
+
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_raise("oops")
|
229
|
+
end
|
230
|
+
|
231
|
+
it "sends a node_load_failed event and re-raises" do
|
232
|
+
expect(events).to receive(:node_load_failed)
|
233
|
+
expect { policy_builder.load_node }.to raise_error("oops")
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
context "when an error occurs in the implementation's finish_load_node call" do
|
239
|
+
|
240
|
+
before do
|
241
|
+
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
242
|
+
expect(policy_builder).to receive(:select_implementation).with(node)
|
243
|
+
expect(implementation).to receive(:finish_load_node).and_raise("oops")
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
it "sends a node_load_failed event and re-raises" do
|
248
|
+
expect(events).to receive(:node_load_failed)
|
249
|
+
expect { policy_builder.load_node }.to raise_error("oops")
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
context "when running chef solo" do
|
257
|
+
|
258
|
+
before do
|
259
|
+
Chef::Config[:solo] = true
|
260
|
+
expect(Chef::Node).to receive(:build).with(node_name).and_return(node)
|
261
|
+
expect(policy_builder).to receive(:select_implementation).with(node)
|
262
|
+
expect(implementation).to receive(:finish_load_node).with(node)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "selects the backend implementation and continues node loading" do
|
266
|
+
policy_builder.load_node
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
@@ -34,10 +34,18 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
34
34
|
expect(policy_builder).to respond_to(:node)
|
35
35
|
end
|
36
36
|
|
37
|
-
it "implements a load_node method" do
|
37
|
+
it "implements a load_node method for backwards compatibility until Chef 13" do
|
38
38
|
expect(policy_builder).to respond_to(:load_node)
|
39
39
|
end
|
40
40
|
|
41
|
+
it "has removed the deprecated #load_node method", :chef_gte_13_only do
|
42
|
+
expect(policy_builder).to_not respond_to(:load_node)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "implements a finish_load_node method" do
|
46
|
+
expect(policy_builder).to respond_to(:finish_load_node)
|
47
|
+
end
|
48
|
+
|
41
49
|
it "implements a build_node method" do
|
42
50
|
expect(policy_builder).to respond_to(:build_node)
|
43
51
|
end
|
@@ -63,39 +71,13 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
63
71
|
expect(policy_builder).to respond_to(:temporary_policy?)
|
64
72
|
end
|
65
73
|
|
66
|
-
describe "loading the node" do
|
67
|
-
|
68
|
-
context "on chef-solo" do
|
69
|
-
|
70
|
-
before do
|
71
|
-
Chef::Config[:solo] = true
|
72
|
-
end
|
73
|
-
|
74
|
-
it "creates a new in-memory node object with the given name" do
|
75
|
-
policy_builder.load_node
|
76
|
-
expect(policy_builder.node.name).to eq(node_name)
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
context "on chef-client" do
|
82
|
-
|
83
|
-
let(:node) { Chef::Node.new.tap { |n| n.name(node_name) } }
|
84
|
-
|
85
|
-
it "loads or creates a node on the server" do
|
86
|
-
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
87
|
-
policy_builder.load_node
|
88
|
-
expect(policy_builder.node).to eq(node)
|
89
|
-
end
|
74
|
+
describe "finishing loading the node" do
|
90
75
|
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "building the node" do
|
76
|
+
let(:node) { Chef::Node.new.tap { |n| n.name(node_name) } }
|
95
77
|
|
96
|
-
|
97
|
-
|
98
|
-
|
78
|
+
it "stores the node" do
|
79
|
+
policy_builder.finish_load_node(node)
|
80
|
+
expect(policy_builder.node).to eq(node)
|
99
81
|
end
|
100
82
|
|
101
83
|
end
|
@@ -124,7 +106,8 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
124
106
|
|
125
107
|
end
|
126
108
|
|
127
|
-
context "
|
109
|
+
context "deprecated #load_node method" do
|
110
|
+
|
128
111
|
let(:node) do
|
129
112
|
node = Chef::Node.new
|
130
113
|
node.name(node_name)
|
@@ -133,10 +116,29 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
133
116
|
end
|
134
117
|
|
135
118
|
before do
|
119
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
136
120
|
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
137
121
|
policy_builder.load_node
|
138
122
|
end
|
139
123
|
|
124
|
+
it "loads the node" do
|
125
|
+
expect(policy_builder.node).to eq(node)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
context "once the node has been loaded" do
|
131
|
+
let(:node) do
|
132
|
+
node = Chef::Node.new
|
133
|
+
node.name(node_name)
|
134
|
+
node.run_list(["recipe[a::default]", "recipe[b::server]"])
|
135
|
+
node
|
136
|
+
end
|
137
|
+
|
138
|
+
before do
|
139
|
+
policy_builder.finish_load_node(node)
|
140
|
+
end
|
141
|
+
|
140
142
|
it "expands the run_list" do
|
141
143
|
expect(policy_builder.expand_run_list).to be_a(Chef::RunList::RunListExpansion)
|
142
144
|
expect(policy_builder.run_list_expansion).to be_a(Chef::RunList::RunListExpansion)
|
@@ -167,8 +169,7 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
167
169
|
|
168
170
|
before do
|
169
171
|
Chef::Config[:environment] = configured_environment
|
170
|
-
|
171
|
-
policy_builder.load_node
|
172
|
+
policy_builder.finish_load_node(node)
|
172
173
|
policy_builder.build_node
|
173
174
|
end
|
174
175
|
|
@@ -302,11 +303,9 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
302
303
|
let(:cookbook_synchronizer) { double("CookbookSynchronizer") }
|
303
304
|
|
304
305
|
before do
|
305
|
-
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
306
|
-
|
307
306
|
allow(policy_builder).to receive(:api_service).and_return(chef_http)
|
308
307
|
|
309
|
-
policy_builder.
|
308
|
+
policy_builder.finish_load_node(node)
|
310
309
|
policy_builder.build_node
|
311
310
|
|
312
311
|
run_list_expansion = policy_builder.run_list_expansion
|