Skip to content

Commit

Permalink
(maint) Refactor aix mountpoints reading
Browse files Browse the repository at this point in the history
Previously, the AIX mountpoint resolver would check each line of the
`mount` command output to check if it matches the header of the table,
so it can be skipped.

This is not efficient and it can cause many problems, such as not
skipping the first line of the output if spaces are not present before
`node`, therefore considering the header of the table as a mountpoint.

```
  node       mounted        mounted over    vfs       date        options
-------- ---------------  ---------------  ------ ------------ ---------------
         /dev/hd4         /                jfs2   Mar 22 08:05 rw,log=/dev/hd8
         /dev/hd2         /usr             jfs2   Mar 22 08:05 rw,log=/dev/hd8
         /proc            /proc            procfs Mar 22 08:05 rw
         /dev/hd10opt     /opt             jfs2   Mar 22 08:05 rw,log=/dev/hd8
         /dev/hd3         /var             x      Mar 22 08:05 rw,nodev,log=/dev/hd3
```

To fix this, instead of checking a line matches the header, we just
simply skip the first 2 lines of the output, removing unnecessary regex
expresions and improving performance
  • Loading branch information
BobosilaVictor committed Nov 15, 2021
1 parent b6bf218 commit f1c3411
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/facter/resolvers/aix/mountpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ def post_resolve(fact_name, _options)
def read_mount(fact_name)
@fact_list[:mountpoints] = {}
output = Facter::Core::Execution.execute('mount', logger: log)
output.split("\n").map do |line|
next if line =~ /\s+node\s+|---|procfs|ahafs/
output.split("\n").drop(2).map do |line|
next if line =~ /procfs|ahafs/

elem = line.split("\s")

@fact_list[:mountpoints][elem[1]] = { device: elem[0], filesystem: elem[2],
options: elem.last.split(',') }
add_mount_points_fact(line)
end

retrieve_sizes_for_mounts
@fact_list[fact_name]
end

def add_mount_points_fact(line)
elem = line.split("\s")
@fact_list[:mountpoints][elem[1]] = { device: elem[0], filesystem: elem[2],
options: elem.last.split(',') }
end

def retrieve_sizes_for_mounts
output = Facter::Core::Execution.execute('df -P', logger: log)
output.split("\n").map do |line|
next if line =~ /Filesystem|-\s+-\s+-/
output.split("\n").drop(1).map do |line|
next if line =~ /-\s+-\s+-/

mount_info = line.split("\s")
mount_info[3] = translate_to_bytes(mount_info[3])
Expand Down

0 comments on commit f1c3411

Please sign in to comment.