Debian Codegraph @

test/verify/check-storage-vdo

raw
1 #!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)
2
3 #
4 # Copyright (C) 2015 Red Hat, Inc.
5 # SPDX-License-Identifier: LGPL-2.1-or-later
6
7
8 import packagelib
9 import storagelib
10 import testlib
11
12 SIZE_10G = "10000000000"
13
14 # OS images that support VDO logical volumes
15 VDO_IMAGE_PREFIXES = ("rhel-", "centos-", "arch")
16
17
18 @testlib.skipImage("VDO support not installed", "*-bootc")
19 class TestStorageVDO(storagelib.StorageCase):
20
21 provision = {"0": {"memory_mb": 1800}}
22
23 def testVdo(self):
24 m = self.machine
25 b = self.browser
26
27 self.login_and_go("/storage")
28 # an empty xfs filesystem created with 6.4.0 is smaller then newer xfs versions
29 old_xfs = m.image.startswith('rhel-9') or m.image.startswith('centos-9') or m.image.startswith('rhel-8')
30
31 # Make a volume group in which to create the VDO LV
32 dev = "/dev/" + m.add_disk(SIZE_10G, serial="DISK1")["dev"]
33 b.wait_visible(self.card_row("Storage", name=dev))
34 m.execute("vgcreate vdo_vgroup /dev/sda")
35
36 self.click_card_row("Storage", name="vdo_vgroup")
37 b.wait_in_text(self.card("LVM2 logical volumes"), "No logical volumes")
38
39 b.click(self.card_button("LVM2 logical volumes", "Create new logical volume"))
40 self.dialog_wait_open()
41 b._wait_present("[data-field='purpose'] select option[value='block']")
42
43 # Currently, vdo is only supported by Cockpit on RHEL
44 if not m.image.startswith(VDO_IMAGE_PREFIXES):
45 b.wait_not_present("[data-field='purpose'] select option[value='vdo']")
46 return
47
48 # create VDO LV with default options and default virtual size
49 self.dialog_set_val("name", "vdo0")
50 self.dialog_set_val("purpose", "vdo")
51 self.dialog_set_val("vdo_psize", 6000)
52 self.dialog_apply()
53 self.dialog_wait_close()
54
55 # pool name gets auto-generated
56 pool_name = "vpool0"
57
58 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "vdo0")
59 # the pool does not appear as a top-level volume
60 b.wait_not_present(self.card_row("LVM2 logical volumes", name=pool_name))
61 self.click_card_row("LVM2 logical volumes", 1)
62 # Volume card
63 b.wait_text(self.card_desc("LVM2 logical volume", "Name"), "vdo0")
64 b.wait_in_text(self.card_desc("LVM2 logical volume", "Size"), "10.0 GB")
65 # VDO pool card
66 b.wait_text(self.card_desc("LVM2 VDO pool", "Name"), pool_name)
67 b.wait_in_text(self.card_desc("LVM2 VDO pool", "Size"), "6.00 GB")
68 # initial physical usage is ~ 4 GB, overhead for the deduplication index
69 b.wait_text(self.card_desc("LVM2 VDO pool", "Data used"), "3.86 GB (64%)")
70 b.wait_text(self.card_desc("LVM2 VDO pool", "Metadata used"), "0%")
71 b.wait_visible(self.card("LVM2 VDO pool") + " input[aria-label='Use compression']:checked")
72 b.wait_visible(self.card("LVM2 VDO pool") + " input[aria-label='Use deduplication']:checked")
73
74 # create a filesystem
75 self.click_card_dropdown("Unformatted data", "Format")
76 self.dialog({"type": "xfs",
77 "name": "vdofs",
78 "mount_point": "/run/data"})
79 b.wait_visible(self.card("xfs filesystem"))
80
81 # compressible data should affect logical usage
82 m.execute("dd if=/dev/zero of=/run/data/empty bs=1M count=1000")
83 b.wait_in_text(self.card_desc("xfs filesystem", "Usage"), "1.2 / " if old_xfs else "1.3 / ")
84 # but not physical usage
85 b.wait_text(self.card_desc("LVM2 VDO pool", "Data used"), "3.86 GB (64%)")
86
87 # incompressible data
88 m.execute("dd if=/dev/urandom of=/run/data/gibberish bs=1M count=1000")
89 b.wait_in_text(self.card_desc("xfs filesystem", "Usage"), "2.2 / " if old_xfs else "2.3 / ")
90 # equal amount of physical space (not completely predictable due to random data)
91 b.wait_in_text(self.card_desc("LVM2 VDO pool", "Data used"), "4.")
92
93 def wait_prop(device, prop, value):
94 m.execute(f"until lvdisplay --noheadings -Co {prop} /dev/vdo_vgroup/{device} | grep -q '{value}'; do sleep 0.1; done")
95
96 # change compression/deduplication
97 b.click("input[aria-label='Use compression']")
98 b.wait_visible("input[aria-label='Use compression']:not(checked):not([disabled])")
99 wait_prop(pool_name, "vdo_compression_state", "offline")
100 b.click("input[aria-label='Use compression']")
101 b.wait_visible("input[aria-label='Use compression']:checked:not([disabled])")
102 wait_prop(pool_name, "vdo_compression_state", "online")
103
104 b.click("input[aria-label='Use deduplication']")
105 b.wait_visible("input[aria-label='Use deduplication']:not(checked):not([disabled])")
106 wait_prop(pool_name, "vdo_index_state", r"offline\|closed")
107 b.click("input[aria-label='Use deduplication']")
108 b.wait_visible("input[aria-label='Use deduplication']:checked:not([disabled])")
109 wait_prop(pool_name, "vdo_index_state", "online")
110
111 # grow volume
112 b.click(self.card_button("LVM2 logical volume", "Grow"))
113 self.dialog({"size": 12000})
114 b.wait_in_text(self.card_desc("LVM2 logical volume", "Size"), "12.0 GB")
115 wait_prop("vdo0", "lv_size", "11.18g")
116
117 # grow pool
118 b.click(self.card_button("LVM2 VDO pool", "Grow"))
119 self.dialog({"size": 8000})
120 b.wait_in_text(self.card_desc("LVM2 VDO pool", "Size"), "8.15 GB")
121 wait_prop(pool_name, "lv_size", "7.59g")
122
123 # deleting the vdo0 volume deletes the pool as well
124 self.click_card_dropdown("LVM2 logical volume", "Delete")
125 self.confirm()
126 b.wait_in_text(self.card("LVM2 logical volumes"), "No logical volumes")
127 self.assertEqual(m.execute("lvs --noheadings").strip(), "")
128
129 # create VDO LV with customized options
130 b.click(self.card_button("LVM2 logical volumes", "Create new logical volume"))
131 self.dialog_wait_open()
132 b._wait_present("[data-field='purpose'] select option[value='block']")
133 self.dialog_set_val("name", "vdo0")
134 self.dialog_set_val("purpose", "vdo")
135 self.dialog_set_val("vdo_psize", 6000)
136 # grossly overcommitted
137 self.dialog_set_val("vdo_lsize", 20000)
138 self.dialog_set_val("vdo_options.compression", val=False)
139 self.dialog_apply()
140 self.dialog_wait_close()
141 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "vdo0")
142
143 self.click_card_row("LVM2 logical volumes", 1)
144 # Volume card
145 b.wait_text(self.card_desc("LVM2 logical volume", "Name"), "vdo0")
146 b.wait_in_text(self.card_desc("LVM2 logical volume", "Size"), "20.0 GB")
147 # VDO Pool tab
148 b.wait_in_text(self.card_desc("LVM2 VDO pool", "Size"), "6.00 GB")
149 b.wait_visible("input[aria-label='Use compression']:not(:checked)")
150 b.wait_visible("input[aria-label='Use deduplication']:checked")
151 wait_prop(pool_name, "vdo_compression_state", "offline")
152 wait_prop(pool_name, "vdo_index_state", "online")
153
154 # delete again
155 self.click_card_dropdown("LVM2 logical volume", "Delete")
156 self.confirm()
157 b.wait_in_text(self.card("LVM2 logical volumes"), "No logical volumes")
158 self.assertEqual(m.execute("lvs --noheadings").strip(), "")
159
160 # react to CLI
161 m.execute("lvcreate --type vdo --size 6g --virtualsize 10g --name vdo1 --yes vdo_vgroup")
162 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "vdo1")
163 m.execute("lvremove --yes /dev/vdo_vgroup/vdo1")
164 b.wait_in_text(self.card("LVM2 logical volumes"), "No logical volumes")
165
166
167 @testlib.onlyImage("legacy VDO API only supported on RHEL 8", "rhel-8*")
168 class TestStorageLegacyVDO(storagelib.StorageCase):
169
170 def setUp(self):
171 super().setUp()
172 # packagekit eats too much CPU/memory in the background
173 self.machine.execute("systemctl mask packagekit; systemctl stop packagekit")
174
175 def testVdo(self):
176 m = self.machine
177 b = self.browser
178
179 self.login_and_go("/storage")
180
181 # Make a logical volume for use as the backing device.
182 m.add_disk(SIZE_10G, serial="DISK1")
183 b.wait_visible(self.card_row("Storage", name="/dev/sda"))
184 m.execute("vgcreate vdo_vgroup /dev/sda; lvcreate -n lvol -L 5G vdo_vgroup")
185 # Create VDO; this is not supported any more, thus no UI for it
186 m.execute("vdo create --device /dev/vdo_vgroup/lvol --name vdo0 --vdoLogicalSize 5G", timeout=300)
187
188 self.click_card_row("Storage", name="lvol")
189
190 def detail(index):
191 card = self.card("VDO device vdo0")
192 return f'{card} .pf-v6-c-description-list__group:nth-of-type({index}) > dd'
193
194 b.wait_text(detail(1), "/dev/mapper/vdo0")
195 b.wait_in_text(detail(2), "used of 5.37 GB")
196 b.wait_in_text(detail(3), "used of 5.37 GB")
197 b.wait_text(detail(4), "268 MB")
198 b.wait_visible(detail(5) + " input:checked")
199 b.wait_visible(detail(6) + " input:checked")
200
201 # Make a filesystem on it
202
203 self.click_card_dropdown("Unformatted data", "Format")
204 self.dialog({"type": "xfs",
205 "name": "FILESYSTEM",
206 "mount_point": "/run/data"})
207 b.wait_in_text(self.card_desc("xfs filesystem", "Mount point"), "after network")
208 b.wait_in_text(self.card_desc("xfs filesystem", "Mount point"), "x-systemd.device-timeout=0")
209 b.wait_in_text(self.card_desc("xfs filesystem", "Mount point"), "x-systemd.requires=vdo.service")
210 b.wait_in_text(self.card_desc("xfs filesystem", "Usage"), "/ 5.4 GB")
211
212 # Grow physical
213
214 m.execute("lvresize vdo_vgroup/lvol -L 9G")
215 b.wait_in_text(".pf-v6-c-alert__description", 'Only 5.37 GB of 9')
216 b.click("button:contains('Grow to take all space')")
217 b.wait_not_present(".pf-v6-c-alert")
218 b.wait_in_text(detail(2), "used of 9.66 GB")
219
220 # Grow logical
221
222 b.click(detail(3) + " button:contains('Grow')")
223 self.dialog({"lsize": 10000})
224 b.wait_in_text(detail(3), "used of 10.0 GB")
225 b.wait_in_text(self.card_desc("xfs filesystem", "Usage"), "/ 10 GB")
226
227 # Stop
228
229 b.wait_visible(self.card("xfs filesystem"))
230 b.click(self.card_button("VDO device vdo0", "Stop"))
231 self.dialog_wait_open()
232 b.wait_in_text("#dialog", "unmount, stop")
233 self.dialog_apply()
234 self.dialog_wait_close()
235 b.wait_not_present(self.card("xfs filesystem"))
236
237 # Delete
238
239 self.click_card_dropdown("VDO device vdo0", "Delete")
240 self.dialog_wait_open()
241 self.dialog_apply_with_retry(expected_errors=["Device or resource busy"])
242 b.wait_not_present(self.card("VDO device vdo0"))
243 b.wait_visible(self.card("Unformatted data"))
244 b.wait_visible(self.card("LVM2 logical volume"))
245
246 def testBrokenVdo(self):
247 m = self.machine
248 b = self.browser
249
250 self.login_and_go("/storage")
251
252 m.add_disk(SIZE_10G, serial="DISK1")
253 b.wait_visible(self.card_row("Storage", name="/dev/sda"))
254
255 # Install a valid configuration file that describes a broken VDO
256 m.write("/etc/vdoconf.yml", """
257 config: !Configuration
258 vdos:
259 vdo0: !VDOService
260 _operationState: beginCreate
261 ackThreads: 1
262 activated: enabled
263 bioRotationInterval: 64
264 bioThreads: 4
265 blockMapCacheSize: 128M
266 blockMapPeriod: 16380
267 compression: enabled
268 cpuThreads: 2
269 deduplication: enabled
270 device: /dev/sda
271 hashZoneThreads: 1
272 indexCfreq: 0
273 indexMemory: 0.25
274 indexSparse: disabled
275 indexThreads: 0
276 logicalBlockSize: 4096
277 logicalSize: 10G
278 logicalThreads: 1
279 name: vdo0
280 physicalSize: 10G
281 physicalThreads: 1
282 readCache: disabled
283 readCacheSize: 0M
284 slabSize: 2G
285 writePolicy: sync
286 version: 538380551
287 """)
288
289 self.click_card_row("Storage", name="/dev/sda")
290 b.click(".pf-m-danger button:contains('Remove device')")
291 b.wait_visible(self.card("Unformatted data"))
292
293 def testBrokenVdoConfig(self):
294 m = self.machine
295 b = self.browser
296
297 self.login_and_go("/storage")
298
299 m.add_disk(SIZE_10G, serial="DISK1")
300 b.wait_visible(self.card_row("Storage", name="/dev/sda"))
301
302 # Install a valid configuration file
303 m.write("/etc/vdoconf.yml", """
304 config: !Configuration
305 vdos:
306 vdo0: !VDOService
307 _operationState: finished
308 ackThreads: 1
309 activated: enabled
310 bioRotationInterval: 64
311 bioThreads: 4
312 blockMapCacheSize: 128M
313 blockMapPeriod: 16380
314 compression: enabled
315 cpuThreads: 2
316 deduplication: enabled
317 device: /dev/sda
318 hashZoneThreads: 1
319 indexCfreq: 0
320 indexMemory: 0.25
321 indexSparse: disabled
322 indexThreads: 0
323 logicalBlockSize: 4096
324 logicalSize: 10G
325 logicalThreads: 1
326 name: vdo0
327 physicalSize: 10G
328 physicalThreads: 1
329 readCache: disabled
330 readCacheSize: 0M
331 slabSize: 2G
332 writePolicy: sync
333 version: 538380551
334 """)
335
336 b.wait_in_text(self.card_row("Storage", name="/dev/sda"), "VDO device")
337
338 # Install a broken configuration file
339 m.write("/etc/vdoconf.yml", """
340 config: !Configuration
341 vdos:
342 vdo0: !VDOService
343 blah: 12
344 """)
345
346 b.wait_in_text(self.card_row("Storage", name="/dev/sda"), "Unformatted data")
347
348 # Install a valid configuration file again
349 m.write("/etc/vdoconf.yml", """
350 config: !Configuration
351 vdos:
352 vdo1: !VDOService
353 _operationState: finished
354 ackThreads: 1
355 activated: enabled
356 bioRotationInterval: 64
357 bioThreads: 4
358 blockMapCacheSize: 128M
359 blockMapPeriod: 16380
360 compression: enabled
361 cpuThreads: 2
362 deduplication: enabled
363 device: /dev/sda
364 hashZoneThreads: 1
365 indexCfreq: 0
366 indexMemory: 0.25
367 indexSparse: disabled
368 indexThreads: 0
369 logicalBlockSize: 4096
370 logicalSize: 10G
371 logicalThreads: 1
372 name: vdo1
373 physicalSize: 10G
374 physicalThreads: 1
375 readCache: disabled
376 readCacheSize: 0M
377 slabSize: 2G
378 writePolicy: sync
379 version: 538380551
380 """)
381
382 b.wait_in_text(self.card_row("Storage", name="/dev/sda"), "VDO device")
383
384
385 @testlib.onlyImage("VDO package installation only supported on RHEL", "rhel-*", "centos-*")
386 @testlib.skipOstree("package installation not supported on ostree images")
387 class TestStoragePackagesVDO(packagelib.PackageCase, storagelib.StorageHelpers):
388
389 provision = {"0": {"memory_mb": 1500}}
390
391 def testVdoMissingPackages(self):
392 m = self.machine
393 b = self.browser
394
395 # Remove the vdoformat utility by uninstalling the vdo
396 # package. Older versions of LVM2 will need it and Cockpit
397 # will help to install the "vdo" package again. Newer
398 # versions of LVM2 do not need vdoformat and Cockpit should
399 # not try to install it.
400
401 m.execute("rpm --erase --verbose vdo")
402
403 needs_vdoformat = m.image.startswith(("rhel-8", "rhel-9", "centos-9"))
404
405 self.login_and_go("/storage")
406 m.add_disk(SIZE_10G, serial="DISK1")
407 b.wait_visible(self.card_row("Storage", name="/dev/sda"))
408 m.execute("vgcreate vdo_vgroup /dev/sda")
409
410 self.click_card_row("Storage", name="vdo_vgroup")
411 b.click("button:contains('Create new logical volume')")
412 self.dialog_wait_open()
413 b._wait_present("[data-field='purpose'] select option[value='block']")
414 # no package installation helper text
415 self.assertFalse(b.is_present("#dialog .pf-v6-c-helper-text"))
416 self.dialog_set_val("purpose", "vdo")
417
418 if needs_vdoformat:
419 # shows the package installation note
420 b.wait_in_text("#dialog .pf-v6-c-helper-text", "vdo package will be installed")
421
422 # vdo package does not exist
423 self.dialog_apply()
424 b.wait_in_text("#dialog .pf-v6-c-alert.pf-m-danger", "vdo is not available from any repository")
425
426 self.createPackage("vdo", "999", "1")
427 self.enableRepo()
428
429 self.dialog_apply()
430 # gets over package installation now, but it's a mock package
431 b.wait_in_text("#dialog .pf-v6-c-alert.pf-m-danger", "vdoformat")
432 b.wait_in_text("#dialog .pf-v6-c-alert.pf-m-danger", "No such file or directory")
433 # but it got past package installation
434 self.assertIn("999", m.execute("rpm -q vdo"))
435
436 self.dialog_cancel()
437
438 else:
439 # Don't need vdoformat, volume can be created
440 b.wait_not_present("#dialog .pf-v6-c-helper-text")
441 self.dialog_apply()
442 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "lvol0")
443
444
445 if __name__ == '__main__':
446 testlib.test_main()