Пример #1
0
    def _install_test_firmware(self, mount_point):
        if self.config.vexpress_complete_firmware:
            if unicode_path_check(self.complete_firmware_test):
                self._copy_firmware_to_juno(self.complete_firmware_test,
                                            mount_point)
            else:
                raise CriticalError("No path to complete firmware")
        else:
            uefi_path = self.config.vexpress_uefi_path
            uefi = os.path.join(mount_point, uefi_path)

            if unicode_path_check(self.test_uefi):
                self.context.run_command('cp %s %s' % (self.test_uefi, uefi))
            else:
                raise CriticalError("No path to uefi firmware")

            if self.config.vexpress_requires_trusted_firmware:
                bl1_path = self.config.vexpress_bl1_path
                bl1 = os.path.join(mount_point, bl1_path)

                if unicode_path_check(self.test_bl1):
                    self.context.run_command('cp %s %s' % (self.test_bl1, bl1))
                else:
                    raise CriticalError("No path to bl1 firmware")

                if self.config.vexpress_requires_bl0:
                    bl0_path = self.config.vexpress_bl0_path
                    bl0 = os.path.join(mount_point, bl0_path)

                    if unicode_path_check(self.test_bl0):
                        self.context.run_command('cp %s %s' %
                                                 (self.test_bl0, bl0))
                    else:
                        raise CriticalError("No path to bl0 firmware")
Пример #2
0
    def _customize_linux(self):
        # XXX Re-examine what to do here in light of deployment_data import.
        # perhaps make self.deployment_data = deployment_data({overrides: dict})
        # and remove the write function completely?

        os_release_id = 'linux'
        mnt = self.mount_info['rootfs']
        os_release_file = '%s/etc/os-release' % mnt
        if unicode_path_check(os_release_file):
            for line in open(os_release_file):
                if line.startswith('ID='):
                    os_release_id = line[(len('ID=')):]
                    os_release_id = os_release_id.strip('\"\n')
                    break

        profile_path = "%s/etc/profile" % mnt
        if os_release_id == 'debian' or os_release_id == 'ubuntu' or \
                unicode_path_check('%s/etc/debian_version' % mnt):
            self.deployment_data = deployment_data.ubuntu
            profile_path = '%s/root/.bashrc' % mnt
        elif os_release_id == 'fedora':
            self.deployment_data = deployment_data.fedora
        else:
            # assume an OE based image. This is actually pretty safe
            # because we are doing pretty standard linux stuff, just
            # just no upstart or dash assumptions
            self.deployment_data = deployment_data.oe

        self._customize_prompt_hostname(mnt, profile_path)
Пример #3
0
    def _customize_linux(self):
        # XXX Re-examine what to do here in light of deployment_data import.
        # perhaps make self.deployment_data = deployment_data({overrides: dict})
        # and remove the write function completely?

        os_release_id = 'linux'
        mnt = self.mount_info['rootfs']
        os_release_file = '%s/etc/os-release' % mnt
        if unicode_path_check(os_release_file):
            for line in open(os_release_file):
                if line.startswith('ID='):
                    os_release_id = line[(len('ID=')):]
                    os_release_id = os_release_id.strip('\"\n')
                    break

        profile_path = "%s/etc/profile" % mnt
        if os_release_id == 'debian' or os_release_id == 'ubuntu' or \
                unicode_path_check('%s/etc/debian_version' % mnt):
            self.deployment_data = deployment_data.ubuntu
            profile_path = '%s/root/.bashrc' % mnt
        elif os_release_id == 'fedora':
            self.deployment_data = deployment_data.fedora
        else:
            # assume an OE based image. This is actually pretty safe
            # because we are doing pretty standard linux stuff, just
            # just no upstart or dash assumptions
            self.deployment_data = deployment_data.oe

        self._customize_prompt_hostname(mnt, profile_path)
Пример #4
0
    def _install_test_firmware(self, mount_point):
        if self.config.vexpress_complete_firmware:
            if unicode_path_check(self.complete_firmware_test):
                self._copy_firmware_to_juno(self.complete_firmware_test, mount_point)
            else:
                raise CriticalError("No path to complete firmware")
        else:
            uefi_path = self.config.vexpress_uefi_path
            uefi = os.path.join(mount_point, uefi_path)

            if unicode_path_check(self.test_uefi):
                self.context.run_command('cp %s %s' % (self.test_uefi, uefi))
            else:
                raise CriticalError("No path to uefi firmware")

            if self.config.vexpress_requires_trusted_firmware:
                bl1_path = self.config.vexpress_bl1_path
                bl1 = os.path.join(mount_point, bl1_path)

                if unicode_path_check(self.test_bl1):
                    self.context.run_command('cp %s %s' % (self.test_bl1, bl1))
                else:
                    raise CriticalError("No path to bl1 firmware")

                if self.config.vexpress_requires_bl0:
                    bl0_path = self.config.vexpress_bl0_path
                    bl0 = os.path.join(mount_point, bl0_path)

                    if unicode_path_check(self.test_bl0):
                        self.context.run_command('cp %s %s' % (self.test_bl0, bl0))
                    else:
                        raise CriticalError("No path to bl0 firmware")
Пример #5
0
    def _restore_firmware_backup(self, mount_point):
        if self.config.vexpress_complete_firmware:
            tarball = download_image(self.config.vexpress_firmware_default,
                                     self.context,
                                     self.scratch_dir,
                                     decompress=False)
            self._extract_compressed_firmware_master(tarball)
            self._copy_firmware_to_juno(self.complete_firmware_master,
                                        mount_point)
        else:
            uefi_path = self.config.vexpress_uefi_path
            uefi = os.path.join(mount_point, uefi_path)
            uefi_backup_path = self.config.vexpress_uefi_backup_path
            uefi_backup = os.path.join(mount_point, uefi_backup_path)

            if unicode_path_check(uefi_backup):
                # restore the uefi backup
                self.context.run_command_with_retries('cp %s %s' %
                                                      (uefi_backup, uefi))
            else:
                # no existing backup yet means that this is the first time ever;
                # the uefi in there is the good one, and we backup it up.
                self.context.run_command_with_retries('cp %s %s' %
                                                      (uefi, uefi_backup))

            if self.config.vexpress_requires_trusted_firmware:
                bl1_path = self.config.vexpress_bl1_path
                bl1 = os.path.join(mount_point, bl1_path)
                bl1_backup_path = self.config.vexpress_bl1_backup_path
                bl1_backup = os.path.join(mount_point, bl1_backup_path)

                if unicode_path_check(bl1_backup):
                    # restore the firmware backup
                    self.context.run_command_with_retries('cp %s %s' %
                                                          (bl1_backup, bl1))
                else:
                    # no existing backup yet means that this is the first time ever;
                    # the firmware in there is the good one, and we backup it up.
                    self.context.run_command_with_retries('cp %s %s' %
                                                          (bl1, bl1_backup))

                if self.config.vexpress_requires_bl0:
                    bl0_path = self.config.vexpress_bl0_path
                    bl0 = os.path.join(mount_point, bl0_path)
                    bl0_backup_path = self.config.vexpress_bl0_backup_path
                    bl0_backup = os.path.join(mount_point, bl0_backup_path)

                    if unicode_path_check(bl0_backup):
                        # restore the bl0 backup
                        self.context.run_command_with_retries(
                            'cp %s %s' % (bl0_backup, bl0))
                    else:
                        # no existing backup yet means that this is the first time ever;
                        # the bl0 in there is the good one, and we backup it up.
                        self.context.run_command_with_retries(
                            'cp %s %s' % (bl0, bl0_backup))
Пример #6
0
    def _customize_prompt_hostname(self, rootdir, profile_path):
        if re.search("%s", profile_path):
            # If profile path is expecting a rootdir in it, perform string
            # substitution.
            profile_path = profile_path % rootdir

        if unicode_path_check(profile_path):
            with open(profile_path, 'a') as f:
                f.write('export PS1="%s"\n' % self.tester_ps1)
        if unicode_path_check('%s/etc/hostname' % rootdir):
            with open('%s/etc/hostname' % rootdir, 'w') as f:
                f.write('%s\n' % self.config.hostname)
Пример #7
0
    def _customize_prompt_hostname(self, rootdir, profile_path):
        if re.search("%s", profile_path):
            # If profile path is expecting a rootdir in it, perform string
            # substitution.
            profile_path = profile_path % rootdir

        if unicode_path_check(profile_path):
            with open(profile_path, 'a') as f:
                f.write('export PS1="%s"\n' % self.tester_ps1)
        if unicode_path_check('%s/etc/hostname' % rootdir):
            with open('%s/etc/hostname' % rootdir, 'w') as f:
                f.write('%s\n' % self.config.hostname)
Пример #8
0
    def copy_to(self, context, local_path=None):
        # copy file from image to local path
        des_path = None

        # make default local path in the lava
        if local_path is None:
            local_path = utils.mkdtemp(
                basedir=context.config.lava_image_tmpdir)

        src_path = '%s/%s' % (self.part_mntdir, self.path)
        if not unicode_path_check(src_path):
            raise CriticalError(
                'Can not find source in image (%s at part %s)!' %
                (self.path, self.part))
        if os.path.isdir(src_path):
            if not unicode_path_check(local_path):
                des_path = local_path
            else:
                if self.file_name == '':
                    des_name = self.dir_name
                else:
                    des_name = self.file_name
                des_path = os.path.join(local_path, des_name)
            logging.debug("Copying dir from #%s:%s(%s) to %s!", self.part,
                          self.path, src_path, des_path)
            shutil.copytree(src_path, des_path)
        elif os.path.isfile(src_path):
            if not unicode_path_check(local_path):
                if os.path.basename(local_path) == '':
                    des_name = os.path.basename(src_path)
                    des_path = os.path.join(local_path, des_name)
                    os.makedirs(local_path)
                else:
                    if not unicode_path_check(os.path.dirname(local_path)):
                        os.makedirs(os.path.dirname(local_path))
                    des_path = local_path
            else:
                if os.path.isdir(local_path):
                    des_name = os.path.basename(src_path)
                    des_path = os.path.join(local_path, des_name)
                else:
                    des_path = local_path
            logging.debug("Copying file from #%s:%s(%s) to %s!", self.part,
                          self.path, src_path, des_path)
            shutil.copyfile(src_path, des_path)
        else:
            raise CriticalError(
                'Please check the source file type, we only support file and dir!'
            )

        return des_path
Пример #9
0
    def _mcc_setup(self):
        """
        This method will manage the context for manipulating the USB mass
        storage device, and pass the mount point where the USB MSD is mounted
        to the inner block.

        Example:

            with self._mcc_setup() as mount_point:
                do_stuff_with(mount_point)


        This can be used for example to copy files from/to the USB MSD.
        Mounting and unmounting is managed by this method, so the inner block
        does not have to handle that.
        """

        mount_point = os.path.join(self.scratch_dir, 'vexpress-usb')
        if not unicode_path_check(mount_point):
            os.makedirs(mount_point)

        self._enter_mcc()
        self._mount_usbmsd(mount_point)
        try:
            yield mount_point
        finally:
            self._umount_usbmsd(mount_point)
            self._leave_mcc()
Пример #10
0
    def _mcc_setup(self):
        """
        This method will manage the context for manipulating the USB mass
        storage device, and pass the mount point where the USB MSD is mounted
        to the inner block.

        Example:

            with self._mcc_setup() as mount_point:
                do_stuff_with(mount_point)


        This can be used for example to copy files from/to the USB MSD.
        Mounting and unmounting is managed by this method, so the inner block
        does not have to handle that.
        """

        mount_point = os.path.join(self.scratch_dir, 'vexpress-usb')
        if not unicode_path_check(mount_point):
            os.makedirs(mount_point)

        self._enter_mcc()
        self._mount_usbmsd(mount_point)
        try:
            yield mount_point
        finally:
            self._umount_usbmsd(mount_point)
            self._leave_mcc()
Пример #11
0
    def _restore_firmware_backup(self, mount_point):
        if self.config.vexpress_complete_firmware:
            tarball = download_image(self.config.vexpress_firmware_default, self.context,
                                     self.scratch_dir, decompress=False)
            self._extract_compressed_firmware_master(tarball)
            self._copy_firmware_to_juno(self.complete_firmware_master, mount_point)
        else:
            uefi_path = self.config.vexpress_uefi_path
            uefi = os.path.join(mount_point, uefi_path)
            uefi_backup_path = self.config.vexpress_uefi_backup_path
            uefi_backup = os.path.join(mount_point, uefi_backup_path)

            if unicode_path_check(uefi_backup):
                # restore the uefi backup
                self.context.run_command_with_retries('cp %s %s' % (uefi_backup, uefi))
            else:
                # no existing backup yet means that this is the first time ever;
                # the uefi in there is the good one, and we backup it up.
                self.context.run_command_with_retries('cp %s %s' % (uefi, uefi_backup))

            if self.config.vexpress_requires_trusted_firmware:
                bl1_path = self.config.vexpress_bl1_path
                bl1 = os.path.join(mount_point, bl1_path)
                bl1_backup_path = self.config.vexpress_bl1_backup_path
                bl1_backup = os.path.join(mount_point, bl1_backup_path)

                if unicode_path_check(bl1_backup):
                    # restore the firmware backup
                    self.context.run_command_with_retries('cp %s %s' % (bl1_backup, bl1))
                else:
                    # no existing backup yet means that this is the first time ever;
                    # the firmware in there is the good one, and we backup it up.
                    self.context.run_command_with_retries('cp %s %s' % (bl1, bl1_backup))

                if self.config.vexpress_requires_bl0:
                    bl0_path = self.config.vexpress_bl0_path
                    bl0 = os.path.join(mount_point, bl0_path)
                    bl0_backup_path = self.config.vexpress_bl0_backup_path
                    bl0_backup = os.path.join(mount_point, bl0_backup_path)

                    if unicode_path_check(bl0_backup):
                        # restore the bl0 backup
                        self.context.run_command_with_retries('cp %s %s' % (bl0_backup, bl0))
                    else:
                        # no existing backup yet means that this is the first time ever;
                        # the bl0 in there is the good one, and we backup it up.
                        self.context.run_command_with_retries('cp %s %s' % (bl0, bl0_backup))
Пример #12
0
    def copy_to(self, context, local_path=None):
        # copy file from image to local path
        des_path = None

        # make default local path in the lava
        if local_path is None:
            local_path = utils.mkdtemp(basedir=context.config.lava_image_tmpdir)

        src_path = '%s/%s' % (self.part_mntdir, self.path)
        if not unicode_path_check(src_path):
            raise CriticalError('Can not find source in image (%s at part %s)!' % (self.path, self.part))
        if os.path.isdir(src_path):
            if not unicode_path_check(local_path):
                des_path = local_path
            else:
                if self.file_name == '':
                    des_name = self.dir_name
                else:
                    des_name = self.file_name
                des_path = os.path.join(local_path, des_name)
            logging.debug("Copying dir from #%s:%s(%s) to %s!", self.part, self.path, src_path, des_path)
            shutil.copytree(src_path, des_path)
        elif os.path.isfile(src_path):
            if not unicode_path_check(local_path):
                if os.path.basename(local_path) == '':
                    des_name = os.path.basename(src_path)
                    des_path = os.path.join(local_path, des_name)
                    os.makedirs(local_path)
                else:
                    if not unicode_path_check(os.path.dirname(local_path)):
                        os.makedirs(os.path.dirname(local_path))
                    des_path = local_path
            else:
                if os.path.isdir(local_path):
                    des_name = os.path.basename(src_path)
                    des_path = os.path.join(local_path, des_name)
                else:
                    des_path = local_path
            logging.debug("Copying file from #%s:%s(%s) to %s!", self.part, self.path, src_path, des_path)
            shutil.copyfile(src_path, des_path)
        else:
            raise CriticalError('Please check the source file type, we only support file and dir!')

        return des_path
Пример #13
0
    def copy_from(self, local_path):
        # copy file from local path into image
        src_path = local_path
        if not unicode_path_check(src_path):
            raise CriticalError('Can not find source in local server (%s)!' %
                                src_path)

        if os.path.isdir(src_path):
            des_path = '%s/%s' % (self.part_mntdir, self.path)
            if unicode_path_check(des_path):
                if os.path.basename(src_path) == '':
                    des_name = os.path.basename(os.path.dirname(src_path))
                else:
                    des_name = os.path.basename(src_path)
                des_path = os.path.join(des_path, des_name)
            logging.debug("Copying dir from %s to #%s:%s(%s)!", des_path,
                          self.part, self.path, src_path)
            shutil.copytree(src_path, des_path)
        elif os.path.isfile(src_path):
            des_path = '%s/%s' % (self.part_mntdir, self.path)
            if not unicode_path_check(des_path):
                if os.path.basename(des_path) == '':
                    os.makedirs(des_path)
                    des_name = os.path.basename(src_path)
                    des_path = os.path.join(des_path, des_name)
                else:
                    if not unicode_path_check(os.path.dirname(des_path)):
                        os.makedirs(os.path.dirname(des_path))
            else:
                if os.path.isdir(des_path):
                    des_name = os.path.basename(src_path)
                    des_path = os.path.join(des_path, des_name)
            logging.debug("Copying file from %s to #%s:%s(%s)!", des_path,
                          self.part, self.path, src_path)
            shutil.copyfile(src_path, des_path)
        else:
            raise CriticalError(
                'Please check the source file type, we only support file and dir!'
            )

        return des_path
Пример #14
0
    def copy_from(self, local_path):
        # copy file from local path into image
        src_path = local_path
        if not unicode_path_check(src_path):
            raise CriticalError('Can not find source in local server (%s)!' % src_path)

        if os.path.isdir(src_path):
            des_path = '%s/%s' % (self.part_mntdir, self.path)
            if unicode_path_check(des_path):
                if os.path.basename(src_path) == '':
                    des_name = os.path.basename(os.path.dirname(src_path))
                else:
                    des_name = os.path.basename(src_path)
                des_path = os.path.join(des_path, des_name)
            logging.debug("Copying dir from %s to #%s:%s(%s)!", des_path, self.part, self.path, src_path)
            shutil.copytree(src_path, des_path)
        elif os.path.isfile(src_path):
            des_path = '%s/%s' % (self.part_mntdir, self.path)
            if not unicode_path_check(des_path):
                if os.path.basename(des_path) == '':
                    os.makedirs(des_path)
                    des_name = os.path.basename(src_path)
                    des_path = os.path.join(des_path, des_name)
                else:
                    if not unicode_path_check(os.path.dirname(des_path)):
                        os.makedirs(os.path.dirname(des_path))
            else:
                if os.path.isdir(des_path):
                    des_name = os.path.basename(src_path)
                    des_path = os.path.join(des_path, des_name)
            logging.debug("Copying file from %s to #%s:%s(%s)!", des_path, self.part, self.path, src_path)
            shutil.copyfile(src_path, des_path)
        else:
            raise CriticalError('Please check the source file type, we only support file and dir!')

        return des_path
Пример #15
0
    def _read_boot_cmds(self, image=None, boot_tgz=None):
        boot_file_path = None

        if not self.config.read_boot_cmds_from_image:
            return

        # If we have already obtained boot commands dynamically, then return.
        if self.__boot_cmds_dynamic__ is not None:
            logging.debug("We already have boot commands in place.")
            return

        if image:
            boot_part = self.config.boot_part
            # Read boot related file from the boot partition of image.
            with image_partition_mounted(image, boot_part) as mnt:
                for boot_file in self.config.boot_files:
                    boot_path = os.path.join(mnt, boot_file)
                    if unicode_path_check(boot_path):
                        boot_file_path = boot_path
                        break

        elif boot_tgz:
            tmp_dir = mkdtemp()
            extracted_files = extract_tar(boot_tgz, tmp_dir)
            for boot_file in self.config.boot_files:
                for file_path in extracted_files:
                    if boot_file == os.path.basename(file_path):
                        boot_file_path = file_path
                        break

        if boot_file_path and unicode_path_check(boot_file_path):
            with open(boot_file_path, 'r') as f:
                boot_cmds = self._rewrite_boot_cmds(f.read())
                self.__boot_cmds_dynamic__ = boot_cmds
        else:
            logging.debug("Unable to read boot commands dynamically.")
Пример #16
0
    def _read_boot_cmds(self, image=None, boot_tgz=None):
        boot_file_path = None

        if not self.config.read_boot_cmds_from_image:
            return

        # If we have already obtained boot commands dynamically, then return.
        if self.__boot_cmds_dynamic__ is not None:
            logging.debug("We already have boot commands in place.")
            return

        if image:
            boot_part = self.config.boot_part
            # Read boot related file from the boot partition of image.
            with image_partition_mounted(image, boot_part) as mnt:
                for boot_file in self.config.boot_files:
                    boot_path = os.path.join(mnt, boot_file)
                    if unicode_path_check(boot_path):
                        boot_file_path = boot_path
                        break

        elif boot_tgz:
            tmp_dir = mkdtemp()
            extracted_files = extract_tar(boot_tgz, tmp_dir)
            for boot_file in self.config.boot_files:
                for file_path in extracted_files:
                    if boot_file == os.path.basename(file_path):
                        boot_file_path = file_path
                        break

        if boot_file_path and unicode_path_check(boot_file_path):
            with open(boot_file_path, 'r') as f:
                boot_cmds = self._rewrite_boot_cmds(f.read())
                self.__boot_cmds_dynamic__ = boot_cmds
        else:
            logging.debug("Unable to read boot commands dynamically.")