Skip to content

Commit f1dd867

Browse files
committed
Merge pull request #56 from bkw/resurrectChefSolo
bring back support for chef-solo
2 parents 71f4021 + 8af0ee9 commit f1dd867

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

recipes/server.rb

+8
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@
9797
notifies :restart, 'service[sshd]'
9898
end
9999

100+
def chef_solo_search_installed?
101+
klass = ::Search.const_get('Helper')
102+
return klass.is_a?(Class)
103+
rescue NameError
104+
return false
105+
end
106+
100107
# authorized_key management will be deprecated in the next major release:
101108
def get_key_from(field)
109+
return [] if Chef::Config[:solo] && !chef_solo_search_installed?
102110
return [] unless Chef::DataBag.list.key?('users')
103111
search('users', "#{field}:*").map do |v| # ~FC003 ignore footcritic violation
104112
Chef::Log.info "ssh_server: installing ssh-keys for root access of user #{v['id']}"

spec/recipes/client_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,14 @@
290290
end
291291
end
292292
end
293+
294+
context 'chef-solo' do
295+
cached(:chef_run) do
296+
ChefSpec::SoloRunner.new.converge(described_recipe)
297+
end
298+
299+
it 'does not raise an error' do
300+
expect { chef_run }.not_to raise_error
301+
end
302+
end
293303
end

spec/recipes/default_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@
3333
expect(chef_run).to include_recipe('ssh-hardening::client')
3434
end
3535

36+
context 'chef-solo' do
37+
cached(:chef_run) do
38+
ChefSpec::SoloRunner.new.converge(described_recipe)
39+
end
40+
41+
it 'does not raise an error' do
42+
expect { chef_run }.not_to raise_error
43+
end
44+
end
3645
end

spec/recipes/server_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,14 @@
391391
expect(chef_run).not_to write_log('deprecated-databag')
392392
end
393393
end
394+
395+
context 'chef-solo' do
396+
cached(:chef_run) do
397+
ChefSpec::SoloRunner.new.converge(described_recipe)
398+
end
399+
400+
it 'does not raise an error' do
401+
expect { chef_run }.not_to raise_error
402+
end
403+
end
394404
end

0 commit comments

Comments
 (0)