|
|
e662d2 |
diff --git a/library/blivet.py b/library/blivet.py
|
|
|
e662d2 |
index eb8bb11..e927121 100644
|
|
|
e662d2 |
--- a/library/blivet.py
|
|
|
e662d2 |
+++ b/library/blivet.py
|
|
|
e662d2 |
@@ -104,6 +104,7 @@ try:
|
|
|
e662d2 |
from blivet3.formats import get_format
|
|
|
e662d2 |
from blivet3.partitioning import do_partitioning
|
|
|
e662d2 |
from blivet3.size import Size
|
|
|
e662d2 |
+ from blivet3.udev import trigger
|
|
|
e662d2 |
from blivet3.util import set_up_logging
|
|
|
e662d2 |
BLIVET_PACKAGE = 'blivet3'
|
|
|
e662d2 |
except ImportError:
|
|
|
e662d2 |
@@ -116,6 +117,7 @@ except ImportError:
|
|
|
e662d2 |
from blivet.formats import get_format
|
|
|
e662d2 |
from blivet.partitioning import do_partitioning
|
|
|
e662d2 |
from blivet.size import Size
|
|
|
e662d2 |
+ from blivet.udev import trigger
|
|
|
e662d2 |
from blivet.util import set_up_logging
|
|
|
e662d2 |
BLIVET_PACKAGE = 'blivet'
|
|
|
e662d2 |
except ImportError:
|
|
|
e662d2 |
@@ -821,7 +823,10 @@ class BlivetPool(BlivetBase):
|
|
|
e662d2 |
|
|
|
e662d2 |
def _look_up_disks(self):
|
|
|
e662d2 |
""" Look up the pool's disks in blivet's device tree. """
|
|
|
e662d2 |
- if not self._pool['disks']:
|
|
|
e662d2 |
+ if self._disks:
|
|
|
e662d2 |
+ return
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ if not self._device and not self._pool['disks']:
|
|
|
e662d2 |
raise BlivetAnsibleError("no disks specified for pool '%s'" % self._pool['name'])
|
|
|
e662d2 |
elif not isinstance(self._pool['disks'], list):
|
|
|
e662d2 |
raise BlivetAnsibleError("pool disks must be specified as a list")
|
|
|
e662d2 |
@@ -832,7 +837,7 @@ class BlivetPool(BlivetBase):
|
|
|
e662d2 |
if device is not None: # XXX fail if any disk isn't resolved?
|
|
|
e662d2 |
disks.append(device)
|
|
|
e662d2 |
|
|
|
e662d2 |
- if self._pool['disks'] and not disks:
|
|
|
e662d2 |
+ if self._pool['disks'] and not self._device and not disks:
|
|
|
e662d2 |
raise BlivetAnsibleError("unable to resolve any disks specified for pool '%s' (%s)" % (self._pool['name'], self._pool['disks']))
|
|
|
e662d2 |
|
|
|
e662d2 |
self._disks = disks
|
|
|
e662d2 |
@@ -974,9 +979,9 @@ class BlivetPool(BlivetBase):
|
|
|
e662d2 |
""" Schedule actions to configure this pool according to the yaml input. """
|
|
|
e662d2 |
global safe_mode
|
|
|
e662d2 |
# look up the device
|
|
|
e662d2 |
- self._look_up_disks()
|
|
|
e662d2 |
self._look_up_device()
|
|
|
e662d2 |
self._apply_defaults()
|
|
|
e662d2 |
+ self._look_up_disks()
|
|
|
e662d2 |
|
|
|
e662d2 |
# schedule destroy if appropriate, including member type change
|
|
|
e662d2 |
if not self.ultimately_present:
|
|
|
e662d2 |
@@ -999,6 +1004,7 @@ class BlivetPartitionPool(BlivetPool):
|
|
|
e662d2 |
return self._device.partitionable
|
|
|
e662d2 |
|
|
|
e662d2 |
def _look_up_device(self):
|
|
|
e662d2 |
+ self._look_up_disks()
|
|
|
e662d2 |
self._device = self._disks[0]
|
|
|
e662d2 |
|
|
|
e662d2 |
def _create(self):
|
|
|
e662d2 |
@@ -1354,6 +1360,13 @@ def run_module():
|
|
|
e662d2 |
|
|
|
e662d2 |
actions.append(action)
|
|
|
e662d2 |
|
|
|
e662d2 |
+ def ensure_udev_update(action):
|
|
|
e662d2 |
+ if action.is_create:
|
|
|
e662d2 |
+ sys_path = action.device.path
|
|
|
e662d2 |
+ if os.path.islink(sys_path):
|
|
|
e662d2 |
+ sys_path = os.readlink(action.device.path)
|
|
|
e662d2 |
+ trigger(action='change', subsystem='block', name=os.path.basename(sys_path))
|
|
|
e662d2 |
+
|
|
|
e662d2 |
def action_dict(action):
|
|
|
e662d2 |
return dict(action=action.type_desc_str,
|
|
|
e662d2 |
fs_type=action.format.type if action.is_format else None,
|
|
|
e662d2 |
@@ -1395,6 +1408,7 @@ def run_module():
|
|
|
e662d2 |
if scheduled:
|
|
|
e662d2 |
# execute the scheduled actions, committing changes to disk
|
|
|
e662d2 |
callbacks.action_executed.add(record_action)
|
|
|
e662d2 |
+ callbacks.action_executed.add(ensure_udev_update)
|
|
|
e662d2 |
try:
|
|
|
e662d2 |
b.devicetree.actions.process(devices=b.devicetree.devices, dry_run=module.check_mode)
|
|
|
e662d2 |
except Exception as e:
|
|
|
e662d2 |
diff --git a/tests/tests_existing_lvm_pool.yml b/tests/tests_existing_lvm_pool.yml
|
|
|
e662d2 |
new file mode 100644
|
|
|
e662d2 |
index 0000000..854ac0d
|
|
|
e662d2 |
--- /dev/null
|
|
|
e662d2 |
+++ b/tests/tests_existing_lvm_pool.yml
|
|
|
e662d2 |
@@ -0,0 +1,54 @@
|
|
|
e662d2 |
+---
|
|
|
e662d2 |
+- hosts: all
|
|
|
e662d2 |
+ become: true
|
|
|
e662d2 |
+ vars:
|
|
|
e662d2 |
+ mount_location: '/opt/test1'
|
|
|
e662d2 |
+ volume_group_size: '5g'
|
|
|
e662d2 |
+ volume_size: '4g'
|
|
|
e662d2 |
+ pool_name: foo
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ tasks:
|
|
|
e662d2 |
+ - include_role:
|
|
|
e662d2 |
+ name: linux-system-roles.storage
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ - include_tasks: get_unused_disk.yml
|
|
|
e662d2 |
+ vars:
|
|
|
e662d2 |
+ min_size: "{{ volume_group_size }}"
|
|
|
e662d2 |
+ max_return: 1
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ - name: Create one LVM logical volume under one volume group
|
|
|
e662d2 |
+ include_role:
|
|
|
e662d2 |
+ name: linux-system-roles.storage
|
|
|
e662d2 |
+ vars:
|
|
|
e662d2 |
+ storage_pools:
|
|
|
e662d2 |
+ - name: "{{ pool_name }}"
|
|
|
e662d2 |
+ disks: "{{ unused_disks }}"
|
|
|
e662d2 |
+ volumes:
|
|
|
e662d2 |
+ - name: test1
|
|
|
e662d2 |
+ size: "{{ volume_size }}"
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ - include_tasks: verify-role-results.yml
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ - name: Create another volume in the existing pool, identified only by name.
|
|
|
e662d2 |
+ include_role:
|
|
|
e662d2 |
+ name: linux-system-roles.storage
|
|
|
e662d2 |
+ vars:
|
|
|
e662d2 |
+ storage_pools:
|
|
|
e662d2 |
+ - name: "{{ pool_name }}"
|
|
|
e662d2 |
+ volumes:
|
|
|
e662d2 |
+ - name: newvol
|
|
|
e662d2 |
+ size: '2 GiB'
|
|
|
e662d2 |
+ fs_type: ext4
|
|
|
e662d2 |
+ fs_label: newvol
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ - include_tasks: verify-role-results.yml
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ - name: Clean up.
|
|
|
e662d2 |
+ include_role:
|
|
|
e662d2 |
+ name: linux-system-roles.storage
|
|
|
e662d2 |
+ vars:
|
|
|
e662d2 |
+ storage_pools:
|
|
|
e662d2 |
+ - name: "{{ pool_name }}"
|
|
|
e662d2 |
+ state: absent
|
|
|
e662d2 |
+
|
|
|
e662d2 |
+ - include_tasks: verify-role-results.yml
|