Commits

M0E-lnx  committed a9e7557 Merge

Bring in updated tests

  • Participants
  • Parent commits 6c2c55e, c91453f

Comments (0)

Files changed (2)

File vinstall/backend/bootloader.py

     """Grub2 bootloader
 
     """
-    def __init__(self, target):
-        self.config_path = "/etc/default/grub"
+    def __init__(self, target, config_path = "/etc/default/grub"):
+        self.config_path = config_path
         self.type = GRUB2
         self.timeout = 3
         self.target = target
     def backup_config(self):
         pass
 
-    def write_config(self, config_path="/etc/default/grub"):
+    def write_config(self, output_file="/boot/grub/grub.cfg"):
         """The grub2 config file is automatically generated, so we use
         this method to save the values to /etc/default/grub which is
         parsed while the config file is generated
                  "# END OF /etc/default/grub",""]
 
         # save the new file
-        with open(config_path, "w") as f:
+        with open(self.config_path, "w") as f:
             f.writelines("\n".join(ndata))
 
         # after these are set, we just need to run grub-mkconfig
-        subprocess.check_call(["grub-mkconfig", "-o", "/boot/grub/grub.cfg"])
+        subprocess.check_call(["grub-mkconfig", "-o", output_file ])
 
     def install(self):
         """Install grub to the target
         subprocess.check_call(["grub-mkdevicemap", "--no-floppy"])
         subprocess.check_call(["grub-install", "--no-floppy", self.target])
 
-    def test_install(self, config_file, bootdev):
+    def test_install(self, bootdev):
         subprocess.check_call(["grub-mkdevicemap", "--no-floppy"])
         subprocess.check_call(["grub-install", "--no-floppy", bootdev])
 
     def test_lilo(self):
         import os
         if not os.path.exists('/bin/lilo'):
-            print "LiLO not found.  Skipping test"
-            return True
+            #return self.fail("Cannot test without Lilo")
+            return
         lilo = Lilo(self.path)
         for ops in OperatingSystem.all(include_running_os=True):
             lilo.add_os(ops)
         self.assertEqual(mbr.bootloader(), LILO)
 
 
-class Grub2TestCase(FakeDeviceTestCase):
-
+class Grub2TestCase(unittest.TestCase):
+    def setUp(self):
+        import subprocess as sp
+        self.lodev = "/dev/loop1"
+        self.img = "/tmp/vram.img"
+        self.defaults = '/tmp/grub2-defaults'
+        self.output_file = '/tmp/grub2-test'
+        sp.check_call(['dd','if=/dev/zero','of=%s'%self.img, 'bs=512', 'count=5120'])
+        sp.check_call(['losetup', self.lodev, self.img])
+        # create partition table (label)
+        sp.check_call(['parted', self.lodev, '-s', 'mklabel msdos'])
+        sp.check_call(['parted', self.lodev, '-s', 'mkpart primary ext2 1M 2M'])
+        
+    def tearDown(self):
+        import subprocess as sp
+        import os
+        sp.check_call(['losetup', '-d', self.lodev])
+        os.remove(self.img)
+        os.remove(self.defaults)
+        os.remove(self.output_file)
+        #os.remove('/tmp/grub2-grub-default')
+        
     def test_grub2(self):
-        return True
-        grub2 = Grub2(self.path)
-        grub2.write_config(config_path="/tmp/grub2-test")
-        grub2.test_install("/tmp/grub2-test", self.path)
-        mbr = MasterBootRecord(self.path)
+        grub2 = Grub2(self.lodev, config_path=self.defaults)
+        grub2.write_config(output_file= self.output_file)
+        grub2.test_install(bootdev=self.lodev)
+        mbr = MasterBootRecord(self.lodev)
         self.assertEqual(mbr.bootloader(), GRUB2)
 
 

File vinstall/backend/fstab.py

 
 
 import os
+import unittest
 
 
+    
 class FstabEntry(object):
     """ Object representing an entry in /etc/fstab
 
         """
         assert isinstance(entry, FstabEntry), "entry argument is of invalid type"
         assert hasattr(entry, 'mountpoint'), "Missing mountpoint attribute."
+        assert entry.device is not None, "No device specified"
+        assert entry.mountpoint is not None, "No mountpoint defined for this entry"
         sep = " "*5
         if entry.uuid is None:
             entry.uuid = entry.find_uuid()
             if item.device == device_path:
                 return True
         return False
+
+
+class FstabTests(unittest.TestCase):
+    def setUp(self):
+        self.fobject = Fstab(fstab_path = "/tmp/test-fstab")
+        self.fentry = FstabEntry(device = "/dev/sda1",
+            mountpoint = "/",
+            filesystem = "ext2")
+    
+    def test_makeEntry(self):
+        """Test the attributes on the entry"""
+        self.assertEqual(self.fentry.device, "/dev/sda1")
+        self.assertEqual(self.fentry.filesystem, "ext2")
+        self.assertEqual(self.fentry.mountpoint, "/")
+    
+    def test_add_invalid_entry(self):
+        self.assertRaises(AssertionError, self.fobject.add_entry, "/dev/sda1")
+    
+    def test_add_incomplete_entry(self):
+        self.fentry.mountpoint = None
+        self.fentry.device = None
+        self.assertRaises(AssertionError, self.fobject.add_entry, self.fentry)
+        self.assertRaises(AssertionError, self.fobject.add_entry, self.fentry)
+    
+    def test_add_valid_entry(self):
+        self.fobject.add_entry(self.fentry)
+        self.assertTrue(self.fobject.has_entry, "/dev/sda1")
+        rentry = self.fobject.get_entry("/dev/sda1")
+        
+        self.assertEqual(rentry.device, self.fentry.device)
+        self.assertEqual(rentry.filesystem, self.fentry.filesystem)
+        self.assertEqual(rentry.mountpoint, self.fentry.mountpoint)
+    
+
+if __name__ == "__main__":
+    unittest.main()