Debian Codegraph @

tests/test_writers_util.py

raw
1 # vim: set ft=python ts=4 sw=4 expandtab:
2 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3 #
4 # C E D A R
5 # S O L U T I O N S "Software done right."
6 # S O F T W A R E
7 #
8 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
9 #
10 # Copyright (c) 2004-2007,2010,2011,2015 Kenneth J. Pronovici.
11 # All rights reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License,
15 # Version 2, as published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 #
21 # Copies of the GNU General Public License are available from
22 # the Free Software Foundation website, http://www.gnu.org/.
23 #
24 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
25 #
26 # Author : Kenneth J. Pronovici <[email protected]>
27 # Language : Python 3
28 # Project : Cedar Backup, release 3
29 # Purpose : Tests writer utility functionality.
30 #
31 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
32
33 ########################################################################
34 # Module documentation
35 ########################################################################
36
37 """
38 Unit tests for CedarBackup3/writers/util.py.
39
40 Code Coverage
41 =============
42
43 This module contains individual tests for the public functions and classes
44 implemented in writers/util.py.
45
46 I usually prefer to test only the public interface to a class, because that
47 way the regression tests don't depend on the internal implementation. In
48 this case, I've decided to test some of the private methods, because their
49 "privateness" is more a matter of presenting a clean external interface than
50 anything else (most of the private methods are static). Being able to test
51 these methods also makes it easier to gain some reasonable confidence in the
52 code even if some tests are not run because WRITERSUTILTESTS_FULL is not set to
53 "Y" in the environment (see below).
54
55 Naming Conventions
56 ==================
57
58 I prefer to avoid large unit tests which validate more than one piece of
59 functionality, and I prefer to avoid using overly descriptive (read: long)
60 test names, as well. Instead, I use lots of very small tests that each
61 validate one specific thing. These small tests are then named with an index
62 number, yielding something like ``testAddDir_001`` or ``testValidate_010``.
63 Each method has a docstring describing what it's supposed to accomplish. I
64 feel that this makes it easier to judge how important a given failure is,
65 and also makes it somewhat easier to diagnose and fix individual problems.
66
67 Full vs. Reduced Tests
68 ======================
69
70 Some Cedar Backup regression tests require a specialized environment in
71 order to run successfully. This environment won't necessarily be available
72 on every build system out there (for instance, on a Debian autobuilder).
73 Because of this, the default behavior is to run a "reduced feature set" test
74 suite that has no surprising system, kernel or network requirements. If you
75 want to run all of the tests, set WRITERSUTILTESTS_FULL to "Y" in the environment.
76
77 In this module, there are three dependencies: the system must have
78 ``mkisofs`` installed, the kernel must allow ISO images to be mounted
79 in-place via a loopback mechanism, and the current user must be allowed (via
80 ``sudo``) to mount and unmount such loopback filesystems. See documentation
81 by the :any:`TestIsoImage.mountImage` and :any:`TestIsoImage.unmountImage` methods
82 for more information on what ``sudo`` access is required.
83
84 @author Kenneth J. Pronovici <[email protected]>
85 """
86
87
88 ########################################################################
89 # Import modules and do runtime validations
90 ########################################################################
91
92 import os
93 import tempfile
94 import time
95 import unittest
96
97 from CedarBackup3.filesystem import FilesystemList
98 from CedarBackup3.testutil import (
99 buildPath,
100 configureLogging,
101 extractTar,
102 findResources,
103 platformMacOsX,
104 platformSupportsLinks,
105 removedir,
106 setupOverrides,
107 )
108 from CedarBackup3.util import executeCommand, pathJoin
109 from CedarBackup3.writers.util import IsoImage, validateDriveSpeed, validateScsiId
110
111 #######################################################################
112 # Module-wide configuration and constants
113 #######################################################################
114
115 DATA_DIRS = ["./data", "./tests/data"]
116 RESOURCES = ["tree9.tar.gz"]
117 SUDO_CMD = ["sudo"]
118 HDIUTIL_CMD = ["hdiutil"]
119 GCONF_CMD = ["gconftool-2"]
120
121 INVALID_FILE = "bogus" # This file name should never exist
122
123
124 #######################################################################
125 # Utility functions
126 #######################################################################
127
128
129 def runAllTests():
130 """Returns true/false depending on whether the full test suite should be run."""
131 if "WRITERSUTILTESTS_FULL" in os.environ:
132 return os.environ["WRITERSUTILTESTS_FULL"] == "Y"
133 else:
134 return False
135
136
137 #######################################################################
138 # Test Case Classes
139 #######################################################################
140
141 ######################
142 # TestFunctions class
143 ######################
144
145
146 class TestFunctions(unittest.TestCase):
147 """Tests for the various public functions."""
148
149 ################
150 # Setup methods
151 ################
152
153 @classmethod
154 def setUpClass(cls):
155 configureLogging()
156
157 # We absolutely need the overrides set properly for this test, since it
158 # runs programs. Since other tests might mess with the overrides and/or
159 # singletons, and we don't control the order of execution, we need to set
160 # them up here.
161 setupOverrides()
162
163 def setUp(self):
164 pass
165
166 def tearDown(self):
167 pass
168
169 ########################
170 # Test validateScsiId()
171 ########################
172
173 def testValidateScsiId_001(self):
174 """
175 Test with simple scsibus,target,lun address.
176 """
177 scsiId = "0,0,0"
178 result = validateScsiId(scsiId)
179 self.assertEqual(scsiId, result)
180
181 def testValidateScsiId_002(self):
182 """
183 Test with simple scsibus,target,lun address containing spaces.
184 """
185 scsiId = " 0, 0, 0 "
186 result = validateScsiId(scsiId)
187 self.assertEqual(scsiId, result)
188
189 def testValidateScsiId_003(self):
190 """
191 Test with simple ATA address.
192 """
193 scsiId = "ATA:3,2,1"
194 result = validateScsiId(scsiId)
195 self.assertEqual(scsiId, result)
196
197 def testValidateScsiId_004(self):
198 """
199 Test with simple ATA address containing spaces.
200 """
201 scsiId = "ATA: 3, 2,1 "
202 result = validateScsiId(scsiId)
203 self.assertEqual(scsiId, result)
204
205 def testValidateScsiId_005(self):
206 """
207 Test with simple ATAPI address.
208 """
209 scsiId = "ATAPI:1,2,3"
210 result = validateScsiId(scsiId)
211 self.assertEqual(scsiId, result)
212
213 def testValidateScsiId_006(self):
214 """
215 Test with simple ATAPI address containing spaces.
216 """
217 scsiId = " ATAPI:1, 2, 3"
218 result = validateScsiId(scsiId)
219 self.assertEqual(scsiId, result)
220
221 def testValidateScsiId_007(self):
222 """
223 Test with default-device Mac address.
224 """
225 scsiId = "IOCompactDiscServices"
226 result = validateScsiId(scsiId)
227 self.assertEqual(scsiId, result)
228
229 def testValidateScsiId_008(self):
230 """
231 Test with an alternate-device Mac address.
232 """
233 scsiId = "IOCompactDiscServices/2"
234 result = validateScsiId(scsiId)
235 self.assertEqual(scsiId, result)
236
237 def testValidateScsiId_009(self):
238 """
239 Test with an alternate-device Mac address.
240 """
241 scsiId = "IOCompactDiscServices/12"
242 result = validateScsiId(scsiId)
243 self.assertEqual(scsiId, result)
244
245 def testValidateScsiId_010(self):
246 """
247 Test with an invalid address with a missing field.
248 """
249 scsiId = "1,2"
250 self.assertRaises(ValueError, validateScsiId, scsiId)
251
252 def testValidateScsiId_011(self):
253 """
254 Test with an invalid Mac-style address with a backslash.
255 """
256 scsiId = "IOCompactDiscServices\\3"
257 self.assertRaises(ValueError, validateScsiId, scsiId)
258
259 def testValidateScsiId_012(self):
260 """
261 Test with an invalid address with an invalid prefix separator.
262 """
263 scsiId = "ATAPI;1,2,3"
264 self.assertRaises(ValueError, validateScsiId, scsiId)
265
266 def testValidateScsiId_013(self):
267 """
268 Test with an invalid address with an invalid prefix separator.
269 """
270 scsiId = "ATA-1,2,3"
271 self.assertRaises(ValueError, validateScsiId, scsiId)
272
273 def testValidateScsiId_014(self):
274 """
275 Test with a None SCSI id.
276 """
277 scsiId = None
278 result = validateScsiId(scsiId)
279 self.assertEqual(scsiId, result)
280
281 ############################
282 # Test validateDriveSpeed()
283 ############################
284
285 def testValidateDriveSpeed_001(self):
286 """
287 Test for a valid drive speed.
288 """
289 speed = 1
290 result = validateDriveSpeed(speed)
291 self.assertEqual(result, speed)
292 speed = 2
293 result = validateDriveSpeed(speed)
294 self.assertEqual(result, speed)
295 speed = 30
296 result = validateDriveSpeed(speed)
297 self.assertEqual(result, speed)
298 speed = 2.0
299 result = validateDriveSpeed(speed)
300 self.assertEqual(result, speed)
301 speed = 1.3
302 result = validateDriveSpeed(speed)
303 self.assertEqual(result, 1) # truncated
304
305 def testValidateDriveSpeed_002(self):
306 """
307 Test for a None drive speed (special case).
308 """
309 speed = None
310 result = validateDriveSpeed(speed)
311 self.assertEqual(result, speed)
312
313 def testValidateDriveSpeed_003(self):
314 """
315 Test for an invalid drive speed (zero)
316 """
317 speed = 0
318 self.assertRaises(ValueError, validateDriveSpeed, speed)
319
320 def testValidateDriveSpeed_004(self):
321 """
322 Test for an invalid drive speed (negative)
323 """
324 speed = -1
325 self.assertRaises(ValueError, validateDriveSpeed, speed)
326
327 def testValidateDriveSpeed_005(self):
328 """
329 Test for an invalid drive speed (not integer)
330 """
331 speed = "ken"
332 self.assertRaises(ValueError, validateDriveSpeed, speed)
333
334
335 #####################
336 # TestIsoImage class
337 #####################
338
339
340 class TestIsoImage(unittest.TestCase):
341 """Tests for the IsoImage class."""
342
343 ################
344 # Setup methods
345 ################
346
347 @classmethod
348 def setUpClass(cls):
349 configureLogging()
350
351 def setUp(self):
352 try:
353 self.disableGnomeAutomount()
354 self.mounted = False
355 self.tmpdir = tempfile.mkdtemp()
356 self.resources = findResources(RESOURCES, DATA_DIRS)
357 except Exception as e:
358 self.fail(e)
359
360 def tearDown(self):
361 if self.mounted:
362 self.unmountImage()
363 removedir(self.tmpdir)
364 self.enableGnomeAutomount()
365
366 ##################
367 # Utility methods
368 ##################
369
370 def extractTar(self, tarname):
371 """Extracts a tarfile with a particular name."""
372 extractTar(self.tmpdir, self.resources["%s.tar.gz" % tarname])
373
374 def buildPath(self, components):
375 """Builds a complete search path from a list of components."""
376 components.insert(0, self.tmpdir)
377 return buildPath(components)
378
379 def mountImage(self, imagePath):
380 """
381 Mounts an ISO image at ``self.tmpdir/mnt`` using loopback.
382
383 This function chooses the correct operating system-specific function and
384 calls it. If there is no operating-system-specific function, we fall
385 back to the generic function, which uses 'sudo mount'.
386
387 Returns:
388 Path the image is mounted at
389 Raises:
390 IOError: If the command cannot be executed
391 """
392 if platformMacOsX():
393 return self.mountImageDarwin(imagePath)
394 else:
395 return self.mountImageGeneric(imagePath)
396
397 def mountImageDarwin(self, imagePath):
398 """
399 Mounts an ISO image at ``self.tmpdir/mnt`` using Darwin's ``hdiutil`` program.
400
401 Darwin (Mac OS X) uses the ``hdiutil`` program to mount volumes. The
402 mount command doesn't really exist (or rather, doesn't know what to do
403 with ISO 9660 volumes).
404
405 *Note:* According to the manpage, the mountpoint path can't be any longer
406 than MNAMELEN characters (currently 90?) so you might have problems with
407 this depending on how your test environment is set up.
408
409 Returns:
410 Path the image is mounted at
411 Raises:
412 IOError: If the command cannot be executed
413 """
414 mountPath = self.buildPath(["mnt"])
415 os.mkdir(mountPath)
416 args = [
417 "attach",
418 "-mountpoint",
419 mountPath,
420 imagePath,
421 ]
422 (result, _) = executeCommand(HDIUTIL_CMD, args, returnOutput=True)
423 if result != 0:
424 raise OSError("Error (%d) executing command to mount image." % result)
425 self.mounted = True
426 return mountPath
427
428 def mountImageGeneric(self, imagePath):
429 """
430 Mounts an ISO image at ``self.tmpdir/mnt`` using loopback.
431
432 Note that this will fail unless the user has been granted permissions via
433 sudo, using something like this:
434
435 Cmnd_Alias LOOPMOUNT = /bin/mount -d -t iso9660 -o loop * *
436
437 Keep in mind that this entry is a security hole, so you might not want to
438 keep it in ``/etc/sudoers`` all of the time.
439
440 Returns:
441 Path the image is mounted at
442 Raises:
443 IOError: If the command cannot be executed
444 """
445 mountPath = self.buildPath(["mnt"])
446 os.mkdir(mountPath)
447 args = [
448 "mount",
449 "-t",
450 "iso9660",
451 "-o",
452 "loop",
453 imagePath,
454 mountPath,
455 ]
456 (result, _) = executeCommand(SUDO_CMD, args, returnOutput=True)
457 if result != 0:
458 raise OSError("Error (%d) executing command to mount image." % result)
459 self.mounted = True
460 return mountPath
461
462 def unmountImage(self):
463 """
464 Unmounts an ISO image from ``self.tmpdir/mnt``.
465
466 This function chooses the correct operating system-specific function and
467 calls it. If there is no operating-system-specific function, we fall
468 back to the generic function, which uses 'sudo unmount'.
469
470 Raises:
471 IOError: If the command cannot be executed
472 """
473 if platformMacOsX():
474 self.unmountImageDarwin()
475 else:
476 self.unmountImageGeneric()
477
478 def unmountImageDarwin(self):
479 """
480 Unmounts an ISO image from ``self.tmpdir/mnt`` using Darwin's ``hdiutil`` program.
481
482 Darwin (Mac OS X) uses the ``hdiutil`` program to mount volumes. The
483 mount command doesn't really exist (or rather, doesn't know what to do
484 with ISO 9660 volumes).
485
486 *Note:* According to the manpage, the mountpoint path can't be any longer
487 than MNAMELEN characters (currently 90?) so you might have problems with
488 this depending on how your test environment is set up.
489
490 Raises:
491 IOError: If the command cannot be executed
492 """
493 mountPath = self.buildPath(["mnt"])
494 args = [
495 "detach",
496 mountPath,
497 ]
498 (result, _) = executeCommand(HDIUTIL_CMD, args, returnOutput=True)
499 if result != 0:
500 raise OSError("Error (%d) executing command to unmount image." % result)
501 self.mounted = False
502
503 def unmountImageGeneric(self):
504 """
505 Unmounts an ISO image from ``self.tmpdir/mnt``.
506
507 Sometimes, multiple tries are needed because the ISO filesystem is still
508 in use. We try twice with a 1-second pause between attempts. If this
509 isn't successful, you may run out of loopback devices. Check for leftover
510 mounts using 'losetup -a' as root. You can remove a leftover mount using
511 something like 'losetup -d /dev/loop0'.
512
513 Note that this will fail unless the user has been granted permissions via
514 sudo, using something like this:
515
516 Cmnd_Alias LOOPUNMOUNT = /bin/umount -d -t iso9660 *
517
518 Keep in mind that this entry is a security hole, so you might not want to
519 keep it in ``/etc/sudoers`` all of the time.
520
521 Raises:
522 IOError: If the command cannot be executed
523 """
524 mountPath = self.buildPath(["mnt"])
525 args = [
526 "umount",
527 "-d",
528 "-t",
529 "iso9660",
530 mountPath,
531 ]
532 (result, _) = executeCommand(SUDO_CMD, args, returnOutput=True)
533 if result != 0:
534 time.sleep(1)
535 (result, _) = executeCommand(SUDO_CMD, args, returnOutput=True)
536 if result != 0:
537 raise OSError("Error (%d) executing command to unmount image." % result)
538 self.mounted = False
539
540 def disableGnomeAutomount(self):
541 """
542 Disables GNOME auto-mounting of ISO volumes when full tests are enabled.
543
544 As of this writing (October 2011), recent versions of GNOME in Debian
545 come pre-configured to auto-mount various kinds of media (like CDs and
546 thumb drives). Besides auto-mounting the media, GNOME also often opens
547 up a Nautilus browser window to explore the newly-mounted media.
548
549 This causes lots of problems for these unit tests, which assume that they
550 have complete control over the mounting and unmounting process. So, for
551 these tests to work, we need to disable GNOME auto-mounting.
552 """
553 self.origMediaAutomount = None
554 self.origMediaAutomountOpen = None
555 if runAllTests():
556 args = [
557 "--get",
558 "/apps/nautilus/preferences/media_automount",
559 ]
560 (result, output) = executeCommand(GCONF_CMD, args, returnOutput=True)
561 if result == 0:
562 self.origMediaAutomount = output[0][:-1]
563 if self.origMediaAutomount == "true":
564 args = [
565 "--type",
566 "bool",
567 "--set",
568 "/apps/nautilus/preferences/media_automount",
569 "false",
570 ]
571 executeCommand(GCONF_CMD, args)
572 args = [
573 "--get",
574 "/apps/nautilus/preferences/media_automount_open",
575 ]
576 (result, output) = executeCommand(GCONF_CMD, args, returnOutput=True)
577 if result == 0:
578 self.origMediaAutomountOpen = output[0][:-1]
579 if self.origMediaAutomountOpen == "true":
580 args = [
581 "--type",
582 "bool",
583 "--set",
584 "/apps/nautilus/preferences/media_automount_open",
585 "false",
586 ]
587 executeCommand(GCONF_CMD, args)
588
589 def enableGnomeAutomount(self):
590 """
591 Resets GNOME auto-mounting options back to their state prior to disableGnomeAutomount().
592 """
593 if self.origMediaAutomount == "true":
594 args = [
595 "--type",
596 "bool",
597 "--set",
598 "/apps/nautilus/preferences/media_automount",
599 "true",
600 ]
601 executeCommand(GCONF_CMD, args)
602 if self.origMediaAutomountOpen == "true":
603 args = [
604 "--type",
605 "bool",
606 "--set",
607 "/apps/nautilus/preferences/media_automount_open",
608 "true",
609 ]
610 executeCommand(GCONF_CMD, args)
611
612 ###################
613 # Test constructor
614 ###################
615
616 def testConstructor_001(self):
617 """
618 Test the constructor using all default arguments.
619 """
620 isoImage = IsoImage()
621 self.assertEqual(None, isoImage.device)
622 self.assertEqual(None, isoImage.boundaries)
623 self.assertEqual(None, isoImage.graftPoint)
624 self.assertEqual(True, isoImage.useRockRidge)
625 self.assertEqual(None, isoImage.applicationId)
626 self.assertEqual(None, isoImage.biblioFile)
627 self.assertEqual(None, isoImage.publisherId)
628 self.assertEqual(None, isoImage.preparerId)
629 self.assertEqual(None, isoImage.volumeId)
630
631 def testConstructor_002(self):
632 """
633 Test the constructor using non-default arguments.
634 """
635 isoImage = IsoImage("/dev/cdrw", boundaries=(1, 2), graftPoint="/france")
636 self.assertEqual("/dev/cdrw", isoImage.device)
637 self.assertEqual((1, 2), isoImage.boundaries)
638 self.assertEqual("/france", isoImage.graftPoint)
639 self.assertEqual(True, isoImage.useRockRidge)
640 self.assertEqual(None, isoImage.applicationId)
641 self.assertEqual(None, isoImage.biblioFile)
642 self.assertEqual(None, isoImage.publisherId)
643 self.assertEqual(None, isoImage.preparerId)
644 self.assertEqual(None, isoImage.volumeId)
645
646 ################################
647 # Test IsoImage utility methods
648 ################################
649
650 def testUtilityMethods_001(self):
651 """
652 Test _buildDirEntries() with an empty entries dictionary.
653 """
654 entries = {}
655 result = IsoImage._buildDirEntries(entries)
656 self.assertEqual(0, len(result))
657
658 def testUtilityMethods_002(self):
659 """
660 Test _buildDirEntries() with an entries dictionary that has no graft points.
661 """
662 entries = {}
663 entries["/one/two/three"] = None
664 entries["/four/five/six"] = None
665 entries["/seven/eight/nine"] = None
666 result = IsoImage._buildDirEntries(entries)
667 self.assertEqual(3, len(result))
668 self.assertTrue("/one/two/three" in result)
669 self.assertTrue("/four/five/six" in result)
670 self.assertTrue("/seven/eight/nine" in result)
671
672 def testUtilityMethods_003(self):
673 """
674 Test _buildDirEntries() with an entries dictionary that has all graft points.
675 """
676 entries = {}
677 entries["/one/two/three"] = "/backup1"
678 entries["/four/five/six"] = "backup2"
679 entries["/seven/eight/nine"] = "backup3"
680 result = IsoImage._buildDirEntries(entries)
681 self.assertEqual(3, len(result))
682 self.assertTrue("backup1/=/one/two/three" in result)
683 self.assertTrue("backup2/=/four/five/six" in result)
684 self.assertTrue("backup3/=/seven/eight/nine" in result)
685
686 def testUtilityMethods_004(self):
687 """
688 Test _buildDirEntries() with an entries dictionary that has mixed graft points and not.
689 """
690 entries = {}
691 entries["/one/two/three"] = "backup1"
692 entries["/four/five/six"] = None
693 entries["/seven/eight/nine"] = "/backup3"
694 result = IsoImage._buildDirEntries(entries)
695 self.assertEqual(3, len(result))
696 self.assertTrue("backup1/=/one/two/three" in result)
697 self.assertTrue("/four/five/six" in result)
698 self.assertTrue("backup3/=/seven/eight/nine" in result)
699
700 def testUtilityMethods_005(self):
701 """
702 Test _buildGeneralArgs() with all optional values as None.
703 """
704 isoImage = IsoImage()
705 result = isoImage._buildGeneralArgs()
706 self.assertEqual(0, len(result))
707
708 def testUtilityMethods_006(self):
709 """
710 Test _buildGeneralArgs() with applicationId set.
711 """
712 isoImage = IsoImage()
713 isoImage.applicationId = "one"
714 result = isoImage._buildGeneralArgs()
715 self.assertEqual(["-A", "one"], result)
716
717 def testUtilityMethods_007(self):
718 """
719 Test _buildGeneralArgs() with biblioFile set.
720 """
721 isoImage = IsoImage()
722 isoImage.biblioFile = "two"
723 result = isoImage._buildGeneralArgs()
724 self.assertEqual(["-biblio", "two"], result)
725
726 def testUtilityMethods_008(self):
727 """
728 Test _buildGeneralArgs() with publisherId set.
729 """
730 isoImage = IsoImage()
731 isoImage.publisherId = "three"
732 result = isoImage._buildGeneralArgs()
733 self.assertEqual(["-publisher", "three"], result)
734
735 def testUtilityMethods_009(self):
736 """
737 Test _buildGeneralArgs() with preparerId set.
738 """
739 isoImage = IsoImage()
740 isoImage.preparerId = "four"
741 result = isoImage._buildGeneralArgs()
742 self.assertEqual(["-p", "four"], result)
743
744 def testUtilityMethods_010(self):
745 """
746 Test _buildGeneralArgs() with volumeId set.
747 """
748 isoImage = IsoImage()
749 isoImage.volumeId = "five"
750 result = isoImage._buildGeneralArgs()
751 self.assertEqual(["-V", "five"], result)
752
753 def testUtilityMethods_011(self):
754 """
755 Test _buildSizeArgs() with device and boundaries at defaults.
756 """
757 entries = {}
758 entries["/one/two/three"] = "backup1"
759 isoImage = IsoImage()
760 result = isoImage._buildSizeArgs(entries)
761 self.assertEqual(["-print-size", "-graft-points", "-r", "backup1/=/one/two/three"], result)
762
763 def testUtilityMethods_012(self):
764 """
765 Test _buildSizeArgs() with useRockRidge set to True and device and
766 boundaries at defaults.
767 """
768 entries = {}
769 entries["/one/two/three"] = "backup1"
770 isoImage = IsoImage()
771 isoImage.useRockRidge = True
772 result = isoImage._buildSizeArgs(entries)
773 self.assertEqual(["-print-size", "-graft-points", "-r", "backup1/=/one/two/three"], result)
774
775 def testUtilityMethods_013(self):
776 """
777 Test _buildSizeArgs() with useRockRidge set to False and device and
778 boundaries at defaults.
779 """
780 entries = {}
781 entries["/one/two/three"] = "backup1"
782 isoImage = IsoImage()
783 isoImage.useRockRidge = False
784 result = isoImage._buildSizeArgs(entries)
785 self.assertEqual(["-print-size", "-graft-points", "backup1/=/one/two/three"], result)
786
787 def testUtilityMethods_014(self):
788 """
789 Test _buildSizeArgs() with device as None and boundaries as non-None.
790 """
791 entries = {}
792 entries["/one/two/three"] = "backup1"
793 isoImage = IsoImage(device=None, boundaries=(1, 2))
794 result = isoImage._buildSizeArgs(entries)
795 self.assertEqual(["-print-size", "-graft-points", "-r", "backup1/=/one/two/three"], result)
796
797 def testUtilityMethods_015(self):
798 """
799 Test _buildSizeArgs() with device as non-None and boundaries as None.
800 """
801 entries = {}
802 entries["/one/two/three"] = "backup1"
803 isoImage = IsoImage(device="/dev/cdrw", boundaries=None)
804 result = isoImage._buildSizeArgs(entries)
805 self.assertEqual(["-print-size", "-graft-points", "-r", "backup1/=/one/two/three"], result)
806
807 def testUtilityMethods_016(self):
808 """
809 Test _buildSizeArgs() with device and boundaries as non-None.
810 """
811 entries = {}
812 entries["/one/two/three"] = "backup1"
813 isoImage = IsoImage(device="/dev/cdrw", boundaries=(1, 2))
814 result = isoImage._buildSizeArgs(entries)
815 self.assertEqual(["-print-size", "-graft-points", "-r", "-C", "1,2", "-M", "/dev/cdrw", "backup1/=/one/two/three"], result)
816
817 def testUtilityMethods_017(self):
818 """
819 Test _buildWriteArgs() with device and boundaries at defaults.
820 """
821 entries = {}
822 entries["/one/two/three"] = "backup1"
823 isoImage = IsoImage()
824 result = isoImage._buildWriteArgs(entries, "/tmp/file.iso")
825 self.assertEqual(["-graft-points", "-r", "-o", "/tmp/file.iso", "backup1/=/one/two/three"], result)
826
827 def testUtilityMethods_018(self):
828 """
829 Test _buildWriteArgs() with useRockRidge set to True and device and
830 boundaries at defaults.
831 """
832 entries = {}
833 entries["/one/two/three"] = "backup1"
834 isoImage = IsoImage()
835 isoImage.useRockRidge = True
836 result = isoImage._buildWriteArgs(entries, "/tmp/file.iso")
837 self.assertEqual(["-graft-points", "-r", "-o", "/tmp/file.iso", "backup1/=/one/two/three"], result)
838
839 def testUtilityMethods_019(self):
840 """
841 Test _buildWriteArgs() with useRockRidge set to False and device and
842 boundaries at defaults.
843 """
844 entries = {}
845 entries["/one/two/three"] = "backup1"
846 isoImage = IsoImage()
847 isoImage.useRockRidge = False
848 result = isoImage._buildWriteArgs(entries, "/tmp/file.iso")
849 self.assertEqual(["-graft-points", "-o", "/tmp/file.iso", "backup1/=/one/two/three"], result)
850
851 def testUtilityMethods_020(self):
852 """
853 Test _buildWriteArgs() with device as None and boundaries as non-None.
854 """
855 entries = {}
856 entries["/one/two/three"] = "backup1"
857 isoImage = IsoImage(device=None, boundaries=(3, 4))
858 isoImage.useRockRidge = False
859 result = isoImage._buildWriteArgs(entries, "/tmp/file.iso")
860 self.assertEqual(["-graft-points", "-o", "/tmp/file.iso", "backup1/=/one/two/three"], result)
861
862 def testUtilityMethods_021(self):
863 """
864 Test _buildWriteArgs() with device as non-None and boundaries as None.
865 """
866 entries = {}
867 entries["/one/two/three"] = "backup1"
868 isoImage = IsoImage(device="/dev/cdrw", boundaries=None)
869 isoImage.useRockRidge = False
870 result = isoImage._buildWriteArgs(entries, "/tmp/file.iso")
871 self.assertEqual(["-graft-points", "-o", "/tmp/file.iso", "backup1/=/one/two/three"], result)
872
873 def testUtilityMethods_022(self):
874 """
875 Test _buildWriteArgs() with device and boundaries as non-None.
876 """
877 entries = {}
878 entries["/one/two/three"] = "backup1"
879 isoImage = IsoImage(device="/dev/cdrw", boundaries=(3, 4))
880 isoImage.useRockRidge = False
881 result = isoImage._buildWriteArgs(entries, "/tmp/file.iso")
882 self.assertEqual(
883 ["-graft-points", "-o", "/tmp/file.iso", "-C", "3,4", "-M", "/dev/cdrw", "backup1/=/one/two/three"], result
884 )
885
886 ##################
887 # Test addEntry()
888 ##################
889
890 def testAddEntry_001(self):
891 """
892 Attempt to add a non-existent entry.
893 """
894 file1 = self.buildPath([INVALID_FILE])
895 isoImage = IsoImage()
896 self.assertRaises(ValueError, isoImage.addEntry, file1)
897
898 @unittest.skipUnless(platformSupportsLinks(), "Requires soft links")
899 def testAddEntry_002(self):
900 """
901 Attempt to add a an entry that is a soft link to a file.
902 """
903 self.extractTar("tree9")
904 file1 = self.buildPath(["tree9", "dir002", "link003"])
905 isoImage = IsoImage()
906 self.assertRaises(ValueError, isoImage.addEntry, file1)
907
908 @unittest.skipUnless(platformSupportsLinks(), "Requires soft links")
909 def testAddEntry_003(self):
910 """
911 Attempt to add a an entry that is a soft link to a directory
912 """
913 self.extractTar("tree9")
914 file1 = self.buildPath(["tree9", "link001"])
915 isoImage = IsoImage()
916 self.assertRaises(ValueError, isoImage.addEntry, file1)
917
918 def testAddEntry_004(self):
919 """
920 Attempt to add a file, no graft point set.
921 """
922 self.extractTar("tree9")
923 file1 = self.buildPath(["tree9", "file001"])
924 isoImage = IsoImage()
925 self.assertEqual({}, isoImage.entries)
926 isoImage.addEntry(file1)
927 self.assertEqual({file1: None}, isoImage.entries)
928
929 def testAddEntry_005(self):
930 """
931 Attempt to add a file, graft point set on the object level.
932 """
933 self.extractTar("tree9")
934 file1 = self.buildPath(["tree9", "file001"])
935 isoImage = IsoImage(graftPoint="whatever")
936 self.assertEqual({}, isoImage.entries)
937 isoImage.addEntry(file1)
938 self.assertEqual({file1: "whatever"}, isoImage.entries)
939
940 def testAddEntry_006(self):
941 """
942 Attempt to add a file, graft point set on the method level.
943 """
944 self.extractTar("tree9")
945 file1 = self.buildPath(["tree9", "file001"])
946 isoImage = IsoImage()
947 self.assertEqual({}, isoImage.entries)
948 isoImage.addEntry(file1, graftPoint="stuff")
949 self.assertEqual({file1: "stuff"}, isoImage.entries)
950
951 def testAddEntry_007(self):
952 """
953 Attempt to add a file, graft point set on the object and method levels.
954 """
955 self.extractTar("tree9")
956 file1 = self.buildPath(["tree9", "file001"])
957 isoImage = IsoImage(graftPoint="whatever")
958 self.assertEqual({}, isoImage.entries)
959 isoImage.addEntry(file1, graftPoint="stuff")
960 self.assertEqual({file1: "stuff"}, isoImage.entries)
961
962 def testAddEntry_008(self):
963 """
964 Attempt to add a file, graft point set on the object and method levels,
965 where method value is None (which can't be distinguished from the method
966 value being unset).
967 """
968 self.extractTar("tree9")
969 file1 = self.buildPath(["tree9", "file001"])
970 isoImage = IsoImage(graftPoint="whatever")
971 self.assertEqual({}, isoImage.entries)
972 isoImage.addEntry(file1, graftPoint=None)
973 self.assertEqual({file1: "whatever"}, isoImage.entries)
974
975 def testAddEntry_009(self):
976 """
977 Attempt to add a directory, no graft point set.
978 """
979 self.extractTar("tree9")
980 dir1 = self.buildPath(["tree9"])
981 isoImage = IsoImage()
982 self.assertEqual({}, isoImage.entries)
983 isoImage.addEntry(dir1)
984 self.assertEqual({dir1: os.path.basename(dir1)}, isoImage.entries)
985
986 def testAddEntry_010(self):
987 """
988 Attempt to add a directory, graft point set on the object level.
989 """
990 self.extractTar("tree9")
991 dir1 = self.buildPath(["tree9"])
992 isoImage = IsoImage(graftPoint="p")
993 self.assertEqual({}, isoImage.entries)
994 isoImage.addEntry(dir1)
995 self.assertEqual({dir1: pathJoin("p", "tree9")}, isoImage.entries)
996
997 def testAddEntry_011(self):
998 """
999 Attempt to add a directory, graft point set on the method level.
1000 """
1001 self.extractTar("tree9")
1002 dir1 = self.buildPath(["tree9"])
1003 isoImage = IsoImage()
1004 self.assertEqual({}, isoImage.entries)
1005 isoImage.addEntry(dir1, graftPoint="s")
1006 self.assertEqual({dir1: pathJoin("s", "tree9")}, isoImage.entries)
1007
1008 def testAddEntry_012(self):
1009 """
1010 Attempt to add a file, no graft point set, contentsOnly=True.
1011 """
1012 self.extractTar("tree9")
1013 file1 = self.buildPath(["tree9", "file001"])
1014 isoImage = IsoImage()
1015 self.assertEqual({}, isoImage.entries)
1016 isoImage.addEntry(file1, contentsOnly=True)
1017 self.assertEqual({file1: None}, isoImage.entries)
1018
1019 def testAddEntry_013(self):
1020 """
1021 Attempt to add a file, graft point set on the object level,
1022 contentsOnly=True.
1023 """
1024 self.extractTar("tree9")
1025 file1 = self.buildPath(["tree9", "file001"])
1026 isoImage = IsoImage(graftPoint="whatever")
1027 self.assertEqual({}, isoImage.entries)
1028 isoImage.addEntry(file1, contentsOnly=True)
1029 self.assertEqual({file1: "whatever"}, isoImage.entries)
1030
1031 def testAddEntry_014(self):
1032 """
1033 Attempt to add a file, graft point set on the method level,
1034 contentsOnly=True.
1035 """
1036 self.extractTar("tree9")
1037 file1 = self.buildPath(["tree9", "file001"])
1038 isoImage = IsoImage()
1039 self.assertEqual({}, isoImage.entries)
1040 isoImage.addEntry(file1, graftPoint="stuff", contentsOnly=True)
1041 self.assertEqual({file1: "stuff"}, isoImage.entries)
1042
1043 def testAddEntry_015(self):
1044 """
1045 Attempt to add a file, graft point set on the object and method levels,
1046 contentsOnly=True.
1047 """
1048 self.extractTar("tree9")
1049 file1 = self.buildPath(["tree9", "file001"])
1050 isoImage = IsoImage(graftPoint="whatever")
1051 self.assertEqual({}, isoImage.entries)
1052 isoImage.addEntry(file1, graftPoint="stuff", contentsOnly=True)
1053 self.assertEqual({file1: "stuff"}, isoImage.entries)
1054
1055 def testAddEntry_016(self):
1056 """
1057 Attempt to add a file, graft point set on the object and method levels,
1058 where method value is None (which can't be distinguished from the method
1059 value being unset), contentsOnly=True.
1060 """
1061 self.extractTar("tree9")
1062 file1 = self.buildPath(["tree9", "file001"])
1063 isoImage = IsoImage(graftPoint="whatever")
1064 self.assertEqual({}, isoImage.entries)
1065 isoImage.addEntry(file1, graftPoint=None, contentsOnly=True)
1066 self.assertEqual({file1: "whatever"}, isoImage.entries)
1067
1068 def testAddEntry_017(self):
1069 """
1070 Attempt to add a directory, no graft point set, contentsOnly=True.
1071 """
1072 self.extractTar("tree9")
1073 dir1 = self.buildPath(["tree9"])
1074 isoImage = IsoImage()
1075 self.assertEqual({}, isoImage.entries)
1076 isoImage.addEntry(dir1, contentsOnly=True)
1077 self.assertEqual({dir1: None}, isoImage.entries)
1078
1079 def testAddEntry_018(self):
1080 """
1081 Attempt to add a directory, graft point set on the object level,
1082 contentsOnly=True.
1083 """
1084 self.extractTar("tree9")
1085 dir1 = self.buildPath(["tree9"])
1086 isoImage = IsoImage(graftPoint="p")
1087 self.assertEqual({}, isoImage.entries)
1088 isoImage.addEntry(dir1, contentsOnly=True)
1089 self.assertEqual({dir1: "p"}, isoImage.entries)
1090
1091 def testAddEntry_019(self):
1092 """
1093 Attempt to add a directory, graft point set on the method level,
1094 contentsOnly=True.
1095 """
1096 self.extractTar("tree9")
1097 dir1 = self.buildPath(["tree9"])
1098 isoImage = IsoImage()
1099 self.assertEqual({}, isoImage.entries)
1100 isoImage.addEntry(dir1, graftPoint="s", contentsOnly=True)
1101 self.assertEqual({dir1: "s"}, isoImage.entries)
1102
1103 def testAddEntry_020(self):
1104 """
1105 Attempt to add a directory, graft point set on the object and methods
1106 levels, contentsOnly=True.
1107 """
1108 self.extractTar("tree9")
1109 dir1 = self.buildPath(["tree9"])
1110 isoImage = IsoImage(graftPoint="p")
1111 self.assertEqual({}, isoImage.entries)
1112 isoImage.addEntry(dir1, graftPoint="s", contentsOnly=True)
1113 self.assertEqual({dir1: "s"}, isoImage.entries)
1114
1115 def testAddEntry_021(self):
1116 """
1117 Attempt to add a directory, graft point set on the object and methods
1118 levels, contentsOnly=True.
1119 """
1120 self.extractTar("tree9")
1121 dir1 = self.buildPath(["tree9"])
1122 isoImage = IsoImage(graftPoint="p")
1123 self.assertEqual({}, isoImage.entries)
1124 isoImage.addEntry(dir1, graftPoint="s", contentsOnly=True)
1125 self.assertEqual({dir1: "s"}, isoImage.entries)
1126
1127 def testAddEntry_022(self):
1128 """
1129 Attempt to add a file that has already been added, override=False.
1130 """
1131 self.extractTar("tree9")
1132 file1 = self.buildPath(["tree9", "file001"])
1133 isoImage = IsoImage()
1134 self.assertEqual({}, isoImage.entries)
1135 isoImage.addEntry(file1)
1136 self.assertEqual({file1: None}, isoImage.entries)
1137 self.assertRaises(ValueError, isoImage.addEntry, file1, override=False)
1138 self.assertEqual({file1: None}, isoImage.entries)
1139
1140 def testAddEntry_023(self):
1141 """
1142 Attempt to add a file that has already been added, override=True.
1143 """
1144 self.extractTar("tree9")
1145 file1 = self.buildPath(["tree9", "file001"])
1146 isoImage = IsoImage()
1147 self.assertEqual({}, isoImage.entries)
1148 isoImage.addEntry(file1)
1149 self.assertEqual({file1: None}, isoImage.entries)
1150 isoImage.addEntry(file1, override=True)
1151 self.assertEqual({file1: None}, isoImage.entries)
1152
1153 def testAddEntry_024(self):
1154 """
1155 Attempt to add a directory that has already been added, override=False, changing the graft point.
1156 """
1157 self.extractTar("tree9")
1158 file1 = self.buildPath(["tree9", "file001"])
1159 isoImage = IsoImage(graftPoint="whatever")
1160 self.assertEqual({}, isoImage.entries)
1161 isoImage.addEntry(file1, graftPoint="one")
1162 self.assertEqual({file1: "one"}, isoImage.entries)
1163 self.assertRaises(ValueError, isoImage.addEntry, file1, graftPoint="two", override=False)
1164 self.assertEqual({file1: "one"}, isoImage.entries)
1165
1166 def testAddEntry_025(self):
1167 """
1168 Attempt to add a directory that has already been added, override=True, changing the graft point.
1169 """
1170 self.extractTar("tree9")
1171 file1 = self.buildPath(["tree9", "file001"])
1172 isoImage = IsoImage(graftPoint="whatever")
1173 self.assertEqual({}, isoImage.entries)
1174 isoImage.addEntry(file1, graftPoint="one")
1175 self.assertEqual({file1: "one"}, isoImage.entries)
1176 isoImage.addEntry(file1, graftPoint="two", override=True)
1177 self.assertEqual({file1: "two"}, isoImage.entries)
1178
1179 ##########################
1180 # Test getEstimatedSize()
1181 ##########################
1182
1183 @unittest.skipUnless(runAllTests(), "Limited test suite")
1184 def testGetEstimatedSize_001(self):
1185 """
1186 Test with an empty list.
1187 """
1188 self.extractTar("tree9")
1189 isoImage = IsoImage()
1190 self.assertRaises(ValueError, isoImage.getEstimatedSize)
1191
1192 @unittest.skipUnless(runAllTests(), "Limited test suite")
1193 def testGetEstimatedSize_002(self):
1194 """
1195 Test with non-empty empty list.
1196 """
1197 self.extractTar("tree9")
1198 dir1 = self.buildPath(["tree9"])
1199 isoImage = IsoImage()
1200 isoImage.addEntry(dir1, graftPoint="base")
1201 result = isoImage.getEstimatedSize()
1202 self.assertTrue(result > 0)
1203
1204 ####################
1205 # Test writeImage()
1206 ####################
1207
1208 @unittest.skipUnless(runAllTests(), "Limited test suite")
1209 def testWriteImage_001(self):
1210 """
1211 Attempt to write an image containing no entries.
1212 """
1213 isoImage = IsoImage()
1214 imagePath = self.buildPath(["image.iso"])
1215 self.assertRaises(ValueError, isoImage.writeImage, imagePath)
1216
1217 @unittest.skipUnless(runAllTests(), "Limited test suite")
1218 def testWriteImage_002(self):
1219 """
1220 Attempt to write an image containing only an empty directory, no graft point.
1221 """
1222 self.extractTar("tree9")
1223 isoImage = IsoImage()
1224 dir1 = self.buildPath(["tree9", "dir001", "dir002"])
1225 imagePath = self.buildPath(["image.iso"])
1226 isoImage.addEntry(dir1)
1227 isoImage.writeImage(imagePath)
1228 mountPath = self.mountImage(imagePath)
1229 fsList = FilesystemList()
1230 fsList.addDirContents(mountPath)
1231 self.assertEqual(2, len(fsList))
1232 self.assertTrue(mountPath in fsList)
1233 self.assertTrue(pathJoin(mountPath, "dir002") in fsList)
1234
1235 @unittest.skipUnless(runAllTests(), "Limited test suite")
1236 def testWriteImage_003(self):
1237 """
1238 Attempt to write an image containing only an empty directory, with a graft point.
1239 """
1240 self.extractTar("tree9")
1241 isoImage = IsoImage()
1242 dir1 = self.buildPath(["tree9", "dir001", "dir002"])
1243 imagePath = self.buildPath(["image.iso"])
1244 isoImage.addEntry(dir1, graftPoint="base")
1245 isoImage.writeImage(imagePath)
1246 mountPath = self.mountImage(imagePath)
1247 fsList = FilesystemList()
1248 fsList.addDirContents(mountPath)
1249 self.assertEqual(3, len(fsList))
1250 self.assertTrue(mountPath in fsList)
1251 self.assertTrue(pathJoin(mountPath, "base") in fsList)
1252 self.assertTrue(pathJoin(mountPath, "base", "dir002") in fsList)
1253
1254 @unittest.skipUnless(runAllTests(), "Limited test suite")
1255 def testWriteImage_004(self):
1256 """
1257 Attempt to write an image containing only a non-empty directory, no graft
1258 point.
1259 """
1260 self.extractTar("tree9")
1261 isoImage = IsoImage()
1262 dir1 = self.buildPath(["tree9", "dir002"])
1263 imagePath = self.buildPath(["image.iso"])
1264 isoImage.addEntry(dir1)
1265 isoImage.writeImage(imagePath)
1266 mountPath = self.mountImage(imagePath)
1267 fsList = FilesystemList()
1268 fsList.addDirContents(mountPath)
1269 self.assertEqual(10, len(fsList))
1270 self.assertTrue(mountPath in fsList)
1271 self.assertTrue(pathJoin(mountPath, "dir002") in fsList)
1272 self.assertTrue(pathJoin(mountPath, "dir002", "file001") in fsList)
1273 self.assertTrue(pathJoin(mountPath, "dir002", "file002") in fsList)
1274 self.assertTrue(pathJoin(mountPath, "dir002", "link001") in fsList)
1275 self.assertTrue(pathJoin(mountPath, "dir002", "link002") in fsList)
1276 self.assertTrue(pathJoin(mountPath, "dir002", "link003") in fsList)
1277 self.assertTrue(pathJoin(mountPath, "dir002", "link004") in fsList)
1278 self.assertTrue(pathJoin(mountPath, "dir002", "dir001") in fsList)
1279 self.assertTrue(pathJoin(mountPath, "dir002", "dir002") in fsList)
1280
1281 @unittest.skipUnless(runAllTests(), "Limited test suite")
1282 def testWriteImage_005(self):
1283 """
1284 Attempt to write an image containing only a non-empty directory, with a
1285 graft point.
1286 """
1287 self.extractTar("tree9")
1288 isoImage = IsoImage()
1289 dir1 = self.buildPath(["tree9", "dir002"])
1290 imagePath = self.buildPath(["image.iso"])
1291 isoImage.addEntry(dir1, graftPoint=pathJoin("something", "else"))
1292 isoImage.writeImage(imagePath)
1293 mountPath = self.mountImage(imagePath)
1294 fsList = FilesystemList()
1295 fsList.addDirContents(mountPath)
1296 self.assertEqual(12, len(fsList))
1297 self.assertTrue(mountPath in fsList)
1298 self.assertTrue(pathJoin(mountPath, "something") in fsList)
1299 self.assertTrue(pathJoin(mountPath, "something", "else") in fsList)
1300 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002") in fsList)
1301 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002", "file001") in fsList)
1302 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002", "file002") in fsList)
1303 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002", "link001") in fsList)
1304 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002", "link002") in fsList)
1305 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002", "link003") in fsList)
1306 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002", "link004") in fsList)
1307 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002", "dir001") in fsList)
1308 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002", "dir002") in fsList)
1309
1310 @unittest.skipUnless(runAllTests(), "Limited test suite")
1311 def testWriteImage_006(self):
1312 """
1313 Attempt to write an image containing only a file, no graft point.
1314 """
1315 self.extractTar("tree9")
1316 isoImage = IsoImage()
1317 file1 = self.buildPath(["tree9", "file001"])
1318 imagePath = self.buildPath(["image.iso"])
1319 isoImage.addEntry(file1)
1320 isoImage.writeImage(imagePath)
1321 mountPath = self.mountImage(imagePath)
1322 fsList = FilesystemList()
1323 fsList.addDirContents(mountPath)
1324 self.assertEqual(2, len(fsList))
1325 self.assertTrue(mountPath in fsList)
1326 self.assertTrue(pathJoin(mountPath, "file001") in fsList)
1327
1328 @unittest.skipUnless(runAllTests(), "Limited test suite")
1329 def testWriteImage_007(self):
1330 """
1331 Attempt to write an image containing only a file, with a graft point.
1332 """
1333 self.extractTar("tree9")
1334 isoImage = IsoImage()
1335 file1 = self.buildPath(["tree9", "file001"])
1336 imagePath = self.buildPath(["image.iso"])
1337 isoImage.addEntry(file1, graftPoint="point")
1338 isoImage.writeImage(imagePath)
1339 mountPath = self.mountImage(imagePath)
1340 fsList = FilesystemList()
1341 fsList.addDirContents(mountPath)
1342 self.assertEqual(3, len(fsList))
1343 self.assertTrue(mountPath in fsList)
1344 self.assertTrue(pathJoin(mountPath, "point") in fsList)
1345 self.assertTrue(pathJoin(mountPath, "point", "file001") in fsList)
1346
1347 @unittest.skipUnless(runAllTests(), "Limited test suite")
1348 def testWriteImage_008(self):
1349 """
1350 Attempt to write an image containing a file and an empty directory, no
1351 graft points.
1352 """
1353 self.extractTar("tree9")
1354 isoImage = IsoImage()
1355 file1 = self.buildPath(["tree9", "file001"])
1356 dir1 = self.buildPath(["tree9", "dir001", "dir002"])
1357 imagePath = self.buildPath(["image.iso"])
1358 isoImage.addEntry(file1)
1359 isoImage.addEntry(dir1)
1360 isoImage.writeImage(imagePath)
1361 mountPath = self.mountImage(imagePath)
1362 fsList = FilesystemList()
1363 fsList.addDirContents(mountPath)
1364 self.assertEqual(3, len(fsList))
1365 self.assertTrue(mountPath in fsList)
1366 self.assertTrue(pathJoin(mountPath, "file001") in fsList)
1367 self.assertTrue(pathJoin(mountPath, "dir002") in fsList)
1368
1369 @unittest.skipUnless(runAllTests(), "Limited test suite")
1370 def testWriteImage_009(self):
1371 """
1372 Attempt to write an image containing a file and an empty directory, with
1373 graft points.
1374 """
1375 self.extractTar("tree9")
1376 isoImage = IsoImage(graftPoint="base")
1377 file1 = self.buildPath(["tree9", "file001"])
1378 dir1 = self.buildPath(["tree9", "dir001", "dir002"])
1379 imagePath = self.buildPath(["image.iso"])
1380 isoImage.addEntry(file1, graftPoint="other")
1381 isoImage.addEntry(dir1)
1382 isoImage.writeImage(imagePath)
1383 mountPath = self.mountImage(imagePath)
1384 fsList = FilesystemList()
1385 fsList.addDirContents(mountPath)
1386 self.assertEqual(5, len(fsList))
1387 self.assertTrue(mountPath in fsList)
1388 self.assertTrue(pathJoin(mountPath, "other") in fsList)
1389 self.assertTrue(pathJoin(mountPath, "base") in fsList)
1390 self.assertTrue(pathJoin(mountPath, "other", "file001") in fsList)
1391 self.assertTrue(pathJoin(mountPath, "base", "dir002") in fsList)
1392
1393 @unittest.skipUnless(runAllTests(), "Limited test suite")
1394 def testWriteImage_010(self):
1395 """
1396 Attempt to write an image containing a file and a non-empty directory,
1397 mixed graft points.
1398 """
1399 self.extractTar("tree9")
1400 isoImage = IsoImage(graftPoint="base")
1401 file1 = self.buildPath(["tree9", "file001"])
1402 dir1 = self.buildPath(["tree9", "dir001"])
1403 imagePath = self.buildPath(["image.iso"])
1404 isoImage.addEntry(file1, graftPoint=None)
1405 isoImage.addEntry(dir1)
1406 isoImage.writeImage(imagePath)
1407 mountPath = self.mountImage(imagePath)
1408 fsList = FilesystemList()
1409 fsList.addDirContents(mountPath)
1410 self.assertEqual(11, len(fsList))
1411 self.assertTrue(mountPath in fsList)
1412 self.assertTrue(pathJoin(mountPath, "base") in fsList)
1413 self.assertTrue(pathJoin(mountPath, "base", "file001") in fsList)
1414 self.assertTrue(pathJoin(mountPath, "base", "dir001") in fsList)
1415 self.assertTrue(pathJoin(mountPath, "base", "dir001", "file001") in fsList)
1416 self.assertTrue(pathJoin(mountPath, "base", "dir001", "file002") in fsList)
1417 self.assertTrue(pathJoin(mountPath, "base", "dir001", "link001") in fsList)
1418 self.assertTrue(pathJoin(mountPath, "base", "dir001", "link002") in fsList)
1419 self.assertTrue(pathJoin(mountPath, "base", "dir001", "link003") in fsList)
1420 self.assertTrue(pathJoin(mountPath, "base", "dir001", "dir001") in fsList)
1421 self.assertTrue(pathJoin(mountPath, "base", "dir001", "dir002") in fsList)
1422
1423 @unittest.skipUnless(runAllTests(), "Limited test suite")
1424 def testWriteImage_011(self):
1425 """
1426 Attempt to write an image containing several files and a non-empty
1427 directory, mixed graft points.
1428 """
1429 self.extractTar("tree9")
1430 isoImage = IsoImage()
1431 file1 = self.buildPath(["tree9", "file001"])
1432 file2 = self.buildPath(["tree9", "file002"])
1433 dir1 = self.buildPath(["tree9", "dir001"])
1434 imagePath = self.buildPath(["image.iso"])
1435 isoImage.addEntry(file1)
1436 isoImage.addEntry(file2, graftPoint="other")
1437 isoImage.addEntry(dir1, graftPoint="base")
1438 isoImage.writeImage(imagePath)
1439 mountPath = self.mountImage(imagePath)
1440 fsList = FilesystemList()
1441 fsList.addDirContents(mountPath)
1442 self.assertEqual(13, len(fsList))
1443 self.assertTrue(mountPath in fsList)
1444 self.assertTrue(pathJoin(mountPath, "base") in fsList)
1445 self.assertTrue(pathJoin(mountPath, "other") in fsList)
1446 self.assertTrue(pathJoin(mountPath, "file001") in fsList)
1447 self.assertTrue(pathJoin(mountPath, "other", "file002") in fsList)
1448 self.assertTrue(pathJoin(mountPath, "base", "dir001") in fsList)
1449 self.assertTrue(pathJoin(mountPath, "base", "dir001", "file001") in fsList)
1450 self.assertTrue(pathJoin(mountPath, "base", "dir001", "file002") in fsList)
1451 self.assertTrue(pathJoin(mountPath, "base", "dir001", "link001") in fsList)
1452 self.assertTrue(pathJoin(mountPath, "base", "dir001", "link002") in fsList)
1453 self.assertTrue(pathJoin(mountPath, "base", "dir001", "link003") in fsList)
1454 self.assertTrue(pathJoin(mountPath, "base", "dir001", "dir001") in fsList)
1455 self.assertTrue(pathJoin(mountPath, "base", "dir001", "dir002") in fsList)
1456
1457 @unittest.skipUnless(runAllTests(), "Limited test suite")
1458 def testWriteImage_012(self):
1459 """
1460 Attempt to write an image containing a deeply-nested directory.
1461 """
1462 self.extractTar("tree9")
1463 isoImage = IsoImage()
1464 dir1 = self.buildPath(["tree9"])
1465 imagePath = self.buildPath(["image.iso"])
1466 isoImage.addEntry(dir1, graftPoint="something")
1467 isoImage.writeImage(imagePath)
1468 mountPath = self.mountImage(imagePath)
1469 fsList = FilesystemList()
1470 fsList.addDirContents(mountPath)
1471 self.assertEqual(24, len(fsList))
1472 self.assertTrue(mountPath in fsList)
1473 self.assertTrue(pathJoin(mountPath, "something") in fsList)
1474 self.assertTrue(pathJoin(mountPath, "something", "tree9") in fsList)
1475 self.assertTrue(pathJoin(mountPath, "something", "tree9", "file001") in fsList)
1476 self.assertTrue(pathJoin(mountPath, "something", "tree9", "file002") in fsList)
1477 self.assertTrue(pathJoin(mountPath, "something", "tree9", "link001") in fsList)
1478 self.assertTrue(pathJoin(mountPath, "something", "tree9", "link002") in fsList)
1479 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir001") in fsList)
1480 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir001", "file001") in fsList)
1481 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir001", "file002") in fsList)
1482 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir001", "link001") in fsList)
1483 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir001", "link002") in fsList)
1484 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir001", "link003") in fsList)
1485 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir001", "dir001") in fsList)
1486 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir001", "dir002") in fsList)
1487 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002") in fsList)
1488 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002", "file001") in fsList)
1489 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002", "file002") in fsList)
1490 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002", "link001") in fsList)
1491 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002", "link002") in fsList)
1492 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002", "link003") in fsList)
1493 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002", "link004") in fsList)
1494 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002", "dir001") in fsList)
1495 self.assertTrue(pathJoin(mountPath, "something", "tree9", "dir002", "dir002") in fsList)
1496
1497 @unittest.skipUnless(runAllTests(), "Limited test suite")
1498 def testWriteImage_013(self):
1499 """
1500 Attempt to write an image containing only an empty directory, no graft
1501 point, contentsOnly=True.
1502 """
1503 self.extractTar("tree9")
1504 isoImage = IsoImage()
1505 dir1 = self.buildPath(["tree9", "dir001", "dir002"])
1506 imagePath = self.buildPath(["image.iso"])
1507 isoImage.addEntry(dir1, contentsOnly=True)
1508 isoImage.writeImage(imagePath)
1509 mountPath = self.mountImage(imagePath)
1510 fsList = FilesystemList()
1511 fsList.addDirContents(mountPath)
1512 self.assertEqual(1, len(fsList))
1513 self.assertTrue(mountPath in fsList)
1514
1515 @unittest.skipUnless(runAllTests(), "Limited test suite")
1516 def testWriteImage_014(self):
1517 """
1518 Attempt to write an image containing only an empty directory, with a
1519 graft point, contentsOnly=True.
1520 """
1521 self.extractTar("tree9")
1522 isoImage = IsoImage()
1523 dir1 = self.buildPath(["tree9", "dir001", "dir002"])
1524 imagePath = self.buildPath(["image.iso"])
1525 isoImage.addEntry(dir1, graftPoint="base", contentsOnly=True)
1526 isoImage.writeImage(imagePath)
1527 mountPath = self.mountImage(imagePath)
1528 fsList = FilesystemList()
1529 fsList.addDirContents(mountPath)
1530 self.assertEqual(2, len(fsList))
1531 self.assertTrue(mountPath in fsList)
1532 self.assertTrue(pathJoin(mountPath, "base") in fsList)
1533
1534 @unittest.skipUnless(runAllTests(), "Limited test suite")
1535 def testWriteImage_015(self):
1536 """
1537 Attempt to write an image containing only a non-empty directory, no graft
1538 point, contentsOnly=True.
1539 """
1540 self.extractTar("tree9")
1541 isoImage = IsoImage()
1542 dir1 = self.buildPath(["tree9", "dir002"])
1543 imagePath = self.buildPath(["image.iso"])
1544 isoImage.addEntry(dir1, contentsOnly=True)
1545 isoImage.writeImage(imagePath)
1546 mountPath = self.mountImage(imagePath)
1547 fsList = FilesystemList()
1548 fsList.addDirContents(mountPath)
1549 self.assertEqual(9, len(fsList))
1550 self.assertTrue(mountPath in fsList)
1551 self.assertTrue(pathJoin(mountPath, "file001") in fsList)
1552 self.assertTrue(pathJoin(mountPath, "file002") in fsList)
1553 self.assertTrue(pathJoin(mountPath, "link001") in fsList)
1554 self.assertTrue(pathJoin(mountPath, "link002") in fsList)
1555 self.assertTrue(pathJoin(mountPath, "link003") in fsList)
1556 self.assertTrue(pathJoin(mountPath, "link004") in fsList)
1557 self.assertTrue(pathJoin(mountPath, "dir001") in fsList)
1558 self.assertTrue(pathJoin(mountPath, "dir002") in fsList)
1559
1560 @unittest.skipUnless(runAllTests(), "Limited test suite")
1561 def testWriteImage_016(self):
1562 """
1563 Attempt to write an image containing only a non-empty directory, with a
1564 graft point, contentsOnly=True.
1565 """
1566 self.extractTar("tree9")
1567 isoImage = IsoImage()
1568 dir1 = self.buildPath(["tree9", "dir002"])
1569 imagePath = self.buildPath(["image.iso"])
1570 isoImage.addEntry(dir1, graftPoint=pathJoin("something", "else"), contentsOnly=True)
1571 isoImage.writeImage(imagePath)
1572 mountPath = self.mountImage(imagePath)
1573 fsList = FilesystemList()
1574 fsList.addDirContents(mountPath)
1575 self.assertEqual(11, len(fsList))
1576 self.assertTrue(mountPath in fsList)
1577 self.assertTrue(pathJoin(mountPath, "something") in fsList)
1578 self.assertTrue(pathJoin(mountPath, "something", "else") in fsList)
1579 self.assertTrue(pathJoin(mountPath, "something", "else", "file001") in fsList)
1580 self.assertTrue(pathJoin(mountPath, "something", "else", "file002") in fsList)
1581 self.assertTrue(pathJoin(mountPath, "something", "else", "link001") in fsList)
1582 self.assertTrue(pathJoin(mountPath, "something", "else", "link002") in fsList)
1583 self.assertTrue(pathJoin(mountPath, "something", "else", "link003") in fsList)
1584 self.assertTrue(pathJoin(mountPath, "something", "else", "link004") in fsList)
1585 self.assertTrue(pathJoin(mountPath, "something", "else", "dir001") in fsList)
1586 self.assertTrue(pathJoin(mountPath, "something", "else", "dir002") in fsList)
1587
1588 @unittest.skipUnless(runAllTests(), "Limited test suite")
1589 def testWriteImage_017(self):
1590 """
1591 Attempt to write an image containing only a file, no graft point,
1592 contentsOnly=True.
1593 """
1594 self.extractTar("tree9")
1595 isoImage = IsoImage()
1596 file1 = self.buildPath(["tree9", "file001"])
1597 imagePath = self.buildPath(["image.iso"])
1598 isoImage.addEntry(file1, contentsOnly=True)
1599 isoImage.writeImage(imagePath)
1600 mountPath = self.mountImage(imagePath)
1601 fsList = FilesystemList()
1602 fsList.addDirContents(mountPath)
1603 self.assertEqual(2, len(fsList))
1604 self.assertTrue(mountPath in fsList)
1605 self.assertTrue(pathJoin(mountPath, "file001") in fsList)
1606
1607 @unittest.skipUnless(runAllTests(), "Limited test suite")
1608 def testWriteImage_018(self):
1609 """
1610 Attempt to write an image containing only a file, with a graft point,
1611 contentsOnly=True.
1612 """
1613 self.extractTar("tree9")
1614 isoImage = IsoImage()
1615 file1 = self.buildPath(["tree9", "file001"])
1616 imagePath = self.buildPath(["image.iso"])
1617 isoImage.addEntry(file1, graftPoint="point", contentsOnly=True)
1618 isoImage.writeImage(imagePath)
1619 mountPath = self.mountImage(imagePath)
1620 fsList = FilesystemList()
1621 fsList.addDirContents(mountPath)
1622 self.assertEqual(3, len(fsList))
1623 self.assertTrue(mountPath in fsList)
1624 self.assertTrue(pathJoin(mountPath, "point") in fsList)
1625 self.assertTrue(pathJoin(mountPath, "point", "file001") in fsList)
1626
1627 @unittest.skipUnless(runAllTests(), "Limited test suite")
1628 def testWriteImage_019(self):
1629 """
1630 Attempt to write an image containing a file and an empty directory, no
1631 graft points, contentsOnly=True.
1632 """
1633 self.extractTar("tree9")
1634 isoImage = IsoImage()
1635 file1 = self.buildPath(["tree9", "file001"])
1636 dir1 = self.buildPath(["tree9", "dir001", "dir002"])
1637 imagePath = self.buildPath(["image.iso"])
1638 isoImage.addEntry(file1, contentsOnly=True)
1639 isoImage.addEntry(dir1, contentsOnly=True)
1640 isoImage.writeImage(imagePath)
1641 mountPath = self.mountImage(imagePath)
1642 fsList = FilesystemList()
1643 fsList.addDirContents(mountPath)
1644 self.assertEqual(2, len(fsList))
1645 self.assertTrue(mountPath in fsList)
1646 self.assertTrue(pathJoin(mountPath, "file001") in fsList)
1647
1648 @unittest.skipUnless(runAllTests(), "Limited test suite")
1649 def testWriteImage_020(self):
1650 """
1651 Attempt to write an image containing a file and an empty directory, with
1652 graft points, contentsOnly=True.
1653 """
1654 self.extractTar("tree9")
1655 isoImage = IsoImage(graftPoint="base")
1656 file1 = self.buildPath(["tree9", "file001"])
1657 dir1 = self.buildPath(["tree9", "dir001", "dir002"])
1658 imagePath = self.buildPath(["image.iso"])
1659 isoImage.addEntry(file1, graftPoint="other", contentsOnly=True)
1660 isoImage.addEntry(dir1, contentsOnly=True)
1661 isoImage.writeImage(imagePath)
1662 mountPath = self.mountImage(imagePath)
1663 fsList = FilesystemList()
1664 fsList.addDirContents(mountPath)
1665 self.assertEqual(4, len(fsList))
1666 self.assertTrue(mountPath in fsList)
1667 self.assertTrue(pathJoin(mountPath, "other") in fsList)
1668 self.assertTrue(pathJoin(mountPath, "base") in fsList)
1669 self.assertTrue(pathJoin(mountPath, "other", "file001") in fsList)
1670
1671 @unittest.skipUnless(runAllTests(), "Limited test suite")
1672 def testWriteImage_021(self):
1673 """
1674 Attempt to write an image containing a file and a non-empty directory,
1675 mixed graft points, contentsOnly=True.
1676 """
1677 self.extractTar("tree9")
1678 isoImage = IsoImage(graftPoint="base")
1679 file1 = self.buildPath(["tree9", "file001"])
1680 dir1 = self.buildPath(["tree9", "dir001"])
1681 imagePath = self.buildPath(["image.iso"])
1682 isoImage.addEntry(file1, graftPoint=None, contentsOnly=True)
1683 isoImage.addEntry(dir1, contentsOnly=True)
1684 self.assertRaises(IOError, isoImage.writeImage, imagePath) # ends up with a duplicate name
1685
1686 @unittest.skipUnless(runAllTests(), "Limited test suite")
1687 def testWriteImage_022(self):
1688 """
1689 Attempt to write an image containing several files and a non-empty
1690 directory, mixed graft points, contentsOnly=True.
1691 """
1692 self.extractTar("tree9")
1693 isoImage = IsoImage()
1694 file1 = self.buildPath(["tree9", "file001"])
1695 file2 = self.buildPath(["tree9", "file002"])
1696 dir1 = self.buildPath(["tree9", "dir001"])
1697 imagePath = self.buildPath(["image.iso"])
1698 isoImage.addEntry(file1, contentsOnly=True)
1699 isoImage.addEntry(file2, graftPoint="other", contentsOnly=True)
1700 isoImage.addEntry(dir1, graftPoint="base", contentsOnly=True)
1701 isoImage.writeImage(imagePath)
1702 mountPath = self.mountImage(imagePath)
1703 fsList = FilesystemList()
1704 fsList.addDirContents(mountPath)
1705 self.assertEqual(12, len(fsList))
1706 self.assertTrue(mountPath in fsList)
1707 self.assertTrue(pathJoin(mountPath, "base") in fsList)
1708 self.assertTrue(pathJoin(mountPath, "other") in fsList)
1709 self.assertTrue(pathJoin(mountPath, "file001") in fsList)
1710 self.assertTrue(pathJoin(mountPath, "other", "file002") in fsList)
1711 self.assertTrue(pathJoin(mountPath, "base", "file001") in fsList)
1712 self.assertTrue(pathJoin(mountPath, "base", "file002") in fsList)
1713 self.assertTrue(pathJoin(mountPath, "base", "link001") in fsList)
1714 self.assertTrue(pathJoin(mountPath, "base", "link002") in fsList)
1715 self.assertTrue(pathJoin(mountPath, "base", "link003") in fsList)
1716 self.assertTrue(pathJoin(mountPath, "base", "dir001") in fsList)
1717 self.assertTrue(pathJoin(mountPath, "base", "dir002") in fsList)
1718
1719 @unittest.skipUnless(runAllTests(), "Limited test suite")
1720 def testWriteImage_023(self):
1721 """
1722 Attempt to write an image containing a deeply-nested directory,
1723 contentsOnly=True.
1724 """
1725 self.extractTar("tree9")
1726 isoImage = IsoImage()
1727 dir1 = self.buildPath(["tree9"])
1728 imagePath = self.buildPath(["image.iso"])
1729 isoImage.addEntry(dir1, graftPoint="something", contentsOnly=True)
1730 isoImage.writeImage(imagePath)
1731 mountPath = self.mountImage(imagePath)
1732 fsList = FilesystemList()
1733 fsList.addDirContents(mountPath)
1734 self.assertEqual(23, len(fsList))
1735 self.assertTrue(mountPath in fsList)
1736 self.assertTrue(pathJoin(mountPath, "something") in fsList)
1737 self.assertTrue(pathJoin(mountPath, "something", "file001") in fsList)
1738 self.assertTrue(pathJoin(mountPath, "something", "file002") in fsList)
1739 self.assertTrue(pathJoin(mountPath, "something", "link001") in fsList)
1740 self.assertTrue(pathJoin(mountPath, "something", "link002") in fsList)
1741 self.assertTrue(pathJoin(mountPath, "something", "dir001") in fsList)
1742 self.assertTrue(pathJoin(mountPath, "something", "dir001", "file001") in fsList)
1743 self.assertTrue(pathJoin(mountPath, "something", "dir001", "file002") in fsList)
1744 self.assertTrue(pathJoin(mountPath, "something", "dir001", "link001") in fsList)
1745 self.assertTrue(pathJoin(mountPath, "something", "dir001", "link002") in fsList)
1746 self.assertTrue(pathJoin(mountPath, "something", "dir001", "link003") in fsList)
1747 self.assertTrue(pathJoin(mountPath, "something", "dir001", "dir001") in fsList)
1748 self.assertTrue(pathJoin(mountPath, "something", "dir001", "dir002") in fsList)
1749 self.assertTrue(pathJoin(mountPath, "something", "dir002") in fsList)
1750 self.assertTrue(pathJoin(mountPath, "something", "dir002", "file001") in fsList)
1751 self.assertTrue(pathJoin(mountPath, "something", "dir002", "file002") in fsList)
1752 self.assertTrue(pathJoin(mountPath, "something", "dir002", "link001") in fsList)
1753 self.assertTrue(pathJoin(mountPath, "something", "dir002", "link002") in fsList)
1754 self.assertTrue(pathJoin(mountPath, "something", "dir002", "link003") in fsList)
1755 self.assertTrue(pathJoin(mountPath, "something", "dir002", "link004") in fsList)
1756 self.assertTrue(pathJoin(mountPath, "something", "dir002", "dir001") in fsList)
1757 self.assertTrue(pathJoin(mountPath, "something", "dir002", "dir002") in fsList)