Example #1
0
 def _bootstrap_with_tarball(self, suite):
     self.check_target_exists()
     suite_path = path(self.defenv.get('installer', 'suite_storage'))
     filename = '%s.tar.gz' % suite
     basefile = suite_path / filename
     taropts = '-xzf'
     # we normally expect a tar.gz
     # but we'll check for a plain tar also
     if not basefile.exists():
         filename = '%s.tar' % suite
         basefile = suite_path / filename
         taropts = '-xf'
     if not basefile.exists():
         # We don't really want to ruin an install
         # by not having a tarball, so we log a warning
         # and proceed with a debootstrap.
         msg = "base tarball not found, reverting to debootstrap"
         self.log.warn(msg)
         self._bootstrap_with_debootstrap(suite)
     else:
         #cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile)
         cmd = ['tar', '-C', str(self.target), taropts, str(basefile)]
         # if cmd returns nonzero, runlog will raise an error
         runlog(cmd)
         # we need to do certain things after extraction
         # that debootstrap does for us,
         # like copy /etc/resolv.conf to the target.
         # these things should be done in the
         # ready_base_for_install process
         self._bootstrapped = True
Example #2
0
 def install_grub_package(self, grub="grub"):
     # cmd = self.chroot_precommand + self.aptinstall + [grub]
     apt_command = install_packages_command(
         [grub], self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag="paella-bootloader"
     )
     cmd = self.chroot_precommand + apt_command
     runlog(cmd)
Example #3
0
 def _determine_disks_for_grub(self, bootdevice):
     if not bootdevice.startswith('/dev/md'):
         msg = "This method is only to be used when the "
         msg += "boot device is set to /dev/md*"
         self.log.error(msg)
         raise RuntimeError, msg
     device_map = self.target / 'boot/grub/device.map'
     if not device_map.isfile():
         #raise RuntimeError , 'We need the device.map from grub'
         cmd = self.chroot_precommand + ['grub-mkdevicemap', '-n']
         runlog(cmd)
         self.log.info('device.map should be created now.')
         if not device_map.isfile():
             msg = 'Failed to make device.map'
             self.log.error(msg)
             raise RuntimeError, msg
     else:
         self.log.info('device.map has been found')
     lines = [line for line in file(device_map) if line.startswith('(hd0)')]
     if len(lines) != 1:
         msg = "Unable to find (hd0) in device.map"
         self.log.error(msg)
         raise RuntimeError, msg
     line = lines[0]
     grubdev, bootdevice = line.split()
     self.log.info('going to use %s as the boot device for grub' %
                   bootdevice)
     return bootdevice
Example #4
0
 def mount_target(self):
     print "in mount_target"
     fstab_filename = self.disklogpath / "fstab"
     if not fstab_filename.isfile():
         msg = "couldn't find fstab at %s" % fstab_filename
         self.log.error(msg)
         raise RuntimeError, msg
     fstab_lines = [line.split() for line in fstab_filename.open() if not line.startswith("#")]
     # print fstab_lines
     # start mounting
     for line in fstab_lines:
         # print line
         device = line[0]
         mtpt = line[1]
         fstype = line[2]
         # print 'device, mtpt, fstype', device, mtpt, fstype
         if mtpt.startswith("/"):
             target_path = self.target / mtpt[1:]
             if not target_path.isdir():
                 target_path.mkdir()
             # in case we're mounting /tmp as tmpfs
             # or similar
             if fstype not in ["tmpfs"]:
                 cmd = ["mount", "-t", fstype, device, target_path]
                 # print ' '.join(cmd)
                 runlog(cmd)
             else:
                 self.log.info("not mounting %s with %s fstype" % (mtpt, fstype))
Example #5
0
 def mount_target(self):
     print "in mount_target"
     fstab_filename = self.disklogpath / 'fstab'
     if not fstab_filename.isfile():
         msg = "couldn't find fstab at %s" % fstab_filename
         self.log.error(msg)
         raise RuntimeError, msg
     fstab_lines = [
         line.split() for line in fstab_filename.open()
         if not line.startswith('#')
     ]
     #print fstab_lines
     # start mounting
     for line in fstab_lines:
         #print line
         device = line[0]
         mtpt = line[1]
         fstype = line[2]
         #print 'device, mtpt, fstype', device, mtpt, fstype
         if mtpt.startswith('/'):
             target_path = self.target / mtpt[1:]
             if not target_path.isdir():
                 target_path.mkdir()
             # in case we're mounting /tmp as tmpfs
             # or similar
             if fstype not in ['tmpfs']:
                 cmd = ['mount', '-t', fstype, device, target_path]
                 #print ' '.join(cmd)
                 runlog(cmd)
             else:
                 self.log.info('not mounting %s with %s fstype' %
                               (mtpt, fstype))
Example #6
0
 def install_packages_for_extra_modules(self, modules):
     """Install the packages required to handle these modules."""
     #cmd = self.chroot_precommand + self.aptinstall
     packages = []
     for module in modules:
         if module == 'dm-mod':
             append_unique('lvm2', packages)
             append_unique('dmsetup', packages)
         if module.startswith('raid'):
             append_unique('mdadm', packages)
     #cmd += packages
     if packages:
         msg = "Installing these extra packages: %s" % ', '.join(packages)
         self.log.info(msg)
         apt_command = install_packages_command(
             packages,
             self.defenv,
             loginfo=self.log.info,
             logerror=self.log.error,
             usertag='paella-kernel-extras')
         cmd = self.chroot_precommand + apt_command
         runlog(cmd)
     else:
         msg = 'No extra packages required for the kernel'
         self.log.info(msg)
Example #7
0
 def install_kernel_package(self):
     self.log.info('called install_kernel_package')
     kernel = self.machine.current.kernel
     cmd = self.chroot_precommand + self.aptinstall + [kernel]
     self.log.info('install cmd is: %s' % ' '.join(cmd))
     kimgconf = self.target / 'etc' / 'kernel-img.conf'
     kimgconf_old = path('%s.paella-orig' % kimgconf)
     kimgconflines = ['do_bootloader = No',
                      'do_initrd = Yes',
                      'warn_initrd = No'
                      ]
     if kimgconf.exists():
         self.log.info('/etc/kernel-img.conf already exists')
         k = '/etc/kernel-img.conf'
         msg ='renaming %s to %s.paella-orig' % (k, k)
         self.log.info(msg)
         if kimgconf_old.exists():
             raise RuntimeError, '%s already exists, aborting install.' % kimgconf_old
         os.rename(kimgconf, kimgconf_old)
     kimgconf.write_lines(kimgconflines)
     runlog(cmd)
     self.log.info('Kernel installation is complete.')
     if kimgconf_old.exists():
         self.log.info('Restoring /etc/kernel-img.conf')
         os.remove(kimgconf)
         os.rename(kimgconf_old, kimgconf)
Example #8
0
 def _bootstrap_with_tarball(self, suite):
     self.check_target_exists()
     suite_path = path(self.defenv.get('installer', 'suite_storage'))
     arch = get_architecture()
     filename = '%s-%s.tar.gz' % (suite, arch)
     basefile = suite_path / filename
     taropts = '-xzf'
     # we normally expect a tar.gz
     # but we'll check for a plain tar also
     if not basefile.exists():
         filename = '%s-%s.tar' % (suite, arch)
         basefile = suite_path / filename
         taropts = '-xf'
     if not basefile.exists():
         # We don't really want to ruin an install
         # by not having a tarball, so we log a warning
         # and proceed with a debootstrap.
         msg = "base tarball not found, reverting to debootstrap"
         self.log.warn(msg)
         self._bootstrap_with_debootstrap(suite)
     else:
         #cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile)
         cmd = ['tar', '-C', str(self.target), taropts, str(basefile)]
         # if cmd returns nonzero, runlog will raise an error
         runlog(cmd)
Example #9
0
 def _bootstrap_with_debootstrap(self, suite):
     self.check_target_exists()
     mirror = self.defenv.get('installer', 'http_mirror')
     # debug stuff
     cmd = debootstrap(suite, self.target, mirror)
     # if cmd returns nonzero, runlog will raise an error
     runlog(cmd)
 def install_kernel_package(self):
     self.log.info('called install_kernel_package')
     extra_modules = self.determine_extra_modules_from_diskconfig()
     if extra_modules:
         self.log.info('Checking if extra packages are required before kernel install.')
         self.install_packages_for_extra_modules(extra_modules)
     kernel = self.machine.get_kernel()
     cmd = self.chroot_precommand + self.aptinstall + [kernel]
     self.log.info('install cmd is: %s' % ' '.join(cmd))
     kimgconf = self.target / 'etc' / 'kernel-img.conf'
     kimgconf_old = path('%s.paella-orig' % kimgconf)
     kimgconflines = ['do_bootloader = No',
                      'do_initrd = Yes',
                      'warn_initrd = No'
                      ]
     if kimgconf.exists():
         self.log.info('/etc/kernel-img.conf already exists')
         k = '/etc/kernel-img.conf'
         msg ='renaming %s to %s.paella-orig' % (k, k)
         self.log.info(msg)
         if kimgconf_old.exists():
             raise RuntimeError , '%s already exists, aborting install.' % kimgconf_old
         os.rename(kimgconf, kimgconf_old)
     kimgconf.write_lines(kimgconflines)
     runlog(cmd)
     self.log.info('Kernel installation is complete.')
     if kimgconf_old.exists():
         self.log.info('Restoring /etc/kernel-img.conf')
         os.remove(kimgconf)
         os.rename(kimgconf_old, kimgconf)
Example #11
0
 def _bootstrap_with_tarball(self, suite):
     self.check_target_exists()
     suite_path = path(self.defenv.get('installer', 'suite_storage'))
     filename = '%s.tar.gz' % suite
     basefile = suite_path / filename
     taropts = '-xzf'
     # we normally expect a tar.gz
     # but we'll check for a plain tar also
     if not basefile.exists():
         filename = '%s.tar' % suite
         basefile = suite_path / filename
         taropts = '-xf'
     if not basefile.exists():
         # We don't really want to ruin an install
         # by not having a tarball, so we log a warning
         # and proceed with a debootstrap.
         msg = "base tarball not found, reverting to debootstrap"
         self.log.warn(msg)
         self._bootstrap_with_debootstrap(suite)
     else:
         #cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile)
         cmd = ['tar', '-C', str(self.target), taropts, str(basefile)]
         # if cmd returns nonzero, runlog will raise an error
         runlog(cmd)
         # we need to do certain things after extraction
         # that debootstrap does for us,
         # like copy /etc/resolv.conf to the target.
         # these things should be done in the
         # ready_base_for_install process
         self._bootstrapped = True
Example #12
0
 def _determine_disks_for_grub(self, bootdevice):
     if not bootdevice.startswith("/dev/md"):
         msg = "This method is only to be used when the "
         msg += "boot device is set to /dev/md*"
         self.log.error(msg)
         raise RuntimeError, msg
     device_map = self.target / "boot/grub/device.map"
     if not device_map.isfile():
         # raise RuntimeError , 'We need the device.map from grub'
         cmd = self.chroot_precommand + ["grub-mkdevicemap", "-n"]
         runlog(cmd)
         self.log.info("device.map should be created now.")
         if not device_map.isfile():
             msg = "Failed to make device.map"
             self.log.error(msg)
             raise RuntimeError, msg
     else:
         self.log.info("device.map has been found")
     lines = [line for line in file(device_map) if line.startswith("(hd0)")]
     if len(lines) != 1:
         msg = "Unable to find (hd0) in device.map"
         self.log.error(msg)
         raise RuntimeError, msg
     line = lines[0]
     grubdev, bootdevice = line.split()
     self.log.info("going to use %s as the boot device for grub" % bootdevice)
     return bootdevice
 def update_initrd_with_extra_modules(self, modules):
     self.add_extra_modules_to_initrd(extra_modules)
     msg = 'adding these extra modules to initrd: %s' % ', '.join(extra_modules)
     self.log.info(msg)
     cmd = self.chroot_precommand + ['update-initramfs', '-u']
     if 'DEBUG' in os.environ:
         cmd.append('-v')
     runlog(cmd)
 def install_grub(self, device="/dev/hda", floppy=False):
     if not device.startswith("/dev"):
         device = "/dev/%s" % device
     opts = ["--recheck"]
     if not floppy:
         opts.append("--no-floppy")
     bin = "/usr/sbin/grub-install"
     runlog(self.chroot_precommand + [bin] + opts + [device])
Example #15
0
 def run_process_script(self, procname, script):
     if procname == 'chroot':
         retval = runlog(script)
     else:
         retval = runlog([script])
     if retval:
         msg = "script for process %s exited with error code %d" % (procname, retval)
         raise RunLogError, msg
Example #16
0
 def install_grub(self, device='/dev/hda', floppy=False):
     if not device.startswith('/dev'):
         device = '/dev/%s' % device
     opts = ['--recheck']
     if not floppy:
         opts.append('--no-floppy')
     bin = '/usr/sbin/grub-install'
     runlog(self.chroot_precommand + [bin] + opts + [device])
Example #17
0
 def update_initrd_with_extra_modules(self, modules):
     self.add_extra_modules_to_initrd(extra_modules)
     msg = "adding these extra modules to initrd: %s" % ", ".join(extra_modules)
     self.log.info(msg)
     cmd = self.chroot_precommand + ["update-initramfs", "-u"]
     if "DEBUG" in os.environ:
         cmd.append("-v")
     runlog(cmd)
Example #18
0
 def install_grub_package(self, grub='grub'):
     #cmd = self.chroot_precommand + self.aptinstall + [grub]
     apt_command = install_packages_command([grub],
                                            self.defenv,
                                            loginfo=self.log.info,
                                            logerror=self.log.error,
                                            usertag='paella-bootloader')
     cmd = self.chroot_precommand + apt_command
     runlog(cmd)
Example #19
0
 def update_initrd_with_extra_modules(self, modules):
     self.add_extra_modules_to_initrd(extra_modules)
     msg = 'adding these extra modules to initrd: %s' % ', '.join(
         extra_modules)
     self.log.info(msg)
     cmd = self.chroot_precommand + ['update-initramfs', '-u']
     if 'DEBUG' in os.environ:
         cmd.append('-v')
     runlog(cmd)
Example #20
0
 def make_device_entries(self):
     "this is a default process"
     if self.defenv.is_it_true('installer', 'use_devices_tarball'):
         runlog('echo extracting devices tarball')
         self._extract_devices_tarball()
     else:
         runlog('echo using MAKEDEV to make generic devices')
         self.make_generic_devices()
     self.make_disk_devices()
Example #21
0
 def make_device_entries(self):
     "this is a default process"
     if self.defenv.is_it_true('installer', 'use_devices_tarball'):
         runlog('echo extracting devices tarball')
         self._extract_devices_tarball()
     else:
         runlog('echo using MAKEDEV to make generic devices')
         self.make_generic_devices()
     self.make_disk_devices()
Example #22
0
 def run_process_script(self, procname, script):
     if procname == 'chroot':
         retval = runlog(script)
     else:
         retval = runlog([script])
     if retval:
         msg = "script for process %s exited with error code %d" % (
             procname, retval)
         raise RunLogError, msg
Example #23
0
 def _mount_target_virtfs(self, fs):
     fstype = dict(proc='proc', sys='sysfs', devpts='devpts')
     target = self.target / fs
     if fs == 'devpts':
         target = self.target / 'dev' / 'pts'
     if not target.isdir():
         target.mkdir()
     #cmd = 'mount -t %s none %s' % (fstype[fs], target)
     cmd = ['mount', '-t', fstype[fs], 'none', str(target)]
     runlog(cmd)
Example #24
0
 def _mount_target_virtfs(self, fs):
     fstype = dict(proc='proc', sys='sysfs', devpts='devpts')
     target = self.target / fs
     if fs == 'devpts':
         target = self.target / 'dev' / 'pts'
     if not target.isdir():
         target.mkdir()
     #cmd = 'mount -t %s none %s' % (fstype[fs], target)
     cmd = ['mount', '-t', fstype[fs], 'none', str(target)]
     runlog(cmd)
Example #25
0
    def install_grub(self, device='/dev/hda', floppy=False):
        if not device.startswith('/dev'):
            device = '/dev/%s' % device
        opts = ['--recheck']
        if not floppy:
            opts.append('--no-floppy')
        if device.startswith('/dev/md'):
            self.log.warn('The boot device appears to be a raid array.')
            self.log.info('Trying to determine the mbr for installing grub')
            device = self._determine_disks_for_grub(device)

        bin = '/usr/sbin/grub-install'
        runlog(self.chroot_precommand + [bin] + opts + [device])
Example #26
0
    def install_grub(self, device="/dev/hda", floppy=False):
        if not device.startswith("/dev"):
            device = "/dev/%s" % device
        opts = ["--recheck"]
        if not floppy:
            opts.append("--no-floppy")
        if device.startswith("/dev/md"):
            self.log.warn("The boot device appears to be a raid array.")
            self.log.info("Trying to determine the mbr for installing grub")
            device = self._determine_disks_for_grub(device)

        bin = "/usr/sbin/grub-install"
        runlog(self.chroot_precommand + [bin] + opts + [device])
 def install_grub(self, device='/dev/hda', floppy=False):
     if not device.startswith('/dev'):
         device = '/dev/%s' % device
     opts = ['--recheck']
     if not floppy:
         opts.append('--no-floppy')
     if device.startswith('/dev/md'):
         self.log.warn('The boot device appears to be a raid array.')
         self.log.info('Trying to determine the mbr for installing grub')
         device = self._determine_disks_for_grub(device)
         
     bin = '/usr/sbin/grub-install'
     runlog(self.chroot_precommand + [bin] + opts + [device])
Example #28
0
 def install_packages_for_extra_modules(self, modules):
     """Install the packages required to handle these modules."""
     cmd = self.chroot_precommand + self.aptinstall
     packages = []
     for module in modules:
         if module == 'dm-mod':
             append_unique('lvm2', packages)
             append_unique('dmsetup', packages)
         if module.startswith('raid'):
             append_unique('mdadm', packages)
     msg = "Installing these extra packages: %s" % ', '.join(packages)
     self.log.info(msg)
     cmd += packages
     runlog(cmd)
 def install_packages_for_extra_modules(self, modules):
     """Install the packages required to handle these modules."""
     cmd = self.chroot_precommand + self.aptinstall
     packages = []
     for module in modules:
         if module == 'dm-mod':
             append_unique('lvm2', packages)
             append_unique('dmsetup', packages)
         if module.startswith('raid'):
             append_unique('mdadm', packages)
     msg = "Installing these extra packages: %s" % ', '.join(packages)
     self.log.info(msg)
     cmd += packages
     runlog(cmd)
Example #30
0
 def _bootstrap_with_tarball(self, suite):
     suite_path = path(self.defenv.get('installer', 'suite_storage'))
     filename = '%s.tar.gz' % suite
     basefile = suite_path / filename
     taropts = '-xzf'
     if not basefile.exists():
         filename = '%s.tar' % suite
         basefile = suite_path / filename
         taropts = '-xf'
     cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile)
     # if cmd returns nonzero, runlog will raise an error
     runlog(cmd)
     # we need to do certain things here that debootstrap
     # does for us, like copy /etc/resolv.conf
     self._bootstrapped = True
Example #31
0
 def _bootstrap_with_tarball(self, suite):
     suite_path = path(self.defenv.get('installer', 'suite_storage'))
     filename = '%s.tar.gz' % suite
     basefile = suite_path / filename
     taropts = '-xzf'
     if not basefile.exists():
         filename = '%s.tar' % suite
         basefile = suite_path / filename
         taropts = '-xf'
     cmd = 'tar -C %s %s %s' % (self.target, taropts, basefile)
     # if cmd returns nonzero, runlog will raise an error
     runlog(cmd)
     # we need to do certain things here that debootstrap
     # does for us, like copy /etc/resolv.conf
     self._bootstrapped = True
Example #32
0
 def chroot(self, command, failure_suppressed=False):
     # we need to remove this if/else when we're sure
     # we don't need it anymore
     if type(command) is list:
         cmd = ["chroot", str(self.target)] + command
     else:
         cmd = "chroot %s %s" % (self.target, command)
     return runlog(cmd, failure_suppressed=failure_suppressed)
Example #33
0
 def _umount_target_virtfs(self, fs):
     # work around binfmt-support /proc locking
     # found this idea while messing around in live-helper
     target = self.target / fs
     if fs == 'proc':
         binfmt_misc = self.target / 'proc/sys/fs/binfmt_misc'
         status = binfmt_misc / 'status'
         if status.exists():
             self.log.info('Unmounting /proc/sys/fs/binfmt_misc in chroot')
             #cmd = 'umount %s' % binfmt
             cmd = ['umount', str(binfmt_misc)]
             runlog(cmd)
     if fs == 'devpts':
         target = self.target / 'dev' / 'pts'
     #cmd = 'umount %s' % target
     cmd = ['umount', str(target)]
     runlog(cmd)
Example #34
0
 def chroot(self, command, failure_suppressed=False):
     # we need to remove this if/else when we're sure
     # we don't need it anymore
     if type(command) is list:
         cmd = ['chroot', str(self.target)] + command
     else:
         cmd = 'chroot %s %s' % (self.target, command)
     return runlog(cmd, failure_suppressed=failure_suppressed)
Example #35
0
 def install_kernel_package(self):
     self.log.info('called install_kernel_package')
     extra_modules = self.determine_extra_modules_from_diskconfig()
     if extra_modules:
         self.log.info(
             'Checking if extra packages are required before kernel install.'
         )
         self.install_packages_for_extra_modules(extra_modules)
     else:
         msg = "There doesn't seem to be a need for extra modules on this machine."
         self.log.info(msg)
     kernel = self.machine.get_kernel()
     if kernel == 'default':
         self.log.info("Using default kernel")
         kernel = self._determine_default_kernel()
         self.log.info("Default kernel for this machine is %s" % kernel)
     #cmd = self.chroot_precommand + self.aptinstall + [kernel]
     apt_command = install_packages_command([kernel],
                                            self.defenv,
                                            loginfo=self.log.info,
                                            logerror=self.log.error,
                                            usertag='paella-kernel')
     cmd = self.chroot_precommand + apt_command
     self.log.info('install cmd is: %s' % ' '.join(cmd))
     kimgconf = self.target / 'etc' / 'kernel-img.conf'
     kimgconf_old = path('%s.paella-orig' % kimgconf)
     kimgconflines = [
         'do_bootloader = No', 'do_initrd = Yes', 'warn_initrd = No'
     ]
     if kimgconf.exists():
         self.log.info('/etc/kernel-img.conf already exists')
         k = '/etc/kernel-img.conf'
         msg = 'renaming %s to %s.paella-orig' % (k, k)
         self.log.info(msg)
         if kimgconf_old.exists():
             msg = '%s already exists, aborting install.' % kimgconf_old
             self.log.error(msg)
             raise RuntimeError, msg
         os.rename(kimgconf, kimgconf_old)
     kimgconf.write_lines(kimgconflines)
     runlog(cmd)
     self.log.info('Kernel installation is complete.')
     if kimgconf_old.exists():
         self.log.info('Restoring /etc/kernel-img.conf')
         os.remove(kimgconf)
         os.rename(kimgconf_old, kimgconf)
Example #36
0
 def _umount_target_virtfs(self, fs):
     # work around binfmt-support /proc locking
     # found this idea while messing around in live-helper
     target = self.target / fs
     if fs == 'proc':
         binfmt_misc = self.target / 'proc/sys/fs/binfmt_misc'
         status = binfmt_misc / 'status'
         if status.exists():
             self.log.info('Unmounting /proc/sys/fs/binfmt_misc in chroot')
             #cmd = 'umount %s' % binfmt
             cmd = ['umount', str(binfmt_misc)]
             runlog(cmd)
     if fs == 'devpts':
         target = self.target / 'dev' / 'pts'
     #cmd = 'umount %s' % target
     cmd = ['umount', str(target)]
     runlog(cmd)
Example #37
0
 def debootstrap_target(self):
     suite = self.installer.suite
     debmirror = self.installer.debmirror
     cmd = debootstrap(suite, self.target, debmirror)
     info = self.installer.log.info
     info('running debootstrap with cmd %s' % cmd)
     runvalue = runlog(debootstrap(self.installer.suite, self.target, self.installer.debmirror))
     if runvalue:
         raise InstallError, 'problems bootstrapping with %s' % cmd
Example #38
0
 def _setup_storage_fai(self):
     diskconfig = self.machine.get_diskconfig_content()
     self.diskconfig = diskconfig
     # FIXME:  disklist is hardcoded here
     disklist = None
     if disklist is None:
         disklist = []
         cmd = ['/usr/lib/fai/disk-info']
         proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
         retval = proc.wait()
         if retval:
             raise RuntimeError, 'disk-info returned %d' % retval
         for line in proc.stdout:
             disklist.append(line.split()[0])
         print disklist
     #os.environ['DEBUG'] = 'true'
     cmd = setup_storage_fai(disklist, diskconfig, self.disklogpath)
     runlog(cmd)
     print "done", self.disklogpath
Example #39
0
 def unmount_device(self, device):
     # mounted = os.system('umount %s' % device)
     # this is how the command should look
     # mounted = runlog(['umount', device])
     # LOOK FOR WHERE THIS IS CALLED
     # why assign the return to mounted if I wasn't going
     # to return it?
     # passing str to runlog to find where this
     # is called.
     mounted = runlog("umount %s" % device)
Example #40
0
 def unmount_device(self, device):
     #mounted = os.system('umount %s' % device)
     # this is how the command should look
     #mounted = runlog(['umount', device])
     # LOOK FOR WHERE THIS IS CALLED
     # why assign the return to mounted if I wasn't going
     # to return it?
     # passing str to runlog to find where this
     # is called.
     mounted = runlog('umount %s' % device)
 def install_kernel_package(self):
     self.log.info('called install_kernel_package')
     extra_modules = self.determine_extra_modules_from_diskconfig()
     if extra_modules:
         self.log.info('Checking if extra packages are required before kernel install.')
         self.install_packages_for_extra_modules(extra_modules)
     else:
         msg = "There doesn't seem to be a need for extra modules on this machine."
         self.log.info(msg)
     kernel = self.machine.get_kernel()
     if kernel == 'default':
         self.log.info("Using default kernel")
         kernel = self._determine_default_kernel()
         self.log.info("Default kernel for this machine is %s" % kernel)
     #cmd = self.chroot_precommand + self.aptinstall + [kernel]
     apt_command = install_packages_command([kernel], self.defenv,
                                            loginfo=self.log.info, logerror=self.log.error,
                                            usertag='paella-kernel')
     cmd = self.chroot_precommand + apt_command
     self.log.info('install cmd is: %s' % ' '.join(cmd))
     kimgconf = self.target / 'etc' / 'kernel-img.conf'
     kimgconf_old = path('%s.paella-orig' % kimgconf)
     kimgconflines = ['do_bootloader = No',
                      'do_initrd = Yes',
                      'warn_initrd = No'
                      ]
     if kimgconf.exists():
         self.log.info('/etc/kernel-img.conf already exists')
         k = '/etc/kernel-img.conf'
         msg ='renaming %s to %s.paella-orig' % (k, k)
         self.log.info(msg)
         if kimgconf_old.exists():
             msg = '%s already exists, aborting install.' % kimgconf_old
             self.log.error(msg)
             raise RuntimeError , msg
         os.rename(kimgconf, kimgconf_old)
     kimgconf.write_lines(kimgconflines)
     runlog(cmd)
     self.log.info('Kernel installation is complete.')
     if kimgconf_old.exists():
         self.log.info('Restoring /etc/kernel-img.conf')
         os.remove(kimgconf)
         os.rename(kimgconf_old, kimgconf)
 def _setup_storage_fai(self):
     diskconfig = self.machine.get_diskconfig_content()
     self.diskconfig = diskconfig
     # FIXME:  disklist is hardcoded here
     disklist = None
     if disklist is None:
         disklist = []
         cmd = ['/usr/lib/fai/disk-info']
         proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
         retval = proc.wait()
         if retval:
             raise RuntimeError , 'disk-info returned %d' % retval
         for line in proc.stdout:
             disklist.append(line.split()[0])
         print disklist
     #os.environ['DEBUG'] = 'true'
     cmd = setup_storage_fai(disklist, diskconfig, self.disklogpath)
     runlog(cmd)
     print "done", self.disklogpath
Example #43
0
 def debootstrap_target(self):
     suite = self.installer.suite
     debmirror = self.installer.debmirror
     cmd = debootstrap(suite, self.target, debmirror)
     info = self.installer.log.info
     info('running debootstrap with cmd %s' % cmd)
     runvalue = runlog(
         debootstrap(self.installer.suite, self.target,
                     self.installer.debmirror))
     if runvalue:
         raise InstallError, 'problems bootstrapping with %s' % cmd
Example #44
0
 def _umount_target_virtfs(self, fs):
     self.log.info('running umount for %s' % fs)
     # work around binfmt-support /proc locking
     # found this idea while messing around in live-helper
     target = self.target / fs
     if fs == 'proc':
         binfmt_misc = self.target / 'proc/sys/fs/binfmt_misc'
         status = binfmt_misc / 'status'
         if status.exists():
             self.log.info('Unmounting /proc/sys/fs/binfmt_misc in chroot')
             #cmd = 'umount %s' % binfmt
             cmd = ['umount', str(binfmt_misc)]
             runlog(cmd)
         # hack to stop mdadm on target
         mdstat = self.target / 'proc/mdstat'
         if mdstat.isfile():
             mdadm_initscript = self.target / 'etc/init.d/mdadm'
             if mdadm_initscript.isfile():
                 self.log.info("Stopping mdadm from running on target.")
                 cmd = ['chroot', self.target, '/etc/init.d/mdadm', 'stop']
                 runlog(cmd)
     if fs == 'devpts':
         target = self.target / 'dev' / 'pts'
     #cmd = 'umount %s' % target
     cmd = ['umount', str(target)]
     runlog(cmd)
Example #45
0
 def install_kernel_package(self):
     self.log.info("called install_kernel_package")
     extra_modules = self.determine_extra_modules_from_diskconfig()
     if extra_modules:
         self.log.info("Checking if extra packages are required before kernel install.")
         self.install_packages_for_extra_modules(extra_modules)
     else:
         msg = "There doesn't seem to be a need for extra modules on this machine."
         self.log.info(msg)
     kernel = self.machine.get_kernel()
     if kernel == "default":
         self.log.info("Using default kernel")
         kernel = self._determine_default_kernel()
         self.log.info("Default kernel for this machine is %s" % kernel)
     # cmd = self.chroot_precommand + self.aptinstall + [kernel]
     apt_command = install_packages_command(
         [kernel], self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag="paella-kernel"
     )
     cmd = self.chroot_precommand + apt_command
     self.log.info("install cmd is: %s" % " ".join(cmd))
     kimgconf = self.target / "etc" / "kernel-img.conf"
     kimgconf_old = path("%s.paella-orig" % kimgconf)
     kimgconflines = ["do_bootloader = No", "do_initrd = Yes", "warn_initrd = No"]
     if kimgconf.exists():
         self.log.info("/etc/kernel-img.conf already exists")
         k = "/etc/kernel-img.conf"
         msg = "renaming %s to %s.paella-orig" % (k, k)
         self.log.info(msg)
         if kimgconf_old.exists():
             msg = "%s already exists, aborting install." % kimgconf_old
             self.log.error(msg)
             raise RuntimeError, msg
         os.rename(kimgconf, kimgconf_old)
     kimgconf.write_lines(kimgconflines)
     runlog(cmd)
     self.log.info("Kernel installation is complete.")
     if kimgconf_old.exists():
         self.log.info("Restoring /etc/kernel-img.conf")
         os.remove(kimgconf)
         os.rename(kimgconf_old, kimgconf)
Example #46
0
 def install_packages_for_extra_modules(self, modules):
     """Install the packages required to handle these modules."""
     # cmd = self.chroot_precommand + self.aptinstall
     packages = []
     for module in modules:
         if module == "dm-mod":
             append_unique("lvm2", packages)
             append_unique("dmsetup", packages)
         if module.startswith("raid"):
             append_unique("mdadm", packages)
     # cmd += packages
     if packages:
         msg = "Installing these extra packages: %s" % ", ".join(packages)
         self.log.info(msg)
         apt_command = install_packages_command(
             packages, self.defenv, loginfo=self.log.info, logerror=self.log.error, usertag="paella-kernel-extras"
         )
         cmd = self.chroot_precommand + apt_command
         runlog(cmd)
     else:
         msg = "No extra packages required for the kernel"
         self.log.info(msg)
Example #47
0
 def ready_base_for_install(self):
     self._check_bootstrap()
     fstab = '#unconfigured for chroot install\n'
     ready_base_for_install(self.target, self.conn, self.suite, fstab)
     self._mount_target_proc()
     self._check_target_proc()
     cmd = self.command('apt-get', '-y update', chroot=True)
     runvalue = runlog(cmd)
     if runvalue:
         raise InstallError, 'problem updating the apt lists.'
     if os.environ.has_key('FAKE_START_STOP_DAEMON'):
         make_fake_start_stop_daemon(self.target)
     self._base_ready = True
 def install_packages_for_extra_modules(self, modules):
     """Install the packages required to handle these modules."""
     #cmd = self.chroot_precommand + self.aptinstall
     packages = []
     for module in modules:
         if module == 'dm-mod':
             append_unique('lvm2', packages)
             append_unique('dmsetup', packages)
         if module.startswith('raid'):
             append_unique('mdadm', packages)
     #cmd += packages
     if packages:
         msg = "Installing these extra packages: %s" % ', '.join(packages)
         self.log.info(msg)
         apt_command = install_packages_command(packages, self.defenv,
                                                loginfo=self.log.info, logerror=self.log.error,
                                                usertag='paella-kernel-extras')
         cmd = self.chroot_precommand + apt_command
         runlog(cmd)
     else:
         msg = 'No extra packages required for the kernel'
         self.log.info(msg)
Example #49
0
 def ready_base_for_install(self):
     self._check_bootstrap()
     fstab = '#unconfigured for chroot install\n'
     ready_base_for_install(self.target, self.conn, self.suite, fstab)
     self._mount_target_proc()
     self._check_target_proc()
     cmd = self.command('apt-get', '-y update', chroot=True)
     runvalue = runlog(cmd)
     if runvalue:
         raise InstallError, 'problem updating the apt lists.'
     if os.environ.has_key('FAKE_START_STOP_DAEMON'):
         make_fake_start_stop_daemon(self.target)
     self._base_ready = True
 def install_kernel_package(self):
     self.log.info("called install_kernel_package")
     kernel = self.machine.current.kernel
     cmd = self.chroot_precommand + self.aptinstall + [kernel]
     self.log.info("install cmd is: %s" % " ".join(cmd))
     kimgconf = self.target / "etc" / "kernel-img.conf"
     kimgconf_old = path("%s.paella-orig" % kimgconf)
     kimgconflines = ["do_bootloader = No", "do_initrd = Yes", "warn_initrd = No"]
     if kimgconf.exists():
         self.log.info("/etc/kernel-img.conf already exists")
         k = "/etc/kernel-img.conf"
         msg = "renaming %s to %s.paella-orig" % (k, k)
         self.log.info(msg)
         if kimgconf_old.exists():
             raise RuntimeError, "%s already exists, aborting install." % kimgconf_old
         os.rename(kimgconf, kimgconf_old)
     kimgconf.write_lines(kimgconflines)
     runlog(cmd)
     self.log.info("Kernel installation is complete.")
     if kimgconf_old.exists():
         self.log.info("Restoring /etc/kernel-img.conf")
         os.remove(kimgconf)
         os.rename(kimgconf_old, kimgconf)
Example #51
0
 def umount_dev(self):
     umount_devpts = ["umount", "/dev/pts"]
     runlog(self.chroot_precommand + umount_devpts)
     umount_cmd = ["umount", self.targetdev]
     try:
         runlog(umount_cmd)
     except RunLogError:
         self.log.error("There was a problem with unmounting /dev in target")
         self.log.info("attempting to do a lazy umount")
         umount_cmd = ["umount", "-l", self.targetdev]
         runlog(umount_cmd)
Example #52
0
 def umount_dev(self):
     umount_devpts = ['umount', '/dev/pts']
     runlog(self.chroot_precommand + umount_devpts)
     umount_cmd = ['umount', self.targetdev]
     try:
         runlog(umount_cmd)
     except RunLogError:
         self.log.error(
             "There was a problem with unmounting /dev in target")
         self.log.info("attempting to do a lazy umount")
         umount_cmd = ['umount', '-l', self.targetdev]
         runlog(umount_cmd)
Example #53
0
 def set_debconf_selections(self, template):
     trait = self.trait
     self.log.info('Setting debconf selections for trait %s' % trait)
     self.traittemplate.set_template(template.template)
     tmpl = self.traittemplate.template.template
     self._update_templatedata()
     sub = self.traittemplate.template.sub()
     if tmpl == sub:
         msg = "static debconf selections, no substitutions for trait %s" % trait
     else:
         msg = "debconf selections contain substitutions for trait %s" % trait
     self.log.info(msg)
     config_path = self.target / 'root/paella_debconf'
     self._check_debconf_destroyed(config_path)
     config_path.write_text(sub + '\n')
     cmd = [
         'chroot', self.target, 'debconf-set-selections', '-v',
         '/root/paella_debconf'
     ]
     try:
         retval = runlog(cmd)
     except RunLogError:
         self.log.info('there was a problem with debconf-set-selections')
         self.log.info('command was %s' % ' '.join(cmd))
         # make sure that we raise an error if this is not the
         # first run of debconf-set-selections
         if self.debconf_problem:
             msg = "We already had a problem with set_debconf_selections"
             self.log.error(msg)
             raise RuntimeError, msg
         self.debconf_problem = True
     # we're going to keep these files
     # instead of rm'ing them, until I feel
     # better about this code.  Besides, the
     # format of the files has to be just so
     # or debconf has problems, so this is a
     # good way to figure out what happened.
     if False:
         os.remove(config_path)
         self._check_debconf_destroyed(config_path)
     os.rename(config_path, '%s-%s' % (config_path, trait))
Example #54
0
 def update_grub(self):
     runlog(self.chroot_precommand + ['update-grub'])
Example #55
0
 def install_grub_package(self, grub='grub'):
     cmd = self.chroot_precommand + self.aptinstall + [grub]
     runlog(cmd)
Example #56
0
 def umount_dev(self):
     umount_devpts = ['umount', '/dev/pts']
     runlog(self.chroot_precommand + umount_devpts)
     umount_cmd = ['umount', self.targetdev]
     runlog(umount_cmd)
Example #57
0
 def bind_mount_dev(self):
     mount_cmd = ['mount', '-o', 'bind', '/dev', self.targetdev]
     mount_devpts = ['mount', '-t', 'devpts', 'devpts', '/dev/pts']
     runlog(mount_cmd)
     runlog(self.chroot_precommand + mount_devpts)