def upload_pkg_dir(self, dir_path, upload_path): ''' Upload a full directory. Depending on the upload path, the appropriate method for that protocol is called. Currently this copies the whole tmp package directory to the target directory. This assumes that the web server is running on the same machine where the method is being called from. The upload_path's files are basically served by that web server. ''' local_path = os.path.join(dir_path, "*") try: if upload_path.startswith('ssh://'): hostline, remote_path = parse_ssh_path(upload_path) try: utils.run('scp %s %s:%s' % (local_path, hostline, remote_path)) ssh_path = os.path.join(remote_path, "*") utils.run("ssh %s 'chmod 644 %s'" % (hostline, ssh_path)) except error.CmdError: logging.error("Error uploading to repository: %s", upload_path) else: utils.run("cp %s %s " % (local_path, upload_path)) up_path = os.path.join(upload_path, "*") utils.run("chmod 644 %s" % up_path) except (IOError, os.error), why: raise error.PackageUploadError("Upload of %s to %s failed: %s" % (dir_path, upload_path, why))
def upload_pkg(self, pkg_path, upload_path=None, update_checksum=False, timeout=300): from autotest.server import subcommand if upload_path: upload_path_list = [upload_path] self.upkeep(upload_path_list) elif len(self.upload_paths) > 0: self.upkeep() upload_path_list = self.upload_paths else: raise error.PackageUploadError("Invalid Upload Path specified") if update_checksum: # get the packages' checksum file and update it with the current # package's checksum self.update_checksum(pkg_path) commands = [] for path in upload_path_list: commands.append( subcommand.subcommand(self.upload_pkg_parallel, (pkg_path, path, update_checksum))) results = subcommand.parallel(commands, timeout, return_results=True) for result in results: if result: print str(result)
def parse_ssh_path(repo): ''' Parse ssh://xx@xx/path/to/ and return a tuple with host_line and remote path ''' match = re.search('^ssh://(.*?)(/.*)$', repo) if match: return match.groups() else: raise error.PackageUploadError( "Incorrect SSH path in global_config: %s" % repo)
def parse_ssh_path(repo): ''' Parse an SSH url :type repo: string :param repo: a repo uri like ssh://xx@xx/path/to/ :return: tuple with (host, remote_path) ''' match = re.search('^ssh://([^/]+)(/.*)$', repo) if match: return match.groups() else: raise error.PackageUploadError("Incorrect SSH path in settings: %s" % repo)
def parse_ssh_path(repo): ''' Parse an SSH url @type repo: string @param repo: a repo uri like ssh://xx@xx/path/to/ @returns: tuple with (host, remote_path) ''' match = re.search('^ssh://(.*?)(/.*)$', repo) if match: return match.groups() else: raise error.PackageUploadError( "Incorrect SSH path in global_config: %s" % repo)