Esempio n. 1
0
 def _setup_solver(self):
     solver = Sat()
     for xml_repo in self.xml_state.get_repository_sections_used_for_build(
     ):
         repo_source = xml_repo.get_source().get_path()
         repo_sourcetype = xml_repo.get_sourcetype() or ''
         repo_user = xml_repo.get_username()
         repo_secret = xml_repo.get_password()
         repo_type = xml_repo.get_type()
         repo_dist = xml_repo.get_distribution()
         repo_components = xml_repo.get_components()
         if not repo_type:
             repo_type = SolverRepositoryBase(
                 Uri(uri=repo_source, source_type=repo_sourcetype),
                 repo_user, repo_secret).get_repo_type()
         if repo_type == 'apt-deb':
             # Debian based repos can be setup for a specific
             # distribution including a list of individual components.
             # For each component of the selected distribution extra
             # repository metadata exists. In such a case we iterate
             # over the configured dist components and add them as
             # repository each.
             dist_type = solver.set_dist_type('deb')
             if repo_components and repo_dist:
                 for component in repo_components.split():
                     repo_source_for_component = os.sep.join([
                         repo_source.rstrip(os.sep), 'dists', repo_dist,
                         component, f'binary-{dist_type.get("arch")}'
                     ])
                     solver.add_repository(
                         SolverRepository.new(
                             Uri(repo_source_for_component, repo_type,
                                 repo_sourcetype), repo_user, repo_secret))
                 continue
         solver.add_repository(
             SolverRepository.new(
                 Uri(repo_source, repo_type, repo_sourcetype), repo_user,
                 repo_secret))
     return solver
Esempio n. 2
0
 def test_solver_repository_apt(self, mock_deb):
     self.uri.repo_type = 'apt-deb'
     SolverRepository.new(self.uri)
     mock_deb.assert_called_once_with(self.uri, None, None)
Esempio n. 3
0
 def test_solver_repository_rpm_dir(self, mock_rpm_dir):
     self.uri.repo_type = 'rpm-dir'
     SolverRepository.new(self.uri)
     mock_rpm_dir.assert_called_once_with(self.uri, None, None)
Esempio n. 4
0
 def test_solver_repository_suse(self, mock_suse):
     self.uri.repo_type = 'yast2'
     SolverRepository.new(self.uri)
     mock_suse.assert_called_once_with(self.uri, None, None)
Esempio n. 5
0
 def test_solver_repository_type_not_implemented(self):
     with raises(KiwiSolverRepositorySetupError):
         SolverRepository.new(self.uri)
Esempio n. 6
0
    def fetch(self, update_check=True):
        """
        Download box from the open build service

        :param bool update_check: check for box updates True|False
        """
        download = update_check
        repo_source = self.box_config.get_box_source()
        if repo_source:
            repo = SolverRepository.new(Uri(repo_source, 'rpm-md'))
            packages_file = self.box_config.get_box_packages_file()
            packages_shasum_file = \
                self.box_config.get_box_packages_shasum_file()
            if update_check and packages_file and packages_shasum_file:
                local_packages_file = os.sep.join(
                    [self.box_dir, packages_file])
                local_packages_shasum_file = os.sep.join(
                    [self.box_dir, packages_shasum_file])
                local_packages_file_tmp = self.box_stage.register(
                    local_packages_file)
                local_packages_shasum_file_tmp = self.box_stage.register(
                    local_packages_shasum_file)
                repo.download_from_repository(packages_file,
                                              local_packages_file_tmp)
                checksum = Checksum(local_packages_file_tmp)
                shasum = checksum.sha256()
                if checksum.matches(shasum, local_packages_shasum_file):
                    download = False
                else:
                    self._create_packages_checksum(
                        local_packages_shasum_file_tmp, shasum)

            for box_file in self.box_config.get_box_files():
                local_box_file = os.sep.join([self.box_dir, box_file])
                if not os.path.exists(local_box_file):
                    download = True
                if download:
                    log.info('Downloading {0}'.format(box_file))
                    local_box_file_tmp = self.box_stage.register(
                        local_box_file)
                    repo.download_from_repository(box_file, local_box_file_tmp)

            if download:
                self.box_stage.commit()

            for box_file in self.box_config.get_box_files():
                local_box_file = os.sep.join([self.box_dir, box_file])
                if box_file.endswith('.qcow2'):
                    self.system = local_box_file
                if box_file.endswith('.tar.xz'):
                    self.kernel = self._extract_kernel_from_tarball(
                        local_box_file)
                    if self.box_config.use_initrd():
                        self.initrd = self._extract_initrd_from_tarball(
                            local_box_file)

        return self.vm_setup_type(
            system=self.system,
            kernel=self.kernel,
            initrd=self.initrd,
            append='root={0} console={1} {2}'.format(
                self.box_config.get_box_root(),
                self.box_config.get_box_console(),
                self.box_config.get_box_kernel_cmdline()),
            ram=self.box_config.get_box_memory_mbytes(),
            smp=self.box_config.get_box_processors())