Skip to content

Commit f6a2235

Browse files
committed
fix #3
1 parent 0492dc2 commit f6a2235

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

.kitchen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ provisioner:
88

99
verifier:
1010
name: inspec
11+
sudo: true
1112

1213
platforms:
1314
- name: ubuntu-12.04

controls/patches.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
control 'verify-patches' do
1111
impact 0.3
1212
title "All patches should be installed"
13-
describe linux_update.updates.length do
14-
it { should eq 0}
13+
describe linux_update do
14+
it { should be_uptodate}
1515
end
1616
end
1717

libraries/linux_updates.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def updates
2828
u['available']
2929
end
3030

31+
def uptodate?
32+
u = @update_mgmt.updates
33+
return false if u.nil? || !u['available'].empty?
34+
true
35+
end
36+
3137
def packages
3238
p = @update_mgmt.packages
3339
return [] if p.nil? || u.empty?
@@ -53,10 +59,10 @@ def updates
5359
end
5460

5561
def parse_json(script)
56-
cmd = @inspec.command(script)
62+
cmd = @inspec.bash(script)
5763
begin
5864
JSON.parse(cmd.stdout)
59-
rescue JSON::ParserError => _e
65+
rescue JSON::ParserError => e
6066
return []
6167
end
6268
end
@@ -111,13 +117,19 @@ def updates
111117
#!/bin/sh
112118
python -c 'import sys; sys.path.insert(0, "/usr/share/yum-cli"); import cli; list = cli.YumBaseCli().returnPkgLists(["updates"]);res = ["{\\"name\\":\\""+x.name+"\\", \\"version\\":\\""+x.version+"-"+x.release+"\\",\\"arch\\":\\""+x.arch+"\\",\\"repository\\":\\""+x.repo.id+"\\"}" for x in list.updates]; print "{\\"available\\":["+",".join(res)+"]}"'
113119
EOH
114-
cmd = @inspec.command(rhel_updates)
120+
puts rhel_updates
121+
cmd = @inspec.bash(rhel_updates)
122+
unless cmd.exit_status == 0
123+
# essentially we want https://github.com/chef/inspec/issues/1205
124+
STDERR.puts "Could not determine patch status."
125+
return nil
126+
end
127+
115128
first = cmd.stdout.index('{')
116129
res = cmd.stdout.slice(first, cmd.stdout.size - first)
117130
begin
118131
JSON.parse(res)
119132
rescue JSON::ParserError => e
120-
puts
121133
return []
122134
end
123135
end

0 commit comments

Comments
 (0)