Skip to content

Commit 5e31c2c

Browse files
committed
Add rhel 8+ dnf support
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
1 parent c4f04b9 commit 5e31c2c

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

libraries/linux_updates.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,17 @@ def packages
208208
end
209209

210210
def updates
211-
rhel_updates = <<~PRINT_JSON
212-
#!/bin/sh
213-
python -c 'import sys; sys.path.insert(0, "/usr/share/yum-cli"); import cli; ybc = cli.YumBaseCli(); ybc.setCacheDir("/tmp"); list = ybc.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)+"]}"'
214-
PRINT_JSON
211+
rhel_updates = if os.release.to_i > 7
212+
<<~PRINT_JSON
213+
#!/usr/bin/sh
214+
/usr/libexec/platform-python -c 'import dnf; base = dnf.Base(); base.read_all_repos(); base.fill_sack(); q = base.sack.query(); list = list(q.upgrades()); res = ["{\\"name\\":\\""+x.name+"\\",\\"version\\":\\""+x.version+"-"+x.release+"\\",\\"arch\\":\\""+x.arch+"\\",\\"repository\\":\\""+x.reponame+"\\"}" for x in list]; print("{\\"available\\":["+",".join(res)+"]}")'
215+
PRINT_JSON
216+
else
217+
<<~PRINT_JSON
218+
#!/bin/sh
219+
python -c 'import sys; sys.path.insert(0, "/usr/share/yum-cli"); import cli; ybc = cli.YumBaseCli(); ybc.setCacheDir("/tmp"); list = ybc.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)+"]}"'
220+
PRINT_JSON
221+
end
215222
cmd = @inspec.bash(rhel_updates)
216223
unless cmd.exit_status.zero?
217224
# essentially we want https://github.com/chef/inspec/issues/1205

0 commit comments

Comments
 (0)