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.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +5 -110
  6. data/distro/common/html/knife_cookbook_site.html +18 -18
  7. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  8. data/lib/chef/application.rb +1 -1
  9. data/lib/chef/application/apply.rb +19 -1
  10. data/lib/chef/application/client.rb +11 -5
  11. data/lib/chef/application/knife.rb +2 -2
  12. data/lib/chef/application/windows_service_manager.rb +9 -7
  13. data/lib/chef/chef_class.rb +39 -0
  14. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  15. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  16. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  17. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  18. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  19. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  20. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  21. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  22. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  23. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  24. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  25. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
  26. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  27. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  28. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  29. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  30. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  31. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  32. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  33. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  35. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  36. data/lib/chef/client.rb +2 -3
  37. data/lib/chef/config.rb +34 -2
  38. data/lib/chef/cookbook/metadata.rb +25 -3
  39. data/lib/chef/cookbook/synchronizer.rb +1 -1
  40. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  41. data/lib/chef/cookbook_version.rb +3 -3
  42. data/lib/chef/deprecation/mixin/template.rb +1 -2
  43. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  44. data/lib/chef/deprecation/provider/file.rb +1 -1
  45. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  46. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  47. data/lib/chef/deprecation/provider/template.rb +1 -1
  48. data/lib/chef/deprecation/warnings.rb +3 -4
  49. data/lib/chef/dsl/reboot_pending.rb +3 -2
  50. data/lib/chef/dsl/recipe.rb +6 -5
  51. data/lib/chef/dsl/resources.rb +2 -2
  52. data/lib/chef/event_dispatch/base.rb +12 -7
  53. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  54. data/lib/chef/exceptions.rb +22 -0
  55. data/lib/chef/file_content_management/tempfile.rb +1 -1
  56. data/lib/chef/formatters/base.rb +3 -0
  57. data/lib/chef/formatters/doc.rb +53 -5
  58. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  59. data/lib/chef/formatters/minimal.rb +2 -2
  60. data/lib/chef/knife.rb +35 -55
  61. data/lib/chef/knife/bootstrap.rb +41 -0
  62. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  63. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  64. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  65. data/lib/chef/knife/cookbook_create.rb +1 -1
  66. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  67. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  68. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  69. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  70. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  71. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  72. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  73. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  74. data/lib/chef/knife/core/node_presenter.rb +24 -1
  75. data/lib/chef/knife/core/object_loader.rb +1 -0
  76. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  77. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  78. data/lib/chef/knife/null.rb +10 -0
  79. data/lib/chef/knife/rehash.rb +62 -0
  80. data/lib/chef/knife/search.rb +3 -3
  81. data/lib/chef/knife/ssh.rb +52 -30
  82. data/lib/chef/local_mode.rb +5 -0
  83. data/lib/chef/log.rb +5 -1
  84. data/lib/chef/mixin/deprecation.rb +8 -8
  85. data/lib/chef/mixin/params_validate.rb +2 -2
  86. data/lib/chef/mixin/template.rb +48 -0
  87. data/lib/chef/mixin/which.rb +1 -1
  88. data/lib/chef/mixin/wide_string.rb +72 -0
  89. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  90. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  91. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  92. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  93. data/lib/chef/node.rb +97 -3
  94. data/lib/chef/node_map.rb +2 -2
  95. data/lib/chef/platform/provider_mapping.rb +5 -6
  96. data/lib/chef/platform/query_helpers.rb +46 -4
  97. data/lib/chef/platform/service_helpers.rb +30 -32
  98. data/lib/chef/policy_builder.rb +1 -8
  99. data/lib/chef/policy_builder/dynamic.rb +186 -0
  100. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  101. data/lib/chef/policy_builder/policyfile.rb +155 -18
  102. data/lib/chef/property.rb +38 -9
  103. data/lib/chef/provider.rb +104 -12
  104. data/lib/chef/provider/batch.rb +8 -0
  105. data/lib/chef/provider/deploy.rb +2 -2
  106. data/lib/chef/provider/directory.rb +14 -2
  107. data/lib/chef/provider/dsc_resource.rb +5 -9
  108. data/lib/chef/provider/group/pw.rb +1 -1
  109. data/lib/chef/provider/ifconfig.rb +2 -2
  110. data/lib/chef/provider/mount.rb +7 -3
  111. data/lib/chef/provider/package/dpkg.rb +5 -11
  112. data/lib/chef/provider/package/rpm.rb +2 -2
  113. data/lib/chef/provider/package/rubygems.rb +1 -1
  114. data/lib/chef/provider/package/windows/msi.rb +2 -2
  115. data/lib/chef/provider/package/yum.rb +17 -5
  116. data/lib/chef/provider/powershell_script.rb +27 -4
  117. data/lib/chef/provider/remote_directory.rb +190 -102
  118. data/lib/chef/provider/service.rb +12 -2
  119. data/lib/chef/provider/service/aix.rb +1 -1
  120. data/lib/chef/provider/service/debian.rb +3 -5
  121. data/lib/chef/provider/service/freebsd.rb +1 -1
  122. data/lib/chef/provider/service/gentoo.rb +3 -3
  123. data/lib/chef/provider/service/init.rb +3 -3
  124. data/lib/chef/provider/service/insserv.rb +2 -4
  125. data/lib/chef/provider/service/invokercd.rb +2 -4
  126. data/lib/chef/provider/service/openbsd.rb +2 -1
  127. data/lib/chef/provider/service/redhat.rb +52 -16
  128. data/lib/chef/provider/service/simple.rb +2 -2
  129. data/lib/chef/provider/service/systemd.rb +3 -5
  130. data/lib/chef/provider/service/upstart.rb +4 -6
  131. data/lib/chef/provider/subversion.rb +13 -7
  132. data/lib/chef/provider/template/content.rb +16 -6
  133. data/lib/chef/provider/user/solaris.rb +32 -4
  134. data/lib/chef/provider/windows_script.rb +3 -5
  135. data/lib/chef/provider_resolver.rb +2 -2
  136. data/lib/chef/resource.rb +85 -27
  137. data/lib/chef/resource/action_class.rb +83 -0
  138. data/lib/chef/resource/chef_gem.rb +3 -3
  139. data/lib/chef/resource/deploy.rb +8 -2
  140. data/lib/chef/resource/dsc_script.rb +2 -0
  141. data/lib/chef/resource/file/verification.rb +1 -1
  142. data/lib/chef/resource/registry_key.rb +1 -1
  143. data/lib/chef/resource/service.rb +10 -2
  144. data/lib/chef/resource/subversion.rb +5 -0
  145. data/lib/chef/resource/windows_script.rb +6 -2
  146. data/lib/chef/resource/yum_package.rb +10 -1
  147. data/lib/chef/resource_resolver.rb +3 -3
  148. data/lib/chef/run_context.rb +6 -8
  149. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  150. data/lib/chef/run_lock.rb +30 -21
  151. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  152. data/lib/chef/util/windows.rb +0 -32
  153. data/lib/chef/util/windows/net_group.rb +85 -106
  154. data/lib/chef/util/windows/net_use.rb +35 -71
  155. data/lib/chef/util/windows/net_user.rb +0 -1
  156. data/lib/chef/util/windows/volume.rb +19 -19
  157. data/lib/chef/version.rb +3 -3
  158. data/lib/chef/win32/api.rb +1 -0
  159. data/lib/chef/win32/api/file.rb +20 -0
  160. data/lib/chef/win32/api/net.rb +163 -43
  161. data/lib/chef/win32/api/registry.rb +51 -0
  162. data/lib/chef/win32/api/system.rb +23 -0
  163. data/lib/chef/win32/api/unicode.rb +0 -43
  164. data/lib/chef/win32/crypto.rb +2 -1
  165. data/lib/chef/win32/file.rb +28 -3
  166. data/lib/chef/win32/mutex.rb +1 -2
  167. data/lib/chef/win32/net.rb +162 -8
  168. data/lib/chef/win32/process.rb +13 -0
  169. data/lib/chef/win32/registry.rb +25 -28
  170. data/lib/chef/win32/security.rb +1 -1
  171. data/lib/chef/win32/security/token.rb +1 -1
  172. data/lib/chef/win32/system.rb +62 -0
  173. data/lib/chef/win32/unicode.rb +7 -2
  174. data/lib/chef/win32/version.rb +0 -4
  175. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  176. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  177. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  178. data/spec/data/dsc_lcm.pfx +0 -0
  179. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  180. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  181. data/spec/functional/knife/ssh_spec.rb +16 -0
  182. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  183. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  184. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  185. data/spec/functional/resource/group_spec.rb +67 -44
  186. data/spec/functional/resource/powershell_script_spec.rb +104 -15
  187. data/spec/functional/resource/windows_service_spec.rb +1 -1
  188. data/spec/functional/run_lock_spec.rb +368 -189
  189. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
  190. data/spec/integration/client/client_spec.rb +51 -0
  191. data/spec/integration/knife/download_spec.rb +4 -0
  192. data/spec/integration/knife/list_spec.rb +8 -0
  193. data/spec/integration/knife/upload_spec.rb +1 -1
  194. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  195. data/spec/integration/recipes/remote_directory.rb +74 -0
  196. data/spec/integration/recipes/resource_action_spec.rb +42 -22
  197. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  198. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  199. data/spec/spec_helper.rb +8 -0
  200. data/spec/support/platform_helpers.rb +13 -0
  201. data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
  202. data/spec/support/shared/functional/windows_script.rb +63 -26
  203. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  204. data/spec/support/shared/unit/provider/file.rb +10 -4
  205. data/spec/unit/application/client_spec.rb +16 -3
  206. data/spec/unit/application/knife_spec.rb +2 -2
  207. data/spec/unit/chef_class_spec.rb +0 -4
  208. data/spec/unit/client_spec.rb +6 -1
  209. data/spec/unit/config_spec.rb +31 -0
  210. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  211. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  212. data/spec/unit/deprecation_spec.rb +3 -6
  213. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  214. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  215. data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
  216. data/spec/unit/formatters/doc_spec.rb +32 -0
  217. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  218. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  219. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  220. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  221. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  222. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  223. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  224. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  225. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  226. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  227. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  228. data/spec/unit/mixin/template_spec.rb +5 -1
  229. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  230. data/spec/unit/node_spec.rb +213 -0
  231. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  232. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  233. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  234. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  235. data/spec/unit/property/validation_spec.rb +5 -0
  236. data/spec/unit/property_spec.rb +152 -26
  237. data/spec/unit/provider/deploy_spec.rb +5 -5
  238. data/spec/unit/provider/directory_spec.rb +35 -0
  239. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  240. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  241. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  242. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  243. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  244. data/spec/unit/provider/mount_spec.rb +12 -1
  245. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  246. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  247. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  248. data/spec/unit/provider/package/yum_spec.rb +97 -24
  249. data/spec/unit/provider/powershell_script_spec.rb +52 -26
  250. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  251. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  252. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  253. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  254. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  255. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  256. data/spec/unit/provider/service/windows_spec.rb +211 -200
  257. data/spec/unit/provider/subversion_spec.rb +50 -31
  258. data/spec/unit/provider/template/content_spec.rb +93 -2
  259. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  260. data/spec/unit/provider_resolver_spec.rb +707 -650
  261. data/spec/unit/resource/deploy_spec.rb +7 -1
  262. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  263. data/spec/unit/resource/file/verification_spec.rb +1 -1
  264. data/spec/unit/resource/powershell_script_spec.rb +17 -13
  265. data/spec/unit/resource/service_spec.rb +4 -4
  266. data/spec/unit/resource/subversion_spec.rb +4 -0
  267. data/spec/unit/resource/yum_package_spec.rb +10 -1
  268. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  269. data/spec/unit/win32/registry_spec.rb +394 -0
  270. data/tasks/external_tests.rb +47 -23
  271. data/tasks/maintainers.rb +155 -14
  272. metadata +51 -26
  273. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  274. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  275. data/spec/unit/registry_helper_spec.rb +0 -390
@@ -0,0 +1,206 @@
1
+ require 'support/shared/integration/integration_helper'
2
+
3
+ describe "Resource.load_current_value" do
4
+ include IntegrationSupport
5
+
6
+ module Namer
7
+ extend self
8
+ attr_accessor :current_index
9
+ def incrementing_value
10
+ @incrementing_value += 1
11
+ @incrementing_value
12
+ end
13
+ attr_writer :incrementing_value
14
+ end
15
+
16
+ before(:all) { Namer.current_index = 1 }
17
+ before { Namer.current_index += 1 }
18
+ before { Namer.incrementing_value = 0 }
19
+
20
+ let(:resource_name) { :"load_current_value_dsl#{Namer.current_index}" }
21
+ let(:resource_class) {
22
+ result = Class.new(Chef::Resource) do
23
+ def self.to_s; resource_name; end
24
+ def self.inspect; resource_name.inspect; end
25
+ property :x, default: lazy { "default #{Namer.incrementing_value}" }
26
+ def self.created_x=(value)
27
+ @created = value
28
+ end
29
+ def self.created_x
30
+ @created
31
+ end
32
+ action :create do
33
+ new_resource.class.created_x = x
34
+ end
35
+ end
36
+ result.resource_name resource_name
37
+ result
38
+ }
39
+
40
+ # Pull on resource_class to initialize it
41
+ before { resource_class }
42
+
43
+ context "with a resource with load_current_value" do
44
+ before :each do
45
+ resource_class.load_current_value do
46
+ x "loaded #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }.
47
+ select { |name,p| p.is_set?(self) }.
48
+ map { |name,p| "#{name}=#{p.get(self)}" }.
49
+ join(", ") })"
50
+ end
51
+ end
52
+
53
+ context "and a resource with x set to a desired value" do
54
+ let(:resource) do
55
+ e = self
56
+ r = nil
57
+ converge {
58
+ r = public_send(e.resource_name, 'blah') do
59
+ x 'desired'
60
+ end
61
+ }
62
+ r
63
+ end
64
+
65
+ it "current_resource is passed name but not x" do
66
+ expect(resource.current_value.x).to eq 'loaded 2 (name=blah)'
67
+ end
68
+
69
+ it "resource.current_value returns a different resource" do
70
+ expect(resource.current_value.x).to eq 'loaded 2 (name=blah)'
71
+ expect(resource.x).to eq 'desired'
72
+ end
73
+
74
+ it "resource.current_value constructs the resource anew each time" do
75
+ expect(resource.current_value.x).to eq 'loaded 2 (name=blah)'
76
+ expect(resource.current_value.x).to eq 'loaded 3 (name=blah)'
77
+ end
78
+
79
+ it "the provider accesses the current value of x" do
80
+ expect(resource.class.created_x).to eq 'desired'
81
+ end
82
+
83
+ context "and identity: :i and :d with desired_state: false" do
84
+ before {
85
+ resource_class.class_eval do
86
+ property :i, identity: true
87
+ property :d, desired_state: false
88
+ end
89
+ }
90
+
91
+ before {
92
+ resource.i 'desired_i'
93
+ resource.d 'desired_d'
94
+ }
95
+
96
+ it "i, name and d are passed to load_current_value, but not x" do
97
+ expect(resource.current_value.x).to eq 'loaded 2 (d=desired_d, i=desired_i, name=blah)'
98
+ end
99
+ end
100
+
101
+ context "and name_property: :i and :d with desired_state: false" do
102
+ before {
103
+ resource_class.class_eval do
104
+ property :i, name_property: true
105
+ property :d, desired_state: false
106
+ end
107
+ }
108
+
109
+ before {
110
+ resource.i 'desired_i'
111
+ resource.d 'desired_d'
112
+ }
113
+
114
+ it "i, name and d are passed to load_current_value, but not x" do
115
+ expect(resource.current_value.x).to eq 'loaded 2 (d=desired_d, i=desired_i, name=blah)'
116
+ end
117
+ end
118
+ end
119
+
120
+ context "and a resource with no values set" do
121
+ let(:resource) do
122
+ e = self
123
+ r = nil
124
+ converge {
125
+ r = public_send(e.resource_name, 'blah') do
126
+ end
127
+ }
128
+ r
129
+ end
130
+
131
+ it "the provider accesses values from load_current_value" do
132
+ expect(resource.class.created_x).to eq 'loaded 1 (name=blah)'
133
+ end
134
+ end
135
+
136
+ let (:subresource_name) {
137
+ :"load_current_value_subresource_dsl#{Namer.current_index}"
138
+ }
139
+ let (:subresource_class) {
140
+ r = Class.new(resource_class) do
141
+ property :y, default: lazy { "default_y #{Namer.incrementing_value}" }
142
+ end
143
+ r.resource_name subresource_name
144
+ r
145
+ }
146
+
147
+ # Pull on subresource_class to initialize it
148
+ before { subresource_class }
149
+
150
+ let(:subresource) do
151
+ e = self
152
+ r = nil
153
+ converge {
154
+ r = public_send(e.subresource_name, 'blah') do
155
+ x 'desired'
156
+ end
157
+ }
158
+ r
159
+ end
160
+
161
+ context "and a child resource class with no load_current_value" do
162
+ it "the parent load_current_value is used" do
163
+ expect(subresource.current_value.x).to eq 'loaded 2 (name=blah)'
164
+ end
165
+ it "load_current_value yields a copy of the child class" do
166
+ expect(subresource.current_value).to be_kind_of(subresource_class)
167
+ end
168
+ end
169
+
170
+ context "And a child resource class with load_current_value" do
171
+ before {
172
+ subresource_class.load_current_value do
173
+ y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }.
174
+ select { |name,p| p.is_set?(self) }.
175
+ map { |name,p| "#{name}=#{p.get(self)}" }.
176
+ join(", ") })"
177
+ end
178
+ }
179
+
180
+ it "the overridden load_current_value is used" do
181
+ current_resource = subresource.current_value
182
+ expect(current_resource.x).to eq 'default 3'
183
+ expect(current_resource.y).to eq 'loaded_y 2 (name=blah)'
184
+ end
185
+ end
186
+
187
+ context "and a child resource class with load_current_value calling super()" do
188
+ before {
189
+ subresource_class.load_current_value do
190
+ super()
191
+ y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }.
192
+ select { |name,p| p.is_set?(self) }.
193
+ map { |name,p| "#{name}=#{p.get(self)}" }.
194
+ join(", ") })"
195
+ end
196
+ }
197
+
198
+ it "the original load_current_value is called as well as the child one" do
199
+ current_resource = subresource.current_value
200
+ expect(current_resource.x).to eq 'loaded 3 (name=blah)'
201
+ expect(current_resource.y).to eq 'loaded_y 4 (name=blah, x=loaded 3 (name=blah))'
202
+ end
203
+ end
204
+ end
205
+
206
+ end
@@ -73,6 +73,7 @@ require 'spec/support/local_gems.rb' if File.exists?(File.join(File.dirname(__FI
73
73
 
74
74
  # Explicitly require spec helpers that need to load first
75
75
  require 'spec/support/platform_helpers'
76
+ require 'spec/support/shared/unit/mock_shellout'
76
77
 
77
78
  # Autoloads support files
78
79
  # Excludes support/platforms by default
@@ -98,6 +99,7 @@ TEST_PLATFORM_VERSION = TEST_NODE['platform_version']
98
99
 
99
100
  RSpec.configure do |config|
100
101
  config.include(Matchers)
102
+ config.include(MockShellout::RSpec)
101
103
  config.filter_run :focus => true
102
104
  config.filter_run_excluding :external => true
103
105
 
@@ -126,10 +128,14 @@ RSpec.configure do |config|
126
128
  config.filter_run_excluding :mac_osx_only=> true if !mac_osx?
127
129
  config.filter_run_excluding :not_supported_on_win2k3 => true if windows_win2k3?
128
130
  config.filter_run_excluding :not_supported_on_solaris => true if solaris?
131
+ config.filter_run_excluding :not_supported_on_nano => true if windows_nano_server?
129
132
  config.filter_run_excluding :win2k3_only => true unless windows_win2k3?
130
133
  config.filter_run_excluding :windows_2008r2_or_later => true unless windows_2008r2_or_later?
131
134
  config.filter_run_excluding :windows64_only => true unless windows64?
132
135
  config.filter_run_excluding :windows32_only => true unless windows32?
136
+ config.filter_run_excluding :windows_nano_only => true unless windows_nano_server?
137
+ config.filter_run_excluding :ruby64_only => true unless ruby_64bit?
138
+ config.filter_run_excluding :ruby32_only => true unless ruby_32bit?
133
139
  config.filter_run_excluding :windows_powershell_dsc_only => true unless windows_powershell_dsc?
134
140
  config.filter_run_excluding :windows_powershell_no_dsc_only => true unless ! windows_powershell_dsc?
135
141
  config.filter_run_excluding :windows_domain_joined_only => true unless windows_domain_joined?
@@ -183,6 +189,8 @@ RSpec.configure do |config|
183
189
  config.run_all_when_everything_filtered = true
184
190
 
185
191
  config.before(:each) do
192
+ Chef.reset!
193
+
186
194
  Chef::Config.reset
187
195
 
188
196
  # By default, treat deprecation warnings as errors in tests.
@@ -26,6 +26,14 @@ def ruby_20?
26
26
  !!(RUBY_VERSION =~ /^2.0/)
27
27
  end
28
28
 
29
+ def ruby_64bit?
30
+ !!(RbConfig::CONFIG['host_cpu'] =~ /x86_64/)
31
+ end
32
+
33
+ def ruby_32bit?
34
+ !!(RbConfig::CONFIG['host_cpu'] =~ /i686/)
35
+ end
36
+
29
37
  def windows?
30
38
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
31
39
  end
@@ -75,6 +83,11 @@ def windows_powershell_dsc?
75
83
  supports_dsc
76
84
  end
77
85
 
86
+ def windows_nano_server?
87
+ require 'chef/platform/query_helpers'
88
+ Chef::Platform.windows_nano_server?
89
+ end
90
+
78
91
  def mac_osx_106?
79
92
  if File.exists? "/usr/bin/sw_vers"
80
93
  result = ShellHelpers.shell_out("/usr/bin/sw_vers")
@@ -1,6 +1,5 @@
1
1
  #
2
- # Author:: Jay Mundrawala(<jdm@chef.io>)
3
- # Copyright:: Copyright 2015 Chef Software
2
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
3
  # License:: Apache License, Version 2.0
5
4
  #
6
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,16 +15,20 @@
16
15
  # limitations under the License.
17
16
  #
18
17
 
19
- class Chef
20
- module Mixin
21
- module WideString
22
- def wstring(str)
23
- if str.nil? || str.encoding == Encoding::UTF_16LE
24
- str
25
- else
26
- str.to_wstring
27
- end
28
- end
18
+ RSpec.shared_context "Win32" do
19
+ before(:all) do
20
+ @original_win32 = if defined?(Win32)
21
+ win32 = Object.send(:const_get, 'Win32')
22
+ Object.send(:remove_const, 'Win32')
23
+ win32
24
+ else
25
+ nil
29
26
  end
27
+ Win32 = Module.new
28
+ end
29
+
30
+ after(:all) do
31
+ Object.send(:remove_const, 'Win32') if defined?(Win32)
32
+ Object.send(:const_set, 'Win32', @original_win32) if @original_win32
30
33
  end
31
34
  end
@@ -19,14 +19,15 @@
19
19
  # Shared context used by both Powershell and Batch script provider
20
20
  # tests.
21
21
 
22
+ require 'chef/platform/query_helpers'
23
+
22
24
  shared_context Chef::Resource::WindowsScript do
23
25
  before(:all) do
24
-
25
- ohai_reader = Ohai::System.new
26
- ohai_reader.all_plugins("platform")
26
+ @ohai_reader = Ohai::System.new
27
+ @ohai_reader.all_plugins(["platform", "kernel"])
27
28
 
28
29
  new_node = Chef::Node.new
29
- new_node.consume_external_attrs(ohai_reader.data,{})
30
+ new_node.consume_external_attrs(@ohai_reader.data,{})
30
31
 
31
32
  events = Chef::EventDispatch::Dispatcher.new
32
33
 
@@ -51,12 +52,11 @@ shared_context Chef::Resource::WindowsScript do
51
52
 
52
53
  shared_examples_for "a script resource with architecture attribute" do
53
54
  context "with the given architecture attribute value" do
54
- let(:resource_architecture) { architecture }
55
55
  let(:expected_architecture) do
56
- if architecture
57
- expected_architecture = architecture
56
+ if resource_architecture
57
+ expected_architecture = resource_architecture
58
58
  else
59
- expected_architecture = :i386
59
+ expected_architecture = @ohai_reader.data['kernel']['machine'].to_sym
60
60
  end
61
61
  end
62
62
  let(:expected_architecture_output) do
@@ -77,16 +77,16 @@ shared_context Chef::Resource::WindowsScript do
77
77
 
78
78
  before(:each) do
79
79
  resource.code resource_command
80
- (resource.architecture architecture) if architecture
80
+ (resource.architecture resource_architecture) if resource_architecture
81
81
  resource.returns(0)
82
82
  end
83
83
 
84
- it "should create a process with the expected architecture" do
84
+ it "creates a process with the expected architecture" do
85
85
  resource.run_action(:run)
86
86
  expect(get_process_architecture).to eq(expected_architecture_output.downcase)
87
87
  end
88
88
 
89
- it "should execute guards with the same architecture as the resource" do
89
+ it "executes guards with the same architecture as the resource" do
90
90
  resource.only_if resource_guard_command
91
91
  resource.run_action(:run)
92
92
  expect(get_process_architecture).to eq(expected_architecture_output.downcase)
@@ -94,18 +94,32 @@ shared_context Chef::Resource::WindowsScript do
94
94
  expect(get_guard_process_architecture).to eq(get_process_architecture)
95
95
  end
96
96
 
97
- let (:architecture) { :x86_64 }
98
- it "should execute a 64-bit guard if the guard's architecture is specified as 64-bit", :windows64_only do
99
- resource.only_if resource_guard_command, :architecture => :x86_64
100
- resource.run_action(:run)
101
- expect(get_guard_process_architecture).to eq('amd64')
97
+ context "when the guard's architecture is specified as 64-bit" do
98
+ let (:guard_architecture) { :x86_64 }
99
+ it "executes a 64-bit guard", :windows64_only do
100
+ resource.only_if resource_guard_command, :architecture => guard_architecture
101
+ resource.run_action(:run)
102
+ expect(get_guard_process_architecture).to eq('amd64')
103
+ end
102
104
  end
103
105
 
104
- let (:architecture) { :i386 }
105
- it "should execute a 32-bit guard if the guard's architecture is specified as 32-bit" do
106
- resource.only_if resource_guard_command, :architecture => :i386
107
- resource.run_action(:run)
108
- expect(get_guard_process_architecture).to eq('x86')
106
+ context "when the guard's architecture is specified as 32-bit", :not_supported_on_nano do
107
+ let (:guard_architecture) { :i386 }
108
+ it "executes a 32-bit guard" do
109
+ resource.only_if resource_guard_command, :architecture => guard_architecture
110
+ resource.run_action(:run)
111
+ expect(get_guard_process_architecture).to eq('x86')
112
+ end
113
+ end
114
+
115
+ context "when the guard's architecture is specified as 32-bit", :windows_nano_only do
116
+ let (:guard_architecture) { :i386 }
117
+ it "raises an error" do
118
+ resource.only_if resource_guard_command, :architecture => guard_architecture
119
+ expect{ resource.run_action(:run) }.to raise_error(
120
+ Chef::Exceptions::Win32ArchitectureIncorrect,
121
+ /cannot execute script with requested architecture 'i386' on Windows Nano Server/)
122
+ end
109
123
  end
110
124
  end
111
125
  end
@@ -114,7 +128,28 @@ shared_context Chef::Resource::WindowsScript do
114
128
 
115
129
  describe "when the run action is invoked on Windows" do
116
130
  it "executes the script code" do
117
- resource.code("whoami > #{script_output_path}")
131
+ resource.code("whoami > \"#{script_output_path}\"")
132
+ resource.returns(0)
133
+ resource.run_action(:run)
134
+ end
135
+ end
136
+
137
+ context "when $env:TMP has a space" do
138
+ before(:each) do
139
+ @dir = Dir.mktmpdir("Jerry Smith")
140
+ @original_env = ENV.to_hash.dup
141
+ ENV.delete('TMP')
142
+ ENV['TMP'] = @dir
143
+ end
144
+
145
+ after(:each) do
146
+ FileUtils.remove_entry_secure(@dir)
147
+ ENV.clear
148
+ ENV.update(@original_env)
149
+ end
150
+
151
+ it "executes the script code" do
152
+ resource.code("whoami > \"#{script_output_path}\"")
118
153
  resource.returns(0)
119
154
  resource.run_action(:run)
120
155
  end
@@ -122,6 +157,8 @@ shared_context Chef::Resource::WindowsScript do
122
157
 
123
158
  context "when evaluating guards" do
124
159
  it "has a guard_interpreter attribute set to the short name of the resource" do
160
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
161
+
125
162
  expect(resource.guard_interpreter).to eq(resource.resource_name)
126
163
  resource.not_if "findstr.exe /thiscommandhasnonzeroexitstatus"
127
164
  expect(Chef::Resource).to receive(:resource_for_node).and_call_original
@@ -131,17 +168,17 @@ shared_context Chef::Resource::WindowsScript do
131
168
  end
132
169
 
133
170
  context "when the architecture attribute is not set" do
134
- let(:architecture) { nil }
171
+ let(:resource_architecture) { nil }
135
172
  it_behaves_like "a script resource with architecture attribute"
136
173
  end
137
174
 
138
- context "when the architecture attribute is :i386" do
139
- let(:architecture) { :i386 }
175
+ context "when the architecture attribute is :i386", :not_supported_on_nano do
176
+ let(:resource_architecture) { :i386 }
140
177
  it_behaves_like "a script resource with architecture attribute"
141
178
  end
142
179
 
143
180
  context "when the architecture attribute is :x86_64" do
144
- let(:architecture) { :x86_64 }
181
+ let(:resource_architecture) { :x86_64 }
145
182
  it_behaves_like "a script resource with architecture attribute"
146
183
  end
147
184
  end