File: xml_state_test.py

package info (click to toggle)
kiwi 10.2.36-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,664 kB
  • sloc: python: 69,179; sh: 4,228; xml: 3,383; ansic: 391; makefile: 353
file content (1418 lines) | stat: -rw-r--r-- 56,903 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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
import os
import io
import logging
from collections import namedtuple
from unittest.mock import (
    patch, Mock, MagicMock
)
from pytest import (
    raises, fixture
)

from kiwi.defaults import Defaults
from kiwi.xml_state import XMLState
from kiwi.storage.disk import ptable_entry_type
from kiwi.xml_description import XMLDescription

from kiwi.exceptions import (
    KiwiTypeNotFound,
    KiwiDistributionNameError,
    KiwiProfileNotFound,
    KiwiFileAccessError
)


class TestXMLState:
    @fixture(autouse=True)
    def inject_fixtures(self, caplog):
        self._caplog = caplog

    def setup(self):
        self.volume_type = namedtuple(
            'volume_type', [
                'name',
                'parent',
                'size',
                'realpath',
                'mountpoint',
                'fullsize',
                'label',
                'attributes',
                'is_root_volume'
            ]
        )
        Defaults.set_platform_name('x86_64')
        self.description = XMLDescription(
            '../data/example_config.xml'
        )
        self.state = XMLState(
            self.description.load()
        )
        apt_description = XMLDescription(
            '../data/example_apt_config.xml'
        )
        self.apt_state = XMLState(
            apt_description.load()
        )
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution/config.xml'
        )
        self.boot_state = XMLState(
            boot_description.load()
        )
        no_image_packages_description = XMLDescription(
            '../data/example_no_image_packages_config.xml'
        )
        self.no_image_packages_boot_state = XMLState(
            no_image_packages_description.load()
        )
        self.bootloader = Mock()
        self.bootloader.get_name.return_value = 'some-loader'
        self.bootloader.get_timeout.return_value = 'some-timeout'
        self.bootloader.get_timeout_style.return_value = 'some-style'
        self.bootloader.get_targettype.return_value = 'some-target'
        self.bootloader.get_bls.return_value = False
        self.bootloader.get_output_console.return_value = 'some-console'
        self.bootloader.get_input_console.return_value = None
        self.bootloader.get_serial_line.return_value = 'some-serial'
        self.bootloader.get_use_disk_password.return_value = True

    def setup_method(self, cls):
        self.setup()

    def test_get_description_section(self):
        description = self.state.get_description_section()
        assert description.author == 'Marcus'
        assert description.contact == 'ms@suse.com'
        assert description.specification == \
            'Testing various configuration states'

    def test_get_preferences_by_architecture(self):
        Defaults.set_platform_name('aarch64')
        state = XMLState(
            self.description.load()
        )
        preferences = state.get_preferences_sections()
        Defaults.set_platform_name('x86_64')
        assert len(preferences) == 3
        assert preferences[2].get_arch() == 'aarch64'
        assert state.get_build_type_name() == 'iso'

    def test_build_type_primary_selected(self):
        assert self.state.get_build_type_name() == 'oem'

    def test_build_type_first_selected(self):
        self.state.xml_data.get_preferences()[2].get_type()[0].set_primary(
            False
        )
        assert self.state.get_build_type_name() == 'oem'

    @patch('kiwi.xml_state.XMLState.get_preferences_sections')
    def test_get_rpm_excludedocs_without_entry(self, mock_preferences):
        mock_preferences.return_value = []
        assert self.state.get_rpm_excludedocs() is False

    def test_get_rpm_excludedocs(self):
        assert self.state.get_rpm_excludedocs() is True

    @patch('kiwi.xml_state.XMLState.get_preferences_sections')
    def test_get_rpm_check_signatures_without_entry(self, mock_preferences):
        mock_preferences.return_value = []
        assert self.state.get_rpm_check_signatures() is False

    def test_get_rpm_check_signatures(self):
        assert self.state.get_rpm_check_signatures() is True

    def test_get_package_manager(self):
        assert self.state.get_package_manager() == 'zypper'

    def get_release_version(self):
        assert self.state.get_release_version() == '15.3'

    @patch('kiwi.xml_state.XMLState.get_preferences_sections')
    def test_get_default_package_manager(self, mock_preferences):
        mock_preferences.return_value = []
        assert self.state.get_package_manager() == 'dnf4'

    def test_get_image_version(self):
        assert self.state.get_image_version() == '1.13.2'

    def test_get_bootstrap_packages(self):
        assert self.state.get_bootstrap_packages() == [
            'filesystem', 'zypper'
        ]
        assert self.state.get_bootstrap_packages(plus_packages=['vim']) == [
            'filesystem', 'vim', 'zypper'
        ]
        assert self.no_image_packages_boot_state.get_bootstrap_packages() == [
            'patterns-openSUSE-base'
        ]
        self.state.get_package_manager = Mock(
            return_value="dnf4"
        )
        assert self.state.get_bootstrap_packages() == [
            'dnf', 'filesystem',
        ]
        self.state.get_package_manager = Mock(
            return_value="apk"
        )
        assert self.state.get_bootstrap_packages() == [
            'apk-tools', 'filesystem',
        ]

    def test_get_system_packages(self):
        assert self.state.get_system_packages() == [
            'gfxboot-branding-openSUSE',
            'grub2-branding-openSUSE',
            'ifplugd',
            'iputils',
            'kernel-default',
            'openssh',
            'plymouth-branding-openSUSE',
            'vim'
        ]

    def test_get_system_packages_some_arch(self):
        Defaults.set_platform_name('s390')
        state = XMLState(
            self.description.load()
        )
        assert state.get_system_packages() == [
            'foo',
            'gfxboot-branding-openSUSE',
            'grub2-branding-openSUSE',
            'ifplugd',
            'iputils',
            'kernel-default',
            'openssh',
            'plymouth-branding-openSUSE',
            'vim'
        ]
        Defaults.set_platform_name('x86_64')

    def test_get_system_collections(self):
        assert self.state.get_system_collections() == [
            'base'
        ]
        self.state.host_architecture = 'aarch64'
        assert self.state.get_system_collections() == [
            'base', 'base_for_arch'
        ]

    def test_get_system_products(self):
        assert self.state.get_system_products() == [
            'openSUSE'
        ]

    def test_get_system_files(self):
        assert self.state.\
            get_system_files()['some'].target == ''
        assert self.state.\
            get_system_files()['/absolute/path/to/some'].target == ''

    def test_get_bootstrap_files(self):
        assert self.state.\
            get_bootstrap_files()['some'].target == '/some/target'

    def test_get_system_archives(self):
        assert self.state.get_system_archives() == [
            '/absolute/path/to/image.tgz'
        ]

    def test_get_system_ignore_packages(self):
        assert self.state.get_system_ignore_packages() == [
            'bar', 'baz', 'foo'
        ]
        self.state.host_architecture = 'aarch64'
        assert self.state.get_system_ignore_packages() == [
            'baz', 'foo'
        ]
        self.state.host_architecture = 's390'
        assert self.state.get_system_ignore_packages() == [
            'baz'
        ]

    def test_get_bootstrap_ignore_packages(self):
        assert self.state.get_bootstrap_ignore_packages() == [
            'some'
        ]

    def test_get_system_collection_type(self):
        assert self.state.get_system_collection_type() == 'plusRecommended'

    def test_get_bootstrap_collections(self):
        assert self.state.get_bootstrap_collections() == [
            'bootstrap-collection'
        ]

    def test_get_bootstrap_products(self):
        assert self.state.get_bootstrap_products() == ['kiwi']

    def test_get_bootstrap_archives(self):
        assert self.state.get_bootstrap_archives() == ['bootstrap.tgz']

    def test_get_bootstrap_collection_type(self):
        assert self.state.get_bootstrap_collection_type() == 'onlyRequired'

    def test_set_repository(self):
        self.state.set_repository(
            'repo', 'type', 'alias', 1, True, False, ['key_a', 'key_b'],
            'main universe', 'jammy', False, 'metalink'
        )
        assert self.state.xml_data.get_repository()[0].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[0].get_type() == 'type'
        assert self.state.xml_data.get_repository()[0].get_alias() == 'alias'
        assert self.state.xml_data.get_repository()[0].get_priority() == 1
        assert self.state.xml_data.get_repository()[0] \
            .get_imageinclude() is True
        assert self.state.xml_data.get_repository()[0] \
            .get_package_gpgcheck() is False
        assert self.state.xml_data.get_repository()[0] \
            .get_source().get_signing()[0].get_key() == 'key_a'
        assert self.state.xml_data.get_repository()[0] \
            .get_source().get_signing()[1].get_key() == 'key_b'
        assert self.state.xml_data.get_repository()[0].get_components() \
            == 'main universe'
        assert self.state.xml_data.get_repository()[0].get_distribution() \
            == 'jammy'
        assert self.state.xml_data.get_repository()[0] \
            .get_repository_gpgcheck() is False
        assert self.state.xml_data.get_repository()[0] \
            .get_sourcetype() == 'metalink'

    def test_add_repository(self):
        self.state.add_repository(
            'repo', 'type', 'alias', 1, True, None, ['key_a', 'key_b'],
            'main universe', 'jammy', False, 'metalink'
        )
        assert self.state.xml_data.get_repository()[3].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[3].get_type() == 'type'
        assert self.state.xml_data.get_repository()[3].get_alias() == 'alias'
        assert self.state.xml_data.get_repository()[3].get_priority() == 1
        assert self.state.xml_data.get_repository()[3] \
            .get_imageinclude() is True
        assert self.state.xml_data.get_repository()[3] \
            .get_source().get_signing()[0].get_key() == 'key_a'
        assert self.state.xml_data.get_repository()[3] \
            .get_source().get_signing()[1].get_key() == 'key_b'
        assert self.state.xml_data.get_repository()[3].get_components() \
            == 'main universe'
        assert self.state.xml_data.get_repository()[3].get_distribution() \
            == 'jammy'
        assert self.state.xml_data.get_repository()[3] \
            .get_repository_gpgcheck() is False
        assert self.state.xml_data.get_repository()[3] \
            .get_sourcetype() == 'metalink'

    def test_add_repository_with_empty_values(self):
        self.state.add_repository('repo', 'type', '', '', True)
        assert self.state.xml_data.get_repository()[3].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[3].get_type() == 'type'
        assert self.state.xml_data.get_repository()[3].get_alias() == ''
        assert self.state.xml_data.get_repository()[3].get_priority() is None
        assert self.state.xml_data.get_repository()[3] \
            .get_imageinclude() is True
        assert self.state.xml_data.get_repository()[3] \
            .get_sourcetype() is None

    def test_get_to_become_deleted_packages(self):
        assert self.state.get_to_become_deleted_packages() == [
            'kernel-debug'
        ]

    def test_get_system_files_ignore_packages(self):
        assert self.state.get_system_files_ignore_packages() == [
            'rpm', 'yast', 'zypp'
        ]

    def test_get_build_type_vagrant_config_section(self):
        vagrant_config = self.state.get_build_type_vagrant_config_section()
        assert vagrant_config.get_provider() == 'libvirt'
        assert self.boot_state.get_build_type_vagrant_config_section() is None

    def test_virtualbox_guest_additions_vagrant_config_section(self):
        assert not self.state.get_vagrant_config_virtualbox_guest_additions()

    def test_virtualbox_guest_additions_vagrant_config_section_missing(self):
        self.state. \
            get_build_type_vagrant_config_section() \
            .virtualbox_guest_additions_present = True
        assert self.state.get_vagrant_config_virtualbox_guest_additions()

    def test_get_build_type_system_disk_section(self):
        assert self.state.get_build_type_system_disk_section().get_name() == \
            'mydisk'

    def test_get_build_type_vmdisk_section(self):
        assert self.state.get_build_type_vmdisk_section().get_id() == 0
        assert self.boot_state.get_build_type_vmdisk_section() is None

    def test_get_build_type_vmnic_entries(self):
        assert self.state.get_build_type_vmnic_entries()[0].get_interface() \
            == ''
        assert self.boot_state.get_build_type_vmnic_entries() == []

    def test_get_build_type_vmdvd_section(self):
        assert self.state.get_build_type_vmdvd_section().get_id() == 0
        assert self.boot_state.get_build_type_vmdvd_section() is None

    def test_get_volume_management(self):
        assert self.state.get_volume_management() == 'lvm'

    def test_get_volume_management_none(self):
        assert self.boot_state.get_volume_management() is None

    def test_get_volume_management_btrfs(self):
        description = XMLDescription('../data/example_btrfs_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'btrfs'

    def test_get_volume_management_lvm_prefer(self):
        description = XMLDescription('../data/example_lvm_preferred_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'lvm'

    def test_get_volume_management_lvm_default(self):
        description = XMLDescription('../data/example_lvm_default_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'lvm'

    def test_build_type_explicitly_selected(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_build_type_name() == 'oem'

    def test_build_type_not_found(self):
        xml_data = self.description.load()
        with raises(KiwiTypeNotFound):
            XMLState(xml_data, ['vmxFlavour'], 'foo')

    def test_build_type_not_found_no_default_type(self):
        description = XMLDescription('../data/example_no_default_type.xml')
        xml_data = description.load()
        with raises(KiwiTypeNotFound):
            XMLState(xml_data, ['minimal'])

    def test_profile_not_found(self):
        xml_data = self.description.load()
        with raises(KiwiProfileNotFound):
            XMLState(xml_data, ['foo'])

    def test_profile_requires(self):
        xml_data = self.description.load()
        xml_state = XMLState(xml_data, ['composedProfile'])
        assert xml_state.profiles == [
            'composedProfile', 'vmxSimpleFlavour', 'xenDomUFlavour'
        ]

    def test_get_partitions(self):
        description = XMLDescription(
            '../data/example_partitions_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_partitions() == {
            'var': ptable_entry_type(
                mbsize=100,
                clone=0,
                partition_name='p.lxvar',
                partition_type='t.linux',
                partition_id=None,
                mountpoint='/var',
                filesystem='ext3',
                label=''
            )
        }

    @patch('kiwi.xml_state.Defaults.is_buildservice_worker')
    @patch('kiwi.xml_state.Command.run')
    def test_get_containers_in_buildservice(
        self, mock_Command_run, mock_Defaults_is_buildservice_worker
    ):
        mock_Defaults_is_buildservice_worker.return_value = True
        description = XMLDescription(
            '../data/example_containers_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        containers = state.get_containers()[0]
        containers.fetch_command('root_dir')
        assert containers.name == 'tumbleweed_latest'
        assert containers.backend == 'podman'
        assert containers.container_file == \
            '/var/tmp/kiwi_containers/tumbleweed_latest'
        assert containers.fetch_only is False
        assert containers.load_command == [
            '/usr/bin/podman', 'load', '-i',
            '/var/tmp/kiwi_containers/tumbleweed_latest'
        ]
        mock_Command_run.assert_called_once_with(
            [
                'cp',
                '/usr/src/packages/SOURCES/containers/'
                '_obsrepositories/registry.opensuse.org/opensuse/'
                'tumbleweed:latest.ociarchive',
                'root_dir/var/tmp/kiwi_containers/tumbleweed_latest'
            ]
        )

    @patch('kiwi.xml_state.Command.run')
    def test_get_containers(self, mock_Command_run):
        containers = self.state.get_containers()
        c1 = containers[0]
        c2 = containers[1]
        c3 = containers[2]
        c4 = containers[3]

        c1.fetch_command('root_dir')
        assert c1.name == 'rmtserver_latest'
        assert c1.backend == 'podman'
        assert c1.container_file == \
            '/var/tmp/kiwi_containers/rmtserver_latest'
        assert c1.fetch_only is False
        assert c1.load_command == [
            '/usr/bin/podman', 'load', '-i',
            '/var/tmp/kiwi_containers/rmtserver_latest'
        ]
        mock_Command_run.assert_called_once_with(
            [
                'chroot', 'root_dir',
                '/usr/bin/skopeo', 'copy',
                'docker://registry.suse.com/home/mschaefer/'
                'images_pubcloud/pct/rmtserver:latest',
                'oci-archive:/var/tmp/kiwi_containers/'
                'rmtserver_latest:registry.suse.com/home/mschaefer/'
                'images_pubcloud/pct/rmtserver:latest'
            ]
        )
        mock_Command_run.reset_mock()

        c2.fetch_command('root_dir')
        assert c2.name == 'some_latest'
        assert c2.backend == 'docker'
        assert c2.container_file == \
            '/var/tmp/kiwi_containers/some_latest'
        assert c2.fetch_only is False
        assert c2.load_command == [
            '/usr/bin/docker', 'load', '-i',
            '/var/tmp/kiwi_containers/some_latest'
        ]
        mock_Command_run.assert_called_once_with(
            [
                'chroot', 'root_dir',
                '/usr/bin/skopeo', 'copy',
                'docker://registry.suse.com/some:latest',
                'oci-archive:/var/tmp/kiwi_containers/'
                'some_latest:registry.suse.com/some:latest'
            ]
        )
        mock_Command_run.reset_mock()

        c3.fetch_command('root_dir')
        assert c3.name == 'foo_latest'
        assert c3.backend == 'podman'
        assert c3.container_file == \
            '/var/tmp/kiwi_containers/foo_latest'
        assert c3.fetch_only is True
        assert c3.load_command == []
        mock_Command_run.assert_called_once_with(
            [
                'chroot', 'root_dir',
                '/usr/bin/skopeo', 'copy', 'docker://docker.io/foo:latest',
                'oci-archive:/var/tmp/kiwi_containers/'
                'foo_latest:docker.io/foo:latest'
            ]
        )
        mock_Command_run.reset_mock()

        c4.fetch_command('root_dir')
        assert c4.name == 'test-app_v1.0'
        assert c4.backend == 'container-snap'
        assert c4.container_file == \
            '/var/tmp/kiwi_containers/test-app_v1.0'
        assert c4.fetch_only is False
        assert c4.load_command == [
            '/usr/bin/container-snap', 'load', '-i',
            '/var/tmp/kiwi_containers/test-app_v1.0'
        ]
        mock_Command_run.assert_called_once_with(
            [
                'chroot', 'root_dir',
                '/usr/bin/skopeo', 'copy',
                'docker://registry.example.com/test-app:v1.0',
                'oci-archive:/var/tmp/kiwi_containers/'
                'test-app_v1.0:registry.example.com/test-app:v1.0'
            ]
        )

    def test_get_volumes_custom_root_volume_name(self):
        description = XMLDescription(
            '../data/example_lvm_custom_rootvol_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = self.volume_type
        assert state.get_volumes() == [
            volume_type(
                name='myroot', parent='', size='freespace:500',
                realpath='/',
                mountpoint=None, fullsize=False,
                label=None,
                attributes=[],
                is_root_volume=True
            )
        ]

    def test_get_volumes_btrfs_quota(self):
        description = XMLDescription(
            '../data/example_btrfs_vol_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = self.volume_type
        assert state.get_volumes() == [
            volume_type(
                name='some', parent='', size='freespace:120',
                realpath='some',
                mountpoint='some', fullsize=False,
                label=None,
                attributes=['quota=500M'],
                is_root_volume=False
            ),
            volume_type(
                name='', parent='', size=None,
                realpath='/',
                mountpoint=None, fullsize=True,
                label=None,
                attributes=[],
                is_root_volume=True
            )
        ]

    def test_get_volumes_for_arch(self):
        description = XMLDescription('../data/example_lvm_arch_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        state.host_architecture = 'aarch64'
        volume_type = self.volume_type
        assert state.get_volumes() == [
            volume_type(
                name='usr_lib',
                parent='',
                size='freespace:30',
                realpath='usr/lib',
                mountpoint='usr/lib',
                fullsize=False,
                label=None,
                attributes=[],
                is_root_volume=False
            ),
            volume_type(
                name='LVRoot',
                parent='',
                size=None,
                realpath='/',
                mountpoint=None,
                fullsize=True,
                label=None,
                attributes=[],
                is_root_volume=True
            )
        ]
        state.host_architecture = 'x86_64'
        assert state.get_volumes() == [
            volume_type(
                name='LVRoot',
                parent='',
                size=None,
                realpath='/',
                mountpoint=None,
                fullsize=True,
                label=None,
                attributes=[],
                is_root_volume=True
            )
        ]

    def test_get_volumes(self):
        description = XMLDescription('../data/example_lvm_default_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = self.volume_type
        assert state.get_volumes() == [
            volume_type(
                name='usr_lib', parent='', size='size:1024',
                realpath='usr/lib',
                mountpoint='usr/lib',
                fullsize=False,
                label='library',
                attributes=[],
                is_root_volume=False
            ),
            volume_type(
                name='LVRoot', parent='', size='freespace:500',
                realpath='/',
                mountpoint=None, fullsize=False,
                label=None,
                attributes=[],
                is_root_volume=True
            ),
            volume_type(
                name='etc_volume', parent='', size='freespace:30',
                realpath='etc',
                mountpoint='etc', fullsize=False,
                label=None,
                attributes=['no-copy-on-write', 'enable-for-filesystem-check'],
                is_root_volume=False
            ),
            volume_type(
                name='bin_volume', parent='', size=None,
                realpath='/usr/bin',
                mountpoint='/usr/bin', fullsize=True,
                label=None,
                attributes=[],
                is_root_volume=False
            ),
            volume_type(
                name='LVSwap', parent='', size='size:128',
                realpath='swap',
                mountpoint=None, fullsize=False,
                label='SWAP',
                attributes=[],
                is_root_volume=False
            )
        ]

    def test_get_volumes_no_explicit_root_setup(self):
        description = XMLDescription('../data/example_lvm_no_root_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = self.volume_type
        assert state.get_volumes() == [
            volume_type(
                name='LVRoot', parent='', size=None, realpath='/',
                mountpoint=None, fullsize=True,
                label=None,
                attributes=[],
                is_root_volume=True
            ),
            volume_type(
                name='LVSwap', parent='', size='size:128',
                realpath='swap',
                mountpoint=None, fullsize=False,
                label='SWAP',
                attributes=[],
                is_root_volume=False
            )
        ]

    def test_get_volumes_no_explicit_root_setup_other_fullsize_volume(self):
        description = XMLDescription(
            '../data/example_lvm_no_root_full_usr_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = self.volume_type
        assert state.get_volumes() == [
            volume_type(
                name='usr', parent='', size=None, realpath='usr',
                mountpoint='usr', fullsize=True,
                label=None,
                attributes=[],
                is_root_volume=False
            ),
            volume_type(
                name='LVRoot', parent='', size='freespace:30', realpath='/',
                mountpoint=None, fullsize=False,
                label=None,
                attributes=[],
                is_root_volume=True
            ),
            volume_type(
                name='LVSwap', parent='', size='size:128',
                realpath='swap',
                mountpoint=None, fullsize=False,
                label='SWAP',
                attributes=[],
                is_root_volume=False
            )
        ]

    @patch('kiwi.xml_state.XMLState.get_build_type_system_disk_section')
    def test_get_empty_volumes(self, mock_system_disk):
        mock_system_disk.return_value = None
        assert self.state.get_volumes() == []

    def test_get_strip_files_to_delete(self):
        assert self.state.get_strip_files_to_delete() == ['del-a', 'del-b']

    def test_get_strip_tools_to_keep(self):
        assert self.state.get_strip_tools_to_keep() == ['tool-a', 'tool-b']

    def test_get_strip_libraries_to_keep(self):
        assert self.state.get_strip_libraries_to_keep() == ['lib-a', 'lib-b']

    def test_get_build_type_machine_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        assert state.get_build_type_machine_section().get_guestOS() == 'suse'

    def test_get_drivers_list(self):
        assert self.state.get_drivers_list() == \
            ['crypto/*', 'drivers/acpi/*', 'bar']

    def test_get_build_type_oemconfig_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, None, 'oem')
        assert state.get_build_type_oemconfig_section().get_oem_swap()[0] is \
            True

    def test_get_oemconfig_oem_resize(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_oem_resize() is True
        description = XMLDescription(
            '../data/example_multiple_users_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_oemconfig_oem_resize() is False

    def test_get_oemconfig_oem_systemsize(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_oem_systemsize() == 2048

    def test_get_oemconfig_oem_multipath_scan(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_oem_multipath_scan() is False
        description = XMLDescription(
            '../data/example_disk_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_oemconfig_oem_multipath_scan() is False

    def test_get_oemconfig_swap_mbytes(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        assert state.get_oemconfig_swap_mbytes() is None
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_swap_mbytes() == 42

    def test_get_oemconfig_swap_name(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        assert state.get_oemconfig_swap_name() == 'LVSwap'
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_swap_name() == 'swap'

    def test_get_oemconfig_swap_mbytes_default(self):
        description = XMLDescription(
            '../data/example_btrfs_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_oemconfig_swap_mbytes() == 128

    def test_get_users_sections(self):
        assert self.state.get_users_sections()[0].get_user()[0].get_name() == \
            'root'

    def test_get_users(self):
        description = XMLDescription(
            '../data/example_multiple_users_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)
        users = state.get_users()
        assert len(users) == 3
        assert any(u.get_name() == 'root' for u in users)
        assert any(u.get_name() == 'tux' for u in users)
        assert any(u.get_name() == 'kiwi' for u in users)

    def test_get_user_groups(self):
        description = XMLDescription(
            '../data/example_multiple_users_config.xml'
        )
        xml_data = description.load()
        state = XMLState(xml_data)

        assert len(state.get_user_groups('root')) == 0
        assert len(state.get_user_groups('tux')) == 1
        assert any(grp == 'users' for grp in state.get_user_groups('tux'))
        assert len(state.get_user_groups('kiwi')) == 3
        assert any(grp == 'users' for grp in state.get_user_groups('kiwi'))
        assert any(grp == 'kiwi' for grp in state.get_user_groups('kiwi'))
        assert any(grp == 'admin' for grp in state.get_user_groups('kiwi'))

    def test_copy_displayname(self):
        self.state.copy_displayname(self.boot_state)
        assert self.boot_state.xml_data.get_displayname() == 'Bob'

    def test_copy_drivers_sections(self):
        self.state.copy_drivers_sections(self.boot_state)
        assert 'bar' in self.boot_state.get_drivers_list()

    def test_copy_systemdisk_section(self):
        self.state.copy_systemdisk_section(self.boot_state)
        systemdisk = self.boot_state.get_build_type_system_disk_section()
        assert systemdisk.get_name() == 'mydisk'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_copy_bootloader_section(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        self.state.copy_bootloader_section(self.boot_state)
        assert self.boot_state.get_build_type_bootloader_section() == \
            self.bootloader

    def test_copy_strip_sections(self):
        self.state.copy_strip_sections(self.boot_state)
        assert 'del-a' in self.boot_state.get_strip_files_to_delete()

    def test_copy_machine_section(self):
        self.state.copy_machine_section(self.boot_state)
        machine = self.boot_state.get_build_type_machine_section()
        assert machine.get_memory() == 512

    def test_copy_oemconfig_section(self):
        self.state.copy_oemconfig_section(self.boot_state)
        oemconfig = self.boot_state.get_build_type_oemconfig_section()
        assert oemconfig.get_oem_systemsize()[0] == 2048

    def test_copy_repository_sections(self):
        self.state.copy_repository_sections(self.boot_state, True)
        repository = self.boot_state.get_repository_sections()[0]
        assert repository.get_source().get_path() == 'iso:///image/CDs/dvd.iso'

    def test_copy_preferences_subsections(self):
        self.state.copy_preferences_subsections(
            ['bootsplash_theme'], self.boot_state
        )
        preferences = self.boot_state.get_preferences_sections()[0]
        assert preferences.get_bootsplash_theme()[0] == 'openSUSE'

    def test_copy_build_type_attributes(self):
        self.state.copy_build_type_attributes(
            ['firmware'], self.boot_state
        )
        assert self.boot_state.build_type.get_firmware() == 'efi'

    def test_copy_bootincluded_packages_with_no_image_packages(self):
        self.state.copy_bootincluded_packages(self.boot_state)
        bootstrap_packages = self.boot_state.get_bootstrap_packages()
        assert 'plymouth-branding-openSUSE' in bootstrap_packages
        assert 'grub2-branding-openSUSE' in bootstrap_packages
        assert 'gfxboot-branding-openSUSE' in bootstrap_packages
        to_delete_packages = self.boot_state.get_to_become_deleted_packages()
        assert 'gfxboot-branding-openSUSE' not in to_delete_packages

    def test_copy_bootincluded_packages_with_image_packages(self):
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution/config.xml'
        )
        boot_state = XMLState(boot_description.load(), ['std'])
        self.state.copy_bootincluded_packages(boot_state)
        image_packages = boot_state.get_image_packages_sections()
        bootstrap_packages = boot_state.get_bootstrap_packages()
        assert 'plymouth-branding-openSUSE' in bootstrap_packages
        assert 'grub2-branding-openSUSE' in bootstrap_packages
        assert 'gfxboot-branding-openSUSE' in bootstrap_packages
        assert 'plymouth-branding-openSUSE' not in image_packages
        assert 'grub2-branding-openSUSE' not in image_packages
        assert 'gfxboot-branding-openSUSE' not in image_packages
        to_delete_packages = boot_state.get_to_become_deleted_packages()
        assert 'gfxboot-branding-openSUSE' not in to_delete_packages

    def test_copy_bootincluded_archives(self):
        self.state.copy_bootincluded_archives(self.boot_state)
        bootstrap_archives = self.boot_state.get_bootstrap_archives()
        assert '/absolute/path/to/image.tgz' in bootstrap_archives

    def test_copy_bootdelete_packages(self):
        self.state.copy_bootdelete_packages(self.boot_state)
        to_delete_packages = self.boot_state.get_to_become_deleted_packages()
        assert 'vim' in to_delete_packages

    def test_copy_bootdelete_packages_no_delete_section_in_boot_descr(self):
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution-no-delete-section/config.xml'
        )
        boot_state = XMLState(
            boot_description.load()
        )
        self.state.copy_bootdelete_packages(boot_state)
        to_delete_packages = boot_state.get_to_become_deleted_packages()
        assert 'vim' in to_delete_packages

    def test_build_type_size(self):
        result = self.state.get_build_type_size()
        assert result.mbytes == 1024
        assert result.additive

    def test_build_type_size_with_unpartitioned(self):
        state = XMLState(self.description.load(), ['vmxSimpleFlavour'], 'oem')
        result = state.get_build_type_size()
        assert result.mbytes == 3072
        assert not result.additive
        result = state.get_build_type_size(include_unpartitioned=True)
        assert result.mbytes == 4096
        assert not result.additive

    def test_get_build_type_unpartitioned_bytes(self):
        assert self.state.get_build_type_unpartitioned_bytes() == 0
        state = XMLState(self.description.load(), ['vmxSimpleFlavour'], 'oem')
        assert state.get_build_type_unpartitioned_bytes() == 1073741824
        state = XMLState(self.description.load(), ['vmxFlavour'], 'oem')
        assert state.get_build_type_unpartitioned_bytes() == 0
        state = XMLState(self.description.load(), ['ec2Flavour'], 'oem')
        assert state.get_build_type_unpartitioned_bytes() == 0

    def test_get_volume_group_name(self):
        assert self.state.get_volume_group_name() == 'mydisk'

    def test_get_volume_group_name_default(self):
        assert self.boot_state.get_volume_group_name() == 'systemVG'

    def test_get_distribution_name_from_boot_attribute(self):
        assert self.state.get_distribution_name_from_boot_attribute() == \
            'distribution'

    def test_get_fs_mount_option_list(self):
        assert self.state.get_fs_mount_option_list() == ['async']

    def test_get_fs_create_option_list(self):
        assert self.state.get_fs_create_option_list() == ['-O', '^has_journal']

    @patch('kiwi.xml_parse.type_.get_boot')
    def test_get_distribution_name_from_boot_attribute_no_boot(self, mock_boot):
        mock_boot.return_value = None
        with raises(KiwiDistributionNameError):
            self.state.get_distribution_name_from_boot_attribute()

    @patch('kiwi.xml_parse.type_.get_boot')
    def test_get_distribution_name_from_boot_attribute_invalid_boot(
        self, mock_boot
    ):
        mock_boot.return_value = 'invalid'
        with raises(KiwiDistributionNameError):
            self.state.get_distribution_name_from_boot_attribute()

    def test_delete_repository_sections(self):
        self.state.delete_repository_sections()
        assert self.state.get_repository_sections() == []

    def test_delete_repository_sections_used_for_build(self):
        self.state.delete_repository_sections_used_for_build()
        assert self.state.get_repository_sections()[0].get_imageonly()

    def test_get_build_type_vmconfig_entries(self):
        assert self.state.get_build_type_vmconfig_entries() == []

    def test_get_build_type_vmconfig_entries_for_simple_disk(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        assert state.get_build_type_vmconfig_entries() == [
            'numvcpus = "4"', 'cpuid.coresPerSocket = "2"'
        ]

    def test_get_build_type_vmconfig_entries_no_machine_section(self):
        description = XMLDescription('../data/example_disk_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_build_type_vmconfig_entries() == []

    def test_get_build_type_docker_containerconfig_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        containerconfig = state.get_build_type_containerconfig_section()
        assert containerconfig.get_name() == \
            'container_name'
        assert containerconfig.get_maintainer() == \
            'tux'
        assert containerconfig.get_workingdir() == \
            '/root'

    def test_set_container_tag(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        state.set_container_config_tag('new_tag')
        config = state.get_container_config()
        assert config['container_tag'] == 'new_tag'

    def test_add_container_label(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        state.add_container_config_label('somelabel', 'overwrittenvalue')
        state.add_container_config_label('new_label', 'new value')
        config = state.get_container_config()
        assert config['labels'] == {
            'somelabel': 'overwrittenvalue',
            'someotherlabel': 'anotherlabelvalue',
            'new_label': 'new value'
        }

    def test_add_container_label_without_contianerconfig(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['xenDom0Flavour'], 'docker')
        state.add_container_config_label('somelabel', 'newlabelvalue')
        config = state.get_container_config()
        assert config['labels'] == {
            'somelabel': 'newlabelvalue'
        }

    def test_add_container_label_no_container_image_type(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        state.add_container_config_label('somelabel', 'newlabelvalue')
        with self._caplog.at_level(logging.WARNING):
            config = state.get_container_config()
            assert config == {
                'history': {'author': 'Marcus <ms@suse.com>'},
                'maintainer': 'Marcus <ms@suse.com>'
            }

    def test_set_container_tag_not_applied(self):
        with self._caplog.at_level(logging.WARNING):
            self.state.set_container_config_tag('new_tag')

    def test_get_container_config(self):
        expected_config = {
            'labels': {
                'somelabel': 'labelvalue',
                'someotherlabel': 'anotherlabelvalue'
            },
            'maintainer': 'tux',
            'entry_subcommand': ['ls', '-l'],
            'container_name': 'container_name',
            'container_tag': 'container_tag',
            'additional_names': ['current', 'foobar'],
            'workingdir': '/root',
            'environment': {
                'PATH': '/bin:/usr/bin:/home/user/bin',
                'SOMEVAR': 'somevalue'
            },
            'user': 'root',
            'volumes': ['/tmp', '/var/log'],
            'entry_command': ['/bin/bash', '-x'],
            'expose_ports': ['80', '8080'],
            'stopsignal': 'SIGINT',
            'history': {
                'author': 'history author',
                'comment': 'This is a comment',
                'created_by': 'created by text',
                'application_id': '123',
                'package_version': '2003.12.0.0',
                'launcher': 'app'
            }
        }
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        assert state.get_container_config() == expected_config

    def test_get_container_config_clear_commands(self):
        expected_config = {
            'maintainer': 'tux',
            'entry_subcommand': [],
            'container_name': 'container_name',
            'container_tag': 'container_tag',
            'workingdir': '/root',
            'user': 'root',
            'entry_command': [],
            'history': {'author': 'Marcus <ms@suse.com>'}
        }
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        assert state.get_container_config() == expected_config

    def test_get_spare_part(self):
        assert self.state.get_build_type_spare_part_size() == 200
        assert self.state.get_build_type_spare_part_fs_attributes() == [
            'no-copy-on-write'
        ]

    def test_get_build_type_format_options(self):
        assert self.state.get_build_type_format_options() == {
            'super': 'man',
            'force_size': None
        }

    def test_get_derived_from_image_uri(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        assert state.get_derived_from_image_uri()[0].uri == \
            'obs://project/repo/image#mytag'

    def test_set_derived_from_image_uri(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        state.set_derived_from_image_uri('file:///new_uri')
        assert state.get_derived_from_image_uri()[0].translate() == '/new_uri'

    def test_set_derived_from_image_uri_not_applied(self):
        with self._caplog.at_level(logging.WARNING):
            self.state.set_derived_from_image_uri('file:///new_uri')

    def test_is_xen_server(self):
        assert self.state.is_xen_server() is True

    def test_is_xen_guest_by_machine_setup(self):
        assert self.state.is_xen_guest() is True

    def test_is_xen_guest_no_xen_guest_setup(self):
        assert self.boot_state.is_xen_guest() is False

    def test_is_xen_guest_by_firmware_setup(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['ec2Flavour'], 'oem')
        assert state.is_xen_guest() is True

    def test_is_xen_guest_by_architecture(self):
        Defaults.set_platform_name('unsupported')
        xml_data = self.description.load()
        state = XMLState(xml_data, ['ec2Flavour'], 'oem')
        assert state.is_xen_guest() is False
        Defaults.set_platform_name('x86_64')

    def test_get_initrd_system(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_initrd_system() == 'dracut'
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'iso')
        assert state.get_initrd_system() == 'dracut'
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        assert state.get_initrd_system() == 'none'
        state = XMLState(xml_data, [], 'oem')
        assert state.get_initrd_system() == 'dracut'

    def test_get_rpm_locale_filtering(self):
        assert self.state.get_rpm_locale_filtering() is True
        assert self.boot_state.get_rpm_locale_filtering() is False

    def test_get_locale(self):
        assert self.state.get_locale() == ['en_US', 'de_DE']
        assert self.boot_state.get_locale() is None

    def test_get_rpm_locale(self):
        assert self.state.get_rpm_locale() == [
            'POSIX', 'C', 'C.UTF-8', 'en_US', 'de_DE'
        ]
        assert self.boot_state.get_rpm_locale() is None

    def test_set_root_partition_uuid(self):
        assert self.state.get_root_partition_uuid() is None
        self.state.set_root_partition_uuid('some-id')
        assert self.state.get_root_partition_uuid() == 'some-id'

    def test_set_root_filesystem_uuid(self):
        assert self.state.get_root_filesystem_uuid() is None
        self.state.set_root_filesystem_uuid('some-id')
        assert self.state.get_root_filesystem_uuid() == 'some-id'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_name(self, mock_bootloader):
        mock_bootloader.return_value = [None]
        assert self.state.get_build_type_bootloader_name() == 'grub2'
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_name() == 'some-loader'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_use_disk_password(self, mock_bootloader):
        mock_bootloader.return_value = [None]
        assert self.state.get_build_type_bootloader_use_disk_password() is False
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_use_disk_password() is True

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_bls(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        self.bootloader.get_bls.return_value = False
        assert self.state.get_build_type_bootloader_bls() is False
        self.bootloader.get_bls.return_value = True
        assert self.state.get_build_type_bootloader_bls() is True
        self.bootloader.get_bls.return_value = None
        assert self.state.get_build_type_bootloader_bls() is True

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_console(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_console() == \
            ['some-console', 'some-console']

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_serial_line_setup(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_serial_line_setup() == \
            'some-serial'
        mock_bootloader.return_value = [None]
        assert self.state.get_build_type_bootloader_serial_line_setup() \
            is None

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_timeout(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_timeout() == \
            'some-timeout'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_timeout_style(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_timeout_style() == \
            'some-style'
        mock_bootloader.return_value = [None]
        assert self.state.get_build_type_bootloader_timeout_style() \
            is None

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_targettype(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_targettype() == \
            'some-target'

    def test_get_installintrd_modules(self):
        assert self.state.get_installmedia_initrd_modules('add') == \
            ['network-legacy']
        assert self.state.get_installmedia_initrd_modules('set') == []
        assert self.state.get_installmedia_initrd_modules('omit') == []
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        assert state.get_installmedia_initrd_modules('add') == []

    def test_get_installintrd_driver(self):
        assert self.state.get_installmedia_initrd_drivers('add') == \
            ['erofs']
        assert self.state.get_installmedia_initrd_drivers('omit') == []
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        assert state.get_installmedia_initrd_drivers('add') == []

    def test_get_dracut_config(self):
        assert self.state.get_dracut_config('setup').uefi is False
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        assert state.get_dracut_config('setup').uefi is True
        assert state.get_dracut_config('add').modules == ['some']
        assert state.get_dracut_config('add').drivers == ['driver']

    @patch('kiwi.system.uri.os.path.abspath')
    def test_get_repositories_signing_keys(self, mock_root_path):
        mock_root_path.side_effect = lambda x: f'(mock_abspath){x}'
        assert self.state.get_repositories_signing_keys() == [
            '(mock_abspath)key_a',
            '(mock_abspath)/usr/share/distribution-gpg-keys/'
            'fedora/RPM-GPG-KEY-fedora-15.3-primary',
            '(mock_abspath)key_b'
        ]

    def test_this_path_resolver(self):
        description = XMLDescription('../data/example_this_path_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.xml_data.get_repository()[0].get_source().get_path() \
            == 'dir://{0}/my_repo'.format(os.path.realpath('../data'))

    def test_get_collection_modules(self):
        assert self.state.get_collection_modules() == {
            'disable': ['mod_c'],
            'enable': ['mod_a:stream', 'mod_b']
        }

    @patch('kiwi.xml_parse.type_.get_luks')
    def test_get_luks_credentials(self, mock_get_luks):
        mock_get_luks.return_value = 'data'
        assert self.state.get_luks_credentials() == 'data'
        mock_get_luks.return_value = 'file:///some/data-file'
        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            file_handle = mock_open.return_value.__enter__.return_value
            file_handle.read.return_value = b'data'
            assert self.state.get_luks_credentials() == b'data'
        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            file_handle = mock_open.return_value.__enter__.return_value
            file_handle.read.side_effect = Exception
            with raises(KiwiFileAccessError):
                self.state.get_luks_credentials()

    def test_get_luks_format_options(self):
        assert self.state.get_luks_format_options() == [
            '--type', 'luks2',
            '--cipher', 'aes-gcm-random',
            '--integrity', 'aead',
            '--pbkdf', 'pbkdf2'
        ]

    def test_get_bootstrap_package_name(self):
        assert self.apt_state.get_bootstrap_package_name() == 'bootstrap-me'

    def test_get_bootloader_options(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        assert state.get_bootloader_shim_options() == [
            '--foo', 'bar', '--suse-we-adapt-you-succeed'
        ]
        assert state.get_bootloader_install_options() == [
            '--A', '123', 'B'
        ]
        assert state.get_bootloader_config_options() == [
            '--joe', '-x'
        ]

    def test_get_host_key_certificates(self):
        description = XMLDescription('../data/example_hkd_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_host_key_certificates() == [
            {
                'hkd_cert': ['some1-host.crt', 'some2-host.crt'],
                'hkd_revocation_list': ['some1-revocation.crl'],
                'hkd_ca_cert': 'some-ca.crt',
                'hkd_sign_cert': 'some1-signing.crt'
            },
            {
                'hkd_cert': ['some3-host.crt'],
                'hkd_revocation_list': ['some2-revocation.crl'],
                'hkd_ca_cert': 'some-ca.crt',
                'hkd_sign_cert': 'some2-signing.crt'
            }
        ]

    def test_get_btrfs_root_is_subvolume(self):
        assert self.state.build_type.get_btrfs_root_is_subvolume() is \
            None

    @patch('kiwi.xml_parse.type_.get_btrfs_set_default_volume')
    def test_btrfs_default_volume_requested(
        self, mock_get_btrfs_set_default_volume
    ):
        mock_get_btrfs_set_default_volume.return_value = True
        assert self.state.btrfs_default_volume_requested() is True
        mock_get_btrfs_set_default_volume.return_value = False
        assert self.state.btrfs_default_volume_requested() is False
        mock_get_btrfs_set_default_volume.return_value = None
        assert self.state.btrfs_default_volume_requested() is True

    def test_get_certificates(self):
        assert self.state.get_certificates() == ['/some/ca/filename']
        assert self.state.get_certificates_target_distribution() == 'suse'
        self.state.add_certificate('/new/file', 'rhel')
        assert self.state.get_certificates() == [
            '/new/file', '/some/ca/filename'
        ]
        assert self.state.get_certificates_target_distribution() == 'rhel'
        self.state.add_certificate('/new/file', 'rhel')
        assert self.state.get_certificates() == [
            '/new/file', '/some/ca/filename'
        ]
        assert self.apt_state.get_certificates() == []
        assert self.apt_state.get_certificates_target_distribution() == ''
        self.apt_state.add_certificate('/new/file', 'debian')
        assert self.apt_state.get_certificates() == ['/new/file']
        assert self.apt_state.get_certificates_target_distribution() == 'debian'