chef 12.0.0.alpha.1-x86-mingw32 → 12.0.0.alpha.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/application.rb +8 -1
- data/lib/chef/application/apply.rb +4 -0
- data/lib/chef/application/client.rb +7 -7
- data/lib/chef/application/solo.rb +21 -13
- data/lib/chef/chef_fs/chef_fs_data_store.rb +60 -6
- data/lib/chef/chef_fs/config.rb +78 -4
- data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +2 -2
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/data_handler_base.rb +76 -2
- data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +30 -0
- data/lib/chef/chef_fs/data_handler/organization_invites_data_handler.rb +17 -0
- data/lib/chef/chef_fs/data_handler/organization_members_data_handler.rb +17 -0
- data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/user_data_handler.rb +2 -1
- data/lib/chef/chef_fs/file_system.rb +0 -1
- data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +5 -1
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +73 -13
- data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +44 -5
- data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -3
- data/lib/chef/chef_fs/file_system/org_entry.rb +34 -0
- data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +58 -0
- data/lib/chef/chef_fs/file_system/organization_members_entry.rb +57 -0
- data/lib/chef/chef_fs/file_system/rest_list_entry.rb +13 -4
- data/lib/chef/chef_fs/knife.rb +1 -1
- data/lib/chef/client.rb +8 -2
- data/lib/chef/config.rb +75 -57
- data/lib/chef/config_fetcher.rb +6 -21
- data/lib/chef/dsl/data_query.rb +48 -3
- data/lib/chef/dsl/platform_introspection.rb +42 -0
- data/lib/chef/dsl/reboot_pending.rb +6 -3
- data/lib/chef/encrypted_data_bag_item.rb +1 -1
- data/lib/chef/encrypted_data_bag_item/encryptor.rb +12 -0
- data/lib/chef/exceptions.rb +2 -0
- data/lib/chef/http/basic_client.rb +14 -0
- data/lib/chef/http/json_output.rb +7 -2
- data/lib/chef/knife.rb +36 -121
- data/lib/chef/knife/bootstrap.rb +68 -54
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +6 -1
- data/lib/chef/knife/bootstrap/chef-aix.erb +5 -0
- data/lib/chef/knife/bootstrap/chef-full.erb +5 -1
- data/lib/chef/knife/core/bootstrap_context.rb +70 -29
- data/lib/chef/knife/search.rb +56 -12
- data/lib/chef/knife/serve.rb +1 -1
- data/lib/chef/local_mode.rb +10 -4
- data/lib/chef/mixin/deep_merge.rb +6 -3
- data/lib/chef/mixin/shell_out.rb +33 -17
- data/lib/chef/null_logger.rb +72 -0
- data/lib/chef/platform.rb +2 -1
- data/lib/chef/platform/provider_mapping.rb +1 -1
- data/lib/chef/platform/rebooter.rb +54 -0
- data/lib/chef/provider/ifconfig.rb +15 -16
- data/lib/chef/provider/link.rb +1 -1
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/mount/solaris.rb +102 -64
- data/lib/chef/provider/package/aix.rb +4 -12
- data/lib/chef/provider/package/ips.rb +8 -12
- data/lib/chef/provider/package/macports.rb +4 -12
- data/lib/chef/provider/package/pacman.rb +2 -6
- data/lib/chef/provider/package/portage.rb +2 -6
- data/lib/chef/provider/package/rpm.rb +4 -12
- data/lib/chef/provider/package/solaris.rb +4 -12
- data/lib/chef/provider/reboot.rb +69 -0
- data/lib/chef/provider/service/debian.rb +10 -10
- data/lib/chef/provider/service/freebsd.rb +89 -73
- data/lib/chef/provider/service/gentoo.rb +2 -2
- data/lib/chef/provider/service/init.rb +6 -4
- data/lib/chef/provider/service/insserv.rb +3 -3
- data/lib/chef/provider/service/macosx.rb +2 -2
- data/lib/chef/provider/service/simple.rb +6 -4
- data/lib/chef/provider/service/solaris.rb +1 -1
- data/lib/chef/provider/service/systemd.rb +9 -9
- data/lib/chef/provider/service/upstart.rb +6 -6
- data/lib/chef/provider/subversion.rb +6 -6
- data/lib/chef/provider/user/dscl.rb +32 -28
- data/lib/chef/provider/user/windows.rb +6 -6
- data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/recipe.rb +0 -1
- data/lib/chef/resource.rb +3 -5
- data/lib/chef/resource/mount.rb +9 -0
- data/lib/chef/resource/reboot.rb +48 -0
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/run_context.rb +25 -0
- data/lib/chef/search/query.rb +122 -14
- data/lib/chef/util/path_helper.rb +54 -6
- data/lib/chef/util/windows/net_user.rb +4 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api/file.rb +1 -5
- data/lib/chef/win32/api/net.rb +1 -0
- data/lib/chef/workstation_config_loader.rb +177 -0
- data/spec/functional/http/simple_spec.rb +57 -1
- data/spec/functional/mixin/shell_out_spec.rb +2 -2
- data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +51 -0
- data/spec/functional/rebooter_spec.rb +105 -0
- data/spec/functional/resource/deploy_revision_spec.rb +0 -4
- data/spec/functional/resource/file_spec.rb +26 -3
- data/spec/functional/resource/group_spec.rb +5 -3
- data/spec/functional/resource/link_spec.rb +16 -16
- data/spec/functional/resource/reboot_spec.rb +103 -0
- data/spec/integration/client/client_spec.rb +4 -8
- data/spec/integration/client/ipv6_spec.rb +1 -1
- data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -2
- data/spec/integration/knife/delete_spec.rb +39 -0
- data/spec/integration/knife/deps_spec.rb +30 -20
- data/spec/integration/knife/download_spec.rb +77 -1
- data/spec/integration/knife/list_spec.rb +221 -0
- data/spec/integration/knife/raw_spec.rb +1 -1
- data/spec/integration/knife/show_spec.rb +2 -2
- data/spec/integration/knife/upload_spec.rb +154 -1
- data/spec/support/pedant/run_pedant.rb +0 -1
- data/spec/support/shared/functional/http.rb +8 -1
- data/spec/support/shared/integration/integration_helper.rb +11 -19
- data/spec/support/shared/unit/platform_introspector.rb +22 -0
- data/spec/unit/application/apply.rb +11 -1
- data/spec/unit/application/solo_spec.rb +19 -3
- data/spec/unit/chef_fs/config_spec.rb +58 -0
- data/spec/unit/config_fetcher_spec.rb +1 -3
- data/spec/unit/config_spec.rb +247 -220
- data/spec/unit/dsl/data_query_spec.rb +165 -23
- data/spec/unit/dsl/reboot_pending_spec.rb +1 -7
- data/spec/unit/encrypted_data_bag_item_spec.rb +1 -1
- data/spec/unit/knife/bootstrap_spec.rb +354 -182
- data/spec/unit/knife/core/bootstrap_context_spec.rb +67 -30
- data/spec/unit/knife_spec.rb +3 -30
- data/spec/unit/mixin/deep_merge_spec.rb +14 -0
- data/spec/unit/mixin/shell_out_spec.rb +134 -64
- data/spec/unit/provider/ifconfig/debian_spec.rb +19 -9
- data/spec/unit/provider/ifconfig/redhat_spec.rb +16 -14
- data/spec/unit/provider/ifconfig_spec.rb +3 -3
- data/spec/unit/provider/link_spec.rb +5 -5
- data/spec/unit/provider/mount/mount_spec.rb +10 -1
- data/spec/unit/provider/mount/solaris_spec.rb +185 -11
- data/spec/unit/provider/package/aix_spec.rb +5 -17
- data/spec/unit/provider/package/ips_spec.rb +8 -21
- data/spec/unit/provider/package/macports_spec.rb +12 -12
- data/spec/unit/provider/package/pacman_spec.rb +4 -12
- data/spec/unit/provider/package/portage_spec.rb +5 -15
- data/spec/unit/provider/package/rpm_spec.rb +7 -22
- data/spec/unit/provider/package/solaris_spec.rb +5 -16
- data/spec/unit/provider/service/arch_service_spec.rb +8 -14
- data/spec/unit/provider/service/debian_service_spec.rb +1 -1
- data/spec/unit/provider/service/freebsd_service_spec.rb +457 -225
- data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
- data/spec/unit/provider/service/init_service_spec.rb +10 -10
- data/spec/unit/provider/service/insserv_service_spec.rb +3 -4
- data/spec/unit/provider/service/invokercd_service_spec.rb +8 -9
- data/spec/unit/provider/service/macosx_spec.rb +5 -5
- data/spec/unit/provider/service/simple_service_spec.rb +4 -6
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +1 -3
- data/spec/unit/provider/service/systemd_service_spec.rb +20 -20
- data/spec/unit/provider/service/upstart_service_spec.rb +15 -17
- data/spec/unit/provider/subversion_spec.rb +5 -6
- data/spec/unit/provider/user/dscl_spec.rb +2 -1
- data/spec/unit/provider/user/windows_spec.rb +7 -0
- data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
- data/spec/unit/resource/mount_spec.rb +9 -0
- data/spec/unit/resource_spec.rb +0 -4
- data/spec/unit/rest_spec.rb +1 -1
- data/spec/unit/run_context_spec.rb +15 -0
- data/spec/unit/search/query_spec.rb +196 -40
- data/spec/unit/util/path_helper_spec.rb +111 -28
- data/spec/unit/workstation_config_loader_spec.rb +283 -0
- metadata +36 -20
- data/lib/chef/knife/bootstrap/centos5-gems.erb +0 -62
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +0 -44
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +0 -53
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +0 -48
- data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +0 -46
- data/spec/support/shared/integration/chef_zero_support.rb +0 -130
- data/spec/unit/knife/config_file_selection_spec.rb +0 -135
@@ -33,10 +33,6 @@ describe Chef::Knife::Core::BootstrapContext do
|
|
33
33
|
|
34
34
|
subject(:bootstrap_context) { described_class.new(config, run_list, chef_config) }
|
35
35
|
|
36
|
-
it "installs the same version of chef on the remote host" do
|
37
|
-
bootstrap_context.bootstrap_version_string.should eq "--version #{Chef::VERSION}"
|
38
|
-
end
|
39
|
-
|
40
36
|
it "runs chef with the first-boot.json in the _default environment" do
|
41
37
|
bootstrap_context.start_chef.should eq "chef-client -j /etc/chef/first-boot.json -E _default"
|
42
38
|
end
|
@@ -95,24 +91,6 @@ EXPECTED
|
|
95
91
|
end
|
96
92
|
end
|
97
93
|
|
98
|
-
describe "when installing a prerelease version of chef" do
|
99
|
-
let(:config){ {:prerelease => true }}
|
100
|
-
it "supplies --prerelease as the version string" do
|
101
|
-
bootstrap_context.bootstrap_version_string.should eq '--prerelease'
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "when installing an explicit version of chef" do
|
106
|
-
let(:chef_config) do
|
107
|
-
{
|
108
|
-
:knife => { :bootstrap_version => '123.45.678' }
|
109
|
-
}
|
110
|
-
end
|
111
|
-
it "gives --version $VERSION as the version string" do
|
112
|
-
bootstrap_context.bootstrap_version_string.should eq '--version 123.45.678'
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
94
|
describe "when JSON attributes are given" do
|
117
95
|
let(:config) { {:first_boot_attributes => {:baz => :quux}} }
|
118
96
|
it "adds the attributes to first_boot" do
|
@@ -141,7 +119,20 @@ EXPECTED
|
|
141
119
|
context "via config[:secret_file]" do
|
142
120
|
let(:chef_config) do
|
143
121
|
{
|
144
|
-
:knife => {:secret_file =>
|
122
|
+
:knife => {:secret_file => secret_file}
|
123
|
+
}
|
124
|
+
end
|
125
|
+
it "reads the encrypted_data_bag_secret" do
|
126
|
+
bootstrap_context.encrypted_data_bag_secret.should eq IO.read(secret_file)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "via config[:secret_file] with short home path" do
|
131
|
+
let(:chef_config) do
|
132
|
+
home_path = File.expand_path("~")
|
133
|
+
shorted_secret_file_path = secret_file.gsub(home_path, "~")
|
134
|
+
{
|
135
|
+
:knife => {:secret_file => shorted_secret_file_path}
|
145
136
|
}
|
146
137
|
end
|
147
138
|
it "reads the encrypted_data_bag_secret" do
|
@@ -158,13 +149,6 @@ EXPECTED
|
|
158
149
|
it "sets the @run_list instance variable" do
|
159
150
|
bootstrap_context.instance_variable_get(:@run_list).should eq run_list
|
160
151
|
end
|
161
|
-
|
162
|
-
describe "accepts encrypted_data_bag_secret via Chef::Config" do
|
163
|
-
let(:chef_config) { {:encrypted_data_bag_secret => secret_file }}
|
164
|
-
it "reads the encrypted_data_bag_secret" do
|
165
|
-
bootstrap_context.encrypted_data_bag_secret.should eq IO.read(secret_file)
|
166
|
-
end
|
167
|
-
end
|
168
152
|
end
|
169
153
|
|
170
154
|
describe "when a bootstrap_version is specified" do
|
@@ -197,4 +181,57 @@ EXPECTED
|
|
197
181
|
bootstrap_context.latest_current_chef_version_string.should eq("-v #{Chef::VERSION.to_i}")
|
198
182
|
end
|
199
183
|
end
|
184
|
+
|
185
|
+
describe "ssl_verify_mode" do
|
186
|
+
it "isn't set in the config_content by default" do
|
187
|
+
bootstrap_context.config_content.should_not include("ssl_verify_mode")
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "when configured in config" do
|
191
|
+
let(:chef_config) do
|
192
|
+
{
|
193
|
+
:knife => {:ssl_verify_mode => :verify_peer}
|
194
|
+
}
|
195
|
+
end
|
196
|
+
|
197
|
+
it "uses the config value" do
|
198
|
+
bootstrap_context.config_content.should include("ssl_verify_mode :verify_peer")
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "when configured via CLI" do
|
202
|
+
let(:config) {{:node_ssl_verify_mode => "none"}}
|
203
|
+
|
204
|
+
it "uses CLI value" do
|
205
|
+
bootstrap_context.config_content.should include("ssl_verify_mode :verify_none")
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "verify_api_cert" do
|
212
|
+
it "isn't set in the config_content by default" do
|
213
|
+
bootstrap_context.config_content.should_not include("verify_api_cert")
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "when configured in config" do
|
217
|
+
let(:chef_config) do
|
218
|
+
{
|
219
|
+
:knife => {:verify_api_cert => :false}
|
220
|
+
}
|
221
|
+
end
|
222
|
+
|
223
|
+
it "uses the config value" do
|
224
|
+
bootstrap_context.config_content.should include("verify_api_cert false")
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "when configured via CLI" do
|
228
|
+
let(:config) {{:node_verify_api_cert => true}}
|
229
|
+
|
230
|
+
it "uses CLI value" do
|
231
|
+
bootstrap_context.config_content.should include("verify_api_cert true")
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
200
237
|
end
|
data/spec/unit/knife_spec.rb
CHANGED
@@ -44,34 +44,6 @@ describe Chef::Knife do
|
|
44
44
|
@stderr = StringIO.new
|
45
45
|
end
|
46
46
|
|
47
|
-
describe "selecting a config file" do
|
48
|
-
context "when the current working dir is inside a symlinked directory" do
|
49
|
-
before do
|
50
|
-
Chef::Knife.reset_config_path!
|
51
|
-
# pwd according to your shell is /home/someuser/prod/chef-repo, but
|
52
|
-
# chef-repo is a symlink to /home/someuser/codes/chef-repo
|
53
|
-
if Chef::Platform.windows?
|
54
|
-
ENV.should_receive(:[]).with("CD").and_return("/home/someuser/prod/chef-repo")
|
55
|
-
else
|
56
|
-
ENV.should_receive(:[]).with("PWD").and_return("/home/someuser/prod/chef-repo")
|
57
|
-
end
|
58
|
-
|
59
|
-
Dir.stub(:pwd).and_return("/home/someuser/codes/chef-repo")
|
60
|
-
end
|
61
|
-
|
62
|
-
after do
|
63
|
-
Chef::Knife.reset_config_path!
|
64
|
-
end
|
65
|
-
|
66
|
-
it "loads the config from the non-dereferenced directory path" do
|
67
|
-
File.should_receive(:exist?).with("/home/someuser/prod/chef-repo/.chef").and_return(false)
|
68
|
-
File.should_receive(:exist?).with("/home/someuser/prod/.chef").and_return(true)
|
69
|
-
File.should_receive(:directory?).with("/home/someuser/prod/.chef").and_return(true)
|
70
|
-
Chef::Knife.chef_config_dir.should == "/home/someuser/prod/.chef"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
47
|
describe "after loading a subcommand" do
|
76
48
|
before do
|
77
49
|
Chef::Knife.reset_subcommands!
|
@@ -247,7 +219,7 @@ describe Chef::Knife do
|
|
247
219
|
end
|
248
220
|
|
249
221
|
it "loads lazy dependencies" do
|
250
|
-
|
222
|
+
Chef::Knife.run(%w{test yourself})
|
251
223
|
KnifeSpecs::TestYourself.test_deps_loaded.should be_true
|
252
224
|
end
|
253
225
|
|
@@ -256,7 +228,8 @@ describe Chef::Knife do
|
|
256
228
|
KnifeSpecs::TestYourself.class_eval do
|
257
229
|
deps { other_deps_loaded = true }
|
258
230
|
end
|
259
|
-
|
231
|
+
|
232
|
+
Chef::Knife.run(%w{test yourself})
|
260
233
|
KnifeSpecs::TestYourself.test_deps_loaded.should be_true
|
261
234
|
other_deps_loaded.should be_true
|
262
235
|
end
|
@@ -236,6 +236,20 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
|
|
236
236
|
@dm.deep_merge!(hash_src, hash_dst)
|
237
237
|
hash_dst.should == {"item" => "orange"}
|
238
238
|
end
|
239
|
+
|
240
|
+
it 'should overwrite hashes with nil' do
|
241
|
+
hash_src = {"item" => { "1" => "2"}, "other" => true }
|
242
|
+
hash_dst = {"item" => nil }
|
243
|
+
@dm.deep_merge!(hash_src, hash_dst)
|
244
|
+
hash_dst.should == {"item" => nil, "other" => true }
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should overwrite strings with nil' do
|
248
|
+
hash_src = {"item" => "to_overwrite", "other" => false }
|
249
|
+
hash_dst = {"item" => nil }
|
250
|
+
@dm.deep_merge!(hash_src, hash_dst)
|
251
|
+
hash_dst.should == {"item" => nil, "other" => false }
|
252
|
+
end
|
239
253
|
end # deep_merge!
|
240
254
|
|
241
255
|
# Chef specific
|
@@ -32,7 +32,7 @@ describe Chef::Mixin::ShellOut do
|
|
32
32
|
|
33
33
|
let(:output) { StringIO.new }
|
34
34
|
let!(:capture_log_output) { Chef::Log.logger = Logger.new(output) }
|
35
|
-
let(:assume_deprecation_log_level) { Chef::Log.
|
35
|
+
let(:assume_deprecation_log_level) { allow(Chef::Log).to receive(:level).and_return(:warn) }
|
36
36
|
|
37
37
|
context 'without options' do
|
38
38
|
let(:command_args) { [ cmd ] }
|
@@ -55,9 +55,9 @@ describe Chef::Mixin::ShellOut do
|
|
55
55
|
it 'should emit a deprecation warning' do
|
56
56
|
assume_deprecation_log_level and capture_log_output
|
57
57
|
subject
|
58
|
-
output.string.
|
59
|
-
output.string.
|
60
|
-
output.string.
|
58
|
+
expect(output.string).to match /DEPRECATION:/
|
59
|
+
expect(output.string).to match Regexp.escape(old_option.to_s)
|
60
|
+
expect(output.string).to match Regexp.escape(new_option.to_s)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -106,7 +106,7 @@ describe Chef::Mixin::ShellOut do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
context "when testing individual methods" do
|
110
110
|
before(:each) do
|
111
111
|
@original_env = ENV.to_hash
|
112
112
|
ENV.clear
|
@@ -120,82 +120,152 @@ describe Chef::Mixin::ShellOut do
|
|
120
120
|
let(:shell_out) { Chef::Mixin::ShellOut }
|
121
121
|
let(:cmd) { "echo '#{rand(1000)}'" }
|
122
122
|
|
123
|
-
describe "
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
123
|
+
describe "#shell_out" do
|
124
|
+
|
125
|
+
describe "when the last argument is a Hash" do
|
126
|
+
describe "and environment is an option" do
|
127
|
+
it "should not change environment['LC_ALL'] when set to nil" do
|
128
|
+
options = { :environment => { 'LC_ALL' => nil } }
|
129
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
130
|
+
shell_out.shell_out(cmd, options)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should not change environment['LC_ALL'] when set to non-nil" do
|
134
|
+
options = { :environment => { 'LC_ALL' => 'en_US.UTF-8' } }
|
135
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
136
|
+
shell_out.shell_out(cmd, options)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should set environment['LC_ALL'] to 'en_US.UTF-8' when 'LC_ALL' not present" do
|
140
|
+
options = { :environment => { 'HOME' => '/Users/morty' } }
|
141
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, {
|
142
|
+
:environment => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
|
143
|
+
}).and_return(true)
|
144
|
+
shell_out.shell_out(cmd, options)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should not mutate the options hash when it adds LC_ALL" do
|
148
|
+
options = { :environment => { 'HOME' => '/Users/morty' } }
|
149
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, {
|
150
|
+
:environment => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
|
151
|
+
}).and_return(true)
|
152
|
+
shell_out.shell_out(cmd, options)
|
153
|
+
expect(options[:environment].has_key?('LC_ALL')).to be false
|
154
|
+
end
|
129
155
|
end
|
130
156
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
157
|
+
describe "and env is an option" do
|
158
|
+
it "should not change env when set to nil" do
|
159
|
+
options = { :env => { 'LC_ALL' => nil } }
|
160
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
161
|
+
shell_out.shell_out(cmd, options)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should not change env when set to non-nil" do
|
165
|
+
options = { :env => { 'LC_ALL' => 'de_DE.UTF-8'}}
|
166
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
167
|
+
shell_out.shell_out(cmd, options)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should set env['LC_ALL'] to 'en_US.UTF-8' when 'LC_ALL' not present" do
|
171
|
+
options = { :env => { 'HOME' => '/Users/morty' } }
|
172
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, {
|
173
|
+
:env => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
|
174
|
+
}).and_return(true)
|
175
|
+
shell_out.shell_out(cmd, options)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should not mutate the options hash when it adds LC_ALL" do
|
179
|
+
options = { :env => { 'HOME' => '/Users/morty' } }
|
180
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, {
|
181
|
+
:env => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
|
182
|
+
}).and_return(true)
|
183
|
+
shell_out.shell_out(cmd, options)
|
184
|
+
expect(options[:env].has_key?('LC_ALL')).to be false
|
185
|
+
end
|
135
186
|
end
|
136
187
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
cmd,
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
).and_return(true)
|
146
|
-
shell_out.shell_out_with_systems_locale(cmd, options)
|
188
|
+
describe "and no env/environment option is present" do
|
189
|
+
it "should add environment option and set environment['LC_ALL'] to 'en_US.UTF_8'" do
|
190
|
+
options = { :user => 'morty' }
|
191
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, {
|
192
|
+
:user => 'morty', :environment => { 'LC_ALL' => Chef::Config[:internal_locale] },
|
193
|
+
}).and_return(true)
|
194
|
+
shell_out.shell_out(cmd, options)
|
195
|
+
end
|
147
196
|
end
|
148
197
|
end
|
149
198
|
|
150
|
-
describe "
|
151
|
-
it "should
|
152
|
-
|
153
|
-
|
154
|
-
|
199
|
+
describe "when the last argument is not a Hash" do
|
200
|
+
it "should add environment options and set environment['LC_ALL'] to 'en_US.UTF-8'" do
|
201
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, {
|
202
|
+
:environment => { 'LC_ALL' => Chef::Config[:internal_locale] },
|
203
|
+
}).and_return(true)
|
204
|
+
shell_out.shell_out(cmd)
|
155
205
|
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
156
209
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
210
|
+
describe "#shell_out_with_systems_locale" do
|
211
|
+
|
212
|
+
describe "when the last argument is a Hash" do
|
213
|
+
describe "and environment is an option" do
|
214
|
+
it "should not change environment['LC_ALL'] when set to nil" do
|
215
|
+
options = { :environment => { 'LC_ALL' => nil } }
|
216
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
217
|
+
shell_out.shell_out_with_systems_locale(cmd, options)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should not change environment['LC_ALL'] when set to non-nil" do
|
221
|
+
options = { :environment => { 'LC_ALL' => 'en_US.UTF-8' } }
|
222
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
223
|
+
shell_out.shell_out_with_systems_locale(cmd, options)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should no longer set environment['LC_ALL'] to nil when 'LC_ALL' not present" do
|
227
|
+
options = { :environment => { 'HOME' => '/Users/morty' } }
|
228
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
229
|
+
shell_out.shell_out_with_systems_locale(cmd, options)
|
230
|
+
end
|
161
231
|
end
|
162
232
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
cmd,
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
233
|
+
describe "and env is an option" do
|
234
|
+
it "should not change env when set to nil" do
|
235
|
+
options = { :env => { 'LC_ALL' => nil } }
|
236
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
237
|
+
shell_out.shell_out_with_systems_locale(cmd, options)
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should not change env when set to non-nil" do
|
241
|
+
options = { :env => { 'LC_ALL' => 'en_US.UTF-8'}}
|
242
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
243
|
+
shell_out.shell_out_with_systems_locale(cmd, options)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should no longer set env['LC_ALL'] to nil when 'LC_ALL' not present" do
|
247
|
+
options = { :env => { 'HOME' => '/Users/morty' } }
|
248
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
249
|
+
shell_out.shell_out_with_systems_locale(cmd, options)
|
250
|
+
end
|
173
251
|
end
|
174
|
-
end
|
175
252
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
cmd,
|
181
|
-
|
182
|
-
:user => 'morty'
|
183
|
-
}
|
184
|
-
).and_return(true)
|
185
|
-
shell_out.shell_out_with_systems_locale(cmd, options)
|
253
|
+
describe "and no env/environment option is present" do
|
254
|
+
it "should no longer add environment option and set environment['LC_ALL'] to nil" do
|
255
|
+
options = { :user => 'morty' }
|
256
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
|
257
|
+
shell_out.shell_out_with_systems_locale(cmd, options)
|
258
|
+
end
|
186
259
|
end
|
187
260
|
end
|
188
|
-
end
|
189
261
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
cmd
|
194
|
-
|
195
|
-
).and_return(true)
|
196
|
-
shell_out.shell_out_with_systems_locale(cmd)
|
262
|
+
describe "when the last argument is not a Hash" do
|
263
|
+
it "should no longer add environment options and set environment['LC_ALL'] to nil" do
|
264
|
+
expect(shell_out).to receive(:shell_out_command).with(cmd).and_return(true)
|
265
|
+
shell_out.shell_out_with_systems_locale(cmd)
|
266
|
+
end
|
197
267
|
end
|
198
268
|
end
|
199
|
-
end
|
200
269
|
|
270
|
+
end
|
201
271
|
end
|
@@ -56,8 +56,6 @@ describe Chef::Provider::Ifconfig::Debian do
|
|
56
56
|
describe "generate_config" do
|
57
57
|
|
58
58
|
context "when writing a file" do
|
59
|
-
let(:config_file_ifcfg) { StringIO.new }
|
60
|
-
|
61
59
|
let(:tempfile) { Tempfile.new("rspec-chef-ifconfig-debian") }
|
62
60
|
|
63
61
|
let(:tempdir_path) { Dir.mktmpdir("rspec-chef-ifconfig-debian-dir") }
|
@@ -67,14 +65,13 @@ describe Chef::Provider::Ifconfig::Debian do
|
|
67
65
|
before do
|
68
66
|
stub_const("Chef::Provider::Ifconfig::Debian::INTERFACES_FILE", tempfile.path)
|
69
67
|
stub_const("Chef::Provider::Ifconfig::Debian::INTERFACES_DOT_D_DIR", tempdir_path)
|
70
|
-
expect(File).to receive(:new).with(config_filename_ifcfg, "w").and_return(config_file_ifcfg)
|
71
68
|
end
|
72
69
|
|
73
70
|
it "should write a network-script" do
|
74
71
|
provider.run_action(:add)
|
75
|
-
expect(
|
76
|
-
expect(
|
77
|
-
expect(
|
72
|
+
expect(File.read(config_filename_ifcfg)).to match(/^iface eth0 inet static\s*$/)
|
73
|
+
expect(File.read(config_filename_ifcfg)).to match(/^\s+address 10\.0\.0\.1\s*$/)
|
74
|
+
expect(File.read(config_filename_ifcfg)).to match(/^\s+netmask 255\.255\.254\.0\s*$/)
|
78
75
|
end
|
79
76
|
|
80
77
|
context "when the interface_dot_d directory does not exist" do
|
@@ -123,7 +120,6 @@ iface eth0 inet static
|
|
123
120
|
netmask 255.255.254.0
|
124
121
|
EOF
|
125
122
|
)
|
126
|
-
expect(File).to receive(:new).with(config_filename_ifcfg, "w").and_return(config_file_ifcfg)
|
127
123
|
expect(File.exists?(tempdir_path)).to be_true # since the file exists, the enclosing dir must also exist
|
128
124
|
end
|
129
125
|
|
@@ -139,6 +135,8 @@ EOF
|
|
139
135
|
before do
|
140
136
|
tempfile.write(expected_string)
|
141
137
|
tempfile.close
|
138
|
+
|
139
|
+
expect(provider).not_to receive(:converge_by).with(/modifying #{tempfile.path} to source #{tempdir_path}/)
|
142
140
|
end
|
143
141
|
|
144
142
|
it "should preserve all the contents" do
|
@@ -165,6 +163,9 @@ EOF
|
|
165
163
|
before do
|
166
164
|
tempfile.write("a line\nanother line\n")
|
167
165
|
tempfile.close
|
166
|
+
|
167
|
+
allow(provider).to receive(:converge_by).and_call_original
|
168
|
+
expect(provider).to receive(:converge_by).with(/modifying #{tempfile.path} to source #{tempdir_path}/).and_call_original
|
168
169
|
end
|
169
170
|
|
170
171
|
it "should preserve the original contents and add the source line" do
|
@@ -318,8 +319,17 @@ source #{tempdir_path}/*
|
|
318
319
|
|
319
320
|
it "should delete network-script if it exists" do
|
320
321
|
current_resource.device new_resource.device
|
321
|
-
|
322
|
-
|
322
|
+
|
323
|
+
[:exist?, :exists?, :writable?].each do |cmd|
|
324
|
+
# need to stub :writable? to make why_run? happy
|
325
|
+
allow(File).to receive(cmd).and_call_original
|
326
|
+
allow(File).to receive(cmd).with(config_filename_ifcfg).and_return(true)
|
327
|
+
end
|
328
|
+
|
329
|
+
# stub for Chef::Util::Backup#do_backup
|
330
|
+
expect(FileUtils).to receive(:cp)
|
331
|
+
.with(config_filename_ifcfg, /#{Chef::Config[:file_backup_path]}/, :preserve => true)
|
332
|
+
expect(File).to receive(:delete).with(config_filename_ifcfg)
|
323
333
|
|
324
334
|
provider.run_action(:delete)
|
325
335
|
end
|