Exemplo n.º 1
0
 def run(self, connection, args=None):
     if not self.parameters.get('ramdisk', None):  # idempotency
         return connection
     connection = super(ExtractRamdisk, self).run(connection, args)
     ramdisk = self.data['download_action']['ramdisk']['file']
     ramdisk_dir = self.mkdtemp()
     extracted_ramdisk = os.path.join(ramdisk_dir, 'ramdisk')
     os.mkdir(extracted_ramdisk, 0o755)
     compression = self.parameters['ramdisk'].get('compression', None)
     suffix = ""
     if compression:
         suffix = ".%s" % compression
     ramdisk_compressed_data = os.path.join(ramdisk_dir, RAMDISK_FNAME + suffix)
     if self.parameters['ramdisk'].get('header', None) == 'u-boot':
         # TODO: 64 bytes is empirical - may need to be configurable in the future
         cmd = ('dd if=%s of=%s ibs=64 skip=1' % (ramdisk, ramdisk_compressed_data)).split(' ')
         try:
             self.run_command(cmd)
         except:
             raise RuntimeError('Unable to remove uboot header: %s' % ramdisk)
     else:
         # give the file a predictable name
         shutil.move(ramdisk, ramdisk_compressed_data)
     ramdisk_data = decompress_file(ramdisk_compressed_data, compression)
     pwd = os.getcwd()
     os.chdir(extracted_ramdisk)
     cmd = ('cpio -iud -F %s' % ramdisk_data).split(' ')
     if not self.run_command(cmd):
         raise JobError('Unable to extract cpio arcive: %s - missing header definition (i.e. u-boot)?' % ramdisk_data)
     os.chdir(pwd)
     # tell other actions where the unpacked ramdisk can be found
     self.data[self.name]['extracted_ramdisk'] = extracted_ramdisk  # directory
     self.data[self.name]['ramdisk_file'] = ramdisk_data  # filename
     return connection
Exemplo n.º 2
0
def copy_overlay_to_sparse_fs(image, overlay):
    """copy_overlay_to_sparse_fs
    """
    mnt_dir = mkdtemp()
    ext4_img = image + '.ext4'
    logger = logging.getLogger('dispatcher')
    subprocess.check_output(['/usr/bin/simg2img', image, ext4_img],
                            stderr=subprocess.STDOUT)
    subprocess.check_output(['/bin/mount', '-o', 'loop', ext4_img, mnt_dir],
                            stderr=subprocess.STDOUT)
    if os.path.exists(overlay[:-3]):
        os.unlink(overlay[:-3])
    decompressed_overlay = decompress_file(overlay, 'gz')
    untar_file(decompressed_overlay, mnt_dir)

    # Check if we have space left on the mounted image.
    df = subprocess.Popen(['df', '-k', mnt_dir], stdout=subprocess.PIPE)
    output = df.communicate()[0]
    logger.debug(output)
    device, size, used, available, percent, mountpoint = output.split(
        "\n")[1].split()
    subprocess.check_output(['/bin/umount', mnt_dir], stderr=subprocess.STDOUT)
    if int(available) is 0 or percent is '100%':
        raise JobError("No space in image after applying overlay: %s" % image)
    subprocess.check_output(['/usr/bin/img2simg', ext4_img, image],
                            stderr=subprocess.STDOUT)
    os.remove(ext4_img)
Exemplo n.º 3
0
 def run(self, connection, max_end_time, args=None):
     if not self.parameters.get('ramdisk', None):  # idempotency
         return connection
     ramdisk = self.get_namespace_data(action='download-action',
                                       label='ramdisk',
                                       key='file')
     if self.skip:
         self.logger.info("Not extracting ramdisk.")
         suffix = self.get_namespace_data(action='tftp-deploy',
                                          label='tftp',
                                          key='suffix')
         filename = os.path.join(suffix, "ramdisk",
                                 os.path.basename(ramdisk))
         # declare the original ramdisk as the name to be used later.
         self.set_namespace_data(action='compress-ramdisk',
                                 label='file',
                                 key='ramdisk',
                                 value=filename)
         return
     connection = super(ExtractRamdisk, self).run(connection, max_end_time,
                                                  args)
     ramdisk_dir = self.mkdtemp()
     extracted_ramdisk = os.path.join(ramdisk_dir, 'ramdisk')
     os.mkdir(extracted_ramdisk, 0o755)
     compression = self.parameters['ramdisk'].get('compression', None)
     suffix = ""
     if compression:
         suffix = ".%s" % compression
     ramdisk_compressed_data = os.path.join(ramdisk_dir,
                                            RAMDISK_FNAME + suffix)
     if self.parameters['ramdisk'].get('header', None) == 'u-boot':
         cmd = ('dd if=%s of=%s ibs=%s skip=1' %
                (ramdisk, ramdisk_compressed_data,
                 UBOOT_DEFAULT_HEADER_LENGTH)).split(' ')
         try:
             self.run_command(cmd)
         except:
             raise LAVABug('Unable to remove uboot header: %s' % ramdisk)
     else:
         # give the file a predictable name
         shutil.move(ramdisk, ramdisk_compressed_data)
     ramdisk_data = decompress_file(ramdisk_compressed_data, compression)
     pwd = os.getcwd()
     os.chdir(extracted_ramdisk)
     cmd = ('cpio -iud -F %s' % ramdisk_data).split(' ')
     if not self.run_command(cmd):
         raise JobError(
             'Unable to extract cpio archive: %s - missing header definition (i.e. u-boot)?'
             % ramdisk_data)
     os.chdir(pwd)
     # tell other actions where the unpacked ramdisk can be found
     self.set_namespace_data(action=self.name,
                             label='extracted_ramdisk',
                             key='directory',
                             value=extracted_ramdisk)
     self.set_namespace_data(action=self.name,
                             label='ramdisk_file',
                             key='file',
                             value=ramdisk_data)
     return connection
Exemplo n.º 4
0
def copy_overlay_to_sparse_fs(image, overlay):
    """copy_overlay_to_sparse_fs
    """
    mnt_dir = mkdtemp()
    ext4_img = image + '.ext4'
    subprocess.check_output(['/usr/bin/simg2img', image, ext4_img],
                            stderr=subprocess.STDOUT)
    subprocess.check_output(['/bin/mount', '-o', 'loop', ext4_img, mnt_dir],
                            stderr=subprocess.STDOUT)
    if os.path.exists(overlay[:-3]):
        os.unlink(overlay[:-3])
    decompressed_overlay = decompress_file(overlay, 'gz')
    untar_file(decompressed_overlay, mnt_dir)
    subprocess.check_output(['/bin/umount', mnt_dir], stderr=subprocess.STDOUT)
    subprocess.check_output(['/usr/bin/img2simg', ext4_img, image],
                            stderr=subprocess.STDOUT)
    os.remove(ext4_img)
Exemplo n.º 5
0
def copy_in_overlay(image, root_partition, overlay):
    """
    Mounts test image partition as specified by the test
    writer and extracts overlay at the root
    """
    guest = guestfs.GuestFS(python_return_dict=True)
    guest.add_drive(image)
    guest.launch()
    partitions = guest.list_partitions()
    if not partitions:
        raise InfrastructureError("Unable to prepare guestfs")
    guest_partition = partitions[root_partition]
    guest.mount(guest_partition, '/')
    # FIXME: max message length issues when using tar_in
    # on tar.gz.  Works fine with tar so decompressing
    # overlay first.
    if os.path.exists(overlay[:-3]):
        os.unlink(overlay[:-3])
    decompressed_overlay = decompress_file(overlay, 'gz')
    guest.tar_in(decompressed_overlay, '/')
    guest.umount(guest_partition)
Exemplo n.º 6
0
def copy_in_overlay(image, root_partition, overlay):
    """
    Mounts test image partition as specified by the test
    writer and extracts overlay at the root
    """
    guest = guestfs.GuestFS(python_return_dict=True)
    guest.add_drive(image)
    guest.launch()
    partitions = guest.list_partitions()
    if not partitions:
        raise RuntimeError("Unable to prepare guestfs")
    guest_partition = partitions[root_partition]
    guest.mount(guest_partition, '/')
    # FIXME: max message length issues when using tar_in
    # on tar.gz.  Works fine with tar so decompressing
    # overlay first.
    if os.path.exists(overlay[:-3]):
        os.unlink(overlay[:-3])
    decompressed_overlay = decompress_file(overlay, 'gz')
    guest.tar_in(decompressed_overlay, '/')
    guest.umount(guest_partition)
Exemplo n.º 7
0
 def run(self, connection, args=None):
     if not self.parameters.get('ramdisk', None):  # idempotency
         return connection
     connection = super(ExtractRamdisk, self).run(connection, args)
     ramdisk = self.data['download_action']['ramdisk']['file']
     ramdisk_dir = mkdtemp()
     extracted_ramdisk = os.path.join(ramdisk_dir, 'ramdisk')
     os.mkdir(extracted_ramdisk)
     compression = self.parameters['ramdisk'].get('compression', None)
     suffix = ""
     if compression:
         suffix = ".%s" % compression
     ramdisk_compressed_data = os.path.join(ramdisk_dir,
                                            RAMDISK_FNAME + suffix)
     if self.parameters['ramdisk'].get('header', None) == 'u-boot':
         # TODO: 64 bytes is empirical - may need to be configurable in the future
         cmd = ('dd if=%s of=%s ibs=64 skip=1' %
                (ramdisk, ramdisk_compressed_data)).split(' ')
         try:
             self.run_command(cmd)
         except:
             raise RuntimeError('Unable to remove uboot header: %s' %
                                ramdisk)
     else:
         # give the file a predictable name
         shutil.move(ramdisk, ramdisk_compressed_data)
     self.logger.debug(os.system("file %s" % ramdisk_compressed_data))
     ramdisk_data = decompress_file(ramdisk_compressed_data, compression)
     pwd = os.getcwd()
     os.chdir(extracted_ramdisk)
     cmd = ('cpio -i -F %s' % ramdisk_data).split(' ')
     if not self.run_command(cmd):
         raise JobError('Unable to uncompress: %s - missing ramdisk-type?' %
                        ramdisk_data)
     os.chdir(pwd)
     # tell other actions where the unpacked ramdisk can be found
     self.data[
         self.name]['extracted_ramdisk'] = extracted_ramdisk  # directory
     self.data[self.name]['ramdisk_file'] = ramdisk_data  # filename
     return connection