Esempio n. 1
0
    def run(self, connection, args=None):
        if not self.parameters.get('ramdisk', None):  # idempotency
            return connection
        connection = super(CompressRamdisk, self).run(connection, args)
        if 'extracted_ramdisk' not in self.data['extract-overlay-ramdisk']:
            raise RuntimeError("Unable to find unpacked ramdisk")
        if 'ramdisk_file' not in self.data['extract-overlay-ramdisk']:
            raise RuntimeError("Unable to find ramdisk directory")
        ramdisk_dir = self.data['extract-overlay-ramdisk']['extracted_ramdisk']
        ramdisk_data = self.data['extract-overlay-ramdisk']['ramdisk_file']
        if self.parameters.get('preseed', None):
            if self.parameters["deployment_data"].get("preseed_to_ramdisk", None):
                # download action must have completed to get this far
                # some installers (centos) cannot fetch the preseed file via tftp.
                # Instead, put the preseed file into the ramdisk using a given name
                # from deployment_data which we can use in the boot commands.
                filename = self.parameters["deployment_data"]["preseed_to_ramdisk"]
                self.logger.info("Copying preseed file into ramdisk: %s", filename)
                shutil.copy(self.data['download_action']['preseed']['file'], os.path.join(ramdisk_dir, filename))
                self.set_common_data('file', 'preseed_local', filename)
        pwd = os.getcwd()
        os.chdir(ramdisk_dir)
        self.logger.debug("Building ramdisk %s containing %s",
                          ramdisk_data, ramdisk_dir)
        cmd = "find . | cpio --create --format='newc' > %s" % ramdisk_data
        try:
            # safe to use shell=True here, no external arguments
            log = subprocess.check_output(cmd, shell=True)
        except OSError as exc:
            raise RuntimeError('Unable to create cpio filesystem: %s' % exc)
        # lazy-logging would mean that the quoting of cmd causes invalid YAML
        self.logger.debug("%s\n%s" % (cmd, log))  # pylint: disable=logging-not-lazy

        # we need to compress the ramdisk with the same method is was submitted with
        compression = self.parameters['ramdisk'].get('compression', None)
        final_file = compress_file(ramdisk_data, compression)
        os.chdir(pwd)
        tftp_dir = os.path.dirname(self.data['download_action']['ramdisk']['file'])

        if self.add_header == 'u-boot':
            ramdisk_uboot = final_file + ".uboot"
            self.logger.debug("Adding RAMdisk u-boot header.")
            cmd = ("mkimage -A %s -T ramdisk -C none -d %s %s" % (self.mkimage_arch, final_file, ramdisk_uboot)).split(' ')
            if not self.run_command(cmd):
                raise RuntimeError("Unable to add uboot header to ramdisk")
            final_file = ramdisk_uboot

        shutil.move(final_file, os.path.join(tftp_dir, os.path.basename(final_file)))
        self.logger.debug("rename %s to %s",
                          final_file, os.path.join(tftp_dir, os.path.basename(final_file)))
        if self.parameters['to'] == 'tftp':
            suffix = self.data['tftp-deploy'].get('suffix', '')
            self.set_common_data('file', 'ramdisk', os.path.join(suffix, os.path.basename(final_file)))
        else:
            self.set_common_data('file', 'ramdisk', final_file)
        return connection
Esempio n. 2
0
    def run(self, connection, args=None):
        if not self.parameters.get('ramdisk', None):  # idempotency
            return connection
        connection = super(CompressRamdisk, self).run(connection, args)
        if 'extracted_ramdisk' not in self.data['extract-overlay-ramdisk']:
            raise RuntimeError("Unable to find unpacked ramdisk")
        if 'ramdisk_file' not in self.data['extract-overlay-ramdisk']:
            raise RuntimeError("Unable to find ramdisk directory")
        ramdisk_dir = self.data['extract-overlay-ramdisk']['extracted_ramdisk']
        ramdisk_data = self.data['extract-overlay-ramdisk']['ramdisk_file']
        pwd = os.getcwd()
        os.chdir(ramdisk_dir)
        self.logger.debug("Building ramdisk %s containing %s" % (
            ramdisk_data, ramdisk_dir
        ))
        cmd = "find . | cpio --create --format='newc' > %s" % ramdisk_data
        try:
            # safe to use shell=True here, no external arguments
            log = subprocess.check_output(cmd, shell=True)
        except OSError as exc:
            raise RuntimeError('Unable to create cpio filesystem: %s' % exc)
        self.logger.debug("%s\n%s" % (cmd, log))

        # we need to compress the ramdisk with the same method is was submitted with
        compression = self.parameters['ramdisk'].get('compression', None)
        final_file = compress_file(ramdisk_data, compression)
        os.chdir(pwd)
        tftp_dir = os.path.dirname(self.data['download_action']['ramdisk']['file'])

        if self.parameters['ramdisk'].get('add-header', None) == 'u-boot':
            ramdisk_uboot = final_file + ".uboot"
            self.logger.debug("Adding RAMdisk u-boot header.")
            cmd = ("mkimage -A %s -T ramdisk -C none -d %s %s" % (self.mkimage_arch, final_file, ramdisk_uboot)).split(' ')
            if not self.run_command(cmd):
                raise RuntimeError("Unable to add uboot header to ramdisk")
            final_file = ramdisk_uboot

        shutil.move(final_file, os.path.join(tftp_dir, os.path.basename(final_file)))
        self.logger.debug("rename %s to %s" % (
            final_file, os.path.join(tftp_dir, os.path.basename(final_file))
        ))
        if self.parameters['to'] == 'tftp':
            suffix = self.data['tftp-deploy'].get('suffix', '')
            self.set_common_data('file', 'ramdisk', os.path.join(suffix, os.path.basename(final_file)))
        else:
            self.set_common_data('file', 'ramdisk', final_file)
        return connection
Esempio n. 3
0
    def run(self, connection, args=None):
        if not self.parameters.get('ramdisk', None):  # idempotency
            return connection
        connection = super(CompressRamdisk, self).run(connection, args)
        if 'extracted_ramdisk' not in self.data['extract-overlay-ramdisk']:
            raise RuntimeError("Unable to find unpacked ramdisk")
        if 'ramdisk_file' not in self.data['extract-overlay-ramdisk']:
            raise RuntimeError("Unable to find ramdisk directory")
        ramdisk_dir = self.data['extract-overlay-ramdisk']['extracted_ramdisk']
        ramdisk_data = self.data['extract-overlay-ramdisk']['ramdisk_file']
        if self.parameters.get('preseed', None):
            if self.parameters["deployment_data"].get("preseed_to_ramdisk",
                                                      None):
                # download action must have completed to get this far
                # some installers (centos) cannot fetch the preseed file via tftp.
                # Instead, put the preseed file into the ramdisk using a given name
                # from deployment_data which we can use in the boot commands.
                filename = self.parameters["deployment_data"][
                    "preseed_to_ramdisk"]
                self.logger.info("Copying preseed file into ramdisk: %s",
                                 filename)
                shutil.copy(self.data['download_action']['preseed']['file'],
                            os.path.join(ramdisk_dir, filename))
                self.set_common_data('file', 'preseed_local', filename)
        pwd = os.getcwd()
        os.chdir(ramdisk_dir)
        self.logger.debug("Building ramdisk %s containing %s", ramdisk_data,
                          ramdisk_dir)
        cmd = "find . | cpio --create --format='newc' > %s" % ramdisk_data
        try:
            # safe to use shell=True here, no external arguments
            log = subprocess.check_output(cmd, shell=True)
        except OSError as exc:
            raise RuntimeError('Unable to create cpio filesystem: %s' % exc)
        # lazy-logging would mean that the quoting of cmd causes invalid YAML
        self.logger.debug("%s\n%s" % (cmd, log))  # pylint: disable=logging-not-lazy

        # we need to compress the ramdisk with the same method is was submitted with
        compression = self.parameters['ramdisk'].get('compression', None)
        final_file = compress_file(ramdisk_data, compression)
        os.chdir(pwd)
        tftp_dir = os.path.dirname(
            self.data['download_action']['ramdisk']['file'])

        if self.add_header == 'u-boot':
            ramdisk_uboot = final_file + ".uboot"
            self.logger.debug("Adding RAMdisk u-boot header.")
            cmd = ("mkimage -A %s -T ramdisk -C none -d %s %s" %
                   (self.mkimage_arch, final_file, ramdisk_uboot)).split(' ')
            if not self.run_command(cmd):
                raise RuntimeError("Unable to add uboot header to ramdisk")
            final_file = ramdisk_uboot

        shutil.move(final_file,
                    os.path.join(tftp_dir, os.path.basename(final_file)))
        self.logger.debug("rename %s to %s", final_file,
                          os.path.join(tftp_dir, os.path.basename(final_file)))
        if self.parameters['to'] == 'tftp':
            suffix = self.data['tftp-deploy'].get('suffix', '')
            self.set_common_data(
                'file', 'ramdisk',
                os.path.join(suffix, os.path.basename(final_file)))
        else:
            self.set_common_data('file', 'ramdisk', final_file)
        return connection