facts: Update RAID devices regex for FreeBSD (#82081)

Added support FreeBSD RAID devices and regex to match partitions as well as slices. 
RAID device list is taken from here: https://github.com/freebsd/freebsd-src/blob/main/usr.sbin/bsdconfig/share/device.subr
pull/82624/merge
Peter Whall 7 months ago committed by GitHub
parent aed8c080f6
commit 417db213c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- freebsd - update disk and slices regex for fact gathering (https://github.com/ansible/ansible/pull/82081).

@ -173,13 +173,50 @@ class FreeBSDHardware(Hardware):
sysdir = '/dev' sysdir = '/dev'
device_facts['devices'] = {} device_facts['devices'] = {}
drives = re.compile(r'(ada?\d+|da\d+|a?cd\d+)') # TODO: rc, disks, err = self.module.run_command("/sbin/sysctl kern.disks") # TODO: rc, disks, err = self.module.run_command("/sbin/sysctl kern.disks")
slices = re.compile(r'(ada?\d+s\d+\w*|da\d+s\d+\w*)') drives = re.compile(
r"""(?x)(
(?:
ada? # ATA/SATA disk device
|da # SCSI disk device
|a?cd # SCSI CDROM drive
|amrd # AMI MegaRAID drive
|idad # Compaq RAID array
|ipsd # IBM ServeRAID RAID array
|md # md(4) disk device
|mfid # LSI MegaRAID SAS array
|mlxd # Mylex RAID disk
|twed # 3ware ATA RAID array
|vtbd # VirtIO Block Device
)\d+
)
"""
)
slices = re.compile(
r"""(?x)(
(?:
ada? # ATA/SATA disk device
|a?cd # SCSI CDROM drive
|amrd # AMI MegaRAID drive
|da # SCSI disk device
|idad # Compaq RAID array
|ipsd # IBM ServeRAID RAID array
|md # md(4) disk device
|mfid # LSI MegaRAID SAS array
|mlxd # Mylex RAID disk
|twed # 3ware ATA RAID array
|vtbd # VirtIO Block Device
)\d+[ps]\d+\w*
)
"""
)
if os.path.isdir(sysdir): if os.path.isdir(sysdir):
dirlist = sorted(os.listdir(sysdir)) dirlist = sorted(os.listdir(sysdir))
for device in dirlist: for device in dirlist:
d = drives.match(device) d = drives.match(device)
if d: if d and d.group(1) not in device_facts['devices']:
device_facts['devices'][d.group(1)] = [] device_facts['devices'][d.group(1)] = []
s = slices.match(device) s = slices.match(device)
if s: if s:

@ -0,0 +1,541 @@
ad0
ad1
ad2
ad3
ad4
ad5
ad6
ad7
ad8
ad9
ada0
ada1
ada2
ada3
ada4
ada5
ada6
ada7
ada8
ada9
da0
da1
da2
da3
da4
da5
da6
da7
da8
da9
cd0
cd1
cd2
cd3
cd4
cd5
cd6
cd7
cd8
cd9
acd0
acd1
acd2
acd3
acd4
acd5
acd6
acd7
acd8
acd9
amrd0
amrd1
amrd2
amrd3
amrd4
amrd5
amrd6
amrd7
amrd8
amrd9
idad0
idad1
idad2
idad3
idad4
idad5
idad6
idad7
idad8
idad9
ips0
ips1
ips2
ips3
ips4
ips5
ips6
ips7
ips8
ips9
md0
md1
md2
md3
md4
md5
md6
md7
md8
md9
ipsd0
ipsd1
ipsd2
ipsd3
ipsd4
ipsd5
ipsd6
ipsd7
ipsd8
ipsd9
md0
md1
md2
md3
md4
md5
md6
md7
md8
md9
mfid0
mfid1
mfid2
mfid3
mfid4
mfid5
mfid6
mfid7
mfid8
mfid9
mlxd0
mlxd1
mlxd2
mlxd3
mlxd4
mlxd5
mlxd6
mlxd7
mlxd8
mlxd9
twed0
twed1
twed2
twed3
twed4
twed5
twed6
twed7
twed8
twed9
vtbd0
vtbd1
vtbd2
vtbd3
vtbd4
vtbd5
vtbd6
vtbd7
vtbd8
vtbd9
ad0p0A
ad0p0B
ad0p0C
ad0p0D
ad0p0E
ad0p0F
ad0p0G
ad0p0H
ad0p0I
ad0p0J
ad0p0K
ad0p0L
ad0p0M
ad0p0N
ad0p0O
ad0p0P
ad0p0Q
ad0p0R
ad0p0S
ad0p0T
ad0p0U
ad0p0V
ad0p0W
ad0p0X
ad0p0Y
ad0p0Z
ad0p0a
ad0p0b
ad0p0c
ad0p0d
cd0p0A
cd0p0B
cd0p0C
cd0p0D
cd0p0E
cd0p0F
cd0p0G
cd0p0H
cd0p0I
cd0p0J
cd0p0K
cd0p0L
cd0p0M
cd0p0N
cd0p0O
cd0p0P
cd0p0Q
cd0p0R
cd0p0S
cd0p0T
cd0p0U
cd0p0V
cd0p0W
cd0p0X
cd0p0Y
cd0p0Z
cd0p0a
cd0p0b
cd0p0c
cd0p0d
amrd0p0A
amrd0p0B
amrd0p0C
amrd0p0D
amrd0p0E
amrd0p0F
amrd0p0G
amrd0p0H
amrd0p0I
amrd0p0J
amrd0p0K
amrd0p0L
amrd0p0M
amrd0p0N
amrd0p0O
amrd0p0P
amrd0p0Q
amrd0p0R
amrd0p0S
amrd0p0T
amrd0p0U
amrd0p0V
amrd0p0W
amrd0p0X
amrd0p0Y
amrd0p0Z
amrd0p0a
amrd0p0b
amrd0p0c
amrd0p0d
da0p0A
da0p0B
da0p0C
da0p0D
da0p0E
da0p0F
da0p0G
da0p0H
da0p0I
da0p0J
da0p0K
da0p0L
da0p0M
da0p0N
da0p0O
da0p0P
da0p0Q
da0p0R
da0p0S
da0p0T
da0p0U
da0p0V
da0p0W
da0p0X
da0p0Y
da0p0Z
da0p0a
da0p0b
da0p0c
da0p0d
idad0p0A
idad0p0B
idad0p0C
idad0p0D
idad0p0E
idad0p0F
idad0p0G
idad0p0H
idad0p0I
idad0p0J
idad0p0K
idad0p0L
idad0p0M
idad0p0N
idad0p0O
idad0p0P
idad0p0Q
idad0p0R
idad0p0S
idad0p0T
idad0p0U
idad0p0V
idad0p0W
idad0p0X
idad0p0Y
idad0p0Z
idad0p0a
idad0p0b
idad0p0c
idad0p0d
ipsd0p0A
ipsd0p0B
ipsd0p0C
ipsd0p0D
ipsd0p0E
ipsd0p0F
ipsd0p0G
ipsd0p0H
ipsd0p0I
ipsd0p0J
ipsd0p0K
ipsd0p0L
ipsd0p0M
ipsd0p0N
ipsd0p0O
ipsd0p0P
ipsd0p0Q
ipsd0p0R
ipsd0p0S
ipsd0p0T
ipsd0p0U
ipsd0p0V
ipsd0p0W
ipsd0p0X
ipsd0p0Y
ipsd0p0Z
ipsd0p0a
ipsd0p0b
ipsd0p0c
ipsd0p0d
md0p0A
md0p0B
md0p0C
md0p0D
md0p0E
md0p0F
md0p0G
md0p0H
md0p0I
md0p0J
md0p0K
md0p0L
md0p0M
md0p0N
md0p0O
md0p0P
md0p0Q
md0p0R
md0p0S
md0p0T
md0p0U
md0p0V
md0p0W
md0p0X
md0p0Y
md0p0Z
md0p0a
md0p0b
md0p0c
md0p0d
mfid0p0A
mfid0p0B
mfid0p0C
mfid0p0D
mfid0p0E
mfid0p0F
mfid0p0G
mfid0p0H
mfid0p0I
mfid0p0J
mfid0p0K
mfid0p0L
mfid0p0M
mfid0p0N
mfid0p0O
mfid0p0P
mfid0p0Q
mfid0p0R
mfid0p0S
mfid0p0T
mfid0p0U
mfid0p0V
mfid0p0W
mfid0p0X
mfid0p0Y
mfid0p0Z
mfid0p0a
mfid0p0b
mfid0p0c
mfid0p0d
mlxd0p0A
mlxd0p0B
mlxd0p0C
mlxd0p0D
mlxd0p0E
mlxd0p0F
mlxd0p0G
mlxd0p0H
mlxd0p0I
mlxd0p0J
mlxd0p0K
mlxd0p0L
mlxd0p0M
mlxd0p0N
mlxd0p0O
mlxd0p0P
mlxd0p0Q
mlxd0p0R
mlxd0p0S
mlxd0p0T
mlxd0p0U
mlxd0p0V
mlxd0p0W
mlxd0p0X
mlxd0p0Y
mlxd0p0Z
mlxd0p0a
mlxd0p0b
mlxd0p0c
mlxd0p0d
twed0p0A
twed0p0B
twed0p0C
twed0p0D
twed0p0E
twed0p0F
twed0p0G
twed0p0H
twed0p0I
twed0p0J
twed0p0K
twed0p0L
twed0p0M
twed0p0N
twed0p0O
twed0p0P
twed0p0Q
twed0p0R
twed0p0S
twed0p0T
twed0p0U
twed0p0V
twed0p0W
twed0p0X
twed0p0Y
twed0p0Z
twed0p0a
twed0p0b
twed0p0c
twed0p0d
vtbd0p0A
vtbd0p0B
vtbd0p0C
vtbd0p0D
vtbd0p0E
vtbd0p0F
vtbd0p0G
vtbd0p0H
vtbd0p0I
vtbd0p0J
vtbd0p0K
vtbd0p0L
vtbd0p0M
vtbd0p0N
vtbd0p0O
vtbd0p0P
vtbd0p0Q
vtbd0p0R
vtbd0p0S
vtbd0p0T
vtbd0p0U
vtbd0p0V
vtbd0p0W
vtbd0p0X
vtbd0p0Y
vtbd0p0Z
vtbd0p0a
vtbd0p0b
vtbd0p0c
vtbd0p0d
log
reroot
sndstat
random
urandom
devctl
devctl2
console
geom.ctl
midistat
sequencer0
music0
ctty
fd
stdin
stdout
stderr
tcp_log
auditpipe
audit
consolectl
sysmouse
input
fido
kbdmux0
kbd0
bpf
bpf0
mem
kmem
full
null
zero
uinput
openfirm
pci
klog
vcio
efi
acpi
ttyu0
ttyu0.init
ttyu0.lock
cuau0
cuau0.init
cuau0.lock
ufssuspend
netdump
pfil
usbctl
xpt0
mdctl
devstat
usb
ugen0.1
gpt
ugen0.2
ukbd0
kbd1
ugen0.3
uhid0

File diff suppressed because one or more lines are too long

@ -0,0 +1,23 @@
# Copyright: Contributors to the Ansible project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
import json
import os
import pathlib
from ansible.module_utils.facts.hardware import freebsd
def test_get_device_facts(monkeypatch):
fixtures = pathlib.Path(__file__).parent / 'fixtures'
dev_dir = (fixtures / 'devices').read_text().split()
expected_dev_dir = json.load(open(fixtures / 'expected_devices', 'r'))
monkeypatch.setattr(os.path, 'isdir', lambda x: True)
monkeypatch.setattr(os, 'listdir', lambda x: dev_dir)
freebsd_hardware = freebsd.FreeBSDHardware(None)
facts = freebsd_hardware.get_device_facts()
assert facts == expected_dev_dir
Loading…
Cancel
Save