Exemple #1
0
 def _install_using_packaging(self, host, autodir):
     repos = self.get_fetch_location()
     if not repos:
         raise error.PackageInstallError("No repos to install an "
                                         "autotest client from")
     pkgmgr = packages.PackageManager(autodir,
                                      hostname=host.hostname,
                                      repo_urls=repos,
                                      do_locking=False,
                                      run_function=host.run,
                                      run_function_dargs=dict(timeout=600))
     # The packages dir is used to store all the packages that
     # are fetched on that client. (for the tests,deps etc.
     # too apart from the client)
     pkg_dir = os.path.join(autodir, 'packages')
     # clean up the autodir except for the packages directory
     host.run('cd %s && ls | grep -v "^packages$"'
              ' | xargs rm -rf && rm -rf .[^.]*' % autodir)
     pkgmgr.install_pkg('autotest',
                        'client',
                        pkg_dir,
                        autodir,
                        preserve_install_dir=True)
     self._create_test_output_dir(host, autodir)
     logging.info("Installation of autotest completed")
     self.installed = True
Exemple #2
0
    def install_pkg(self,
                    name,
                    pkg_type,
                    fetch_dir,
                    install_dir,
                    preserve_install_dir=False,
                    repo_url=None):
        '''
        Remove install_dir if it already exists and then recreate it unless
        preserve_install_dir is specified as True.
        Fetch the package into the pkg_dir. Untar the package into install_dir
        The assumption is that packages are of the form :
        <pkg_type>.<pkg_name>.tar.bz2
        name        : name of the package
        type        : type of the package
        fetch_dir   : The directory into which the package tarball will be
                      fetched to.
        install_dir : the directory where the package files will be untarred to
        repo_url    : the url of the repository to fetch the package from.
        '''

        # do_locking flag is on by default unless you disable it (typically
        # in the cases where packages are directly installed from the server
        # onto the client in which case fcntl stuff wont work as the code
        # will run on the server in that case..
        if self.do_locking:
            lockfile_name = '.%s-%s-lock' % (re.sub("/", "_", name), pkg_type)
            lockfile = open(os.path.join(self.pkgmgr_dir, lockfile_name), 'w')

        try:
            if self.do_locking:
                fcntl.flock(lockfile, fcntl.LOCK_EX)

            self._run_command('mkdir -p %s' % fetch_dir)
            pkg_name = self.get_tarball_name(name, pkg_type)
            try:
                # Fetch the package into fetch_dir
                fetcher = self.fetch_pkg(pkg_name,
                                         fetch_dir,
                                         use_checksum=True,
                                         repo_url=repo_url,
                                         install=True)

                fetcher.install_pkg_post(pkg_name, fetch_dir, install_dir,
                                         preserve_install_dir)
            except error.PackageFetchError, why:
                raise error.PackageInstallError(
                    'Installation of %s(type:%s) failed : %s' %
                    (name, pkg_type, why))
        finally:
            if self.do_locking:
                fcntl.flock(lockfile, fcntl.LOCK_UN)
                lockfile.close()
Exemple #3
0
    def install_pkg(self, name, pkg_type, fetch_dir, install_dir,
                    preserve_install_dir=False, repo_url=None):
        '''
        Remove install_dir if it already exists and then recreate it unless
        preserve_install_dir is specified as True.
        Fetch the package into the pkg_dir. Untar the package into install_dir
        The assumption is that packages are of the form :
        <pkg_type>.<pkg_name>.tar.bz2
        name        : name of the package
        type        : type of the package
        fetch_dir   : The directory into which the package tarball will be
                      fetched to.
        install_dir : the directory where the package files will be untarred to
        repo_url    : the url of the repository to fetch the package from.
        '''

        # do_locking flag is on by default unless you disable it (typically
        # in the cases where packages are directly installed from the server
        # onto the client in which case fcntl stuff wont work as the code
        # will run on the server in that case..
        if self.do_locking:
            lockfile_name = '.%s-%s-lock' % (name, pkg_type)
            lockfile = open(os.path.join(self.pkgmgr_dir, lockfile_name), 'w')

        try:
            if self.do_locking:
                fcntl.flock(lockfile, fcntl.LOCK_EX)

            self._run_command('mkdir -p %s' % fetch_dir)

            pkg_name = self.get_tarball_name(name, pkg_type)
            fetch_path = os.path.join(fetch_dir, pkg_name)
            try:
                # Fetch the package into fetch_dir
                self.fetch_pkg(pkg_name, fetch_path, use_checksum=True)

                # check to see if the install_dir exists and if it does
                # then check to see if the .checksum file is the latest
                install_dir_exists = False
                try:
                    self._run_command("ls %s" % install_dir)
                    install_dir_exists = True
                except (error.CmdError, error.AutoservRunError):
                    pass

                if (install_dir_exists and
                    not self.untar_required(fetch_path, install_dir)):
                    return

                # untar the package into install_dir and
                # update the checksum in that directory
                if not preserve_install_dir:
                    # Make sure we clean up the install_dir
                    self._run_command('rm -rf %s' % install_dir)
                self._run_command('mkdir -p %s' % install_dir)

                self.untar_pkg(fetch_path, install_dir)

            except error.PackageFetchError, why:
                raise error.PackageInstallError(
                    'Installation of %s(type:%s) failed : %s'
                    % (name, pkg_type, why))
        finally:
            if self.do_locking:
                fcntl.flock(lockfile, fcntl.LOCK_UN)
                lockfile.close()