Example #1
0
    def test_disk_filename(self):
        tmpfile = get_temp_filename()
        os.unlink(tmpfile)

        disk = Disk(MockHypervisor(), tmpfile, size='1G')
        disk.create()
        self.assertTrue(os.path.exists(tmpfile))
        os.unlink(tmpfile)
Example #2
0
    def test_existing_image_no_overwrite(self):
        tmpfile = get_temp_filename()

        fp = open(tmpfile, 'w')
        fp.write('canary')
        fp.close()

        disk = Disk(MockHypervisor(), tmpfile)
        disk.create()
        fp = open(tmpfile, 'r')
        self.assertEqual(fp.read(), 'canary')
        fp.close()
        os.unlink(tmpfile)
Example #3
0
    def add_disk(self, *args, **kwargs):
        """Adds a disk image to the virtual machine"""
        from VMBuilder.disk import Disk

        disk = Disk(self, *args, **kwargs)
        self.disks.append(disk)
        return disk
Example #4
0
    def test_disk_size(self):
        # parse_size only deals with MB resolution
        K = 1024
        M = K*1024
        G = M*1024
        sizes = [('10G', 10*G),
                 ('400M', 400*M),
                 ('345', 345*M),
                 ('10240k', 10*M),
                 ('10250k', 10*M),
                 ('10230k', 9*M)]

        for (sizestr, size) in sizes:
            tmpfile = get_temp_filename()
            os.unlink(tmpfile)

            disk = Disk(MockHypervisor(), filename=tmpfile, size=sizestr)
            disk.create()
            actual_size = os.stat(tmpfile)[stat.ST_SIZE]
            self.assertEqual(size, actual_size, 'Asked for %s, expected %d, got %d' % (sizestr, size, actual_size))
            os.unlink(tmpfile)
Example #5
0
    def add_disk(self, *args, **kwargs):
        """Adds a disk image to the virtual machine"""
        from VMBuilder.disk import Disk, DiskPartition

        diskpartition = False
        if 'diskpartition' in kwargs:
            diskpartition = kwargs.diskpartition

        if not diskpartition:
            disk = Disk(self, *args, **kwargs)
        else:
            disk = DiskPartition(self, *args, **kwargs)

        self.disks.append(disk)
        return disk
Example #6
0
 def add_disk(self, *args, **kwargs):
     """Adds a disk image to the virtual machine"""
     disk = Disk(self, *args, **kwargs)
     self.disks.append(disk)
     return disk
Example #7
0
 def add_disk(self, *args, **kwargs):
     disk = Disk(self, *args, **kwargs)
     self.disks.append(disk)
     return disk