mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
Fix to capture non indented grub conf values
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
parent
4cf83b2995
commit
ec35c6042a
4 changed files with 38 additions and 1 deletions
|
@ -162,7 +162,7 @@ module Inspec::Resources
|
||||||
|
|
||||||
current_kernel = file_line.split(" ", 2)[1]
|
current_kernel = file_line.split(" ", 2)[1]
|
||||||
lines.drop(index + 1).each do |kernel_line|
|
lines.drop(index + 1).each do |kernel_line|
|
||||||
if kernel_line =~ /^\s.*/
|
if kernel_line =~ /(?:^\s*\w+)/ && !(kernel_line =~ /^title.*/)
|
||||||
option_type = kernel_line.split(" ")[0]
|
option_type = kernel_line.split(" ")[0]
|
||||||
line_options = kernel_line.split(" ").drop(1)
|
line_options = kernel_line.split(" ").drop(1)
|
||||||
if (menu_entry == conf["default"].to_i && @kernel == "default") || current_kernel == @kernel
|
if (menu_entry == conf["default"].to_i && @kernel == "default") || current_kernel == @kernel
|
||||||
|
|
23
test/fixtures/files/non_indented_grub.conf
vendored
Normal file
23
test/fixtures/files/non_indented_grub.conf
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# grub.conf generated by anaconda
|
||||||
|
#
|
||||||
|
# Note that you do not have to rerun grub after making changes to this file
|
||||||
|
# NOTICE: You have a /boot partition. This means that
|
||||||
|
# all kernel and initrd paths are relative to /boot/, eg.
|
||||||
|
# root (hd0,0)
|
||||||
|
# kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
|
||||||
|
# initrd /initrd-[generic-]version.img
|
||||||
|
#boot=/dev/sda
|
||||||
|
default=0
|
||||||
|
timeout=5
|
||||||
|
splashimage=(hd0,0)/grub/splash.xpm.gz
|
||||||
|
hiddenmenu
|
||||||
|
title CentOS (2.6.32-573.7.1.el6.x86_64)
|
||||||
|
root (hd0,0)
|
||||||
|
kernel /vmlinuz-2.6.32-573.7.1.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_GB.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet audit=1
|
||||||
|
initrd /initramfs-2.6.32-573.7.1.el6.x86_64.img
|
||||||
|
|
||||||
|
# another section
|
||||||
|
title CentOS 6 (2.6.32-573.el6.x86_64)
|
||||||
|
root (hd0,0)
|
||||||
|
kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_GB.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet audit=1
|
||||||
|
initrd /initramfs-2.6.32-573.el6.x86_64.img
|
|
@ -103,6 +103,7 @@ class MockLoader
|
||||||
"/etc/inetd.conf" => mockfile.call("inetd.conf"),
|
"/etc/inetd.conf" => mockfile.call("inetd.conf"),
|
||||||
"/etc/group" => mockfile.call("etcgroup"),
|
"/etc/group" => mockfile.call("etcgroup"),
|
||||||
"/etc/grub.conf" => mockfile.call("grub.conf"),
|
"/etc/grub.conf" => mockfile.call("grub.conf"),
|
||||||
|
"/etc/non_indented_grub.conf" => mockfile.call("non_indented_grub.conf"),
|
||||||
"/boot/grub2/grub.cfg" => mockfile.call("grub2.cfg"),
|
"/boot/grub2/grub.cfg" => mockfile.call("grub2.cfg"),
|
||||||
"/boot/grub2/grubenv" => mockfile.call("grubenv"),
|
"/boot/grub2/grubenv" => mockfile.call("grubenv"),
|
||||||
"/boot/grub2/grubenv_invalid" => mockfile.call("grubenv_invalid"),
|
"/boot/grub2/grubenv_invalid" => mockfile.call("grubenv_invalid"),
|
||||||
|
|
|
@ -81,4 +81,17 @@ describe "Inspec::Resources::GrubConfig" do
|
||||||
_(resource.default).must_equal "0"
|
_(resource.default).must_equal "0"
|
||||||
_(resource.timeout).must_equal "5"
|
_(resource.timeout).must_equal "5"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "parses data with no identations correctly with grub1" do
|
||||||
|
resource = MockLoader.new(:centos6).load_resource(
|
||||||
|
"grub_conf",
|
||||||
|
"/etc/non_indented_grub.conf",
|
||||||
|
"CentOS 6 (2.6.32-573.el6.x86_64)"
|
||||||
|
)
|
||||||
|
|
||||||
|
_(resource.kernel).must_include "/vmlinuz-2.6.32-573.el6.x86_64"
|
||||||
|
_(resource.initrd).must_equal "/initramfs-2.6.32-573.el6.x86_64.img"
|
||||||
|
_(resource.default).must_equal "0"
|
||||||
|
_(resource.timeout).must_equal "5"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue