<file_sep># rpm_version_facts

Module to create set fact to give all rpm versions on the systems.
<file_sep>require "spec_helper"

describe Facter::Util::Fact do
  before {
    Facter.clear
  }

  describe 'package_foo_123' do
    context 'returns package versions when rpm present' do
      before do
        Facter.fact(:operatingsystem).stubs(:value).returns("RedHat")
        Facter::Util::Resolution.expects(:which).with("rpm").returns('/bin/rpm')
        Facter::Util::Resolution.stubs(:exec)
      end
      let(:facts) { {:operatingsystem => 'RedHat'} }
      it do
        rpm_query_output = <<-EOS
basesystem||10.0
nss-util||3.19.1
gawk||3.1.7
coreutils-libs||8.4
libcap||2.16
pam||1.1.1
plymouth-core-libs||0.8.3
info||4.13a
nss-softokn||3.14.3
libsepol||2.0.41
sed||4.2.1
bzip2-libs||1.0.5
postfix||2.6.6
cronie||1.4.4
kernel||2.6.32
libtasn1||2.3
libgpg-error||1.7
openssh-clients||5.3p1
libxml2||2.7.6
libidn||1.18
puppetlabs-release-pc1||1.0.0
libgcrypt||1.4.5
lua-filesystem||1.4.2
findutils||4.4.2
lua-alt-getopt||0.7.0
libselinux||2.0.94
checkpolicy||2.0.22
lxc-libs||1.0.8
audit-libs||2.3.7
which||2.19
lxc||1.0.8
pth||2.0.7
docker-io||1.7.1
perl-Module-Pluggable||3.90
libuuid||2.17.2
perl-libs||5.10.1
perl||5.10.1
file-libs||5.04
perl-Git||1.7.1
xz-libs||4.999.9
tree||1.5.3
gmp||4.3.1
cloog-ppl||0.15.7
libselinux-utils||2.0.94
MAKEDEV||3.24
mpfr||2.4.1
compat-readline5||5.2
libgomp||4.4.7
device-mapper-persistent-data||0.3.2
ruby-devel||1.8.7.374
keyutils-libs||1.4
libstdc++-devel||4.4.7
m4||1.4.13
libxml2-devel||2.7.6
make||3.81
libgcrypt-devel||1.4.5
libxslt-devel||1.1.26
yum-plugin-fastestmirror||1.1.30
mosh||1.2.4
less||436
ipset||6.11
cracklib-dicts||2.8.16
python-inotify||0.9.1
glib2||2.28.8
fail2ban||0.9.3
grubby||7.0.15
tzdata||2016a
glibc-common||2.12
libpciaccess||0.13.3
libudev||147
nss||3.19.1
initscripts||9.03.49
util-linux-ng||2.17.2
device-mapper-libs||1.02.95
device-mapper-event-libs||1.02.95
lvm2-libs||2.02.118
kernel-headers||2.6.32
gpgme||1.1.8
selinux-policy||3.7.19
glibc-devel||2.12
cryptsetup-luks-libs||1.2.0
fipscheck-lib||1.2.0
lvm2||2.02.118
puppet-agent||1.3.5
libcap-ng||0.6.4
python-pycurl||7.19.0
pygpgme||0.1
python-iniparse||0.3.1
newt||0.52.11
ustr||1.0.4
rsyslog||5.8.10
libaio||0.3.107
gnupg2||2.0.14
gamin||0.1.10
dbus-glib||0.86
libssh2||1.4.2
cyrus-sasl-lib||2.1.23
cyrus-sasl||2.1.23
libgcc||4.4.7
ncurses-libs||5.7
crontabs||1.10
kbd||1.15
krb5-libs||1.10.3
fuse||2.8.3
sysvinit-tools||2.87
libcurl||7.19.7
curl||7.19.7
passwd||<PASSWORD>
e2fsprogs-libs||1.41.12
binutils||2.20.51.0.2
hwdata||0.233
acl||2.2.49
vim-minimal||7.4.629
bridge-utils||1.2
libstdc++||4.4.7
gpg-pubkey||c105b9de
python||2.6.6
rpm-python||4.8.0
policycoreutils||2.0.83
iproute||2.6.32
p11-kit||0.18.5
device-mapper-multipath-libs||0.4.9
dracut||004
dhcp-common||4.1.1
kernel||2.6.32
device-mapper-multipath||0.4.9
upstart||0.6.5
mdadm||3.3.2
b43-openfwwf||5.2
iptables-ipv6||1.4.7
grub||0.97
e2fsprogs||1.41.12
pinentry||0.7.6
ncurses||5.7
efibootmgr||0.5.4
filesystem||2.4.30
nss-softokn-freebl||3.14.3
bash||4.1.2
nspr||4.10.8
db4||4.7.25
grep||2.20
libattr||2.4.44
coreutils||8.4
plymouth-scripts||0.8.3
zlib||1.2.3
popt||1.13
cpio||2.10
libacl||2.2.49
sqlite||3.6.20
readline||6.0
openssh||5.3p1
plymouth||0.8.3
openldap||2.4.40
cronie-anacron||1.4.4
sudo||1.8.6p3
openssh-server||5.3p1
lua||5.1.4
db4-utils||4.7.25
wget||1.12
expat||2.0.1
gpg-pubkey||4bd6ec30
gpg-pubkey||0608b895
bzip2||1.0.5
libcgroup||0.40.rc1
rsync||3.0.6
lua-lxc||1.0.8
xz||4.999.9
tcp_wrappers-libs||7.6
perl-Pod-Escapes||1.04
perl-version||0.77
libblkid||2.17.2
perl-Pod-Simple||3.13
perl-Error||0.17015
libnih||1.0.1
git||1.7.1
ppl||0.10.2
libusb||0.1.12
libutempter||1.1.5
file||5.04
net-tools||1.60
cpp||4.4.7
ruby-libs||1.8.7.374
gcc||4.4.7
pciutils-libs||3.1.10
zlib-devel||1.2.3
gcc-c++||4.4.7
diffutils||2.8.1
libgpg-error-devel||1.7
dash||0.5.5.1
libxslt||1.1.26
groff||1.18.1.4
protobuf||2.3.0
libmnl||1.0.2
gzip||1.3.12
cracklib||2.8.16
gamin-python||0.1.10
ed||1.1
shared-mime-info||0.70
openssl||1.0.1e
redhat-logos||60.0.14
glibc||2.12
chkconfig||1.3.49.3
nss-sysinit||3.19.1
procps||3.2.8
libedit||2.11
udev||147
mingetty||1.08
device-mapper||1.02.95
device-mapper-event||1.02.95
kernel-firmware||2.6.32
glibc-headers||2.12
selinux-policy-targeted||3.7.19
kernel||2.6.32
fipscheck||1.2.0
nss-tools||3.19.1
logrotate||3.7.8
kernel||2.6.32
libffi||3.0.5
system-config-firewall-base||1.2.27
cryptsetup-luks||1.2.0
python-urlgrabber||3.9.1
slang||2.2.1
newt-python||0.52.11
pkgconfig||0.23
xfsprogs||3.1.1
audit||2.3.7
yum-metadata-parser||1.1.2
acpid||1.0.10
shadow-utils||4.1.4.2
kernel||2.6.32
centos-release||6
ncurses-base||5.7
libcom_err||1.41.12
kbd-misc||1.15
elfutils-libelf||0.161
libsemanage||2.0.43
rpm-libs||4.8.0
rpm||4.8.0
libss||1.41.12
ca-certificates||2015.2.4
tar||1.23
module-init-tools||3.9
attr||2.4.44
ethtool||3.5
rootfiles||8.1
pcre||7.8
gdbm||1.8.0
python-libs||2.6.6
dbus-libs||1.2.24
iptables||1.4.7
iputils||20071127
p11-kit-trust||0.18.5
kpartx||0.4.9
dracut-kernel||004
dhclient||4.1.1
psmisc||22.6
libdrm||2.4.59
iscsi-initiator-utils||6.2.0.873
yum||3.2.29
authconfig||6.1.12
mysql-libs||5.1.73
libuser||0.56.13
        EOS
        Facter::Util::Resolution.expects(:exec).with('rpm --query --all  --qf "%{NAME}||%{VERSION}\n"').returns(rpm_query_output)
        expect(Facter.value(:package_basesystem)).to eq('10.0')
        expect(Facter.value(:'package_nss-util')).to eq('3.19.1')
      end
    end

  end
end
<file_sep># Fact: java_version
#
# Purpose: get full java version string
#
# Resolution:
#   Tests for presence of java, returns nil if not present
#   returns output of "java -version" and splits on \n + '"'
#
# Caveats:
#   none
#
# Notes:
#   None
if Facter::Util::Resolution.which('rpm')
  package_data = Facter::Util::Resolution.exec('rpm --query --all  --qf "%{NAME}||%{VERSION}\n"')

  package_data.split("\n").each do |line|

    rpm_detail      = line.split("||")

    package_name    = 'package_' + rpm_detail[0]
    package_version = rpm_detail[1]

    Facter.add(package_name) do
      setcode do
        package_version
      end
    end

  end
end
