-
Notifications
You must be signed in to change notification settings - Fork 84
/
action_test.py
1163 lines (995 loc) · 53 KB
/
action_test.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import unittest
from tests.storagetestcase import StorageTestCase
import blivet
from blivet.formats import getFormat
from blivet.size import Size
# device classes for brevity's sake -- later on, that is
from blivet.devices import DiskDevice
from blivet.devices import PartitionDevice
from blivet.devices import MDRaidArrayDevice
from blivet.devices import LVMVolumeGroupDevice
from blivet.devices import LVMLogicalVolumeDevice
# action classes
from blivet.deviceaction import ActionCreateDevice
from blivet.deviceaction import ActionResizeDevice
from blivet.deviceaction import ActionDestroyDevice
from blivet.deviceaction import ActionCreateFormat
from blivet.deviceaction import ActionResizeFormat
from blivet.deviceaction import ActionDestroyFormat
from blivet.deviceaction import ActionAddMember
from blivet.deviceaction import ActionRemoveMember
DEVICE_CLASSES = [
DiskDevice,
PartitionDevice,
MDRaidArrayDevice,
LVMVolumeGroupDevice,
LVMLogicalVolumeDevice
]
@unittest.skipUnless(not any(x.unavailableTypeDependencies() for x in DEVICE_CLASSES), "some unsupported device classes required for this test")
class DeviceActionTestCase(StorageTestCase):
""" DeviceActionTestSuite """
def setUp(self):
""" Create something like a preexisting autopart on two disks (sda,sdb).
The other two disks (sdc,sdd) are left for individual tests to use.
"""
super(DeviceActionTestCase, self).setUp()
for name in ["sda", "sdb", "sdc", "sdd"]:
disk = self.newDevice(device_class=DiskDevice,
name=name, size=Size("100 GiB"))
disk.format = self.newFormat("disklabel", path=disk.path,
exists=True)
self.storage.devicetree._addDevice(disk)
# create a layout similar to autopart as a starting point
sda = self.storage.devicetree.getDeviceByName("sda")
sdb = self.storage.devicetree.getDeviceByName("sdb")
sda1 = self.newDevice(device_class=PartitionDevice,
exists=True, name="sda1", parents=[sda],
size=Size("500 MiB"))
sda1.format = self.newFormat("ext4", mountpoint="/boot",
device_instance=sda1,
device=sda1.path, exists=True)
self.storage.devicetree._addDevice(sda1)
sda2 = self.newDevice(device_class=PartitionDevice,
size=Size("99.5 GiB"), name="sda2",
parents=[sda], exists=True)
sda2.format = self.newFormat("lvmpv", device=sda2.path, exists=True)
self.storage.devicetree._addDevice(sda2)
sdb1 = self.newDevice(device_class=PartitionDevice,
size=Size("99.999 GiB"), name="sdb1",
parents=[sdb], exists=True)
sdb1.format = self.newFormat("lvmpv", device=sdb1.path, exists=True)
self.storage.devicetree._addDevice(sdb1)
vg = self.newDevice(device_class=LVMVolumeGroupDevice,
name="VolGroup", parents=[sda2, sdb1],
exists=True)
self.storage.devicetree._addDevice(vg)
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
size=Size("160 GiB"), exists=True)
lv_root.format = self.newFormat("ext4", mountpoint="/",
device_instance=lv_root,
device=lv_root.path, exists=True)
self.storage.devicetree._addDevice(lv_root)
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
size=Size("4000 MiB"), exists=True)
lv_swap.format = self.newFormat("swap", device=lv_swap.path,
device_instance=lv_swap,
exists=True)
self.storage.devicetree._addDevice(lv_swap)
def testActions(self):
""" Verify correct management of actions.
- action creation/registration/cancellation
- ActionCreateDevice adds device to tree
- ActionDestroyDevice removes device from tree
- ActionCreateFormat sets device.format in tree
- ActionDestroyFormat unsets device.format in tree
- cancelled action's registration side-effects reversed
- failure to register destruction of non-leaf device
- failure to register creation of device already in tree?
- failure to register destruction of device not in tree?
- action pruning
- non-existent-device create..destroy cycles removed
- all actions on this device should get removed
- all actions pruned from to-be-destroyed devices
- resize, format, &c
- redundant resize/format actions pruned
- last one registered stays
- action sorting
- destroy..resize..create
- creation
- leaves-last, including formatting
- destruction
- leaves-first
"""
devicetree = self.storage.devicetree
# clear the disks
self.destroyAllDevices()
self.assertEqual(devicetree.getDevicesByType("lvmlv"), [])
self.assertEqual(devicetree.getDevicesByType("lvmvg"), [])
self.assertEqual(devicetree.getDevicesByType("partition"), [])
sda = devicetree.getDeviceByName("sda")
self.assertNotEqual(sda, None, "failed to find disk 'sda'")
sda1 = self.newDevice(device_class=PartitionDevice,
name="sda1", size=Size("500 MiB"),
parents=[sda])
self.scheduleCreateDevice(sda1)
sda2 = self.newDevice(device_class=PartitionDevice,
name="sda2", size=Size("100 GiB"),
parents=[sda])
self.scheduleCreateDevice(sda2)
fmt = self.newFormat("lvmpv", device=sda2.path)
self.scheduleCreateFormat(device=sda2, fmt=fmt)
vg = self.newDevice(device_class=LVMVolumeGroupDevice,
name="vg", parents=[sda2])
self.scheduleCreateDevice(vg)
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
size=Size("60 GiB"))
self.scheduleCreateDevice(lv_root)
fmt = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
self.scheduleCreateFormat(device=lv_root, fmt=fmt)
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
size=Size("4000 MiB"))
self.scheduleCreateDevice(lv_swap)
fmt = self.newFormat("swap", device=lv_swap.path)
self.scheduleCreateFormat(device=lv_swap, fmt=fmt)
sda3 = self.newDevice(device_class=PartitionDevice,
name="sda3", parents=[sda],
size=Size("40 GiB"))
self.scheduleCreateDevice(sda3)
fmt = self.newFormat("mdmember", device=sda3.path)
self.scheduleCreateFormat(device=sda3, fmt=fmt)
sdb = devicetree.getDeviceByName("sdb")
self.assertNotEqual(sdb, None, "failed to find disk 'sdb'")
sdb1 = self.newDevice(device_class=PartitionDevice,
name="sdb1", parents=[sdb],
size=Size("40 GiB"))
self.scheduleCreateDevice(sdb1)
fmt = self.newFormat("mdmember", device=sdb1.path,)
self.scheduleCreateFormat(device=sdb1, fmt=fmt)
md0 = self.newDevice(device_class=MDRaidArrayDevice,
name="md0", level="raid0", minor=0,
memberDevices=2, totalDevices=2,
parents=[sdb1, sda3])
self.scheduleCreateDevice(md0)
fmt = self.newFormat("ext4", device=md0.path, mountpoint="/home")
self.scheduleCreateFormat(device=md0, fmt=fmt)
fmt = self.newFormat("ext4", mountpoint="/boot", device=sda1.path)
self.scheduleCreateFormat(device=sda1, fmt=fmt)
def testActionCreation(self):
""" Verify correct operation of action class constructors. """
# instantiation of device resize action for non-existent device should
# fail
# XXX resizable depends on existence, so this is covered implicitly
sdd = self.storage.devicetree.getDeviceByName("sdd")
p = self.newDevice(device_class=PartitionDevice,
name="sdd1", size=Size("32 GiB"), parents=[sdd])
self.failUnlessRaises(ValueError,
ActionResizeDevice,
p,
p.size + Size("7232 MiB"))
# instantiation of device resize action for non-resizable device
# should fail
vg = self.storage.devicetree.getDeviceByName("VolGroup")
self.assertNotEqual(vg, None)
self.failUnlessRaises(ValueError,
ActionResizeDevice,
vg,
vg.size + Size("32 MiB"))
# instantiation of format resize action for non-resizable format type
# should fail
lv_swap = self.storage.devicetree.getDeviceByName("VolGroup-lv_swap")
self.assertNotEqual(lv_swap, None)
self.failUnlessRaises(ValueError,
ActionResizeFormat,
lv_swap,
lv_swap.size + Size("32 MiB"))
# instantiation of format resize action for non-existent format
# should fail
lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
self.assertNotEqual(lv_root, None)
lv_root.format.exists = False
self.failUnlessRaises(ValueError,
ActionResizeFormat,
lv_root,
lv_root.size - Size("1000 MiB"))
lv_root.format.exists = True
# instantiation of device create action for existing device should
# fail
lv_swap = self.storage.devicetree.getDeviceByName("VolGroup-lv_swap")
self.assertNotEqual(lv_swap, None)
self.assertEqual(lv_swap.exists, True)
self.failUnlessRaises(ValueError,
ActionCreateDevice,
lv_swap)
# instantiation of format destroy action for device causes device's
# format attribute to be a DeviceFormat instance
lv_swap = self.storage.devicetree.getDeviceByName("VolGroup-lv_swap")
self.assertNotEqual(lv_swap, None)
orig_format = lv_swap.format
self.assertEqual(lv_swap.format.type, "swap")
destroy_swap = ActionDestroyFormat(lv_swap)
self.assertEqual(lv_swap.format.type, "swap")
destroy_swap.apply()
self.assertEqual(lv_swap.format.type, None)
# instantiation of format create action for device causes new format
# to be accessible via device's format attribute
new_format = getFormat("vfat", device=lv_swap.path)
create_swap = ActionCreateFormat(lv_swap, new_format)
self.assertEqual(lv_swap.format.type, None)
create_swap.apply()
self.assertEqual(lv_swap.format, new_format)
lv_swap.format = orig_format
def testActionRegistration(self):
""" Verify correct operation of action registration and cancelling. """
# self.setUp has just been run, so we should have something like
# a preexisting autopart config in the devicetree.
# registering a destroy action for a non-leaf device should fail
vg = self.storage.devicetree.getDeviceByName("VolGroup")
self.assertNotEqual(vg, None)
self.assertEqual(vg.isleaf, False)
a = ActionDestroyDevice(vg)
self.failUnlessRaises(ValueError,
self.storage.devicetree.registerAction,
a)
# registering any action other than create for a device that's not in
# the devicetree should fail
sdc = self.storage.devicetree.getDeviceByName("sdc")
self.assertNotEqual(sdc, None)
sdc1 = self.newDevice(device_class=PartitionDevice,
name="sdc1", size=Size("100 GiB"),
parents=[sdc], exists=True)
sdc1_format = self.newFormat("ext2", device=sdc1.path, mountpoint="/")
create_sdc1_format = ActionCreateFormat(sdc1, sdc1_format)
create_sdc1_format.apply()
self.failUnlessRaises(blivet.errors.DeviceTreeError,
self.storage.devicetree.registerAction,
create_sdc1_format)
sdc1_format.exists = True
sdc1_format._resizable = True
resize_sdc1_format = ActionResizeFormat(sdc1,
sdc1.size - Size("10 GiB"))
resize_sdc1_format.apply()
self.failUnlessRaises(blivet.errors.DeviceTreeError,
self.storage.devicetree.registerAction,
resize_sdc1_format)
resize_sdc1 = ActionResizeDevice(sdc1, sdc1.size - Size("10 GiB"))
resize_sdc1.apply()
self.failUnlessRaises(blivet.errors.DeviceTreeError,
self.storage.devicetree.registerAction,
resize_sdc1)
resize_sdc1.cancel()
resize_sdc1_format.cancel()
destroy_sdc1_format = ActionDestroyFormat(sdc1)
self.failUnlessRaises(blivet.errors.DeviceTreeError,
self.storage.devicetree.registerAction,
destroy_sdc1_format)
destroy_sdc1 = ActionDestroyDevice(sdc1)
self.failUnlessRaises(blivet.errors.DeviceTreeError,
self.storage.devicetree.registerAction,
destroy_sdc1)
# registering a device destroy action should cause the device to be
# removed from the devicetree
lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
self.assertNotEqual(lv_root, None)
a = ActionDestroyDevice(lv_root)
self.storage.devicetree.registerAction(a)
lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
self.assertEqual(lv_root, None)
self.storage.devicetree.cancelAction(a)
# registering a device create action should cause the device to be
# added to the devicetree
sdd = self.storage.devicetree.getDeviceByName("sdd")
self.assertNotEqual(sdd, None)
sdd1 = self.storage.devicetree.getDeviceByName("sdd1")
self.assertEqual(sdd1, None)
sdd1 = self.newDevice(device_class=PartitionDevice,
name="sdd1", size=Size("100 GiB"),
parents=[sdd])
a = ActionCreateDevice(sdd1)
self.storage.devicetree.registerAction(a)
sdd1 = self.storage.devicetree.getDeviceByName("sdd1")
self.assertNotEqual(sdd1, None)
def testActionObsoletes(self):
""" Verify correct operation of DeviceAction.obsoletes. """
self.destroyAllDevices(disks=["sdc"])
sdc = self.storage.devicetree.getDeviceByName("sdc")
self.assertNotEqual(sdc, None)
sdc1 = self.newDevice(device_class=PartitionDevice,
name="sdc1", parents=[sdc], size=Size("40 GiB"))
# ActionCreateDevice
#
# - obsoletes other ActionCreateDevice instances w/ lower id and same
# device
create_device_1 = ActionCreateDevice(sdc1)
create_device_1.apply()
create_device_2 = ActionCreateDevice(sdc1)
create_device_2.apply()
self.assertEqual(create_device_2.obsoletes(create_device_1), True)
self.assertEqual(create_device_1.obsoletes(create_device_2), False)
# ActionCreateFormat
#
# - obsoletes other ActionCreateFormat instances w/ lower id and same
# device
format_1 = self.newFormat("ext3", mountpoint="/home", device=sdc1.path)
format_2 = self.newFormat("ext3", mountpoint="/opt", device=sdc1.path)
create_format_1 = ActionCreateFormat(sdc1, format_1)
create_format_1.apply()
create_format_2 = ActionCreateFormat(sdc1, format_2)
create_format_2.apply()
self.assertEqual(create_format_2.obsoletes(create_format_1), True)
self.assertEqual(create_format_1.obsoletes(create_format_2), False)
# ActionResizeFormat
#
# - obsoletes other ActionResizeFormat instances w/ lower id and same
# device
sdc1.exists = True
sdc1.format.exists = True
sdc1.format._resizable = True
resize_format_1 = ActionResizeFormat(sdc1, sdc1.size - Size("1000 MiB"))
resize_format_1.apply()
resize_format_2 = ActionResizeFormat(sdc1, sdc1.size - Size("5000 MiB"))
resize_format_2.apply()
self.assertEqual(resize_format_2.obsoletes(resize_format_1), True)
self.assertEqual(resize_format_1.obsoletes(resize_format_2), False)
sdc1.exists = False
sdc1.format.exists = False
# ActionCreateFormat
#
# - obsoletes resize format actions w/ lower id on same device
new_format = self.newFormat("ext4", mountpoint="/foo", device=sdc1.path)
create_format_3 = ActionCreateFormat(sdc1, new_format)
create_format_3.apply()
self.assertEqual(create_format_3.obsoletes(resize_format_1), True)
self.assertEqual(create_format_3.obsoletes(resize_format_2), True)
# ActionResizeDevice
#
# - obsoletes other ActionResizeDevice instances w/ lower id and same
# device
sdc1.exists = True
sdc1.format.exists = True
sdc1.format._resizable = True
resize_device_1 = ActionResizeDevice(sdc1,
sdc1.size + Size("10 GiB"))
resize_device_1.apply()
resize_device_2 = ActionResizeDevice(sdc1,
sdc1.size - Size("10 GiB"))
resize_device_2.apply()
self.assertEqual(resize_device_2.obsoletes(resize_device_1), True)
self.assertEqual(resize_device_1.obsoletes(resize_device_2), False)
sdc1.exists = False
sdc1.format.exists = False
# ActionDestroyFormat
#
# - obsoletes all format actions w/ higher id on same device (including
# self if format does not exist)
destroy_format_1 = ActionDestroyFormat(sdc1)
destroy_format_1.apply()
destroy_format_2 = ActionDestroyFormat(sdc1)
destroy_format_2.apply()
self.assertEqual(destroy_format_1.obsoletes(create_format_1), True)
self.assertEqual(destroy_format_1.obsoletes(resize_format_1), True)
self.assertEqual(destroy_format_1.obsoletes(destroy_format_1), True)
self.assertEqual(destroy_format_2.obsoletes(destroy_format_1), False)
self.assertEqual(destroy_format_1.obsoletes(destroy_format_2), True)
# ActionDestroyDevice
#
# - obsoletes all actions w/ lower id that act on the same non-existent
# device (including self)
# sdc1 does not exist
destroy_sdc1 = ActionDestroyDevice(sdc1)
destroy_sdc1.apply()
self.assertEqual(destroy_sdc1.obsoletes(create_format_2), True)
self.assertEqual(destroy_sdc1.obsoletes(resize_format_2), True)
self.assertEqual(destroy_sdc1.obsoletes(create_device_1), True)
self.assertEqual(destroy_sdc1.obsoletes(resize_device_1), True)
self.assertEqual(destroy_sdc1.obsoletes(destroy_sdc1), True)
# ActionDestroyDevice
#
# - obsoletes all but ActionDestroyFormat actions w/ lower id on the
# same existing device
# sda1 exists
sda1 = self.storage.devicetree.getDeviceByName("sda1")
self.assertNotEqual(sda1, None)
#sda1.format._resizable = True
resize_sda1_format = ActionResizeFormat(sda1,
sda1.size - Size("50 MiB"))
resize_sda1_format.apply()
resize_sda1 = ActionResizeDevice(sda1, sda1.size - Size("50 MiB"))
resize_sda1.apply()
destroy_sda1_format = ActionDestroyFormat(sda1)
destroy_sda1_format.apply()
destroy_sda1 = ActionDestroyDevice(sda1)
destroy_sda1.apply()
self.assertEqual(destroy_sda1.obsoletes(resize_sda1_format), True)
self.assertEqual(destroy_sda1.obsoletes(resize_sda1), True)
self.assertEqual(destroy_sda1.obsoletes(destroy_sda1), False)
self.assertEqual(destroy_sda1.obsoletes(destroy_sda1_format), False)
def testActionPruning(self):
""" Verify correct functioning of action pruning. """
self.destroyAllDevices()
sda = self.storage.devicetree.getDeviceByName("sda")
self.assertNotEqual(sda, None, "failed to find disk 'sda'")
sda1 = self.newDevice(device_class=PartitionDevice,
name="sda1", size=Size("500 MiB"),
parents=[sda])
self.scheduleCreateDevice(sda1)
sda2 = self.newDevice(device_class=PartitionDevice,
name="sda2", size=Size("100 GiB"),
parents=[sda])
self.scheduleCreateDevice(sda2)
fmt = self.newFormat("lvmpv", device=sda2.path)
self.scheduleCreateFormat(device=sda2, fmt=fmt)
vg = self.newDevice(device_class=LVMVolumeGroupDevice,
name="vg", parents=[sda2])
self.scheduleCreateDevice(vg)
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
size=Size("60 GiB"))
self.scheduleCreateDevice(lv_root)
fmt = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
self.scheduleCreateFormat(device=lv_root, fmt=fmt)
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
size=Size("4 GiB"))
self.scheduleCreateDevice(lv_swap)
fmt = self.newFormat("swap", device=lv_swap.path)
self.scheduleCreateFormat(device=lv_swap, fmt=fmt)
# we'll soon schedule destroy actions for these members and the array,
# which will test pruning. the whole mess should reduce to nothing
sda3 = self.newDevice(device_class=PartitionDevice,
name="sda3", parents=[sda],
size=Size("40 GiB"))
self.scheduleCreateDevice(sda3)
fmt = self.newFormat("mdmember", device=sda3.path)
self.scheduleCreateFormat(device=sda3, fmt=fmt)
sdb = self.storage.devicetree.getDeviceByName("sdb")
self.assertNotEqual(sdb, None, "failed to find disk 'sdb'")
sdb1 = self.newDevice(device_class=PartitionDevice,
name="sdb1", parents=[sdb],
size=Size("40 GiB"))
self.scheduleCreateDevice(sdb1)
fmt = self.newFormat("mdmember", device=sdb1.path,)
self.scheduleCreateFormat(device=sdb1, fmt=fmt)
md0 = self.newDevice(device_class=MDRaidArrayDevice,
name="md0", level="raid0", minor=0,
memberDevices=2, totalDevices=2,
parents=[sdb1, sda3])
self.scheduleCreateDevice(md0)
fmt = self.newFormat("ext4", device=md0.path, mountpoint="/home")
self.scheduleCreateFormat(device=md0, fmt=fmt)
# now destroy the md and its components
self.scheduleDestroyFormat(md0)
self.scheduleDestroyDevice(md0)
self.scheduleDestroyDevice(sdb1)
self.scheduleDestroyDevice(sda3)
fmt = self.newFormat("ext4", mountpoint="/boot", device=sda1.path)
self.scheduleCreateFormat(device=sda1, fmt=fmt)
# verify the md actions are present prior to pruning
md0_actions = self.storage.devicetree.actions.find(devid=md0.id)
self.assertNotEqual(len(md0_actions), 0)
sdb1_actions = self.storage.devicetree.actions.find(devid=sdb1.id)
self.assertNotEqual(len(sdb1_actions), 0)
sda3_actions = self.storage.devicetree.actions.find(devid=sda3.id)
self.assertNotEqual(len(sda3_actions), 0)
self.storage.devicetree.actions.prune()
# verify the md actions are gone after pruning
md0_actions = self.storage.devicetree.actions.find(devid=md0.id)
self.assertEqual(len(md0_actions), 0)
sdb1_actions = self.storage.devicetree.actions.find(devid=sdb1.id)
self.assertEqual(len(sdb1_actions), 0)
sda3_actions = self.storage.devicetree.actions.find(sda3.id)
self.assertEqual(len(sda3_actions), 0)
def testActionDependencies(self):
""" Verify correct functioning of action dependencies. """
# ActionResizeDevice
# an action that shrinks a device should require the action that
# shrinks the device's format
lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
self.assertNotEqual(lv_root, None)
lv_root.format._minInstanceSize = Size("10 MiB")
lv_root.format._targetSize = lv_root.format._minInstanceSize
#lv_root.format._resizable = True
shrink_format = ActionResizeFormat(lv_root,
lv_root.size - Size("5 GiB"))
shrink_format.apply()
shrink_device = ActionResizeDevice(lv_root,
lv_root.size - Size("5 GiB"))
shrink_device.apply()
self.assertEqual(shrink_device.requires(shrink_format), True)
self.assertEqual(shrink_format.requires(shrink_device), False)
shrink_format.cancel()
shrink_device.cancel()
# ActionResizeDevice
# an action that grows a format should require the action that
# grows the device
orig_size = lv_root.currentSize
grow_device = ActionResizeDevice(lv_root,
orig_size + Size("100 MiB"))
grow_device.apply()
grow_format = ActionResizeFormat(lv_root,
orig_size + Size("100 MiB"))
grow_format.apply()
self.assertEqual(grow_format.requires(grow_device), True)
self.assertEqual(grow_device.requires(grow_format), False)
# create something like uncommitted autopart
self.destroyAllDevices()
sda = self.storage.devicetree.getDeviceByName("sda")
sdb = self.storage.devicetree.getDeviceByName("sdb")
sda1 = self.newDevice(device_class=PartitionDevice, name="sda1",
size=Size("500 MiB"), parents=[sda])
sda1_format = self.newFormat("ext4", mountpoint="/boot",
device=sda1.path)
self.scheduleCreateDevice(sda1)
self.scheduleCreateFormat(device=sda1, fmt=sda1_format)
sda2 = self.newDevice(device_class=PartitionDevice, name="sda2",
size=Size("99.5 GiB"), parents=[sda])
sda2_format = self.newFormat("lvmpv", device=sda2.path)
self.scheduleCreateDevice(sda2)
self.scheduleCreateFormat(device=sda2, fmt=sda2_format)
sdb1 = self.newDevice(device_class=PartitionDevice, name="sdb1",
size=Size("100 GiB"), parents=[sdb])
sdb1_format = self.newFormat("lvmpv", device=sdb1.path)
self.scheduleCreateDevice(sdb1)
self.scheduleCreateFormat(device=sdb1, fmt=sdb1_format)
vg = self.newDevice(device_class=LVMVolumeGroupDevice,
name="VolGroup", parents=[sda2, sdb1])
self.scheduleCreateDevice(vg)
lv_root = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_root", parents=[vg],
size=Size("160 GiB"))
self.scheduleCreateDevice(lv_root)
fmt = self.newFormat("ext4", device=lv_root.path, mountpoint="/")
self.scheduleCreateFormat(device=lv_root, fmt=fmt)
lv_swap = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="lv_swap", parents=[vg],
size=Size("4 GiB"))
self.scheduleCreateDevice(lv_swap)
fmt = self.newFormat("swap", device=lv_swap.path)
self.scheduleCreateFormat(device=lv_swap, fmt=fmt)
# ActionCreateDevice
# creation of an LV should require the actions that create the VG,
# its PVs, and the devices that contain the PVs
lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
self.assertNotEqual(lv_root, None)
actions = self.storage.devicetree.actions.find(action_type="create",
object_type="device",
device=lv_root)
self.assertEqual(len(actions), 1,
"wrong number of device create actions for lv_root: "
"%d" % len(actions))
create_lv_action = actions[0]
vgs = [d for d in self.storage.vgs if d.name == "VolGroup"]
self.assertNotEqual(vgs, [])
vg = vgs[0]
actions = self.storage.devicetree.actions.find(action_type="create",
object_type="device",
device=vg)
self.assertEqual(len(actions), 1,
"wrong number of device create actions for VolGroup")
create_vg_action = actions[0]
self.assertEqual(create_lv_action.requires(create_vg_action), True)
create_pv_actions = []
pvs = [d for d in self.storage.pvs if d in vg.pvs]
self.assertNotEqual(pvs, [])
for pv in pvs:
# include device and format create actions for each pv
actions = self.storage.devicetree.actions.find(action_type="create",
device=pv)
self.assertEqual(len(actions), 2,
"wrong number of device create actions for "
"pv %s" % pv.name)
create_pv_actions.append(actions[0])
for pv_action in create_pv_actions:
self.assertEqual(create_lv_action.requires(pv_action), True)
# also check that the vg create action requires the pv actions
self.assertEqual(create_vg_action.requires(pv_action), True)
# ActionCreateDevice
# the higher numbered partition of two that are scheduled to be
# created on a single disk should require the action that creates the
# lower numbered of the two, eg: create sda2 before creating sda3
sdc = self.storage.devicetree.getDeviceByName("sdc")
self.assertNotEqual(sdc, None)
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
parents=[sdc], size=Size("50 GiB"))
create_sdc1 = self.scheduleCreateDevice(sdc1)
self.assertEqual(isinstance(create_sdc1, ActionCreateDevice), True)
sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
parents=[sdc], size=Size("50 GiB"))
create_sdc2 = self.scheduleCreateDevice(sdc2)
self.assertEqual(isinstance(create_sdc2, ActionCreateDevice), True)
self.assertEqual(create_sdc2.requires(create_sdc1), True)
self.assertEqual(create_sdc1.requires(create_sdc2), False)
# ActionCreateDevice
# actions that create partitions on two separate disks should not
# require each other, regardless of the partitions' numbers
sda1 = self.storage.devicetree.getDeviceByName("sda1")
self.assertNotEqual(sda1, None)
actions = self.storage.devicetree.actions.find(action_type="create",
object_type="device",
device=sda1)
self.assertEqual(len(actions), 1,
"wrong number of create actions found for sda1")
create_sda1 = actions[0]
self.assertEqual(create_sdc2.requires(create_sda1), False)
self.assertEqual(create_sda1.requires(create_sdc1), False)
# ActionDestroyDevice
# an action that destroys a device containing an mdmember format
# should require the action that destroys the md array it is a
# member of if an array is defined
self.destroyAllDevices(disks=["sdc", "sdd"])
sdc = self.storage.devicetree.getDeviceByName("sdc")
self.assertNotEqual(sdc, None)
sdd = self.storage.devicetree.getDeviceByName("sdd")
self.assertNotEqual(sdd, None)
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
parents=[sdc], size=Size("40 GiB"))
self.scheduleCreateDevice(sdc1)
fmt = self.newFormat("mdmember", device=sdc1.path)
self.scheduleCreateFormat(device=sdc1, fmt=fmt)
sdd1 = self.newDevice(device_class=PartitionDevice, name="sdd1",
parents=[sdd], size=Size("40 GiB"))
self.scheduleCreateDevice(sdd1)
fmt = self.newFormat("mdmember", device=sdd1.path,)
self.scheduleCreateFormat(device=sdd1, fmt=fmt)
md0 = self.newDevice(device_class=MDRaidArrayDevice,
name="md0", level="raid0", minor=0,
memberDevices=2, totalDevices=2,
parents=[sdc1, sdd1])
self.scheduleCreateDevice(md0)
fmt = self.newFormat("ext4", device=md0.path, mountpoint="/home")
self.scheduleCreateFormat(device=md0, fmt=fmt)
destroy_md0_format = self.scheduleDestroyFormat(md0)
destroy_md0 = self.scheduleDestroyDevice(md0)
destroy_members = [self.scheduleDestroyDevice(sdc1)]
destroy_members.append(self.scheduleDestroyDevice(sdd1))
for member in destroy_members:
# device and format destroy actions for md members should require
# both device and format destroy actions for the md array
for array in [destroy_md0_format, destroy_md0]:
self.assertEqual(member.requires(array), True)
# ActionDestroyDevice
# when there are two actions that will each destroy a partition on the
# same disk, the action that will destroy the lower-numbered
# partition should require the action that will destroy the higher-
# numbered partition, eg: destroy sda2 before destroying sda1
self.destroyAllDevices(disks=["sdc", "sdd"])
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
parents=[sdc], size=Size("50 GiB"))
self.scheduleCreateDevice(sdc1)
sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
parents=[sdc], size=Size("40 GiB"))
self.scheduleCreateDevice(sdc2)
destroy_sdc1 = self.scheduleDestroyDevice(sdc1)
destroy_sdc2 = self.scheduleDestroyDevice(sdc2)
self.assertEqual(destroy_sdc1.requires(destroy_sdc2), True)
self.assertEqual(destroy_sdc2.requires(destroy_sdc1), False)
self.destroyAllDevices(disks=["sdc", "sdd"])
sdc = self.storage.devicetree.getDeviceByName("sdc")
self.assertNotEqual(sdc, None)
sdd = self.storage.devicetree.getDeviceByName("sdd")
self.assertNotEqual(sdd, None)
sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1",
parents=[sdc], size=Size("50 GiB"))
create_pv = self.scheduleCreateDevice(sdc1)
fmt = self.newFormat("lvmpv", device=sdc1.path)
create_pv_format = self.scheduleCreateFormat(device=sdc1, fmt=fmt)
testvg = self.newDevice(device_class=LVMVolumeGroupDevice,
name="testvg", parents=[sdc1])
create_vg = self.scheduleCreateDevice(testvg)
testlv = self.newDevice(device_class=LVMLogicalVolumeDevice,
name="testlv", parents=[testvg],
size=Size("30 GiB"))
create_lv = self.scheduleCreateDevice(testlv)
fmt = self.newFormat("ext4", device=testlv.path)
create_lv_format = self.scheduleCreateFormat(device=testlv, fmt=fmt)
# ActionCreateFormat
# creation of a format on a non-existent device should require the
# action that creates the device
self.assertEqual(create_lv_format.requires(create_lv), True)
# ActionCreateFormat
# an action that creates a format on a device should require an action
# that creates a device that the format's device depends on
self.assertEqual(create_lv_format.requires(create_pv), True)
self.assertEqual(create_lv_format.requires(create_vg), True)
# ActionCreateFormat
# an action that creates a format on a device should require an action
# that creates a format on a device that the format's device depends on
self.assertEqual(create_lv_format.requires(create_pv_format), True)
# XXX from here on, the devices are existing but not in the tree, so
# we instantiate and use actions directly
self.destroyAllDevices(disks=["sdc", "sdd"])
sdc1 = self.newDevice(device_class=PartitionDevice, exists=True,
name="sdc1", parents=[sdc],
size=Size("50 GiB"))
sdc1.format = self.newFormat("lvmpv", device=sdc1.path, exists=True,
device_instance=sdc1)
testvg = self.newDevice(device_class=LVMVolumeGroupDevice, exists=True,
name="testvg", parents=[sdc1],
size=Size("50 GiB"))
testlv = self.newDevice(device_class=LVMLogicalVolumeDevice,
exists=True, size=Size("30 GiB"),
name="testlv", parents=[testvg])
testlv.format = self.newFormat("ext4", device=testlv.path,
exists=True, device_instance=testlv)
# ActionResizeDevice
# an action that resizes a device should require an action that grows
# a device that the first action's device depends on, eg: grow
# device containing PV before resize of VG or LVs
sdc1.format._resizable = True # override lvmpv.resizable
sdc1.exists = True
sdc1.format.exists = True
grow_pv = ActionResizeDevice(sdc1, sdc1.size + Size("10 GiB"))
grow_pv.apply()
grow_lv = ActionResizeDevice(testlv, testlv.size + Size("5 GiB"))
grow_lv.apply()
grow_lv_format = ActionResizeFormat(testlv,
testlv.size + Size("5 GiB"))
grow_lv_format.apply()
sdc1.exists = False
sdc1.format.exists = False
self.assertEqual(grow_lv.requires(grow_pv), True)
self.assertEqual(grow_pv.requires(grow_lv), False)
# ActionResizeFormat
# an action that grows a format should require the action that grows
# the format's device
self.assertEqual(grow_lv_format.requires(grow_lv), True)
self.assertEqual(grow_lv.requires(grow_lv_format), False)
# ActionResizeFormat
# an action that resizes a device's format should depend on an action
# that grows a device the first device depends on
self.assertEqual(grow_lv_format.requires(grow_pv), True)
self.assertEqual(grow_pv.requires(grow_lv_format), False)
# ActionResizeFormat
# an action that resizes a device's format should depend on an action
# that grows a format on a device the first device depends on
# XXX resize of PV format is not allowed, so there's no real-life
# example of this to test
grow_lv_format.cancel()
grow_lv.cancel()
grow_pv.cancel()
# ActionResizeDevice
# an action that resizes a device should require an action that grows
# a format on a device that the first action's device depends on, eg:
# grow PV format before resize of VG or LVs
# XXX resize of PV format is not allowed, so there's no real-life
# example of this to test
# ActionResizeDevice
# an action that resizes a device should require an action that
# shrinks a device that depends on the first action's device, eg:
# shrink LV before resizing VG or PV devices
testlv.format._minInstanceSize = Size("10 MiB")
testlv.format._targetSize = testlv.format._minInstanceSize
shrink_lv = ActionResizeDevice(testlv,
testlv.size - Size("10 GiB"))
shrink_lv.apply()
sdc1.exists = True
sdc1.format.exists = True
shrink_pv = ActionResizeDevice(sdc1, sdc1.size - Size("5 GiB"))
shrink_pv.apply()
sdc1.exists = False
sdc1.format.exists = False
self.assertEqual(shrink_pv.requires(shrink_lv), True)
self.assertEqual(shrink_lv.requires(shrink_pv), False)
# ActionResizeDevice
# an action that resizes a device should require an action that
# shrinks a format on a device that depends on the first action's
# device, eg: shrink LV format before resizing VG or PV devices
shrink_lv_format = ActionResizeFormat(testlv, testlv.size)
shrink_lv_format.apply()
self.assertEqual(shrink_pv.requires(shrink_lv_format), True)
self.assertEqual(shrink_lv_format.requires(shrink_pv), False)
# ActionResizeFormat
# an action that resizes a device's format should depend on an action
# that shrinks a device that depends on the first device
# XXX can't think of a real-world example of this since PVs and MD
# member devices are not resizable in anaconda
# ActionResizeFormat
# an action that resizes a device's format should depend on an action
# that shrinks a format on a device that depends on the first device
# XXX can't think of a real-world example of this since PVs and MD
# member devices are not resizable in anaconda
shrink_lv_format.cancel()
shrink_lv.cancel()
shrink_pv.cancel()
# ActionCreateFormat
# an action that creates a format on a device should require an action
# that resizes a device that the format's device depends on
# XXX Really? Is this always so?
# ActionCreateFormat
# an action that creates a format on a device should require an action
# that resizes a format on a device that the format's device depends on
# XXX Same as above.
# ActionCreateFormat
# an action that creates a format on a device should require an action
# that resizes the device that will contain the format
grow_lv = ActionResizeDevice(testlv, testlv.size + Size("1 GiB"))
fmt = self.newFormat("disklabel", device=testlv.path)
format_lv = ActionCreateFormat(testlv, fmt)
self.assertEqual(format_lv.requires(grow_lv), True)
self.assertEqual(grow_lv.requires(format_lv), False)
# ActionDestroyFormat
# an action that destroys a format should require an action that
# destroys a device that depends on the format's device
destroy_pv_format = ActionDestroyFormat(sdc1)
destroy_lv_format = ActionDestroyFormat(testlv)
destroy_lv = ActionDestroyDevice(testlv)
self.assertEqual(destroy_pv_format.requires(destroy_lv), True)
self.assertEqual(destroy_lv.requires(destroy_pv_format), False)
# ActionDestroyFormat
# an action that destroys a format should require an action that
# destroys a format on a device that depends on the first format's
# device
self.assertEqual(destroy_pv_format.requires(destroy_lv_format), True)
self.assertEqual(destroy_lv_format.requires(destroy_pv_format), False)
sdc2 = self.newDevice(device_class=PartitionDevice, name="sdc2",
size=Size("5 GiB"), parents=[sdc])
create_sdc2 = self.scheduleCreateDevice(sdc2)
# create actions should always require destroy actions -- even for
# unrelated devices -- since, after pruning, it should always be the
# case that destroy actions are processed before create actions (no
# create/destroy loops are allowed)
self.assertEqual(create_sdc2.requires(destroy_lv), True)
# similarly, create actions should also require resize actions
self.assertEqual(create_sdc2.requires(grow_lv), True)
def testActionApplyCancel(self):
lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
# ActionResizeFormat
lv_root.format._minInstanceSize = Size("10 MiB")
lv_root.format._size = lv_root.size
lv_root.format._targetSize = lv_root.size
original_format_size = lv_root.format.currentSize
target_size = lv_root.size - Size("1 GiB")
#lv_root.format._resizable = True
action = ActionResizeFormat(lv_root, target_size)
self.assertEqual(lv_root.format.size, original_format_size)
action.apply()
self.assertEqual(lv_root.format.size, target_size)
action.cancel()
self.assertEqual(lv_root.format.size, original_format_size)
# ActionResizeDevice
original_device_size = lv_root.currentSize
action = ActionResizeDevice(lv_root, target_size)
self.assertEqual(lv_root.size, original_device_size)
action.apply()
self.assertEqual(lv_root.size, target_size)
action.cancel()
self.assertEqual(lv_root.size, original_device_size)