@@ -0,0 +1,3222 @@
+%0Aimport os%0Aimport unittest%0A%0Afrom blivet import Blivet%0Afrom blivet import util%0Afrom blivet.size import Size%0Afrom blivet.flags import flags%0A%0A@unittest.skipUnless(os.geteuid() == 0, %22requires root access%22)%0Aclass ImageBackedTestCase(unittest.TestCase):%0A    %22%22%22 A class to encapsulate testing of blivet using block devices.%0A%0A        The basic idea is you create some scratch block devices and then run%0A        some test code on them.%0A%0A        :attr:%60~.ImageBackedTestCase.disks%60 defines the set of disk images.%0A%0A        :meth:%60~.ImageBackedTestCase._set_up_storage%60 is where you specify the%0A        initial layout of the disks. It will be written to the disk images in%0A        :meth:%60~.ImageBackedTestCase.set_up_storage%60.%0A%0A        You then write test methods as usual that use the disk images, which%0A        will be cleaned up and removed when each test method finishes.%0A    %22%22%22%0A%0A    initialize_disks = True%0A    %22%22%22 Whether or not to create a disklabel on the disks. %22%22%22%0A%0A    disks = %7B %22disk1%22: Size(%222 GiB%22),%0A              %22disk2%22: Size(%222 GiB%22) %7D%0A    %22%22%22 The names and sizes of the disk images to create/use. %22%22%22%0A%0A    def set_up_disks(self):%0A        %22%22%22 Create disk image files to build the test's storage on.%0A%0A            If you are actually creating the disk image files here don't forget%0A            to set the initializeDisks flag so they get a fresh disklabel when%0A            clearPartitions gets called from create_storage later.%0A        %22%22%22%0A        for (name, size) in self.disks.iteritems():%0A            path = util.create_sparse_tempfile(name, size)%0A            self.blivet.config.diskImages%5Bname%5D = path%0A%0A        #%0A        # set up the disk images with a disklabel%0A        #%0A        self.blivet.config.initializeDisks = self.initialize_disks%0A%0A    def _set_up_storage(self):%0A        %22%22%22 Schedule creation of storage devices on the disk images.%0A%0A            .. note::%0A%0A                The disk images should already be in a populated devicetree.%0A%0A        %22%22%22%0A        pass%0A%0A    def set_up_storage(self):%0A        %22%22%22 Create a device stack on top of disk images for this test to run on.%0A%0A            This will write the configuration to whatever disk images are%0A            defined in set_up_disks.%0A        %22%22%22%0A        #%0A        # create disk images%0A        #%0A        self.set_up_disks()%0A%0A        #%0A        # populate the devicetree%0A        #%0A        self.blivet.reset()%0A%0A        #%0A        # clear and/or initialize disks as specified in set_up_disks%0A        #%0A        self.blivet.clearPartitions()%0A%0A        #%0A        # create the rest of the stack%0A        #%0A        self._set_up_storage()%0A%0A        #%0A        # write configuration to disk images%0A        #%0A        self.blivet.doIt()%0A%0A    def setUp(self):%0A        %22%22%22 Do any setup required prior to running a test. %22%22%22%0A        flags.image_install = True%0A        self.blivet = Blivet()%0A%0A        self.addCleanup(self._cleanUp)%0A        self.set_up_storage()%0A%0A    def _cleanUp(self):%0A        %22%22%22 Clean up any resources that may have been set up for a test. %22%22%22%0A        self.blivet.devicetree.teardownDiskImages()%0A        for fn in self.blivet.config.diskImages.values():%0A            if os.path.exists(fn):%0A                os.unlink(fn)%0A%0A        flags.image_install = False%0A

Add a base class for tests backed by disk image storage.