Skip to content

Commit

Permalink
debugging for not enough disks
Browse files Browse the repository at this point in the history
  • Loading branch information
richm committed Feb 15, 2024
1 parent 1b1312e commit 386c697
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tests/get_unused_disk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@
unused_disks: "{{ unused_disks_return.disks }}"
when: "'Unable to find unused disk' not in unused_disks_return.disks"

- name: Print unused disks
debug:
var: unused_disks
verbosity: 2

- name: Print info from find_unused_disk
debug:
var: unused_disks_return.info
when: unused_disks_return.info | d([]) | length > 0

- name: Exit playbook when there's not enough unused disks in the system
fail:
msg: "Unable to find enough unused disks. Exiting playbook."
when: unused_disks | d([]) | length < disks_needed | d(1)

- name: Print unused disks
debug:
var: unused_disks
10 changes: 10 additions & 0 deletions tests/library/find_unused_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,37 +185,47 @@ def run_module():
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

max_size = Size(module.params["max_size"])
info = []
for path, attrs in get_disks(module).items():
if is_ignored(path):
info.append("Disk {} attrs {} is ignored".format(path, attrs))
continue

interface = module.params["with_interface"]

if interface is not None and not is_device_interface(module, path, interface):
info.append("Disk {} attrs {} is not an interface {}".format(path, attrs, interface))
continue

if attrs["fstype"]:
info.append("Disk {} attrs {} has fstype".format(path, attrs))
continue

if Size(attrs["size"]).bytes < Size(module.params["min_size"]).bytes:
info.append("Disk {} attrs {} size is less than requested".format(path, attrs))
continue

if max_size.bytes > 0 and Size(attrs["size"]).bytes > max_size.bytes:
info.append("Disk {} attrs {} size is greater than requested".format(path, attrs))
continue

if get_partitions(path):
info.append("Disk {} attrs {} has partitions".format(path, attrs))
continue

if not no_holders(get_sys_name(path)):
info.append("Disk {} attrs {} has holders".format(path, attrs))
continue

if not can_open(path):
info.append("Disk {} attrs {} cannot be opened exclusively".format(path, attrs))
continue

result["disks"].append(os.path.basename(path))
if len(result["disks"]) >= module.params["max_return"]:
break

result["info"] = info
if not result["disks"]:
result["disks"] = "Unable to find unused disk"
else:
Expand Down

0 comments on commit 386c697

Please sign in to comment.