Skip to content

Commit

Permalink
test: lsblk can return LOG_SEC or LOG-SEC
Browse files Browse the repository at this point in the history
get_unused_disk is broken on some systems because `lsblk ... LOG-SEC` can
return `LOG_SEC` with an underscore instead of the requested
`LOG-SEC` with a dash.
  • Loading branch information
richm committed Jun 5, 2024
1 parent b17ae35 commit 64333ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/find_unused_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def get_disks(module):
if not line:
continue

m = re.search(r'NAME="(?P<path>[^"]*)" TYPE="(?P<type>[^"]*)" SIZE="(?P<size>\d+)" FSTYPE="(?P<fstype>[^"]*)" LOG-SEC="(?P<ssize>\d+)"', line)
m = re.search(r'NAME="(?P<path>[^"]*)" TYPE="(?P<type>[^"]*)" SIZE="(?P<size>\d+)" FSTYPE="(?P<fstype>[^"]*)" LOG[_-]SEC="(?P<ssize>\d+)"', line)
if m is None:
module.log(line)
module.log("Line did not match: " + line)
continue

if m.group('type') != "disk":
Expand Down
9 changes: 9 additions & 0 deletions tests/get_unused_disk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
match_sector_size: "{{ match_sector_size | d(omit) }}"
register: unused_disks_return

- name: Debug why there are no unused disks
shell: |
set -x
exec 1>&2
lsblk -p --pairs --bytes -o NAME,TYPE,SIZE,FSTYPE,LOG-SEC
journalctl -ex
changed_when: false
when: "'Unable to find unused disk' in unused_disks_return.disks"

- name: Set unused_disks if necessary
set_fact:
unused_disks: "{{ unused_disks_return.disks }}"
Expand Down

0 comments on commit 64333ce

Please sign in to comment.