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)
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)
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)