-
Notifications
You must be signed in to change notification settings - Fork 3
/
stratisd_cert.py
1352 lines (1115 loc) · 40.3 KB
/
stratisd_cert.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
# Copyright 2019 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Tests of stratisd.
"""
# pylint: disable=too-many-lines
# isort: STDLIB
import argparse
import json
import os
import subprocess
import sys
import unittest
from tempfile import NamedTemporaryFile
# isort: THIRDPARTY
import dbus
# isort: LOCAL
from testlib.dbus import StratisDbus, fs_n, p_n
from testlib.infra import (
DbusMonitor,
KernelKey,
MountPointManager,
PostTestCheck,
RunPostTestChecks,
StratisdSystemdStart,
SymlinkMonitor,
SysfsMonitor,
)
from testlib.utils import (
create_relative_device_path,
exec_command,
exec_test_command,
revision_number_type,
skip,
)
_ROOT = 0
_NON_ROOT = 1
def _raise_error_exception(return_code, msg, return_value_exists):
"""
Check result of a D-Bus call in a context where it is in error
if the call fails.
:param int return_code: the return code from the D-Bus call
:param str msg: the message returned on the D-Bus
:param bool return_value_exists: whether a value representing
a valid result was returned
"""
if return_code != 0:
raise RuntimeError(
f"Expected return code of 0; actual return code: {return_code}, error_msg: {msg}"
)
if not return_value_exists:
raise RuntimeError(
"Result value was default or placeholder value and does not represent a valid result"
)
def _skip_condition(num_devices_required):
"""
Returns a function that raises a skipTest exception if a test should be
skipped.
"""
def the_func():
if len(StratisCertify.DISKS) < num_devices_required:
raise unittest.SkipTest(
f"Test requires {num_devices_required} devices; "
f"only {len(StratisCertify.DISKS)} available"
)
return the_func
def make_test_pool(pool_name, pool_disks, *, key_desc=None):
"""
Create a test pool that will later get destroyed
:param str pool_name: Name of the pool to be created
:param list pool_disks: List of disks with which the pool will be created
:return: Object path of the created pool, and list of block devices
"""
(obj_path_exists, (obj_path, blkdevs)), return_code, msg = StratisDbus.pool_create(
pool_name,
pool_disks,
key_desc=key_desc,
)
_raise_error_exception(return_code, msg, obj_path_exists)
return obj_path, blkdevs
def make_test_filesystem(pool_path, fs_name):
"""
Create a test filesystem that will later get destroyed
:param str pool_path: Object path of a test pool
:param str fs_name: Name of the filesystem to be created
:return: Object path of the created filesystem
"""
(
(
filesystems_created,
(array_of_tuples_with_obj_paths_and_names),
),
return_code,
msg,
) = StratisDbus.fs_create(pool_path, fs_name)
_raise_error_exception(return_code, msg, filesystems_created)
exec_command(["udevadm", "settle"])
return array_of_tuples_with_obj_paths_and_names[0][0]
class StratisCertify(unittest.TestCase):
"""
Unit tests for the stratisd package.
"""
def _inequality_test(self, result, expected_non_result):
"""
:param object result: the result of a test
:param object expected_non_result: a value which the result must
not match, but which has the
expected type
"""
self.assertIsInstance(result, type(expected_non_result))
self.assertNotEqual(result, expected_non_result)
def _unittest_command(self, result, expected_return_code):
"""
:param result: a tuple of the (optional) return value, the
return code, and the return message from a
D-Bus call
:type result: tuple of object * dbus.UInt16 * str OR tuple
of dbus.UInt16 * str if there is no return value
:raises: AssertionError if the actual return code is not
equal to the expected return code
"""
if len(result) == 3:
(_, return_code, msg) = result
else:
(return_code, msg) = result
self.assertEqual(return_code, expected_return_code, msg=msg)
self.assertEqual(
type(return_code),
type(expected_return_code),
"return code has unexpected D-Bus signature",
)
class StratisdCertify(
StratisdSystemdStart, StratisCertify
): # pylint: disable=too-many-public-methods
"""
Tests on stratisd, the principal daemon.
"""
def setUp(self):
"""
Setup for an individual test.
:return: None
"""
super().setUp()
self._post_test_checks = RunPostTestChecks()
self._post_test_checks.setUp()
def tearDown(self):
"""
Tear down an individual test.
:return: None
"""
super().tearDown()
self._post_test_checks.tearDown()
def _unittest_set_property(
self, object_path, param_iface, dbus_param, dbus_value, exception_name
): # pylint: disable=too-many-arguments
"""
:param object_path: path to the object
:param param_iface: D-Bus interface to use for parameter
:param dbus_param: D-Bus parameter to be set
:param dbus_value: Desired value for the D-Bus parameter
:param exception_name: Name of exception to expect
:type exception_name: NoneType or str
"""
try:
StratisDbus.set_property(object_path, param_iface, dbus_param, dbus_value)
except dbus.exceptions.DBusException as err:
self.assertEqual(err.get_dbus_name(), exception_name)
else:
self.assertIsNone(exception_name)
def _test_permissions(self, dbus_method, args, permissions, *, kwargs=None):
"""
Test running dbus_method with and without root permissions.
:param dbus_method: D-Bus method to be tested
:type dbus_method: StratisDbus method
:param args: the arguments to be passed to the D-Bus method
:type args: list of objects
:param bool permissions: True if dbus_method needs root permissions to succeed.
False if dbus_method should succeed without root permissions.
:param kwargs: the keyword arguments to be passed to the D-Bus method
:type kwargs: dict of objects or NoneType
"""
kwargs = {} if kwargs is None else kwargs
_permissions_flag = False
euid = os.geteuid()
if euid != _ROOT:
raise RuntimeError(
f"This process should be running as root, but the current euid is {euid}."
)
os.seteuid(_NON_ROOT)
StratisDbus.reconnect()
try:
dbus_method(*args, **kwargs)
except dbus.exceptions.DBusException as err:
if err.get_dbus_name() == "org.freedesktop.DBus.Error.AccessDenied":
_permissions_flag = True
else:
os.seteuid(_ROOT)
raise err
except Exception as err:
os.seteuid(_ROOT)
raise err
os.seteuid(_ROOT)
StratisDbus.reconnect()
dbus_method(*args, **kwargs)
self.assertEqual(_permissions_flag, permissions)
def test_get_managed_objects(self):
"""
Test that GetManagedObjects returns a dict w/out failure.
"""
self.assertIsInstance(StratisDbus.get_managed_objects(), type({}))
def test_get_managed_objects_permissions(self):
"""
Test that GetManagedObjects succeeds when root permissions are dropped.
"""
self._test_permissions(StratisDbus.get_managed_objects, [], False)
def test_stratisd_version(self):
"""
Test getting the daemon version.
"""
self._inequality_test(StratisDbus.stratisd_version(), "")
def test_stratisd_version_permissions(self):
"""
Test that getting daemon version succeeds when permissions are dropped.
"""
self._test_permissions(StratisDbus.stratisd_version, [], False)
def test_pool_list_empty(self):
"""
Test listing an non-existent pool.
"""
result = StratisDbus.pool_list()
self.assertEqual(result, [])
def test_pool_list_permissions(self):
"""
Test listing pool succeeds when root permissions are dropped.
"""
self._test_permissions(StratisDbus.pool_list, [], False)
def test_blockdev_list(self):
"""
Test listing a blockdev.
"""
result = StratisDbus.blockdev_list()
self.assertEqual(result, [])
def test_blockdev_list_permissions(self):
"""
Test that listing blockdevs succeeds when root permissions are dropped.
"""
self._test_permissions(StratisDbus.blockdev_list, [], False)
def test_filesystem_list_empty(self):
"""
Test listing an non-existent filesystem.
"""
result = StratisDbus.fs_list()
self.assertEqual(result, {})
def test_filesystem_list_permissions(self):
"""
Test that listing filesystem succeeds when root permissions are dropped.
"""
self._test_permissions(StratisDbus.fs_list, [], False)
def test_key_set_unset(self):
"""
Test setting a key.
"""
key_desc = "test-description"
with NamedTemporaryFile(mode="w") as temp_file:
temp_file.write("test-password")
temp_file.flush()
self._unittest_command(
StratisDbus.set_key(key_desc, temp_file), dbus.UInt16(0)
)
self._unittest_command(StratisDbus.unset_key(key_desc), dbus.UInt16(0))
def test_key_set_unset_permissions(self):
"""
Test setting and unsetting a key fails when root permissions are dropped.
"""
key_desc = "test-description"
def set_key():
"""
Set up a keyfile and set the value of the key in the kernel
keyring.
"""
with NamedTemporaryFile(mode="w") as temp_file:
temp_file.write("test-password")
temp_file.flush()
StratisDbus.set_key(key_desc, temp_file)
self._test_permissions(set_key, [], True)
self._test_permissions(
StratisDbus.unset_key, [], True, kwargs={"key_desc": key_desc}
)
@skip(_skip_condition(1))
def test_pool_create(self):
"""
Test creating a pool.
"""
pool_name = p_n()
self._unittest_command(
StratisDbus.pool_create(pool_name, StratisCertify.DISKS),
dbus.UInt16(0),
)
@skip(_skip_condition(1))
def test_pool_create_permissions(self):
"""
Test that creating a pool fails when root permissions are dropped.
"""
pool_name = p_n()
self._test_permissions(
StratisDbus.pool_create, [pool_name, StratisCertify.DISKS], True
)
@skip(_skip_condition(1))
def test_pool_create_encrypted(self):
"""
Test creating an encrypted pool.
"""
with KernelKey("test-password") as key_desc:
pool_name = p_n()
self._unittest_command(
StratisDbus.pool_create(
pool_name, StratisCertify.DISKS, key_desc=key_desc
),
dbus.UInt16(0),
)
@skip(_skip_condition(2))
def test_pool_create_encrypted_with_cache(self):
"""
Test creating an encrypted pool with cache.
"""
with KernelKey("test-password") as key_desc:
pool_name = p_n()
pool_path, _ = make_test_pool(
pool_name, StratisCertify.DISKS[0:1], key_desc=key_desc
)
self._unittest_command(
StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
dbus.UInt16(0),
)
@skip(_skip_condition(1))
def test_pool_create_no_overprovisioning(self):
"""
Test creating a pool with no overprovisioning
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_set_property(
pool_path,
StratisDbus.POOL_IFACE,
"Overprovisioning",
dbus.Boolean(False),
None,
)
@skip(_skip_condition(1))
def test_pool_stop_started(self):
"""
Test stopping a started pool
"""
pool_name = p_n()
make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_stop(pool_name, "name"),
dbus.UInt16(0),
)
@skip(_skip_condition(1))
def test_pool_stop_stopped(self):
"""
Test stopping a stopped pool
"""
pool_name = p_n()
make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_stop(pool_name, "name"),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_stop(pool_name, "name"),
dbus.UInt16(0),
)
@skip(_skip_condition(1))
def test_pool_start_stopped(self):
"""
Test starting a stopped pool
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
pool_uuid = StratisDbus.pool_uuid(pool_path)
self._unittest_command(
StratisDbus.pool_stop(pool_uuid, "uuid"),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_start(pool_uuid, "uuid"),
dbus.UInt16(0),
)
@skip(_skip_condition(1))
def test_pool_start_by_name(self):
"""
Test starting a stopped pool by its name
"""
pool_name = p_n()
make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_stop(pool_name, "name"),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_start(pool_name, "name"),
dbus.UInt16(0),
)
@skip(_skip_condition(1))
def test_pool_start_started(self):
"""
Test starting a started pool
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
pool_uuid = StratisDbus.pool_uuid(pool_path)
self._unittest_command(
StratisDbus.pool_start(pool_uuid, "uuid"),
dbus.UInt16(0),
)
@skip(_skip_condition(3))
def test_pool_add_cache(self):
"""
Test adding cache to a pool.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_add_cache(pool_path, StratisCertify.DISKS[2:3]),
dbus.UInt16(0),
)
@skip(_skip_condition(2))
def test_pool_add_cache_permissions(self):
"""
Test that adding cache to pool fails when root permissions are dropped.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._test_permissions(
StratisDbus.pool_init_cache,
[pool_path, StratisCertify.DISKS[1:2]],
True,
)
self._test_permissions(
StratisDbus.pool_add_cache, [pool_path, StratisCertify.DISKS[2:3]], True
)
@skip(_skip_condition(2))
def test_pool_create_after_cache(self):
"""
Test creating existing pool after cache was added
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_create(pool_name, StratisCertify.DISKS[0:1]),
dbus.UInt16(0),
)
@skip(_skip_condition(2))
def test_pool_add_data_after_cache(self):
"""
Test adding a data device after a cache is created.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_add_data(pool_path, StratisCertify.DISKS[0:1]),
dbus.UInt16(0),
)
@skip(_skip_condition(3))
def test_pool_add_different_data_after_cache(self):
"""
Test adding a different data device after a cache is created.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_add_data(pool_path, StratisCertify.DISKS[2:3]),
dbus.UInt16(0),
)
@skip(_skip_condition(3))
def test_pool_add_data_init_cache(self):
"""
Test adding data for a pool, then initializing the cache.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
self._unittest_command(
StratisDbus.fs_create(pool_path, fs_name), dbus.UInt16(0)
)
self._unittest_command(
StratisDbus.pool_add_data(pool_path, StratisCertify.DISKS[1:2]),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[2:3]),
dbus.UInt16(0),
)
@skip(_skip_condition(2))
def test_pool_create_with_cache(self):
"""
Test creating existing pool with device already used by cache fails
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
dbus.UInt16(0),
)
self._unittest_command(
StratisDbus.pool_create(pool_name, StratisCertify.DISKS[0:2]),
dbus.UInt16(1),
)
@skip(_skip_condition(3))
def test_pool_add_data(self):
"""
Test adding data to a pool.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:2])
self._unittest_command(
StratisDbus.pool_add_data(pool_path, StratisCertify.DISKS[2:3]),
dbus.UInt16(0),
)
@skip(_skip_condition(3))
def test_pool_add_data_relative_path(self):
"""
Test adding data to a pool with a relative device path.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:2])
add_device = StratisCertify.DISKS[2]
relative_device = create_relative_device_path(add_device)
relative_device_list = [add_device, relative_device]
self._unittest_command(
StratisDbus.pool_add_data(pool_path, relative_device_list),
dbus.UInt16(0),
)
@skip(_skip_condition(3))
def test_pool_add_data_permissions(self):
"""
Test that adding data to a pool fails when root permissions are dropped.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:2])
self._test_permissions(
StratisDbus.pool_add_data, [pool_path, StratisCertify.DISKS[2:3]], True
)
@skip(_skip_condition(1))
def test_pool_list_not_empty(self):
"""
Test listing an non-existent pool.
"""
pool_name = p_n()
make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._inequality_test(StratisDbus.pool_list(), [])
@skip(_skip_condition(1))
def test_pool_create_same_name_and_devices(self):
"""
Test creating a pool that already exists with the same devices.
"""
pool_name = p_n()
make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_create(pool_name, StratisCertify.DISKS[0:1]),
dbus.UInt16(0),
)
@skip(_skip_condition(3))
def test_pool_create_same_name_different_devices(self):
"""
Test creating a pool that already exists with different devices.
"""
pool_name = p_n()
make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_create(pool_name, StratisCertify.DISKS[1:3]),
dbus.UInt16(1),
)
@skip(_skip_condition(1))
def test_pool_destroy(self):
"""
Test destroying a pool.
"""
pool_name = p_n()
make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(StratisDbus.pool_destroy(pool_name), dbus.UInt16(0))
self.assertEqual(StratisDbus.fs_list(), {})
@skip(_skip_condition(1))
def test_pool_get_metadata(self):
"""
Test getting pool metadata info.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(StratisDbus.pool_get_metadata(pool_path), dbus.UInt16(0))
@skip(_skip_condition(1))
def test_pool_get_metadata_written(self):
"""
Test getting most recently written pool metadata info.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_command(
StratisDbus.pool_get_metadata(pool_path, current=False), dbus.UInt16(0)
)
@skip(_skip_condition(1))
def test_pool_destroy_permissions(self):
"""
Test that destroying a pool fails when root permissions are dropped.
"""
pool_name = p_n()
make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._test_permissions(StratisDbus.pool_destroy, [pool_name], True)
@skip(_skip_condition(1))
def test_pool_set_fs_limit_too_low(self):
"""
Test setting the pool filesystem limit too low fails.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_set_property(
pool_path,
StratisDbus.POOL_IFACE,
"FsLimit",
dbus.UInt64(0),
"org.freedesktop.DBus.Error.Failed",
)
@skip(_skip_condition(1))
def test_blockdev_set_userinfo_property(self):
"""
Test setting the UserInfo property on a block device.
"""
pool_name = p_n()
_, blkdev_paths = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
self._unittest_set_property(
blkdev_paths[0],
StratisDbus.BLKDEV_IFACE,
"UserInfo",
(dbus.Boolean(True), dbus.String("eeeeeeeeee")),
None,
)
@skip(_skip_condition(1))
def test_filesystem_create(self):
"""
Test creating a filesystem.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
self._unittest_command(
StratisDbus.fs_create(pool_path, fs_name), dbus.UInt16(0)
)
@skip(_skip_condition(1))
def test_filesystem_create_specified_size(self):
"""
Test creating a filesystem with a specified size.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
self._unittest_command(
StratisDbus.fs_create(pool_path, fs_name, fs_size="549755813888"),
dbus.UInt16(0),
)
@skip(_skip_condition(1))
def test_filesystem_create_specified_size_toosmall(self):
"""
Test creating a filesystem with a specified size that is too small.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
self._unittest_command(
StratisDbus.fs_create(pool_path, fs_name, fs_size="536866816"),
dbus.UInt16(1),
)
@skip(_skip_condition(1))
def test_filesystem_create_specified_size_limit(self):
"""
Test creating a filesystem with a specified size limit.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
self._unittest_command(
StratisDbus.fs_create(
pool_path, fs_name, fs_size="549755813888", fs_sizelimit="1099511627776"
),
dbus.UInt16(0),
)
@skip(_skip_condition(1))
def test_filesystem_create_specified_size_limit_toosmall(self):
"""
Test creating a filesystem with a specified size limit that is too small.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
self._unittest_command(
StratisDbus.fs_create(
pool_path, fs_name, fs_size="549755813888", fs_sizelimit="536866816"
),
dbus.UInt16(1),
)
@skip(_skip_condition(1))
def test_filesystem_create_permissions(self):
"""
Test that creating a filesystem fails when root permissions are dropped.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
self._test_permissions(StratisDbus.fs_create, [pool_path, fs_name], True)
@skip(_skip_condition(1))
def test_filesystem_rename(self):
"""
Test renaming a filesystem.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
make_test_filesystem(pool_path, fs_name)
fs_name_rename = fs_n()
self._unittest_command(
StratisDbus.fs_rename(pool_name, fs_name, fs_name_rename), dbus.UInt16(0)
)
@skip(_skip_condition(1))
def test_filesystem_rename_permissions(self):
"""
Test that renaming a filesystem fails when root permissions are dropped.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
make_test_filesystem(pool_path, fs_name)
fs_name_rename = fs_n()
self._test_permissions(
StratisDbus.fs_rename, [pool_name, fs_name, fs_name_rename], True
)
@skip(_skip_condition(1))
def test_filesystem_rename_same_name(self):
"""
Test renaming a filesystem.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
make_test_filesystem(pool_path, fs_name)
self._unittest_command(
StratisDbus.fs_rename(pool_name, fs_name, fs_name), dbus.UInt16(0)
)
@skip(_skip_condition(1))
def test_filesystem_snapshot(self):
"""
Test snapshotting a filesystem.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
fs_path = make_test_filesystem(pool_path, fs_name)
snapshot_name = fs_n()
self._unittest_command(
StratisDbus.fs_snapshot(pool_path, fs_path, snapshot_name), dbus.UInt16(0)
)
@skip(_skip_condition(1))
def test_filesystem_snapshot_schedule_revert(self):
"""
Test scheduling a revert of a filesystem snapshot.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
fs_path = make_test_filesystem(pool_path, fs_name)
snapshot_name = fs_n()
((_, snapshot_path), _, _) = StratisDbus.fs_snapshot(
pool_path, fs_path, snapshot_name
)
StratisDbus.set_property(
snapshot_path,
StratisDbus.FS_IFACE,
"MergeScheduled",
dbus.Boolean(True),
)
@skip(_skip_condition(1))
def test_filesystem_snapshot_cancel_revert(self):
"""
Test canceling a revert of a filesystem snapshot.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()
fs_path = make_test_filesystem(pool_path, fs_name)
snapshot_name = fs_n()
((_, snapshot_path), _, _) = StratisDbus.fs_snapshot(
pool_path, fs_path, snapshot_name
)
StratisDbus.set_property(
snapshot_path,
StratisDbus.FS_IFACE,
"MergeScheduled",
dbus.Boolean(True),
)
StratisDbus.set_property(
snapshot_path,
StratisDbus.FS_IFACE,
"MergeScheduled",