Exemple #1
0
    def update_db(self):

        self.logger.info('Updating local Beaker database..')

        for task_rpm in self.tasks_added:

            self.logger.debug('Adding %s'% task_rpm)

            with open(os.path.join(self.task_dir,task_rpm)) as f:
                try:
                    session.begin()
                    task = self.tasks.process_taskinfo(self.tasks.read_taskinfo(f))
                    old_rpm = task.rpm
                    task.rpm = task_rpm
                    session.commit()

                except Exception:
                    session.rollback()
                    session.close()
                    self.logger.critical('Error adding task %s' % task_rpm)
                    unlink_ignore(task_rpm)

                else:                    
                    session.close()
                    self.logger.debug('Successfully added %s' % task.rpm)
                    if old_rpm:
                        unlink_ignore(os.path.join(self.task_dir, old_rpm))

        # Update task repo
        self.logger.info('Creating repodata..')
        Task.update_repo()

        return
Exemple #2
0
 def _link_rpms(self, dst):
     """Hardlink the task rpms into dst"""
     makedirs_ignore(dst, 0755)
     for srcpath, name in self._all_rpms():
         dstpath = os.path.join(dst, name)
         unlink_ignore(dstpath)
         os.link(srcpath, dstpath)
Exemple #3
0
 def teardownClass(cls):
     cls.selenium.stop()
     basepath = (turbogears.config.get('basepath.rpms'))
     # These may be missing if a test failed or wasn't run. We shouldn't
     # confuse matters further by complaining that they're missing.
     unlink_ignore(os.path.join(basepath, 'tmp-distribution-beaker-task_test-2.0-5.noarch.rpm'))
     unlink_ignore(os.path.join(basepath, 'tmp-distribution-beaker-dummy_for_bz681143-1.0-1.noarch.rpm'))
Exemple #4
0
 def _link_rpms(self, dst):
     """Hardlink the task rpms into dst"""
     makedirs_ignore(dst, 0755)
     for srcpath, name in self._all_rpms():
         dstpath = os.path.join(dst, name)
         unlink_ignore(dstpath)
         os.link(srcpath, dstpath)
Exemple #5
0
    def _download(self, task_url):

        task_rpm_name = os.path.split(task_url)[1]
        rpm_file = os.path.join(self.task_dir, task_rpm_name)

        if not os.path.exists(rpm_file):

            try:
                with atomically_replaced_file(rpm_file) as f:
                    siphon(urllib2.urlopen(task_url), f)
                    f.flush()

            except urllib2.HTTPError as err:
                self.logger.critical(err)
                #unlink_ignore(rpm_file)

            except Exception as err:
                self.logger.critical(err)
                unlink_ignore(rpm_file)
            else:
                self.logger.debug('Downloaded %s' % task_rpm_name)
                self.tasks_added.append(task_rpm_name)
                self.t_downloaded = self.t_downloaded + 1

        else:
            self.logger.debug('Already downloaded %s' % task_rpm_name)
            self.tasks_added.append(task_rpm_name)
            self.t_downloaded = self.t_downloaded + 1

        return
Exemple #6
0
def clear_armlinux(fqdn, basedir):
    """
    Removes PXE bootloader file created by configure_armlinux
    """
    pxe_dir = os.path.join(basedir, "arm", "pxelinux.cfg")
    basename = pxe_basename(fqdn)
    logger.debug("Removing armlinux config for %s as %s", fqdn, basename)
    unlink_ignore(os.path.join(pxe_dir, basename))
Exemple #7
0
def clear_armlinux(fqdn, basedir):
    """
    Removes PXE bootloader file created by configure_armlinux
    """
    pxe_dir = os.path.join(basedir, 'arm', 'pxelinux.cfg')
    basename = pxe_basename(fqdn)
    logger.debug('Removing armlinux config for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(pxe_dir, basename))
Exemple #8
0
def clear_efigrub(fqdn):
    """
    Removes bootloader file created by configure_efigrub
    """
    grub_dir = os.path.join(get_tftp_root(), 'grub')
    basename = pxe_basename(fqdn)
    logger.debug('Removing grub config for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(grub_dir, basename))
Exemple #9
0
def clear_petitboot(fqdn, basedir):
    """
    Removes bootloader file created by configure_petitboot
    """
    if not basedir:
        basedir = get_tftp_root()
    petitboot_conf_dir = os.path.join(basedir, 'bootloader', fqdn)
    unlink_ignore(os.path.join(petitboot_conf_dir, 'petitboot.cfg'))
Exemple #10
0
def clear_efigrub(fqdn, basedir):
    """
    Removes bootloader file created by configure_efigrub
    """
    grub_dir = os.path.join(basedir, 'grub')
    basename = pxe_basename(fqdn)
    logger.debug('Removing grub config for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(grub_dir, basename))
Exemple #11
0
def clear_netbootloader_directory(fqdn):
    fqdn_dir = os.path.join(get_tftp_root(), 'bootloader', fqdn)
    logger.debug('Removing custom netbootloader config for %s from %s', fqdn, fqdn_dir)
    unlink_ignore(os.path.join(fqdn_dir, 'image'))
    grub2_cfg_file = os.path.join(fqdn_dir, 'grub.cfg-%s'%pxe_basename(fqdn))
    clear_grub2(grub2_cfg_file)
    clear_pxelinux(fqdn, fqdn_dir)
    clear_yaboot(fqdn, fqdn_dir, yaboot_symlink=False)
Exemple #12
0
def clear_petitboot(fqdn, basedir):
    """
    Removes bootloader file created by configure_petitboot
    """
    if not basedir:
        basedir = get_tftp_root()
    petitboot_conf_dir = os.path.join(basedir, 'bootloader', fqdn)
    unlink_ignore(os.path.join(petitboot_conf_dir, 'petitboot.cfg'))
Exemple #13
0
def clear_efigrub(fqdn, basedir):
    """
    Removes bootloader file created by configure_efigrub
    """
    grub_dir = os.path.join(basedir, "grub")
    basename = pxe_basename(fqdn)
    logger.debug("Removing grub config for %s as %s", fqdn, basename)
    unlink_ignore(os.path.join(grub_dir, basename))
Exemple #14
0
def clear_armlinux(fqdn):
    """
    Removes PXE bootloader file created by configure_armlinux
    """
    pxe_dir = os.path.join(get_tftp_root(), 'arm', 'pxelinux.cfg')
    basename = pxe_basename(fqdn)
    logger.debug('Removing armlinux config for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(pxe_dir, basename))
Exemple #15
0
def clear_pxelinux(fqdn):
    """
    Removes PXE bootloader file created by configure_pxelinux
    """
    pxe_dir = os.path.join(get_tftp_root(), "pxelinux.cfg")
    basename = pxe_basename(fqdn)
    configname = os.path.join(pxe_dir, basename)
    logger.debug("Removing pxelinux config for %s as %s", fqdn, basename)
    unlink_ignore(configname)
Exemple #16
0
def clear_pxelinux(fqdn, basedir):
    """
    Removes PXE bootloader file created by configure_pxelinux
    """
    pxe_dir = os.path.join(basedir, 'pxelinux.cfg')
    basename = pxe_basename(fqdn)
    configname = os.path.join(pxe_dir, basename)
    logger.debug('Removing pxelinux config for %s as %s', fqdn, basename)
    unlink_ignore(configname)
Exemple #17
0
def clear_netbootloader_directory(fqdn):
    fqdn_dir = os.path.join(get_tftp_root(), 'bootloader', fqdn)
    logger.debug('Removing custom netbootloader config for %s from %s', fqdn,
                 fqdn_dir)
    unlink_ignore(os.path.join(fqdn_dir, 'image'))
    grub2_cfg_file = os.path.join(fqdn_dir, 'grub.cfg-%s' % pxe_basename(fqdn))
    clear_grub2(grub2_cfg_file)
    clear_pxelinux(fqdn, fqdn_dir)
    clear_yaboot(fqdn, fqdn_dir, yaboot_symlink=False)
Exemple #18
0
def clear_pxelinux(fqdn):
    """
    Removes PXE bootloader file created by configure_pxelinux
    """
    pxe_dir = os.path.join(get_tftp_root(), 'pxelinux.cfg')
    basename = pxe_basename(fqdn)
    configname = os.path.join(pxe_dir, basename)
    logger.debug('Removing pxelinux config for %s as %s', fqdn, basename)
    unlink_ignore(configname)
Exemple #19
0
def clear_ipxe(fqdn, basedir):
    """
    Removes iPXE bootloader file created by configure_ipxe
    """
    ipxe_dir = os.path.join(basedir, 'ipxe')
    basename = pxe_basename(fqdn).lower()
    configname = os.path.join(ipxe_dir, basename)
    logger.debug('Removing iPXE config for %s as %s', fqdn, basename)
    unlink_ignore(configname)
Exemple #20
0
def clear_yaboot(fqdn):
    """
    Removes bootloader file created by configure_yaboot
    """
    basename = pxe_basename(fqdn).lower()
    logger.debug('Removing yaboot config for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(get_tftp_root(), 'etc', basename))
    logger.debug('Removing yaboot symlink for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(get_tftp_root(), 'ppc', basename))
Exemple #21
0
def clear_yaboot(fqdn):
    """
    Removes bootloader file created by configure_yaboot
    """
    basename = pxe_basename(fqdn).lower()
    logger.debug('Removing yaboot config for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(get_tftp_root(), 'etc', basename))
    logger.debug('Removing yaboot symlink for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(get_tftp_root(), 'ppc', basename))
Exemple #22
0
def clear_aarch64(fqdn):
    """
    Removes PXE bootloader file created by configure_aarch64
    """
    pxe_base = os.path.join(get_tftp_root(), 'pxelinux')
    basename = "grub.cfg-%s" % pxe_basename(fqdn)
    logger.debug('Removing aarch64 config for %s as %s', fqdn, basename)
    unlink_ignore(os.path.join(pxe_base, "%s.efi" % fqdn))
    unlink_ignore(os.path.join(pxe_base, basename))
Exemple #23
0
def clear_yaboot(fqdn, basedir, yaboot_symlink=True):
    """
    Removes bootloader file created by configure_yaboot
    """
    basename = pxe_basename(fqdn).lower()
    logger.debug("Removing yaboot config for %s as %s", fqdn, basename)
    unlink_ignore(os.path.join(basedir, "etc", basename))
    if yaboot_symlink:
        logger.debug("Removing yaboot symlink for %s as %s", fqdn, basename)
        unlink_ignore(os.path.join(basedir, "ppc", basename))
Exemple #24
0
 def teardownClass(cls):
     basepath = (turbogears.config.get('basepath.rpms'))
     # These may be missing if a test failed or wasn't run. We shouldn't
     # confuse matters further by complaining that they're missing.
     unlink_ignore(
         os.path.join(basepath,
                      'tmp-distribution-beaker-task_test-2.0-5.noarch.rpm'))
     unlink_ignore(
         os.path.join(
             basepath,
             'tmp-distribution-beaker-dummy_for_bz681143-1.0-1.noarch.rpm'))
Exemple #25
0
def clear_zpxe(fqdn, basedir):
    """
    If this system is configured for zpxe, reconfigures for local boot

    Kept (set to 'local'): <get_tftp_root()>/s390x/s_<fqdn>
    Removed: <get_tftp_root()>/s390x/s_<fqdn>_parm
    Removed: <get_tftp_root()>/s390x/s_<fqdn>_conf
    """
    zpxe_dir = os.path.join(basedir, 's390x')
    configname = os.path.join(zpxe_dir, 's_%s' % fqdn)
    if not os.path.exists(configname):
        # Don't create a default zpxe config if we didn't create
        # a zpxe config for this system
        return

    logger.debug('Writing "local" zpxe index file for %s', fqdn)
    with atomically_replaced_file(configname) as f:
        f.write('local\n')  # XXX or should we just delete it??
    logger.debug('Removing zpxe parm file for %s', fqdn)
    unlink_ignore(os.path.join(zpxe_dir, 's_%s_parm' % fqdn))
    logger.debug('Removing zpxe conf file for %s', fqdn)
    unlink_ignore(os.path.join(zpxe_dir, 's_%s_conf' % fqdn))
Exemple #26
0
def clear_zpxe(fqdn):
    """
    If this system is configured for zpxe, reconfigures for local boot

    Kept (set to 'local'): <get_tftp_root()>/s390x/s_<fqdn>
    Removed: <get_tftp_root()>/s390x/s_<fqdn>_parm
    Removed: <get_tftp_root()>/s390x/s_<fqdn>_conf
    """
    zpxe_dir = os.path.join(get_tftp_root(), 's390x')
    configname = os.path.join(zpxe_dir, 's_%s' % fqdn)
    if not os.path.exists(configname):
        # Don't create a default zpxe config if we didn't create
        # a zpxe config for this system
        return

    logger.debug('Writing "local" zpxe index file for %s', fqdn)
    with atomically_replaced_file(configname) as f:
        f.write('local\n') # XXX or should we just delete it??
    logger.debug('Removing zpxe parm file for %s', fqdn)
    unlink_ignore(os.path.join(zpxe_dir, 's_%s_parm' % fqdn))
    logger.debug('Removing zpxe conf file for %s', fqdn)
    unlink_ignore(os.path.join(zpxe_dir, 's_%s_conf' % fqdn))
Exemple #27
0
def clear_elilo(fqdn, basedir):
    """
    Removes bootloader file created by configure_elilo
    """
    basename = "%s.conf" % pxe_basename(fqdn)
    unlink_ignore(os.path.join(basedir, basename))
Exemple #28
0
 def _unlink_locked_rpms(self, rpm_names):
     # Internal call that assumes the flock is already held
     for rpm_name in rpm_names:
         unlink_ignore(self.get_rpm_path(rpm_name))
Exemple #29
0
def clear_grub2(config):
    unlink_ignore(config)
Exemple #30
0
def clear_elilo(fqdn, basedir):
    """
    Removes bootloader file created by configure_elilo
    """
    basename = '%s.conf' % pxe_basename(fqdn)
    unlink_ignore(os.path.join(basedir, basename))
Exemple #31
0
    if len(entries) <= max_entries:
        return
    ctimes = {}
    for entry in entries:
        try:
            stat = os.stat(os.path.join(cached_images_dir, entry))
        except OSError, e:
            if e.errno == errno.ENOENT:
                continue
            else:
                raise
        ctimes[entry] = stat.st_ctime
    old_entries = sorted(entries, key=lambda entry: ctimes[entry], reverse=True)[max_entries:]
    for entry in old_entries:
        logger.debug("Cleaning %s from image cache", entry)
        unlink_ignore(os.path.join(cached_images_dir, entry))


def fetch_images(distro_tree_id, kernel_url, initrd_url, fqdn):
    """
    Creates references to kernel and initrd files at:

    <get_tftp_root()>/images/<fqdn>/kernel
    <get_tftp_root()>/images/<fqdn>/initrd
    """
    images_dir = os.path.join(get_tftp_root(), "images", fqdn)
    makedirs_ignore(images_dir, 0755)
    distrotree_dir = os.path.join(get_tftp_root(), "distrotrees", str(distro_tree_id))
    cached_images_dir = os.path.join(get_tftp_root(), "cached-images")

    # beaker-pxemenu might have already fetched the images, so let's try there
Exemple #32
0
 def _unlink_locked_rpms(self, rpm_names):
     # Internal call that assumes the flock is already held
     for rpm_name in rpm_names:
         unlink_ignore(self.get_rpm_path(rpm_name))
Exemple #33
0
def clear_grub2(config):
    unlink_ignore(config)
Exemple #34
0
def clear_elilo(fqdn):
    """
    Removes bootloader file created by configure_elilo
    """
    basename = '%s.conf' % pxe_basename(fqdn)
    unlink_ignore(os.path.join(get_tftp_root(), basename))