File: use-custom-uuid-fact.patch

package info (click to toggle)
puppet-module-swift 21.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,084 kB
  • sloc: ruby: 9,261; python: 38; sh: 10; makefile: 10
file content (68 lines) | stat: -rw-r--r-- 2,623 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Description: Use custom UUID fact
Author: Thomas Goirand <zigo@debian.org>
Forwarded: no
Last-Update: 2021-02-15

Index: puppet-module-swift/lib/facter/swift-device-uuids.rb
===================================================================
--- /dev/null
+++ puppet-module-swift/lib/facter/swift-device-uuids.rb
@@ -0,0 +1,26 @@
+# module_name/lib/facter/swift_device_uuids
+require 'open3'
+Facter.add(:swift_device_uuids) do
+  setcode do
+    if Dir.exists?('/dev/disk/oci-sort')
+      dir_for_list = '/dev/disk/oci-sort/'
+    else
+      dir_for_list = '/dev/'
+    end
+
+    myhash = {}
+
+    Dir[dir_for_list + '[vs]d*'].map { |f|
+      devname = File.basename(f)
+      devpath = File.realpath(f)
+      cmd = "blkid  " + devpath + '| grep xfs | sed \'s/.*[ ]UUID=\"\([^\"]*\)[a-zA-Z|0-9|\-]*\".*/\1/p\' | head -n 1'
+      output, exit_code = Open3.capture2(cmd)
+      outputclean = output.gsub( /\n/m, "" )
+      unless output.to_s.strip.empty?
+        c = { devname => outputclean }
+        myhash = myhash.merge(c)
+      end
+    }
+    myhash
+  end
+end
Index: puppet-module-swift/manifests/storage/xfs.pp
===================================================================
--- puppet-module-swift.orig/manifests/storage/xfs.pp
+++ puppet-module-swift/manifests/storage/xfs.pp
@@ -60,6 +60,16 @@ define swift::storage::xfs(
     $target_device = $device
   }
 
+  # This uses our custom fact for fetching uuid on
+  # block devices which aren't partitions
+  if $facts["swift_device_uuids"]["${name}"] {
+    $device_uuid = $facts["swift_device_uuids"]["${name}"]
+  }else{
+    # Fall-back to digging partitions
+    $device_uuid = dig44($facts, ['partitions', $target_device, 'uuid'])
+              unless $mount_device { fail("Unable to fetch uuid of ${target_device}") }
+  }
+
   # Currently, facter doesn't support to fetch the device's uuid, only the partition's.
   # If you want to mount device by uuid, you should set $ext_args to 'mkpart primary 0% 100%'
   # in swift::storage::disk to make a partition. Also, the device name should change accordingly.
@@ -67,9 +77,7 @@ define swift::storage::xfs(
   # The code does NOT work in existing Swift cluster.
   case $mount_type {
     'path': { $mount_device = $target_device }
-    'uuid': { $mount_device = dig44($facts, ['partitions', $target_device, 'uuid'])
-              unless $mount_device { fail("Unable to fetch uuid of ${target_device}") }
-            }
+    'uuid': { $mount_device = "UUID=${device_uuid}" }
     default: { fail("Unsupported mount_type parameter value: '${mount_type}'. Should be 'path' or 'uuid'.") }
   }