Class: Tweek::Section
- Inherits:
-
Array
- Object
- Array
- Tweek::Section
- Defined in:
- lib/tweek/section.rb
Overview
A section is an array of the parsed lines, each element is an OpenStruct There are the following types of Entry With line attributes - single lines With section type and list attributes With parameter value and conditional attributes All entries may have an optional comment attribute
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#each_entry(cs, &block) ⇒ Object
Iterate through each entry in the section.
-
#initialize(lineno, type, list, comment) ⇒ Section
constructor
A new instance of Section.
- #process(cs) ⇒ Object
- #section_entry ⇒ Object
Constructor Details
#initialize(lineno, type, list, comment) ⇒ Section
Returns a new instance of Section.
11 12 13 14 15 16 |
# File 'lib/tweek/section.rb', line 11 def initialize lineno, type, list, comment @lineno = lineno @type = type @list = list @comment = comment end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
10 11 12 |
# File 'lib/tweek/section.rb', line 10 def comment @comment end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
10 11 12 |
# File 'lib/tweek/section.rb', line 10 def lineno @lineno end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
10 11 12 |
# File 'lib/tweek/section.rb', line 10 def list @list end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/tweek/section.rb', line 10 def type @type end |
Instance Method Details
#each_entry(cs, &block) ⇒ Object
Iterate through each entry in the section. If it’s a comment then pass to the generate method If it has a condition which is not met then pass to generate If it passes yield the entry
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tweek/section.rb', line 27 def each_entry cs, &block self.each do |entry| if entry.line cs.generate :line, entry next end begin if cs.condfail entry.cond cs.generate :entry, entry cs.skipcond entry next end yield entry rescue Exception => e cs.error "#{entry.lineno}: #{e.}" end end end |
#process(cs) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/tweek/section.rb', line 46 def process cs cs.generate :section, section_entry unless type == '<initial>' return if self.empty? case type when '<initial>' each_entry (cs) do |entry| end when 'BLKDEV' # BLOCK DEVICE PARAMETERS Dir.chdir('/dev') devices = Dir.glob(self.list.split(' ').map{|dev| dev.gsub(/^\/dev\//,'')}) cs.warn "Block device check skipped: no devices found" if devices.empty? devices.each do |blk| each_entry (cs) do |entry| entry.actual = File.open("/sys/block/#{blk}/queue/#{entry.param}", &:read).chomp rescue $!. if entry.param == 'scheduler' entry.actual = entry.actual.slice(/\[(.*?)\]/,1) unless entry.actual == 'none' end cs.assert_equal entry.value, entry.actual, "/dev/#{blk} #{entry.param}" cs.generate :entry, entry end end when 'KERNEL' # KERNEL PARAMETERS each_entry (cs) do |entry| actual = /\b(#{entry.param})(=\S+)?\b/.match(Tweek::App.bootline) case when (entry.value == 'true' and actual) observed = actual.to_s expected = entry.param when (entry.value == 'true' and actual.nil?) expected = 'to be found' observed = 'was not found' when (entry.value == 'false' and actual) expected = 'to not be found' observed = 'was found' when (entry.value == 'false' and actual.nil?) expected = nil observed = nil else expected = entry.value observed = actual.nil? ? 'was not found' : actual[2][1..-1] end cs.assert_equal expected, observed, "Kernel parameter #{entry.param}" entry.actual = !actual.nil? cs.generate :entry, entry end when 'CLOCKSOURCE' each_entry (cs) do |entry| entry.actual=File.open("/sys/devices/system/clocksource/#{entry.param}/current_clocksource",&:read).chomp rescue $!. cs.assert_equal entry.value, entry.actual, entry.param cs.generate :entry, entry end when 'SYSCTL' # SYSCTL SETTINGS each_entry (cs) do |entry| file = entry.param.gsub(/\./,'/') entry.actual = File.open("/proc/sys/#{file}", &:read).chomp.gsub(/\s+/,' ') rescue $!. cs.assert_equal entry.value, entry.actual, entry.param cs.generate :entry, entry end when 'NET' # NETWORK DEVICES devices = self.list.split(' ').map{|dev| dev.gsub(/^\/dev\//,'')} cs.warn "Network device check skipped: no devices found" if devices.empty? devices.each do |netdev| each_entry (cs) do |entry| case entry.param when 'driver' entry.actual = File.basename(File.readlink("/sys/class/net/#{netdev}/device/driver")) cs.assert_equal entry.value, entry.actual, entry.param when 'irqs' irqs=File.open("/proc/interrupts", &:readlines).grep(/\b#{netdev}\b/).map{|m| m.partition(':')[0].strip} if irqs.empty? cs.warn "#{netdev} IRQ check skipped: none found" entry.actual = 'null' cs.generate :entry, entry next end ncores = `getconf _NPROCESSORS_ONLN`.chomp.to_i rescue 0 mismatches = 0 irqs.each_with_index do |irq, ix| case entry.value when 'null','none','ignore' next when 'aws' expected_rps = ("00000000," * 3) + "0000ff00" expected_rss = ("00000000," * 3) + sprintf("%08x", 1<<ix) when 'pin' case ncores when 32 # RPS on cores 10-15 and 18-31, RSS tied to 0-7 case ix when 0..7 expected_rps = ("00000000," * 3) + "fffefe00" expected_rss = ("00000000," * 3) + sprintf("%08x", 1<<(ix+1)) else cs.warn "#{netdev} IRQ strategy '#{entry.value}' can't handle IRQ#{ix}" end when 64 # Split the work across the two nodes case ix when 0..3 # alloc on node 0 (cpus 0-3) expected_rps = ("00000000," * 2) + "0000ffff," + "0000ffe0" expected_rss = ("00000000," * 3) + sprintf("%08x", 1<<(ix+1)) when 4..7 # alloc on node 1 ( expected_rps = ("00000000," * 2) + "ffff0000," + "ffe00000" expected_rss = ("00000000," * 3) + sprintf("%08x", 1<<(ix + 9)) else cs.warn "#{netdev} IRQ strategy '#{entry.value}' can't handle IRQ#{ix}" end else cs.error "#{entry.lineno}: Can't handle #{ncores} cores in IRQ strategy '#{entry.value}'" end else cs.error "#{entry.lineno}: Unrecognized #{netdev} IRQ strategy '#{entry.value}'" end actual_rss = File.open("/proc/irq/#{irq}/smp_affinity",&:read).chomp rescue $!. actual_rps = File.open("/sys/class/net/#{netdev}/queues/rx-#{ix}/rps_cpus", &:read).chomp rescue $!. mismatches += cs.assert_equal expected_rss, actual_rss, "#{netdev}_irq_#{irq}_rss" mismatches += cs.assert_equal expected_rps, actual_rps, "#{netdev}_irq_#{irq}_rps" end entry.actual = 'null' if mismatches > 0 else # try getting the name begin entry.actual = File.open("/sys/class/net/#{netdev}/#{entry.param}", &:read).chomp.gsub(/\s+/,' ') cs.assert_equal entry.value, entry.actual, entry.param rescue cs.error "#{entry.lineno}: Network parameter #{entry.param} not handled: #{$!.}" next end end cs.generate :entry, entry end end when 'EXT4' # EXT4 filesystems info via `dumpe2fs -h /dev/#{device}` mounted = File.open("/proc/mounts", &:readlines).map{|m| m.split(' ')} mounts = Dir.glob(self.list.split(' ')) mounts.each do |mount| unless this = mounted.select{|m| (mount == m[0] or mount == m[1]) and m[2] == 'ext4'}.first cs.warn "EXT4 path #{mount} is not mounted or is not mounted as ext4" next end device = this[0].gsub('/dev/','') optstring = File.open("/proc/fs/ext4/#{device}/options",&:read) = Hash[optstring.scan(/([^=\s]+)=([^=\s,]+)/)] # options a=b optstring.split(/\n/).reject{|o| o.index('=')}.each{|o| [o] = 'true'} each_entry (cs) do |entry| entry.actual = [entry.param] || "<not found>" cs.assert_equal entry.value, entry.actual, "EXT4 #{mount}: #{entry.param}" cs.generate :entry, entry end end when 'XFS' # XFS filesystems info via `xfs_info` # Dynamically via: /proc/fs/xfs/... ? mounts = self.list.split(' ') if mounts.empty? cs.warn "#{self.lineno}: XFS device check skipped: no mountpoints found" end mounts.each do |mount| xfsinfo = `xfs_info #{mount} 2>/dev/null`.chomp if $?.exitstatus > 0 cs.warn "No XFS filesystem at #{mount}" each_entry (cs) { |entry| cs.generate :entry, entry } next end data = Hash[xfsinfo.slice!(/^meta-data.*(?=^naming)/m).scan(/([^=\s]+)=([^=\s,]+)/)] naming = Hash[xfsinfo.slice!(/^naming.*(?=^log)/m).scan(/([^=\s]+)=([^=\s,]+)/)] log = Hash[xfsinfo.slice!(/^log.*(?=^realtime)/m).scan(/([^=\s]+)=([^=\s,]+)/)] realtime = Hash[xfsinfo.slice!(/^realtime.*$/m).scan(/([^=\s]+)=([^=\s,]+)/)] xfsparms = { 'data' => data, 'naming' => naming, 'log' => log, 'realtime' => realtime } each_entry (cs) do |entry| parameter = entry.param.split('.',2) entry.actual = xfsparms[parameter[0]][parameter[1]] rescue "<invalid name>" cs.assert_equal entry.value, entry.actual, "XFS #{mount}: #{entry.param}" cs.generate :entry, entry end end else cs.error "#{self.lineno}: Unknown type #{self.type}" end end |
#section_entry ⇒ Object
18 19 20 |
# File 'lib/tweek/section.rb', line 18 def section_entry OpenStruct.new(:lineno => lineno, :type => type, :list => list, :comment => comment ) end |