def setUp(self): """ Do any setup required prior to running a test. """ flags.image_install = True self.blivet = InstallerStorage() self.addCleanup(self._clean_up) self.set_up_storage()
def test_bootloader_in_kickstart(self): ''' test that a bootloader such as prepboot/biosboot shows up in the kickstart data ''' with patch('blivet.osinstall.InstallerStorage.bootloader_device', new_callable=PropertyMock) as mock_bootloader_device: with patch('blivet.osinstall.InstallerStorage.mountpoints', new_callable=PropertyMock) as mock_mountpoints: # set up prepboot partition bootloader_device_obj = PartitionDevice( "test_partition_device") bootloader_device_obj.size = Size('5 MiB') bootloader_device_obj.format = formats.get_format("prepboot") blivet_obj = InstallerStorage() # mountpoints must exist for update_ksdata to run mock_bootloader_device.return_value = bootloader_device_obj mock_mountpoints.values.return_value = [] # initialize ksdata test_ksdata = returnClassForVersion()() blivet_obj.ksdata = test_ksdata blivet_obj.update_ksdata() self.assertTrue("part prepboot" in str(blivet_obj.ksdata))
def test_bootloader_in_kickstart(self): ''' test that a bootloader such as prepboot/biosboot shows up in the kickstart data ''' with patch('blivet.osinstall.InstallerStorage.bootloader_device', new_callable=PropertyMock) as mock_bootloader_device: with patch('blivet.osinstall.InstallerStorage.mountpoints', new_callable=PropertyMock) as mock_mountpoints: # set up prepboot partition bootloader_device_obj = PartitionDevice("test_partition_device") bootloader_device_obj.size = Size('5 MiB') bootloader_device_obj.format = formats.get_format("prepboot") blivet_obj = InstallerStorage() # mountpoints must exist for update_ksdata to run mock_bootloader_device.return_value = bootloader_device_obj mock_mountpoints.values.return_value = [] # initialize ksdata test_ksdata = returnClassForVersion()() blivet_obj.ksdata = test_ksdata blivet_obj.update_ksdata() self.assertTrue("part prepboot" in str(blivet_obj.ksdata))
class ImageBackedTestCase(unittest.TestCase): """ A class to encapsulate testing of blivet using block devices. The basic idea is you create some scratch block devices and then run some test code on them. :attr:`~.ImageBackedTestCase.disks` defines the set of disk images. :meth:`~.ImageBackedTestCase._set_up_storage` is where you specify the initial layout of the disks. It will be written to the disk images in :meth:`~.ImageBackedTestCase.set_up_storage`. You then write test methods as usual that use the disk images, which will be cleaned up and removed when each test method finishes. """ initialize_disks = True """ Whether or not to create a disklabel on the disks. """ disks = {"disk1": Size("2 GiB"), "disk2": Size("2 GiB")} """ The names and sizes of the disk images to create/use. """ def set_up_disks(self): """ Create disk image files to build the test's storage on. If you are actually creating the disk image files here don't forget to set the initialize_disks flag so they get a fresh disklabel when clear_partitions gets called from create_storage later. """ for (name, size) in iter(self.disks.items()): path = util.create_sparse_tempfile(name, size) self.blivet.disk_images[name] = path # # set up the disk images with a disklabel # self.blivet.config.initialize_disks = self.initialize_disks def _set_up_storage(self): """ Schedule creation of storage devices on the disk images. .. note:: The disk images should already be in a populated devicetree. """ pass def set_up_storage(self): """ Create a device stack on top of disk images for this test to run on. This will write the configuration to whatever disk images are defined in set_up_disks. """ # # create disk images # self.set_up_disks() # # populate the devicetree # self.blivet.reset() # # clear and/or initialize disks as specified in set_up_disks # self.blivet.clear_partitions() # # create the rest of the stack # self._set_up_storage() # # write configuration to disk images # self.blivet.do_it() def setUp(self): """ Do any setup required prior to running a test. """ flags.image_install = True self.blivet = InstallerStorage() self.addCleanup(self._clean_up) self.set_up_storage() def _clean_up(self): """ Clean up any resources that may have been set up for a test. """ self.blivet.reset() self.blivet.devicetree.teardown_disk_images() for fn in self.blivet.disk_images.values(): if os.path.exists(fn): os.unlink(fn) flags.image_install = False