Skip to content

Commit 332e4b1

Browse files
committed
fix: check for no disks specified and report correct error
Cause: The code did not check for missing or empty disks in the right place. Consequence: The role would issue a strange error which did not indicate that the problem is that no disks were specified. Fix: Check for missing disks early and report appropriate error. Result: The role will report an appropriate error message if no disks are specified. Signed-off-by: Rich Megginson <[email protected]>
1 parent 9922ea3 commit 332e4b1

6 files changed

+74
-0
lines changed

library/blivet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ class BlivetDiskVolume(BlivetVolume):
940940
blivet_device_class = devices.DiskDevice
941941

942942
def _get_device_id(self):
943+
disks = self._volume.get('disks', [])
944+
if not disks:
945+
return None
943946
return self._volume['disks'][0]
944947

945948
def _type_check(self):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# This file was generated by generate_tests.py
3+
- name: Run test tests_create_multiple_partitions_dos.yml for nvme
4+
hosts: all
5+
tags:
6+
- tests::nvme
7+
tasks:
8+
- name: Set disk interface for test
9+
set_fact:
10+
storage_test_use_interface: "nvme"
11+
12+
- name: Import playbook
13+
import_playbook: tests_create_multiple_partitions_dos.yml
14+
tags:
15+
- tests::nvme
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# This file was generated by generate_tests.py
3+
- name: Run test tests_create_multiple_partitions_dos.yml for scsi
4+
hosts: all
5+
tags:
6+
- tests::scsi
7+
tasks:
8+
- name: Set disk interface for test
9+
set_fact:
10+
storage_test_use_interface: "scsi"
11+
12+
- name: Import playbook
13+
import_playbook: tests_create_multiple_partitions_dos.yml
14+
tags:
15+
- tests::scsi
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# This file was generated by generate_tests.py
3+
- name: Run test tests_create_multiple_partitions_gpt.yml for nvme
4+
hosts: all
5+
tags:
6+
- tests::nvme
7+
tasks:
8+
- name: Set disk interface for test
9+
set_fact:
10+
storage_test_use_interface: "nvme"
11+
12+
- name: Import playbook
13+
import_playbook: tests_create_multiple_partitions_gpt.yml
14+
tags:
15+
- tests::nvme
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# This file was generated by generate_tests.py
3+
- name: Run test tests_create_multiple_partitions_gpt.yml for scsi
4+
hosts: all
5+
tags:
6+
- tests::scsi
7+
tasks:
8+
- name: Set disk interface for test
9+
set_fact:
10+
storage_test_use_interface: "scsi"
11+
12+
- name: Import playbook
13+
import_playbook: tests_create_multiple_partitions_gpt.yml
14+
tags:
15+
- tests::scsi

tests/tests_disk_errors.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727
min_size: "10g"
2828
max_return: 1
2929

30+
- name: Verify that the role fails when no disks are specified
31+
include_tasks: verify-role-failed.yml
32+
vars:
33+
__storage_failed_params:
34+
storage_volumes:
35+
- name: test1
36+
type: disk
37+
mount_point: "{{ mount_location }}"
38+
__storage_failed_regex: no disks specified for volume 'test1'
39+
__storage_failed_msg: Role did not report that no disks were specified
40+
3041
- name: Verify that the role fails with the expected error message
3142
include_tasks: verify-role-failed.yml
3243
vars:

0 commit comments

Comments
 (0)