Blame SOURCES/storage-no-disks-existing.diff

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