Commits

M0E-lnx  committed fe4b5e5

add formatting support for xfs,jfs on utils.py. Fix tests on bootloader to automatically find the next avaible loop device

  • Participants
  • Parent commits a9e7557

Comments (0)

Files changed (2)

File vinstall/backend/bootloader.py

 class Grub2TestCase(unittest.TestCase):
     def setUp(self):
         import subprocess as sp
-        self.lodev = "/dev/loop1"
+        # get the next unused loop device
+        nextlodev = sp.check_output(['losetup','-f'])
+        self.lodev = nextlodev.strip()
         self.img = "/tmp/vram.img"
         self.defaults = '/tmp/grub2-defaults'
         self.output_file = '/tmp/grub2-test'

File vinstall/backend/utils.py

 import os
 import subprocess
 import re
+import unittest
+import tempfile
 
 
 def get_mem_size():
     """Create a filesystem in a partition using mkfs.
 
     """
+    assert filesystem in supported_filesystems(), 'Unsupported filesystem'
+    FSFLAGS = {'reiserfs':'-q -f -f',
+        'jfs':'-q',
+        'xfs':'-q',
+        'ext2':'-F',
+        'ext4':'-F',
+        'ext3':'-F',
+        }
     if 'swap' in filesystem:
         command = 'mkswap %s'% path
-    elif 'reiser' in filesystem:
-        command = 'mkfs.%s -f -f %s' % (filesystem, path)
     else:
-        command = 'mkfs.%s -F %s' % (filesystem, path)
+        command = 'mkfs -t %s %s %s'% (filesystem, FSFLAGS[filesystem], path)
     subprocess.call(command.split())
 
 
     return mountpoint
 
 
-
 def umount(mounted):
     """Unmount a filesystem.
 
         os.chdir(self.old_cwd)
 
 
+class FakeDeviceTestCase(unittest.TestCase):
+
+    def setUp(self):
+        (fd, self.path) = tempfile.mkstemp(prefix="fake-device-")
+        f = os.fdopen(fd)
+        f.seek(36000000)
+        os.write(fd, "0")
+        self.img = self.path
+
+    def tearDown(self):
+        os.unlink(self.path)
+
+class FormattingTests(FakeDeviceTestCase):
+
+    def test_ext2(self):
+        format_partition(self.img, 'ext2')
+        # Read the partitioning
+        rformat = subprocess.check_output(['file', self.img])
+        self.assertEqual(rformat.strip().split()[4], 'ext2')
+    
+    def test_ext3(self):
+        format_partition(self.img, 'ext3')
+        rformat = subprocess.check_output(['file', self.img])
+        print rformat
+        self.assertEqual(rformat.strip().split()[4], 'ext3')
+    
+    def test_ext4(self):
+        format_partition(self.img, 'ext4')
+        rformat = subprocess.check_output(['file', self.img])
+        self.assertEqual(rformat.strip().split()[4], 'ext4')
+    
+    def test_xfs(self):
+        format_partition(self.img, 'xfs')
+        rformat = subprocess.check_output(['file', self.img])
+        self.assertEqual(rformat.strip().split()[2], 'XFS')
+    
+    def test_jfs(self):
+        format_partition(self.img, 'jfs')
+        rformat = subprocess.check_output(['file', self.img])
+        self.assertEqual(rformat.strip().split()[1], 'JFS2')
+    
+    def test_reiserfs(self):
+        format_partition(self.img, 'reiserfs')
+        rformat = subprocess.check_output(['file', self.img])
+        self.assertEqual(rformat.strip().split()[1], 'ReiserFS')
+    
+    def test_format_with_unsupported_fs(self):
+        self.assertRaises(AssertionError, format_partition,
+            self.img, 'foofs')
+
+            
+
+if __name__ == "__main__":
+    unittest.main()