chef 12.5.1 → 12.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +6 -4
  4. data/Rakefile +1 -4
  5. data/chef-windows.gemspec +21 -0
  6. data/chef.gemspec +58 -0
  7. data/lib/chef/api_client/registration.rb +9 -4
  8. data/lib/chef/application.rb +3 -84
  9. data/lib/chef/application/apply.rb +9 -2
  10. data/lib/chef/application/client.rb +8 -3
  11. data/lib/chef/application/solo.rb +7 -1
  12. data/lib/chef/application/windows_service.rb +21 -6
  13. data/lib/chef/application/windows_service_manager.rb +2 -3
  14. data/lib/chef/audit/runner.rb +1 -0
  15. data/lib/chef/chef_class.rb +1 -11
  16. data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
  17. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
  18. data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
  19. data/lib/chef/client.rb +28 -1
  20. data/lib/chef/cookbook/cookbook_collection.rb +14 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +115 -9
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +6 -2
  25. data/lib/chef/data_bag.rb +1 -1
  26. data/lib/chef/data_bag_item.rb +1 -1
  27. data/lib/chef/digester.rb +5 -1
  28. data/lib/chef/dsl/chef_provisioning.rb +57 -0
  29. data/lib/chef/dsl/cheffish.rb +64 -0
  30. data/lib/chef/dsl/declare_resource.rb +108 -0
  31. data/lib/chef/dsl/platform_introspection.rb +3 -3
  32. data/lib/chef/dsl/recipe.rb +3 -73
  33. data/lib/chef/dsl/resources.rb +27 -1
  34. data/lib/chef/event_dispatch/base.rb +3 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +5 -0
  36. data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
  37. data/lib/chef/exceptions.rb +21 -1
  38. data/lib/chef/file_access_control/unix.rb +12 -12
  39. data/lib/chef/file_content_management/deploy/cp.rb +2 -2
  40. data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
  41. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  42. data/lib/chef/formatters/base.rb +7 -0
  43. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  44. data/lib/chef/formatters/indentable_output_stream.rb +5 -0
  45. data/lib/chef/http.rb +19 -3
  46. data/lib/chef/http/decompressor.rb +2 -2
  47. data/lib/chef/json_compat.rb +1 -0
  48. data/lib/chef/knife.rb +16 -2
  49. data/lib/chef/knife/bootstrap.rb +55 -10
  50. data/lib/chef/knife/cookbook_site_install.rb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +2 -1
  52. data/lib/chef/knife/core/node_presenter.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +30 -16
  54. data/lib/chef/knife/ssl_check.rb +4 -2
  55. data/lib/chef/knife/ssl_fetch.rb +3 -2
  56. data/lib/chef/knife/status.rb +14 -1
  57. data/lib/chef/log.rb +14 -0
  58. data/lib/chef/mixin/get_source_from_package.rb +7 -2
  59. data/lib/chef/mixin/properties.rb +302 -0
  60. data/lib/chef/mixin/proxified_socket.rb +38 -0
  61. data/lib/chef/mixin/subclass_directive.rb +37 -0
  62. data/lib/chef/node.rb +13 -5
  63. data/lib/chef/platform/query_helpers.rb +14 -3
  64. data/lib/chef/platform/service_helpers.rb +20 -38
  65. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  66. data/lib/chef/policy_builder/policyfile.rb +1 -0
  67. data/lib/chef/property.rb +51 -12
  68. data/lib/chef/provider.rb +40 -35
  69. data/lib/chef/provider/deploy.rb +1 -1
  70. data/lib/chef/provider/dsc_resource.rb +54 -20
  71. data/lib/chef/provider/execute.rb +25 -4
  72. data/lib/chef/provider/group.rb +1 -1
  73. data/lib/chef/provider/lwrp_base.rb +1 -0
  74. data/lib/chef/provider/package.rb +76 -30
  75. data/lib/chef/provider/package/dpkg.rb +152 -69
  76. data/lib/chef/provider/package/openbsd.rb +6 -8
  77. data/lib/chef/provider/package/solaris.rb +2 -0
  78. data/lib/chef/provider/package/windows.rb +95 -14
  79. data/lib/chef/provider/package/windows/exe.rb +129 -0
  80. data/lib/chef/provider/package/windows/msi.rb +37 -13
  81. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
  82. data/lib/chef/provider/package/yum.rb +13 -3
  83. data/lib/chef/provider/powershell_script.rb +3 -0
  84. data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
  85. data/lib/chef/provider/remote_file/http.rb +1 -1
  86. data/lib/chef/provider/script.rb +1 -0
  87. data/lib/chef/provider/service.rb +13 -10
  88. data/lib/chef/provider/service/solaris.rb +43 -17
  89. data/lib/chef/provider/service/upstart.rb +3 -3
  90. data/lib/chef/provider/user.rb +1 -1
  91. data/lib/chef/provider/user/dscl.rb +111 -100
  92. data/lib/chef/provider/user/windows.rb +5 -3
  93. data/lib/chef/recipe.rb +3 -5
  94. data/lib/chef/resource.rb +77 -320
  95. data/lib/chef/resource/action_class.rb +4 -0
  96. data/lib/chef/resource/dpkg_package.rb +4 -3
  97. data/lib/chef/resource/dsc_resource.rb +40 -2
  98. data/lib/chef/resource/execute.rb +9 -1
  99. data/lib/chef/resource/ksh.rb +32 -0
  100. data/lib/chef/resource/lwrp_base.rb +6 -10
  101. data/lib/chef/resource/package.rb +8 -9
  102. data/lib/chef/resource/registry_key.rb +1 -1
  103. data/lib/chef/resource/resource_notification.rb +14 -1
  104. data/lib/chef/resource/script.rb +1 -1
  105. data/lib/chef/resource/windows_package.rb +1 -1
  106. data/lib/chef/resource_builder.rb +14 -7
  107. data/lib/chef/resource_reporter.rb +6 -0
  108. data/lib/chef/resources.rb +1 -7
  109. data/lib/chef/rest.rb +1 -1
  110. data/lib/chef/run_context.rb +45 -2
  111. data/lib/chef/run_list/run_list_expansion.rb +47 -0
  112. data/lib/chef/runner.rb +25 -0
  113. data/lib/chef/search/query.rb +16 -2
  114. data/lib/chef/util/diff.rb +2 -2
  115. data/lib/chef/util/powershell/ps_credential.rb +2 -3
  116. data/lib/chef/version.rb +1 -1
  117. data/lib/chef/win32/api/file.rb +51 -1
  118. data/lib/chef/win32/file.rb +5 -0
  119. data/lib/chef/win32/file/version_info.rb +93 -0
  120. data/lib/chef/win32/mutex.rb +1 -1
  121. data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
  122. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
  123. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
  124. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
  125. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
  126. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
  127. data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
  128. data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
  129. data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
  130. data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
  131. data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
  132. data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
  133. data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
  134. data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
  135. data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
  136. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
  137. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
  138. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
  139. data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
  140. data/spec/functional/application_spec.rb +1 -1
  141. data/spec/functional/audit/runner_spec.rb +4 -0
  142. data/spec/functional/knife/ssh_spec.rb +5 -5
  143. data/spec/functional/notifications_spec.rb +74 -4
  144. data/spec/functional/resource/aix_service_spec.rb +2 -2
  145. data/spec/functional/resource/dpkg_package_spec.rb +339 -0
  146. data/spec/functional/resource/ifconfig_spec.rb +3 -1
  147. data/spec/functional/resource/mount_spec.rb +5 -2
  148. data/spec/functional/resource/package_spec.rb +1 -1
  149. data/spec/functional/resource/user/windows_spec.rb +8 -0
  150. data/spec/functional/resource/windows_package_spec.rb +177 -0
  151. data/spec/functional/win32/version_info_spec.rb +50 -0
  152. data/spec/integration/client/client_spec.rb +80 -0
  153. data/spec/integration/knife/download_spec.rb +9 -0
  154. data/spec/integration/knife/upload_spec.rb +28 -1
  155. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
  156. data/spec/integration/recipes/resource_action_spec.rb +211 -116
  157. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
  158. data/spec/integration/solo/solo_spec.rb +34 -0
  159. data/spec/spec_helper.rb +11 -1
  160. data/spec/support/platform_helpers.rb +8 -0
  161. data/spec/support/shared/integration/integration_helper.rb +6 -0
  162. data/spec/support/shared/unit/execute_resource.rb +5 -0
  163. data/spec/support/shared/unit/platform_introspector.rb +7 -0
  164. data/spec/tiny_server.rb +6 -2
  165. data/spec/unit/api_client/registration_spec.rb +5 -4
  166. data/spec/unit/application_spec.rb +1 -181
  167. data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
  168. data/spec/unit/cookbook/metadata_spec.rb +122 -2
  169. data/spec/unit/http_spec.rb +102 -0
  170. data/spec/unit/knife/bootstrap_spec.rb +55 -13
  171. data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
  172. data/spec/unit/knife/ssl_check_spec.rb +7 -3
  173. data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
  174. data/spec/unit/knife/status_spec.rb +13 -13
  175. data/spec/unit/knife_spec.rb +26 -2
  176. data/spec/unit/lwrp_spec.rb +1 -1
  177. data/spec/unit/mixin/properties_spec.rb +97 -0
  178. data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
  179. data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
  180. data/spec/unit/node_spec.rb +9 -1
  181. data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
  182. data/spec/unit/property/validation_spec.rb +14 -12
  183. data/spec/unit/property_spec.rb +56 -0
  184. data/spec/unit/provider/deploy_spec.rb +1 -1
  185. data/spec/unit/provider/dsc_resource_spec.rb +63 -24
  186. data/spec/unit/provider/execute_spec.rb +95 -28
  187. data/spec/unit/provider/package/dpkg_spec.rb +185 -96
  188. data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
  189. data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
  190. data/spec/unit/provider/package/windows_spec.rb +227 -26
  191. data/spec/unit/provider/package/yum_spec.rb +6 -0
  192. data/spec/unit/provider/package_spec.rb +495 -366
  193. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
  194. data/spec/unit/provider/script_spec.rb +2 -2
  195. data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
  196. data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
  197. data/spec/unit/provider/user/dscl_spec.rb +14 -0
  198. data/spec/unit/provider/user/windows_spec.rb +2 -2
  199. data/spec/unit/provider/user_spec.rb +9 -0
  200. data/spec/unit/provider_resolver_spec.rb +6 -30
  201. data/spec/unit/recipe_spec.rb +46 -20
  202. data/spec/unit/resource/chef_gem_spec.rb +1 -1
  203. data/spec/unit/resource/dsc_resource_spec.rb +14 -3
  204. data/spec/unit/resource/ksh_spec.rb +40 -0
  205. data/spec/unit/resource/registry_key_spec.rb +2 -2
  206. data/spec/unit/resource/resource_notification_spec.rb +44 -45
  207. data/spec/unit/resource_reporter_spec.rb +7 -0
  208. data/spec/unit/resource_spec.rb +268 -253
  209. data/spec/unit/rest_spec.rb +2 -2
  210. data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
  211. data/spec/unit/search/query_spec.rb +19 -1
  212. data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
  213. data/spec/unit/windows_service_spec.rb +83 -38
  214. data/tasks/external_tests.rb +19 -9
  215. data/tasks/rspec.rb +1 -1
  216. metadata +64 -15
  217. data/spec/support/pedant/Gemfile +0 -3
  218. data/spec/support/pedant/pedant_config.rb +0 -129
  219. data/spec/support/pedant/run_pedant.rb +0 -63
  220. data/spec/support/pedant/stickywicket.pem +0 -27
  221. data/spec/unit/provider/package_spec.rbe +0 -0
@@ -20,12 +20,12 @@ require 'spec_helper'
20
20
  require 'uri'
21
21
 
22
22
  CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH = 64
23
- CACHE_FILE_MD5_HEX_LENGTH = 32
23
+ CACHE_FILE_CHECKSUM_HEX_LENGTH = 32
24
24
  CACHE_FILE_JSON_FILE_EXTENSION_LENGTH = 5
25
25
  CACHE_FILE_PATH_LIMIT =
26
26
  CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH +
27
27
  1 +
28
- CACHE_FILE_MD5_HEX_LENGTH +
28
+ CACHE_FILE_CHECKSUM_HEX_LENGTH +
29
29
  CACHE_FILE_JSON_FILE_EXTENSION_LENGTH # {friendly}-{md5hex}.json == 102
30
30
 
31
31
  describe Chef::Provider::RemoteFile::CacheControlData do
@@ -36,7 +36,8 @@ describe Chef::Provider::RemoteFile::CacheControlData do
36
36
  Chef::Provider::RemoteFile::CacheControlData.load_and_validate(uri, current_file_checksum)
37
37
  end
38
38
 
39
- let(:cache_path) { "remote_file/http___www_google_com_robots_txt-9839677abeeadf0691026e0cabca2339.json" }
39
+ let(:cache_path) { "remote_file/http___www_google_com_robots_txt-6dc1b24315d0cff764d30344199c6f7b.json" }
40
+ let(:old_cache_path) { "remote_file/http___www_google_com_robots_txt-9839677abeeadf0691026e0cabca2339.json" }
40
41
 
41
42
  # the checksum of the file we have on disk already
42
43
  let(:current_file_checksum) { "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }
@@ -44,7 +45,8 @@ describe Chef::Provider::RemoteFile::CacheControlData do
44
45
  context "when loading data for an unknown URI" do
45
46
 
46
47
  before do
47
- expect(Chef::FileCache).to receive(:load).with(cache_path).and_raise(Chef::Exceptions::FileNotFound, "nope")
48
+ expect(Chef::FileCache).to receive(:has_key?).with(cache_path).and_return(false)
49
+ expect(Chef::FileCache).to receive(:has_key?).with(old_cache_path).and_return(false)
48
50
  end
49
51
 
50
52
  context "and there is no current copy of the file" do
@@ -64,7 +66,8 @@ describe Chef::Provider::RemoteFile::CacheControlData do
64
66
  context "and the URI contains a password" do
65
67
 
66
68
  let(:uri) { URI.parse("http://bob:password@example.org/") }
67
- let(:cache_path) { "remote_file/http___bob_XXXX_example_org_-f121caacb74c05a35bcefdf578ed5fc9.json" }
69
+ let(:cache_path) { "remote_file/http___bob_XXXX_example_org_-44be109aa176a165ef599c12d97af792.json" }
70
+ let(:old_cache_path) { "remote_file/http___bob_XXXX_example_org_-f121caacb74c05a35bcefdf578ed5fc9.json" }
68
71
 
69
72
  it "loads the cache data from a path based on a sanitized URI" do
70
73
  Chef::Provider::RemoteFile::CacheControlData.load_and_validate(uri, current_file_checksum)
@@ -88,51 +91,73 @@ describe Chef::Provider::RemoteFile::CacheControlData do
88
91
  Chef::JSONCompat.to_json(cache)
89
92
  end
90
93
 
91
- before do
92
- expect(Chef::FileCache).to receive(:load).with(cache_path).and_return(cache_json_data)
93
- end
94
-
95
- context "and there is no on-disk copy of the file" do
96
- let(:current_file_checksum) { nil }
97
-
98
- it "returns empty cache control data" do
99
- expect(cache_control_data.etag).to be_nil
100
- expect(cache_control_data.mtime).to be_nil
94
+ context "when the cache control data uses sha256 for its name" do
95
+ before do
96
+ expect(Chef::FileCache).to receive(:has_key?).with(cache_path).and_return(true)
97
+ expect(Chef::FileCache).to receive(:load).with(cache_path).and_return(cache_json_data)
101
98
  end
102
- end
103
99
 
104
- context "and the cached checksum does not match the on-disk copy" do
105
- let(:current_file_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" }
100
+ context "and there is no on-disk copy of the file" do
101
+ let(:current_file_checksum) { nil }
106
102
 
107
- it "returns empty cache control data" do
108
- expect(cache_control_data.etag).to be_nil
109
- expect(cache_control_data.mtime).to be_nil
103
+ it "returns empty cache control data" do
104
+ expect(cache_control_data.etag).to be_nil
105
+ expect(cache_control_data.mtime).to be_nil
106
+ end
110
107
  end
111
- end
112
108
 
113
- context "and the cached checksum matches the on-disk copy" do
109
+ context "and the cached checksum does not match the on-disk copy" do
110
+ let(:current_file_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" }
114
111
 
115
- it "populates the cache control data" do
116
- expect(cache_control_data.etag).to eq(etag)
117
- expect(cache_control_data.mtime).to eq(mtime)
112
+ it "returns empty cache control data" do
113
+ expect(cache_control_data.etag).to be_nil
114
+ expect(cache_control_data.mtime).to be_nil
115
+ end
118
116
  end
119
- end
120
-
121
- context "and the cached checksum data is corrupted" do
122
- let(:cache_json_data) { '{"foo",,"bar" []}' }
123
117
 
124
- it "returns empty cache control data" do
125
- expect(cache_control_data.etag).to be_nil
126
- expect(cache_control_data.mtime).to be_nil
118
+ context "and the cached checksum matches the on-disk copy" do
119
+ context "when the filename uses sha256" do
120
+ before do
121
+ expect(Chef::FileCache).not_to receive(:has_key?).with(old_cache_path)
122
+ end
123
+ it "populates the cache control data" do
124
+ expect(cache_control_data.etag).to eq(etag)
125
+ expect(cache_control_data.mtime).to eq(mtime)
126
+ end
127
+ end
127
128
  end
128
129
 
129
- context "and it still is valid JSON" do
130
- let(:cache_json_data) { '' }
130
+ context "and the cached checksum data is corrupted" do
131
+ let(:cache_json_data) { '{"foo",,"bar" []}' }
131
132
 
132
133
  it "returns empty cache control data" do
133
134
  expect(cache_control_data.etag).to be_nil
134
135
  expect(cache_control_data.mtime).to be_nil
135
136
  end
137
+
138
+ context "and it still is valid JSON" do
139
+ let(:cache_json_data) { '' }
140
+
141
+ it "returns empty cache control data" do
142
+ expect(cache_control_data.etag).to be_nil
143
+ expect(cache_control_data.mtime).to be_nil
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ context "when the filename uses md5" do
150
+ before do
151
+ expect(Chef::FileCache).to receive(:has_key?).with(cache_path).and_return(false)
152
+ expect(Chef::FileCache).to receive(:has_key?).with(old_cache_path).and_return(true)
153
+ expect(Chef::FileCache).to receive(:load).with(old_cache_path).and_return(cache_json_data)
154
+ end
155
+
156
+ it "populates the cache control data and creates the cache control data file with the correct path" do
157
+ expect(Chef::FileCache).to receive(:store).with(cache_path, cache_json_data)
158
+ expect(Chef::FileCache).to receive(:delete).with(old_cache_path)
159
+ expect(cache_control_data.etag).to eq(etag)
160
+ expect(cache_control_data.mtime).to eq(mtime)
136
161
  end
137
162
  end
138
163
  end
@@ -174,7 +199,8 @@ describe Chef::Provider::RemoteFile::CacheControlData do
174
199
  context "and the URI contains a password" do
175
200
 
176
201
  let(:uri) { URI.parse("http://bob:password@example.org/") }
177
- let(:cache_path) { "remote_file/http___bob_XXXX_example_org_-f121caacb74c05a35bcefdf578ed5fc9.json" }
202
+ let(:cache_path) { "remote_file/http___bob_XXXX_example_org_-44be109aa176a165ef599c12d97af792.json" }
203
+ let(:old_cache_path) { "remote_file/http___bob_XXXX_example_org_-f121caacb74c05a35bcefdf578ed5fc9.json" }
178
204
 
179
205
  it "writes the data to the cache with a sanitized path name" do
180
206
  json_data = cache_control_data.json_data
@@ -88,11 +88,11 @@ describe Chef::Provider::Script, "action_run" do
88
88
 
89
89
  describe "when running the script" do
90
90
  let (:default_opts) {
91
- {timeout: 3600, returns: 0, log_level: :info, log_tag: "script[run some perl code]", live_stream: STDOUT}
91
+ { timeout: 3600, returns: 0, log_level: :info, log_tag: "script[run some perl code]" }
92
92
  }
93
93
 
94
94
  before do
95
- allow(STDOUT).to receive(:tty?).and_return(true)
95
+ allow(STDOUT).to receive(:tty?).and_return(false)
96
96
  end
97
97
 
98
98
  it 'should set the command to "interpreter" "tempfile"' do
@@ -31,66 +31,126 @@ describe Chef::Provider::Service::Solaris do
31
31
  @provider = Chef::Provider::Service::Solaris.new(@new_resource, @run_context)
32
32
  allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource)
33
33
 
34
- @stdin = StringIO.new
35
- @stdout = StringIO.new
36
- @stderr = StringIO.new
37
- @pid = 2342
38
- @stdout_string = "state disabled"
39
- allow(@stdout).to receive(:gets).and_return(@stdout_string)
40
- @status = double("Status", :exitstatus => 0, :stdout => @stdout)
41
- allow(@provider).to receive(:shell_out!).and_return(@status)
34
+ # enabled / started service (svcs -l chef)
35
+ enabled_svc_stdout = [
36
+ 'fmri svc:/application/chef:default',
37
+ 'name chef service',
38
+ 'enabled true',
39
+ 'state online',
40
+ 'next_state none',
41
+ 'state_time April 2, 2015 04:25:19 PM EDT',
42
+ 'logfile /var/svc/log/application-chef:default.log',
43
+ 'restarter svc:/system/svc/restarter:default',
44
+ 'contract_id 1115271',
45
+ 'dependency require_all/error svc:/milestone/multi-user:default (online)'
46
+ ].join("\n")
47
+
48
+ # disabled / stopped service (svcs -l chef)
49
+ disabled_svc_stdout = [
50
+ 'fmri svc:/application/chef:default',
51
+ 'name chef service',
52
+ 'enabled false',
53
+ 'state disabled',
54
+ 'next_state none',
55
+ 'state_time April 2, 2015 04:25:19 PM EDT',
56
+ 'logfile /var/svc/log/application-chef:default.log',
57
+ 'restarter svc:/system/svc/restarter:default',
58
+ 'contract_id 1115271',
59
+ 'dependency require_all/error svc:/milestone/multi-user:default (online)'
60
+ ].join("\n")
61
+
62
+ # disabled / stopped service (svcs -l chef)
63
+ maintenance_svc_stdout = [
64
+ 'fmri svc:/application/chef:default',
65
+ 'name chef service',
66
+ 'enabled true',
67
+ 'state maintenance',
68
+ 'next_state none',
69
+ 'state_time April 2, 2015 04:25:19 PM EDT',
70
+ 'logfile /var/svc/log/application-chef:default.log',
71
+ 'restarter svc:/system/svc/restarter:default',
72
+ 'contract_id 1115271',
73
+ 'dependency require_all/error svc:/milestone/multi-user:default (online)'
74
+ ].join("\n")
75
+
76
+ # shell_out! return value for a service that is running
77
+ @enabled_svc_status = double("Status", :exitstatus => 0, :stdout => enabled_svc_stdout, :stdin => '', :stderr => '')
78
+
79
+ # shell_out! return value for a service that is disabled
80
+ @disabled_svc_status = double("Status", :exitstatus => 0, :stdout => disabled_svc_stdout, :stdin => '', :stderr => '')
81
+
82
+ # shell_out! return value for a service that is in maintenance mode
83
+ @maintenance_svc_status = double("Status", :exitstatus => 0, :stdout => maintenance_svc_stdout, :stdin => '', :stderr => '')
84
+
85
+ # shell_out! return value for a service that does not exist
86
+ @no_svc_status = double("Status", :exitstatus => 1, :stdout => '', :stdin => '', :stderr => "svcs: Pattern 'chef' doesn't match any instances\n")
87
+
88
+ # shell_out! return value for a successful execution
89
+ @success = double("clear", :exitstatus => 0, :stdout => '', :stdin => '', :stderr => '')
42
90
  end
43
91
 
44
- it "should raise an error if /bin/svcs does not exist" do
45
- expect(File).to receive(:exists?).with("/bin/svcs").and_return(false)
92
+ it "should raise an error if /bin/svcs and /usr/sbin/svcadm are not executable" do
93
+ allow(File).to receive(:executable?).with("/bin/svcs").and_return(false)
94
+ allow(File).to receive(:executable?).with("/usr/sbin/svcadm").and_return(false)
46
95
  expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Service)
47
96
  end
48
97
 
49
- describe "on a host with /bin/svcs" do
98
+ it "should raise an error if /bin/svcs is not executable" do
99
+ allow(File).to receive(:executable?).with("/bin/svcs").and_return(false)
100
+ allow(File).to receive(:executable?).with("/usr/sbin/svcadm").and_return(true)
101
+ expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Service)
102
+ end
103
+
104
+ it "should raise an error if /usr/sbin/svcadm is not executable" do
105
+ allow(File).to receive(:executable?).with("/bin/svcs").and_return(true)
106
+ allow(File).to receive(:executable?).with("/usr/sbin/svcadm").and_return(false)
107
+ expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Service)
108
+ end
109
+
110
+ describe "on a host with /bin/svcs and /usr/sbin/svcadm" do
50
111
 
51
112
  before do
52
- allow(File).to receive(:exists?).with('/bin/svcs').and_return(true)
113
+ allow(File).to receive(:executable?).with("/bin/svcs").and_return(true)
114
+ allow(File).to receive(:executable?).with("/usr/sbin/svcadm").and_return(true)
53
115
  end
54
116
 
55
117
  describe "when discovering the current service state" do
56
118
  it "should create a current resource with the name of the new resource" do
57
- allow(@provider).to receive(:shell_out!).with("/bin/svcs -l chef").and_return(@status)
119
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@enabled_svc_status)
58
120
  expect(Chef::Resource::Service).to receive(:new).and_return(@current_resource)
59
121
  @provider.load_current_resource
60
122
  end
61
123
 
62
124
  it "should return the current resource" do
63
- allow(@provider).to receive(:shell_out!).with("/bin/svcs -l chef").and_return(@status)
125
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@enabled_svc_status)
64
126
  expect(@provider.load_current_resource).to eql(@current_resource)
65
127
  end
66
128
 
67
129
  it "should call '/bin/svcs -l service_name'" do
68
- expect(@provider).to receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status)
130
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@enabled_svc_status)
69
131
  @provider.load_current_resource
70
132
  end
71
133
 
72
134
  it "should mark service as not running" do
73
- allow(@provider).to receive(:shell_out!).and_return(@status)
135
+ expect(@provider).to receive(:shell_out!).and_return(@disabled_svc_status)
74
136
  expect(@current_resource).to receive(:running).with(false)
75
137
  @provider.load_current_resource
76
138
  end
77
139
 
78
140
  it "should mark service as running" do
79
- @status = double("Status", :exitstatus => 0, :stdout => 'state online')
80
- allow(@provider).to receive(:shell_out!).and_return(@status)
141
+ expect(@provider).to receive(:shell_out!).and_return(@enabled_svc_status)
81
142
  expect(@current_resource).to receive(:running).with(true)
82
143
  @provider.load_current_resource
83
144
  end
84
145
 
85
146
  it "should not mark service as maintenance" do
86
- allow(@provider).to receive(:shell_out!).and_return(@status)
147
+ expect(@provider).to receive(:shell_out!).and_return(@enabled_svc_status)
87
148
  @provider.load_current_resource
88
149
  expect(@provider.maintenance).to be_falsey
89
150
  end
90
151
 
91
152
  it "should mark service as maintenance" do
92
- @status = double("Status", :exitstatus => 0, :stdout => 'state maintenance')
93
- allow(@provider).to receive(:shell_out!).and_return(@status)
153
+ expect(@provider).to receive(:shell_out!).and_return(@maintenance_svc_status)
94
154
  @provider.load_current_resource
95
155
  expect(@provider.maintenance).to be_truthy
96
156
  end
@@ -99,30 +159,41 @@ describe Chef::Provider::Service::Solaris do
99
159
  describe "when enabling the service" do
100
160
  before(:each) do
101
161
  @provider.current_resource = @current_resource
102
- @current_resource.enabled(true)
103
162
  end
104
163
 
105
164
  it "should call svcadm enable -s chef" do
106
- expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}")
107
- expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status)
165
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@enabled_svc_status)
166
+ expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name)
167
+ expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success)
168
+ @provider.load_current_resource
169
+
108
170
  expect(@provider.enable_service).to be_truthy
109
171
  expect(@current_resource.enabled).to be_truthy
110
172
  end
111
173
 
112
174
  it "should call svcadm enable -s chef for start_service" do
113
- expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}")
114
- expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status)
175
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@enabled_svc_status)
176
+ expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name)
177
+ expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success)
178
+ @provider.load_current_resource
115
179
  expect(@provider.start_service).to be_truthy
116
180
  expect(@current_resource.enabled).to be_truthy
117
181
  end
118
182
 
119
183
  it "should call svcadm clear chef for start_service when state maintenance" do
120
- @status = double("Status", :exitstatus => 0, :stdout => 'state maintenance')
121
- allow(@provider).to receive(:shell_out!).and_return(@status)
184
+ # we are in maint mode
185
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@maintenance_svc_status)
186
+ expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name).and_return(@success)
187
+ expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success)
188
+
189
+ # load the resource, then enable it
122
190
  @provider.load_current_resource
123
- expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}").and_return(@status)
124
- expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status)
125
191
  expect(@provider.enable_service).to be_truthy
192
+
193
+ # now we are enabled
194
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@enabled_svc_status)
195
+ @provider.load_current_resource
196
+
126
197
  expect(@current_resource.enabled).to be_truthy
127
198
  end
128
199
  end
@@ -130,17 +201,20 @@ describe Chef::Provider::Service::Solaris do
130
201
  describe "when disabling the service" do
131
202
  before(:each) do
132
203
  @provider.current_resource = @current_resource
133
- @current_resource.enabled(false)
134
204
  end
135
205
 
136
206
  it "should call svcadm disable -s chef" do
137
- expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm disable -s chef").and_return(@status)
207
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@disabled_svc_status)
208
+ expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "disable", "-s", "chef").and_return(@success)
209
+ @provider.load_current_resource
138
210
  expect(@provider.disable_service).to be_truthy
139
211
  expect(@current_resource.enabled).to be_falsey
140
212
  end
141
213
 
142
214
  it "should call svcadm disable -s chef for stop_service" do
143
- expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm disable -s chef").and_return(@status)
215
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@disabled_svc_status)
216
+ expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "disable", "-s", "chef").and_return(@success)
217
+ @provider.load_current_resource
144
218
  expect(@provider.stop_service).to be_truthy
145
219
  expect(@current_resource.enabled).to be_falsey
146
220
  end
@@ -149,12 +223,12 @@ describe Chef::Provider::Service::Solaris do
149
223
 
150
224
  describe "when reloading the service" do
151
225
  before(:each) do
152
- @status = double("Process::Status", :exitstatus => 0)
153
226
  @provider.current_resource = @current_resource
227
+ allow(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@enabled_svc_status)
154
228
  end
155
229
 
156
230
  it "should call svcadm refresh chef" do
157
- expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/svcadm refresh chef").and_return(@status)
231
+ expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "refresh", "chef")
158
232
  @provider.reload_service
159
233
  end
160
234
 
@@ -162,19 +236,16 @@ describe Chef::Provider::Service::Solaris do
162
236
 
163
237
  describe "when the service doesn't exist" do
164
238
  before(:each) do
165
- @stdout_string = ""
166
- @status = double("Status", :exitstatus => 1, :stdout => @stdout)
167
239
  @provider.current_resource = @current_resource
240
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", {:returns=>[0, 1]}).and_return(@no_svc_status)
168
241
  end
169
242
 
170
243
  it "should be marked not running" do
171
- expect(@provider).to receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status)
172
244
  @provider.service_status
173
245
  expect(@current_resource.running).to be_falsey
174
246
  end
175
247
 
176
248
  it "should be marked not enabled" do
177
- expect(@provider).to receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status)
178
249
  @provider.service_status
179
250
  expect(@current_resource.enabled).to be_falsey
180
251
  end
@@ -123,6 +123,25 @@ describe Chef::Provider::Service::Upstart do
123
123
  end
124
124
  end
125
125
 
126
+ describe "when the status command uses the new format with an instance" do
127
+ before do
128
+ end
129
+
130
+ it "should set running to true if the status command returns 0" do
131
+ @stdout = StringIO.new("rsyslog (test) start/running, process 100")
132
+ allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
133
+ @provider.load_current_resource
134
+ expect(@current_resource.running).to be_truthy
135
+ end
136
+
137
+ it "should set running to false if the status command returns anything except 0" do
138
+ @stdout = StringIO.new("rsyslog (test) stop/waiting, process 100")
139
+ allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
140
+ @provider.load_current_resource
141
+ expect(@current_resource.running).to be_falsey
142
+ end
143
+ end
144
+
126
145
  describe "when the status command uses the old format" do
127
146
  it "should set running to true if the status command returns 0" do
128
147
  @stdout = StringIO.new("rsyslog (start) running, process 32225")