Example #1
0
    def process_delete_requests(self, force=False):
        """
        Process package delete requests (chroot)

        :param bool force: force deletion: true|false
        """
        delete_items = []
        for delete_item in self._delete_items():
            try:
                Command.run(['chroot', self.root_dir, 'rpm', '-q', delete_item])
                delete_items.append(delete_item)
            except Exception:
                # ignore packages which are not installed
                pass
        if not delete_items:
            raise KiwiRequestError(
                'None of the requested packages to delete are installed'
            )
        if force:
            force_options = ['--nodeps', '--allmatches', '--noscripts']
            return Command.call(
                [
                    'chroot', self.root_dir, 'rpm', '-e'
                ] + force_options + delete_items,
                self.chroot_command_env
            )
        else:
            return Command.call(
                [
                    'chroot', self.root_dir, 'zypper'
                ] + self.chroot_zypper_args + [
                    'remove', '-u', '--force-resolution'
                ] + delete_items,
                self.chroot_command_env
            )
Example #2
0
File: zypper.py Project: jfkw/kiwi
    def process_delete_requests(self,
                                force: bool = False) -> command_call_type:
        """
        Process package delete requests (chroot)

        :param bool force: force deletion: true|false

        :raises KiwiRequestError: if none of the packages to delete is
            installed
        :return: process results in command type

        :rtype: namedtuple
        """
        delete_items = []
        for delete_item in self._delete_items():
            try:
                Command.run(
                    ['chroot', self.root_dir, 'rpm', '-q', delete_item])
                delete_items.append(delete_item)
            except Exception:
                # ignore packages which are not installed
                pass
        if not delete_items:
            raise KiwiRequestError(
                'None of the requested packages to delete are installed')
        if force:
            force_options = ['--nodeps', '--allmatches', '--noscripts']
            return Command.call(['chroot', self.root_dir, 'rpm', '-e'] +
                                force_options + delete_items,
                                self.chroot_command_env)
        else:
            return Command.call(
                ['chroot', self.root_dir, 'zypper'] + self.chroot_zypper_args +
                ['remove', '-u', '--force-resolution'] + delete_items,
                self.chroot_command_env)
Example #3
0
    def process_delete_requests(self, force=False):
        """
        Process package delete requests (chroot)

        :param bool force: force deletion: true|false

        :raises KiwiRequestError: if none of the packages to delete is
            installed.
        :return: process results in command type

        :rtype: namedtuple
        """
        delete_items = []
        for delete_item in self.package_requests:
            try:
                Command.run(
                    ['chroot', self.root_dir, 'rpm', '-q', delete_item])
                delete_items.append(delete_item)
            except Exception:
                # ignore packages which are not installed
                pass
        if not delete_items:
            raise KiwiRequestError(
                'None of the requested packages to delete are installed')
        self.cleanup_requests()
        if force:
            delete_options = ['--nodeps', '--allmatches', '--noscripts']
            return Command.call(['chroot', self.root_dir, 'rpm', '-e'] +
                                delete_options + delete_items,
                                self.command_env)
        else:
            chroot_dnf_args = Path.move_to_root(self.root_dir, self.dnf_args)
            return Command.call(['chroot', self.root_dir, 'microdnf'] +
                                chroot_dnf_args + self.custom_args +
                                ['remove'] + delete_items, self.command_env)
Example #4
0
 def _call_script_no_chroot(self, name, option_list, working_directory):
     if not working_directory:
         working_directory = self.root_dir
     script_path = os.path.abspath(
         os.sep.join([self.root_dir, 'image', name]))
     if os.path.exists(script_path):
         bash_command = [
             'cd', working_directory, '&&', 'bash', '--norc', script_path,
             ' '.join(option_list)
         ]
         if log.getLogLevel() == logging.DEBUG and not \
            Defaults.is_buildservice_worker():
             # In debug mode run scripts in a screen session to
             # allow attaching and debugging
             config_script = Command.call([
                 'screen', '-t', '-X', 'bash', '-c', ' '.join(bash_command)
             ])
         else:
             # In standard mode run script through bash
             config_script = Command.call(
                 ['bash', '-c', ' '.join(bash_command)])
         process = CommandProcess(command=config_script,
                                  log_topic='Calling ' + name + ' script')
         result = process.poll_and_watch()
         if result.returncode != 0:
             raise KiwiScriptFailed('{0} failed: {1}'.format(
                 name, result.stderr))
Example #5
0
 def _call_script_no_chroot(
     self, name, option_list, working_directory
 ):
     if not working_directory:
         working_directory = self.root_dir
     script_path = os.path.abspath(
         os.sep.join([self.root_dir, 'image', name])
     )
     if os.path.exists(script_path):
         bash_command = [
             'cd', working_directory, '&&',
             'bash', '--norc', script_path, ' '.join(option_list)
         ]
         if log.getLogFlags().get('run-scripts-in-screen'):
             # Run scripts in a screen session if requested
             config_script = Command.call(
                 ['screen', '-t', '-X', 'bash', '-c', ' '.join(bash_command)]
             )
         else:
             # In standard mode run script through bash
             config_script = Command.call(
                 ['bash', '-c', ' '.join(bash_command)]
             )
         process = CommandProcess(
             command=config_script, log_topic='Calling ' + name + ' script'
         )
         result = process.poll_and_watch()
         if result.returncode != 0:
             raise KiwiScriptFailed(
                 '{0} failed: {1}'.format(name, result.stderr)
             )
Example #6
0
    def process_delete_requests(self, force=False):
        """
        Process package delete requests (chroot)

        :param bool force: force deletion: true|false

        :raises KiwiRequestError: if none of the packages to delete is
            installed
        :return: process results in command type

        :rtype: namedtuple
        """
        delete_items = []
        for delete_item in self.package_requests:
            try:
                Command.run(
                    ['chroot', self.root_dir, 'pacman', '-Qi', delete_item])
                delete_items.append(delete_item)
            except Exception:
                # ignore packages which are not installed
                pass
        if not delete_items:
            raise KiwiRequestError(
                'None of the requested packages to delete are installed')
        self.cleanup_requests()
        chroot_pacman_args = Path.move_to_root(self.root_dir, self.pacman_args)
        return Command.call(['chroot', self.root_dir, 'pacman'] +
                            chroot_pacman_args + self.custom_args +
                            ['-Rdd' if force else '-Rs'] + delete_items,
                            self.command_env)
Example #7
0
 def process_install_requests(self):
     """
     Process package install requests for image phase (chroot)
     """
     yum = self._get_yum_binary_name()
     if self.exclude_requests:
         # For Yum, excluding a package means removing it from
         # the solver operation. This is done by adding --exclude
         # to the command line. This means that if the package is
         # hard required by another package, it will break the transaction.
         for package in self.exclude_requests:
             self.custom_args.append('--exclude=' + package)
     Command.run(
         ['chroot', self.root_dir, 'rpm', '--rebuilddb']
     )
     chroot_yum_args = self.root_bind.move_to_root(
         self.yum_args
     )
     bash_command = [
         'chroot', self.root_dir, yum
     ] + chroot_yum_args + self.custom_args + [
         'install'
     ] + self.package_requests
     if self.collection_requests:
         bash_command += [
             '&&', 'chroot', self.root_dir, yum
         ] + chroot_yum_args + self.custom_args + [
             'groupinstall'
         ] + self.collection_requests
     self.cleanup_requests()
     return Command.call(
         ['bash', '-c', ' '.join(bash_command)], self.command_env
     )
Example #8
0
    def process_delete_requests(self, force=False):
        """
        Process package delete requests (chroot)

        :param bool force: force deletion: true|false
        """
        delete_items = []
        for delete_item in self.package_requests:
            try:
                Command.run(['chroot', self.root_dir, 'rpm', '-q', delete_item])
                delete_items.append(delete_item)
            except Exception:
                # ignore packages which are not installed
                pass
        if not delete_items:
            raise KiwiRequestError(
                'None of the requested packages to delete are installed'
            )
        delete_options = ['--nodeps', '--allmatches', '--noscripts']
        self.cleanup_requests()
        return Command.call(
            [
                'chroot', self.root_dir, 'rpm', '-e'
            ] + delete_options + delete_items,
            self.command_env
        )
Example #9
0
    def process_install_requests(self) -> command_call_type:
        """
        Process package install requests for image phase (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        update_command = ['chroot', self.root_dir, 'apt-get']
        update_command.extend(
            Path.move_to_root(self.root_dir, self.apt_get_args)
        )
        update_command.extend(self.custom_args)
        update_command.append('update')
        Command.run(update_command, self.command_env)

        apt_get_command = ['chroot', self.root_dir, 'apt-get']
        apt_get_command.extend(
            Path.move_to_root(self.root_dir, self.apt_get_args)
        )
        apt_get_command.extend(self.custom_args)
        apt_get_command.append('install')
        apt_get_command.extend(self._package_requests())

        return Command.call(
            apt_get_command, self.command_env
        )
Example #10
0
File: dnf.py Project: D4N/kiwi
    def process_install_requests(self):
        """
        Process package install requests for image phase (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        if self.exclude_requests:
            # For DNF, excluding a package means removing it from
            # the solver operation. This is done by adding --exclude
            # to the command line. This means that if the package is
            # hard required by another package, it will break the transaction.
            for package in self.exclude_requests:
                self.custom_args.append('--exclude=' + package)
        chroot_dnf_args = self.root_bind.move_to_root(self.dnf_args)
        bash_command = ['chroot', self.root_dir,
                        'dnf'] + chroot_dnf_args + self.custom_args + [
                            'install'
                        ] + self.package_requests
        if self.collection_requests:
            bash_command += ['&&', 'chroot', self.root_dir, 'dnf'
                             ] + chroot_dnf_args + self.custom_args + [
                                 'group', 'install'
                             ] + self.collection_requests
        self.cleanup_requests()
        return Command.call(['bash', '-c', ' '.join(bash_command)],
                            self.command_env)
Example #11
0
    def process_install_requests(self) -> command_call_type:
        """
        Process package install requests for image phase (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        if self.exclude_requests:
            # For zypper excluding a package means, removing it from
            # the solver operation. This is done by adding a package
            # lock. This means that if the package is hard required
            # by another package, it will break the transaction.
            metadata_dir = ''.join([self.root_dir, '/etc/zypp'])
            if not os.path.exists(metadata_dir):
                Path.create(metadata_dir)
            for package in self.exclude_requests:
                Command.run(['chroot', self.root_dir, 'zypper'] +
                            self.chroot_zypper_args + ['al'] + [package],
                            self.chroot_command_env)
        return Command.call(
            ['chroot', self.root_dir, 'zypper'] + self.chroot_zypper_args + [
                'install', '--download', 'in-advance',
                '--auto-agree-with-licenses'
            ] + self.custom_args + ['--'] + self._install_items(),
            self.chroot_command_env)
Example #12
0
 def _call_script(self, name, option_list=None):
     script_path = os.path.join(self.root_dir, 'image', name)
     if os.path.exists(script_path):
         options = option_list or []
         if log.getLogFlags().get('run-scripts-in-screen'):
             # Run scripts in a screen session if requested
             command = ['screen', '-t', '-X', 'chroot', self.root_dir]
         else:
             # In standard mode run scripts without a terminal
             # associated to them
             command = ['chroot', self.root_dir]
         if not Path.access(script_path, os.X_OK):
             command.append('bash')
         command.append(
             os.path.join(defaults.IMAGE_METADATA_DIR, name)
         )
         command.extend(options)
         profile = Profile(self.xml_state)
         caller_environment = copy.deepcopy(os.environ)
         caller_environment.update(profile.get_settings())
         config_script = Command.call(command, caller_environment)
         process = CommandProcess(
             command=config_script, log_topic='Calling ' + name + ' script'
         )
         result = process.poll_and_watch()
         if result.returncode != 0:
             raise KiwiScriptFailed(
                 '{0} failed: {1}'.format(name, result.stderr)
             )
Example #13
0
    def process_install_requests(self) -> command_call_type:
        """
        Process package install requests for image phase (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        exclude_args = []
        if self.exclude_requests:
            # For DNF, excluding a package means removing it from
            # the solver operation. This is done by adding --exclude
            # to the command line. This means that if the package is
            # hard required by another package, it will break the transaction.
            for package in self.exclude_requests:
                exclude_args.append('--exclude=' + package)
        chroot_dnf_args = Path.move_to_root(
            self.root_dir, self.dnf_args
        )
        dnf_command = [
            'chroot', self.root_dir, 'dnf'
        ] + chroot_dnf_args + [
            f'--releasever={self.release_version}'
        ] + self.custom_args + exclude_args + [
            'install'
        ] + self.package_requests + self.collection_requests
        self.cleanup_requests()
        return Command.call(
            dnf_command, self.command_env
        )
Example #14
0
    def process_delete_requests(self, force=False):
        """
        Process package delete requests (chroot)

        :param bool force: force deletion: true|false
        """
        delete_items = []
        for delete_item in self.package_requests:
            try:
                Command.run(['chroot', self.root_dir, 'rpm', '-q', delete_item])
                delete_items.append(delete_item)
            except Exception:
                # ignore packages which are not installed
                pass
        if not delete_items:
            raise KiwiRequestError(
                'None of the requested packages to delete are installed'
            )
        delete_options = ['--nodeps', '--allmatches', '--noscripts']
        self.cleanup_requests()
        return Command.call(
            [
                'chroot', self.root_dir, 'rpm', '-e'
            ] + delete_options + delete_items,
            self.command_env
        )
Example #15
0
    def process_install_requests_bootstrap(
        self, root_bind: RootBind = None
    ) -> command_call_type:
        """
        Process package install requests for bootstrap phase (no chroot)

        :param object root_bind: unused

        :return: process results in command type

        :rtype: namedtuple
        """
        microdnf_command = [
            'microdnf'
        ] + ['--refresh'] + self.dnf_args + [
            '--installroot', self.root_dir,
            f'--releasever={self.release_version}',
            '--noplugins',
            '--setopt=cachedir={0}'.format(
                self.repository.shared_dnf_dir['cache-dir']
            ),
            '--setopt=reposdir={0}'.format(
                self.repository.shared_dnf_dir['reposd-dir']
            ),
            '--setopt=varsdir={0}'.format(
                self.repository.shared_dnf_dir['vars-dir']
            )
        ] + self.custom_args + ['install'] + self.package_requests
        self.cleanup_requests()
        return Command.call(
            microdnf_command, self.command_env
        )
Example #16
0
    def process_install_requests_bootstrap(
        self, root_bind: RootBind = None
    ) -> command_call_type:
        """
        Process package install requests for bootstrap phase (no chroot)

        :param object root_bind: unused

        :return: process results in command type

        :rtype: namedtuple
        """
        Command.run(
            ['dnf'] + self.dnf_args + [
                f'--releasever={self.release_version}'
            ] + ['makecache']
        )
        dnf_command = [
            'dnf'
        ] + self.dnf_args + [
            '--installroot', self.root_dir,
            f'--releasever={self.release_version}'
        ] + self.custom_args + [
            'install'
        ] + self.package_requests + self.collection_requests
        self.cleanup_requests()
        return Command.call(
            dnf_command, self.command_env
        )
Example #17
0
    def process_install_requests_bootstrap(self):
        """
        Process package install requests for bootstrap phase (no chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        yum = self._get_yum_binary_name()
        Command.run(
            [yum] + self.yum_args + ['makecache']
        )
        bash_command = [
            yum
        ] + self.yum_args + [
            '--installroot', self.root_dir
        ] + self.custom_args + ['install'] + self.package_requests
        if self.collection_requests:
            bash_command += [
                '&&', yum
            ] + self.yum_args + [
                '--installroot', self.root_dir
            ] + self.custom_args + ['groupinstall'] + self.collection_requests
        self.cleanup_requests()
        return Command.call(
            ['bash', '-c', ' '.join(bash_command)], self.command_env
        )
Example #18
0
    def process_install_requests(self):
        """
        Process package install requests for image phase (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        if self.exclude_requests:
            # For zypper excluding a package means, removing it from
            # the solver operation. This is done by adding a package
            # lock. This means that if the package is hard required
            # by another package, it will break the transaction.
            metadata_dir = ''.join([self.root_dir, '/etc/zypp'])
            if not os.path.exists(metadata_dir):
                Path.create(metadata_dir)
            for package in self.exclude_requests:
                Command.run(
                    ['chroot', self.root_dir, 'zypper'] +
                    self.chroot_zypper_args + ['al'] + [package],
                    self.chroot_command_env
                )
        return Command.call(
            ['chroot', self.root_dir, 'zypper'] + self.chroot_zypper_args + [
                'install', '--auto-agree-with-licenses'
            ] + self.custom_args + self._install_items(),
            self.chroot_command_env
        )
Example #19
0
    def process_install_requests_bootstrap(self, root_bind=None):
        """
        Process package install requests for bootstrap phase (no chroot)

        :param object root_bind: unused

        :return: process results in command type

        :rtype: namedtuple
        """
        Command.run(
            ['dnf'] + self.dnf_args + ['makecache']
        )
        bash_command = [
            'dnf'
        ] + self.dnf_args + [
            '--installroot', self.root_dir
        ] + self.custom_args + ['install'] + self.package_requests
        if self.collection_requests:
            bash_command += [
                '&&', 'dnf'
            ] + self.dnf_args + [
                '--installroot', self.root_dir
            ] + self.custom_args + [
                'group', 'install'
            ] + self.collection_requests
        self.cleanup_requests()
        return Command.call(
            ['bash', '-c', ' '.join(bash_command)], self.command_env
        )
Example #20
0
 def process_install_requests(self):
     """
     Process package install requests for image phase (chroot)
     """
     yum = self._get_yum_binary_name(root=self.root_dir)
     if self.exclude_requests:
         # For Yum, excluding a package means removing it from
         # the solver operation. This is done by adding --exclude
         # to the command line. This means that if the package is
         # hard required by another package, it will break the transaction.
         for package in self.exclude_requests:
             self.custom_args.append('--exclude=' + package)
     Command.run(
         ['chroot', self.root_dir, 'rpm', '--rebuilddb']
     )
     chroot_yum_args = self.root_bind.move_to_root(
         self.yum_args
     )
     bash_command = [
         'chroot', self.root_dir, yum
     ] + chroot_yum_args + self.custom_args + [
         'install'
     ] + self.package_requests
     if self.collection_requests:
         bash_command += [
             '&&', 'chroot', self.root_dir, yum
         ] + chroot_yum_args + self.custom_args + [
             'groupinstall'
         ] + self.collection_requests
     self.cleanup_requests()
     return Command.call(
         ['bash', '-c', ' '.join(bash_command)], self.command_env
     )
Example #21
0
 def update(self):
     """
     Process package update requests (chroot)
     """
     return Command.call(
         ['chroot', self.root_dir, 'zypper'] + self.chroot_zypper_args +
         ['update', '--auto-agree-with-licenses'] + self.custom_args,
         self.chroot_command_env)
Example #22
0
 def process_install_requests_bootstrap(self):
     """
     Process package install requests for bootstrap phase (no chroot)
     """
     command = ['zypper'] + self.zypper_args + [
         '--root', self.root_dir, 'install', '--auto-agree-with-licenses'
     ] + self.custom_args + self._install_items()
     return Command.call(command, self.command_env)
Example #23
0
 def update(self):
     """
     Process package update requests (chroot)
     """
     chroot_dnf_args = self.root_bind.move_to_root(self.dnf_args)
     return Command.call(['chroot', self.root_dir, 'dnf'] +
                         chroot_dnf_args + self.custom_args + ['upgrade'],
                         self.command_env)
Example #24
0
 def update(self):
     """
     Process package update requests (chroot)
     """
     return Command.call(
         ['chroot', self.root_dir, 'zypper'] + self.chroot_zypper_args + [
             'update', '--auto-agree-with-licenses'
         ] + self.custom_args,
         self.chroot_command_env
     )
Example #25
0
    def process_delete_requests(self, force=False):
        """
        Process package delete requests (chroot)

        :param bool force: force deletion: true|false

        :raises KiwiRequestError: if none of the packages to delete is
            installed
        :return: process results in command type

        :rtype: namedtuple
        """
        delete_items = []
        for delete_item in self.package_requests:
            try:
                Command.run(['chroot', self.root_dir, 'rpm', '-q', delete_item])
                delete_items.append(delete_item)
            except Exception:
                # ignore packages which are not installed
                pass
        if not delete_items:
            raise KiwiRequestError(
                'None of the requested packages to delete are installed'
            )
        self.cleanup_requests()
        if force:
            delete_options = ['--nodeps', '--allmatches', '--noscripts']
            return Command.call(
                [
                    'chroot', self.root_dir, 'rpm', '-e'
                ] + delete_options + delete_items,
                self.command_env
            )
        else:
            chroot_yum_args = self.root_bind.move_to_root(self.yum_args)
            return Command.call(
                [
                    'chroot', self.root_dir, self._get_yum_binary_name()
                ] + chroot_yum_args + self.custom_args + [
                    'autoremove'
                ] + delete_items,
                self.command_env
            )
Example #26
0
    def update(self):
        """
        Process package update requests (chroot)
        """
        apt_get_command = ['chroot', self.root_dir, 'apt-get']
        apt_get_command.extend(self.root_bind.move_to_root(self.apt_get_args))
        apt_get_command.extend(self.custom_args)
        apt_get_command.append('upgrade')

        return Command.call(apt_get_command, self.command_env)
Example #27
0
 def _call_script(self, name):
     if os.path.exists(self.root_dir + '/image/' + name):
         config_script = Command.call(
             ['chroot', self.root_dir, 'bash', '/image/' + name])
         process = CommandProcess(command=config_script,
                                  log_topic='Calling ' + name + ' script')
         result = process.poll_and_watch()
         if result.returncode != 0:
             raise KiwiScriptFailed('%s failed: %s' %
                                    (name, format(result.stderr)))
Example #28
0
 def process_install_requests_bootstrap(self):
     """
     Process package install requests for bootstrap phase (no chroot)
     """
     command = ['zypper'] + self.zypper_args + [
         '--root', self.root_dir,
         'install', '--auto-agree-with-licenses'
     ] + self.custom_args + self._install_items()
     return Command.call(
         command, self.command_env
     )
Example #29
0
 def test_call(self, mock_select, mock_popen, mock_which):
     mock_which.return_value = 'command'
     mock_select.return_value = [True, False, False]
     mock_process = mock.Mock()
     mock_popen.return_value = mock_process
     call = Command.call(['command', 'args'])
     assert call.output_available()
     assert call.error_available()
     assert call.output == mock_process.stdout
     assert call.error == mock_process.stderr
     assert call.process == mock_process
Example #30
0
    def update(self):
        """
        Process package update requests (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        chroot_pacman_args = Path.move_to_root(self.root_dir, self.pacman_args)
        return Command.call(['chroot', self.root_dir, 'pacman'] +
                            chroot_pacman_args + self.custom_args + ['-Su'],
                            self.command_env)
Example #31
0
    def update(self):
        """
        Process package update requests (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        yum = self._get_yum_binary_name(root=self.root_dir)
        chroot_yum_args = self.root_bind.move_to_root(self.yum_args)
        return Command.call(['chroot', self.root_dir, yum] + chroot_yum_args +
                            self.custom_args + ['upgrade'], self.command_env)
Example #32
0
    def update(self):
        """
        Process package update requests (chroot)
        """
        apt_get_command = ['chroot', self.root_dir, 'apt-get']
        apt_get_command.extend(self.root_bind.move_to_root(self.apt_get_args))
        apt_get_command.extend(self.custom_args)
        apt_get_command.append('upgrade')

        return Command.call(
            apt_get_command, self.command_env
        )
Example #33
0
 def test_call(self, mock_select, mock_popen, mock_which):
     mock_which.return_value = "command"
     mock_select.return_value = [True, False, False]
     mock_process = mock.Mock()
     mock_popen.return_value = mock_process
     command_call = namedtuple("command", ["output", "output_available", "error", "error_available", "process"])
     call = Command.call(["command", "args"])
     assert call.output_available()
     assert call.error_available()
     assert call.output == mock_process.stdout
     assert call.error == mock_process.stderr
     assert call.process == mock_process
Example #34
0
File: dnf.py Project: D4N/kiwi
    def update(self):
        """
        Process package update requests (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        chroot_dnf_args = self.root_bind.move_to_root(self.dnf_args)
        return Command.call(['chroot', self.root_dir, 'dnf'] +
                            chroot_dnf_args + self.custom_args + ['upgrade'],
                            self.command_env)
Example #35
0
    def update(self):
        """
        Process package update requests (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        return Command.call(
            ['chroot', self.root_dir, 'zypper'] + self.chroot_zypper_args +
            ['update', '--auto-agree-with-licenses'] + self.custom_args,
            self.chroot_command_env)
Example #36
0
 def _call_script(self, name):
     if os.path.exists(self.root_dir + '/image/' + name):
         config_script = Command.call(
             ['chroot', self.root_dir, 'bash', '/image/' + name]
         )
         process = CommandProcess(
             command=config_script, log_topic='Calling ' + name + ' script'
         )
         result = process.poll_and_watch()
         if result.returncode != 0:
             raise KiwiScriptFailed(
                 '%s failed: %s' % (name, format(result.stderr))
             )
Example #37
0
File: dnf.py Project: rabueker/kiwi
    def update(self) -> command_call_type:
        """
        Process package update requests (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        chroot_dnf_args = Path.move_to_root(self.root_dir, self.dnf_args)
        return Command.call(
            ['chroot', self.root_dir, 'dnf'] + chroot_dnf_args +
            [f'--releasever={self.release_version}'] + self.custom_args +
            ['upgrade'], self.command_env)
Example #38
0
 def test_call(self, mock_select, mock_popen):
     mock_select.return_value = [True, False, False]
     mock_process = mock.Mock()
     mock_popen.return_value = mock_process
     command_call = namedtuple('command', [
         'output', 'output_available', 'error', 'error_available', 'process'
     ])
     call = Command.call(['command', 'args'])
     assert call.output_available()
     assert call.error_available()
     assert call.output == mock_process.stdout
     assert call.error == mock_process.stderr
     assert call.process == mock_process
Example #39
0
 def _call_script(self, name):
     script_path = os.path.join(self.root_dir, 'image', name)
     if os.path.exists(script_path):
         command = ['chroot', self.root_dir]
         if not Path.access(script_path, os.X_OK):
             command += ['bash']
         command += ['/image/' + name]
         config_script = Command.call(command)
         process = CommandProcess(command=config_script,
                                  log_topic='Calling ' + name + ' script')
         result = process.poll_and_watch()
         if result.returncode != 0:
             raise KiwiScriptFailed('%s failed: %s' %
                                    (name, format(result.stderr)))
Example #40
0
    def update(self):
        """
        Process package update requests (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        return Command.call(
            ['chroot', self.root_dir, 'zypper'] + self.chroot_zypper_args + [
                'update', '--auto-agree-with-licenses'
            ] + self.custom_args,
            self.chroot_command_env
        )
Example #41
0
    def process_install_requests_bootstrap(self, root_bind=None):
        """
        Process package install requests for bootstrap phase (no chroot)

        :param object root_bind: unused

        :return: process results in command type

        :rtype: namedtuple
        """
        command = ['zypper'] + self.zypper_args + [
            '--root', self.root_dir, 'install', '--auto-agree-with-licenses'
        ] + self.custom_args + ['--'] + self._install_items()
        return Command.call(command, self.command_env)
Example #42
0
 def update(self):
     """
     Process package update requests (chroot)
     """
     chroot_dnf_args = self.root_bind.move_to_root(
         self.dnf_args
     )
     return Command.call(
         [
             'chroot', self.root_dir, 'dnf'
         ] + chroot_dnf_args + self.custom_args + [
             'upgrade'
         ],
         self.command_env
     )
Example #43
0
 def update(self):
     """
     Process package update requests (chroot)
     """
     yum = self._get_yum_binary_name(root=self.root_dir)
     chroot_yum_args = self.root_bind.move_to_root(
         self.yum_args
     )
     return Command.call(
         [
             'chroot', self.root_dir, yum
         ] + chroot_yum_args + self.custom_args + [
             'upgrade'
         ],
         self.command_env
     )
Example #44
0
 def test_call(self, mock_select, mock_popen):
     mock_select.return_value = [True, False, False]
     mock_process = mock.Mock()
     mock_popen.return_value = mock_process
     command_call = namedtuple(
         'command', [
             'output', 'output_available',
             'error', 'error_available',
             'process'
         ]
     )
     call = Command.call(['command', 'args'])
     assert call.output_available()
     assert call.error_available()
     assert call.output == mock_process.stdout
     assert call.error == mock_process.stderr
     assert call.process == mock_process
Example #45
0
    def process_delete_requests(self, force=False):
        """
        Process package delete requests (chroot)

        :param bool force: force deletion: true|false

        :raises KiwiRequestError: if none of the packages to delete is
            installed
        :return: process results in command type

        :rtype: namedtuple
        """
        delete_items = []
        for delete_item in self._package_requests():
            try:
                Command.run(
                    ['chroot', self.root_dir, 'dpkg', '-l', delete_item]
                )
                delete_items.append(delete_item)
            except Exception:
                # ignore packages which are not installed
                pass
        if not delete_items:
            raise KiwiRequestError(
                'None of the requested packages to delete are installed'
            )

        if force:
            apt_get_command = ['chroot', self.root_dir, 'dpkg']
            apt_get_command.extend(['--force-all', '-r'])
            apt_get_command.extend(delete_items)
        else:
            apt_get_command = ['chroot', self.root_dir, 'apt-get']
            apt_get_command.extend(
                self.root_bind.move_to_root(self.apt_get_args)
            )
            apt_get_command.extend(self.custom_args)
            apt_get_command.extend(['--auto-remove', 'remove'])
            apt_get_command.extend(delete_items)

        return Command.call(
            apt_get_command, self.command_env
        )
Example #46
0
    def process_delete_requests(self, force=False):
        """
        Process package delete requests (chroot)

        Note: force deletion of packages is not required for apt-get
        because the apt-get configuration template already enforces
        to process the request as we want it

        :param bool force: unused
        """
        apt_get_command = ['chroot', self.root_dir, 'apt-get']
        apt_get_command.extend(self.root_bind.move_to_root(self.apt_get_args))
        apt_get_command.extend(self.custom_args)
        apt_get_command.append('remove')
        apt_get_command.extend(self._package_requests())

        return Command.call(
            apt_get_command, self.command_env
        )
Example #47
0
    def process_install_requests(self):
        """
        Process package install requests for image phase (chroot)
        """
        update_command = ['chroot', self.root_dir, 'apt-get']
        update_command.extend(self.root_bind.move_to_root(self.apt_get_args))
        update_command.extend(self.custom_args)
        update_command.append('update')
        Command.run(update_command, self.command_env)

        apt_get_command = ['chroot', self.root_dir, 'apt-get']
        apt_get_command.extend(self.root_bind.move_to_root(self.apt_get_args))
        apt_get_command.extend(self.custom_args)
        apt_get_command.append('install')
        apt_get_command.extend(self._package_requests())

        return Command.call(
            apt_get_command, self.command_env
        )
Example #48
0
    def update(self):
        """
        Process package update requests (chroot)

        :return: process results in command type

        :rtype: namedtuple
        """
        chroot_dnf_args = self.root_bind.move_to_root(
            self.dnf_args
        )
        return Command.call(
            [
                'chroot', self.root_dir, 'dnf'
            ] + chroot_dnf_args + self.custom_args + [
                'upgrade'
            ],
            self.command_env
        )
Example #49
0
 def process_install_requests_bootstrap(self):
     """
     Process package install requests for bootstrap phase (no chroot)
     """
     Command.run(
         ['dnf'] + self.dnf_args + ['makecache']
     )
     bash_command = [
         'dnf'
     ] + self.dnf_args + [
         '--installroot', self.root_dir
     ] + self.custom_args + ['install'] + self.package_requests
     if self.collection_requests:
         bash_command += [
             '&&', 'dnf'
         ] + self.dnf_args + [
             '--installroot', self.root_dir
         ] + self.custom_args + [
             'group', 'install'
         ] + self.collection_requests
     self.cleanup_requests()
     return Command.call(
         ['bash', '-c', ' '.join(bash_command)], self.command_env
     )
Example #50
0
 def _call_script_no_chroot(
     self, name, option_list, working_directory
 ):
     if not working_directory:
         working_directory = self.root_dir
     script_path = os.path.abspath(
         os.sep.join([self.root_dir, 'image', name])
     )
     if os.path.exists(script_path):
         bash_command = [
             'cd', working_directory, '&&',
             'bash', '--norc', script_path, ' '.join(option_list)
         ]
         config_script = Command.call(
             ['bash', '-c', ' '.join(bash_command)]
         )
         process = CommandProcess(
             command=config_script, log_topic='Calling ' + name + ' script'
         )
         result = process.poll_and_watch()
         if result.returncode != 0:
             raise KiwiScriptFailed(
                 '%s failed: %s' % (name, format(result.stderr))
             )
Example #51
0
 def test_call_failure(self, mock_popen, mock_which):
     mock_which.return_value = "command"
     mock_popen.side_effect = KiwiCommandError("Call failure")
     call = Command.call(["command", "args"])
Example #52
0
 def test_call_command_does_not_exist(self):
     Command.call(['does-not-exist'], os.environ)