Anonymous avatar Anonymous committed 36ac0b6

Debugging bootloaders modules

Comments (0)

Files changed (7)

modules/bootloaders.py

             methods.append(self.blobject.install)
         
         # execute the methods
-        for f in methods:
+        for f in methods:                
             logger.debug("Executing %s"% f)
-            ret = f()
-            if ret > 0:
+            try:
+                f()
+            except AssertionError, e:
                 self._errors = True
+                self.flag.set()
+                logger.fatal("%s"%e)
             time.sleep(1)
     
     def pulse_pb(self):
         lb = WideLabel("<b>%s</b>"%_("Bootloader:"))
         
         choicesbox.pack_start(lb, False, False, 4)
-        active = BOOTLOADERS.get_active_bootloader()
+        active = BOOTLOADERS.get_active_bootloader() or BOOTLOADERS.DEFAULT_BOOTLOADER
         self.bootloader = active.lower()
         self._lilorb = gtk.RadioButton(label="LILO")
         self._grubrb = gtk.RadioButton(group=self._lilorb,
         lb = WideLabel("<b>%s</b>"% _("Video Resolution"))
         vgabox.pack_start(lb, False, False, 4)
         vgabox.pack_start(self.vgaselector, False, False, 4)
-        #        lb = WideLabel("<b>%s</b>"% _("Video Quality"))
-        # create radiobuttons
-        #        store = gtk.ListStore(str)
-        #        store.append(["low"])
-        #        store.append(["med"])
-        #        store.append(["high"])
-        #        cr = gtk.CellRendererText()
-        #        self.vidqualityselector = gtk.ComboBox(store)
-        #        self.vidqualityselector.pack_start(cr, True)
-        #        self.vidqualityselector.add_attribute(cr, 'text', 0)
-        #        self.vidqualityselector.set_active(1)
-        #        self.vidqualityselector.connect("changed", self.vgaquality_toggle)
-        #        vgabox.pack_start(lb, False, False, 4)
-        #        vgabox.pack_start(self.vidqualityselector, False, False, 2)
         self.pack_start(vgabox, False, True, 4)
         
         # action to perform
             target = self.target,
             timeout = self.timeout,
             vga_size = self.vga_size,
-            vga_quality = self.vga_quality or self.vidqualityselector.get_active_text())
+            vga_quality = self.vga_quality or self.vidqualityselector.get_active_text(),
+            include_running_os=True)
         # Pop a progress
         progress = BootloaderInstallProgress(self._parent,loader, self.todo)
         logger.debug("Saving changes to LiLO setup.")
         """ Remove the unfitter video modes for the different bootloaders """
         model = self.vgaselector.get_model()
         model.clear()
-        if grub2 is True:
-            for mode in ("800x600", "1024x768", "1280x1024"):
-                model.append([mode])
-            self.vgaselector.set_active(0)
-            return
-        for mode in ("640x480", "800x600", "1024x768"):
+        for mode in ("640x480","800x600","1024x768","1280x1024"):
             model.append([mode])
         self.vgaselector.set_active(1)
         return
             self.bootloader = radiobutton.get_label().lower()
         if self.bootloader.lower() == "lilo":
             self.populate_video_modes(False)
-            self.display_valid_video_quality_values(False)
             # connect the correct method for the apply button
             self.apply_button.disconnect(self._apply_id)
             self._apply_id = self.apply_button.connect('clicked',
                 self.apply_lilo_event)
             return self.populate_targets(self.targetselector, True)
         self.populate_video_modes(True)
-        self.display_valid_video_quality_values(True)
         # connect the grub2 apply event to the apply button
         self.apply_button.disconnect(self._apply_id)
         self._apply_id = self.apply_button.connect('clicked',

modules/pyfstab.py

         self.target = ""
         self.options = ""
         self.fstabmodel = fstabmodel
-        
+        self.entryobject = None
         self.fslabel = gtk.Label()
         self.fslabel.set_property('width-chars', 12)
         self.fslabel.set_property('xalign', 0.0)
         targetlabel.set_use_markup(True)
         targetlabel.set_label("<b>%s</b>"% _("Mount point"))
         self.targetbox = gtk.Entry()
+        self.targetbox.connect('changed', self.targetbox_change_event)
         self.btSelectTarget = widgets.MyStockButton("Select",gtk.STOCK_OPEN)
         intbox2.pack_start(targetlabel, False, False, 4)
         intbox2.pack_start(self.targetbox, True, True, 2)
         intbox3.pack_start(self.optionsbox, True, True, 2)
         self.btSelectTarget.connect("clicked", self.select_target_event)
         cbPartSel.connect('changed', self.combobox_change_event)
+        intbox4 = gtk.HBox()
+        mountcb = gtk.CheckButton(_("Mount partition immediately"))
+        mountcb.connect('toggled', self.mountcb_toggle_event)
+        mountcb.set_active(True)
+        intbox4.pack_start(mountcb, False, True, 4)
         
         self.body.pack_start(intbox0, False, True, 12)
         #self.body.pack_start(intbox1, False, True, 2)
         self.body.pack_start(intbox2, False, True, 2)
         self.body.pack_start(intbox3, False, True, 2)
+        self.body.pack_start(intbox4, False, True, 2)
         
         # Load all partitions to the combobox.
         self.load_available_partitions(cbPartSel)
         
         self.set_size_request(450, 300)
         self.body.show_all()
+
+    def mountcb_toggle_event(self, widget=None):
+        if not self.entryobject:
+            return
+        self.entryobject._mount_now = widget.get_active()
+        print widget.get_active()
+
+    def targetbox_change_event(self, widget=None):
+        self.entryobject.mountpoint = widget.get_text()
+        return
     
     def load_available_partitions(self, widget):
         """ Add the available partitions to widget.  Widget is a combobox"""
             self.targetbox.set_property("sensitive", False)
             self.btSelectTarget.set_property("sensitive", False)
         else:
-            self.targetbox.set_text("")
             self.targetbox.set_property("sensitive", True)
             self.btSelectTarget.set_property("sensitive", True)
+            defmpoint = self.entryobject.device.replace('/dev/','/mnt/')
+            self.targetbox.set_text(defmpoint)
     
     def do_add_entry(self):
         """ Add an entry to fstab.  This method needs to check to make sure
         # Create the mountpoint if it does not exist
         if not os.path.exists(self.entryobject.mountpoint):
             os.makedirs(self.entryobject.mountpoint)
+        # Mount the partition if the user so chose to
+        if self.entryobject._mount_now:
+            self.entryobject.mount()
         return
+
+    
+    

modules/support/vectorlinux/BOOTLOADERS.py

             tuientry.initrd = '/boot/initrd'
         own.root = get_current_bootsector()
         tuientry.root = get_current_bootsector()
-        own.appendline = 'root=%s splash=silent'%own.root
-        tuientry.appendline = '2 root=% splash=silent'% tuientry.root
+        own.appendline = 'splash=silent'
+        tuientry.appendline = '2 splash=silent'
         ret.append(own)
         ret.append(tuientry)
     # since we only need this for lilo, we only need to read the short description
                     ret.append("%s initrd = %s"% (spacer, entry.initrd))
                 if entry.appendline not in ("", None):
                     if "splash" not in entry.appendline:
-                        ret.append("%s append = \"%s aplash=silent\""% (spacer, entry.appendline))
+                        ret.append("%s append = \"%s splash=silent\""% (spacer, entry.appendline))
                     else:
                         ret.append("%s append = \"%s\""% (spacer, entry.appendline))
                 ret.append("%s read-only"% spacer)
         fname = "%s_%s"% (kname, host)
         newpath = os.path.join("/boot", "tamu", fname)
         if os.path.exists(newpath):
-            return newpath
+            return newpath            
         try:
-            logger.debug("Copying %s to %s"% (oldpath, newpath))
             shutil.copy2(oldpath, newpath)
+            logger.debug("copied %s to %s "% (oldpath, newpath))
             return newpath
         except:
-            logger.fatal("Unable to copy %s to %s"% (oldpath, newpath))
+            logger.warning("Unable to find initrd for %s on %s"% (kname, root))
             return None
 
+    def _check_if_premounted(self, partition, premountlist):
+        """ Check if partition was part of the partitions that were
+        originally mounted (specified in premountlist)"""
+        for p in premountlist:
+            if p.device == partition:
+                return True
+        return False
+
     def prepare_os_list(self, object_list):
         """ Copy kernels and initrd's from other Os's /boot to lilos /boot/tamu """
+        # before we do anything, take a snapshot of the system to see
+        # which partitions are now mounted
+        mountlist = utils.get_mounted_list()
         try:
             os.makedirs("/boot/tamu")
         except:
                 kpath = os.path.join("/boot", "tamu", kname)
                 if not os.path.exists(kpath):
                     # mount the partition
-                    mount, pre_mounted = utils.mount(entry.root, mpoint)
+                    mount = utils.mount(entry.root, mpoint)
                     # copy the kernel now
                     entry.kernel = self._copy_kernel(entry.root, mpoint, kname)
                     
                     # if the kernel was not there, the initrd is most likely not either.
                     if has_initrd:
                         entry.initrd = self._copy_kernel(entry.root, mpoint, rdname)
-                    # umount if necesssary                    
-                    if pre_mounted is False:
-                        res = utils.umount(mount)
+                    # umount if necesssary
+                    if not self._check_if_premounted(entry.root, mountlist):
+                        utils.umount(mpoint)
         return self.config.getOsListing(object_list)
 
     def install(self):

modules/support/vectorlinux/FSTAB.py

 
 import parted
 import os
+import utils
 
 def list_all_system_partitions():
     """ return a list of all partition paths"""
         self.mountpoint = None
         self.filesystem = None
         self.options = None
+        self._mount_now = True
 
     def find_default_options(self):
         """ Returns the default fstab options for the partitions filesystem """
                 lname = os.readlink(os.path.join(uuiddir, uid))
                 return os.path.join("/dev/", lname.split("/")[-1])
         return None
+
+    def _activate_swap(self):
+        """ Activate a swap partition after it has been added """
+        return utils.activate_swap(self.device)
+
+    def mount(self):
+        """ Mount this entry to its mountpoint """
+        assert self.device not in ("",None), "No partition has been specified.  Cannot mount"
+        assert self.mountpoint not in ("",None), "No mountpoint has been specified for this partition."
+        assert self.options not in ("",None), "No mounting options specified"
+        assert self.filesyxstem not in ("",None), "No filesystem specified"
+        if "swap" in self.filesystem:
+            return self._activate_swap()
+        return utils.mount(self.device, self.mountpoint)
         
     def find_filesystem(self):
         """ Find the partition's filesystem as reported by parted """

modules/support/vectorlinux/utils.py

     
 logger = logging.getLogger('vasm')
 
+def get_mounted_list():
+    """ Return a list of the currently mounted partitions
+    The list consists of objects with a .device, .mountpoint, and .filesystem attributes
+
+    """
+    return psutil.disk_partitions()
+    
+
 def mount(partition, mntpoint):
-    """ Mount the specified partition on mntpoint 
-        returns (mointpoint, pre_mounted)
+    """ Mount the specified partition on mntpoint
+    raises AssertionError when it fails.  Returns the
+    mountpoint when successfull.
     """
     mpoint = get_mountpoint(partition)
-    if mpoint is not None:
-        print "%s is already mounted on %s"% (partition, mpoint)
-        return (mpoint, True)
     if not os.path.isdir(mntpoint):
-        try:
-            os.makedirs(mntpoint)
-        except:
-            pass
+        os.makedirs(mntpoint)
     cmd = ["mount", partition, mntpoint]
     proc = get_popen(cmd)
-    proc.communicate()
+    out, error = proc.communicate()
+    rcode = proc.returncode
+    assert rcode == 0, "Error while mounting partition: %s"% error
+    mpoint = get_mountpoint(partition)
+    assert mpoint  is not None, "Unable to mount partition"
+    return mpoint
+
+def activate_swap(partition):
+    """ Activates swap space on partition for immediate use """
+    proc = get_popen(['swapon',partition])
+    out, err = proc.communicate()
+    rcode = proc.returncode
+    assert rcode == 0, "Unable to activate swap space on %s"% partition
+    return
     
-    # return the mountpoint
-    mpoint = get_mountpoint(partition)
-    if mpoint == mntpoint:
-        return (mpoint, False)
-    return (None, True) # something went wrong, and our partition did not mount
-                # where it should have
 
 def umount(mntpoint):
     """ unmount the partition mounted in mntpoint 
-        Returns 0 when successful, 1 when fails.
+        Raises an assertion error when it fails.
     """
     partition = get_mounted(mntpoint)
     if partition is None:
         return 0
     cmd = ["umount","-f",mntpoint]
     proc = get_popen(cmd)
-    proc.communicate()
+    out, err = proc.communicate()
+    rcode = proc.returncode
+    assert rcode == 0, "Unable to un-mount partition %s."% err
     
-    # make sure it unmounted.
-    res = get_mounted(mntpoint)
-    # this should be None now.
-    if res is None:
-        return 0
-    return 1
 
 def get_mounted(mntpoint):
     """ return the path to the partition currently mounted in mntpoint or None"""

modules/tui/tui_bootloaders.py

 from modules.tuisupport import dialogs
 from modules.tuisupport import widgets
 from modules.tuisupport.tui_utils import _
+import logging
 
+logger = logging.getLogger('vasm')
 class BootloaderTui(dialogs.ModuleDialog):
     def __init__(self, parent):
         self.parent = parent
             try:
                 method()
             except AssertionError, e:
+                logger.fatal("%s"% e)
                 dia = dialogs.Error(
                     parent = self,
                     message = ''.join((
                 self.pop_dialog(dia)
                 return self.resume_ui()
             time.sleep(1)
+        logger.info('%s updated'% sloader)
         dia = dialogs.Info(
             parent = self,
             message = ''.join((

modules/tuisupport/widgets.py

 
     def set_value(self, value):
 	return self.selector.set_text(value)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.