def check_package_exists(self): self.warn(2, "Computing checksum and package info. This may take some time ...") pkg_hash = {} digest_hash = {} for pkg in self.files: pkg_info = {} pkg_key = (pkg.strip()).split("/")[-1] if not os.access(pkg, os.R_OK): if not self.options.tolerant: self.die(-1, "Could not read file %s" % pkg) self.warn(-1, "Could not read file %s" % pkg) continue try: f = open(pkg) header, payload_stream = rhn_mpm.load(file=f) checksum_type = header.checksum_type() except rhn_mpm.InvalidPackageError, e: if not self.options.tolerant: self.die(-1, "ERROR: %s: This file doesn't appear to be a package" % pkg) self.warn(2, "ERROR: %s: This file doesn't appear to be a package" % pkg) continue except IOError: if not self.options.tolerant: self.die(-1, "ERROR: %s: No such file or directory available" % pkg) self.warn(2, "ERROR: %s: No such file or directory available" % pkg) continue
def load_package(package_stream): if package_stream.name.endswith(".deb"): try: header, payload_stream = rhn_deb.load(filename=package_stream.name) except: raise_with_tb(rhnFault(50, "Unable to load package", explain=0), sys.exc_info()[2]) else: try: header, payload_stream = rhn_mpm.load(file=package_stream) except: raise_with_tb(rhnFault(50, "Unable to load package", explain=0), sys.exc_info()[2]) payload_stream.seek(0, 0) if header.packaging == "mpm" or header.packaging == "deb": header.header_start = header.header_end = 0 (header_start, header_end) = (0, 0) else: (header_start, header_end) = get_header_byte_range(payload_stream) payload_stream.seek(0, 0) return header, payload_stream, header_start, header_end
def load_package(package_stream): if package_stream.name.endswith('.deb'): try: header, payload_stream = rhn_deb.load(filename=package_stream.name) except: raise rhnFault(50, "Unable to load package", explain=0), None, sys.exc_info()[2] else: try: header, payload_stream = rhn_mpm.load(file=package_stream) except: raise rhnFault(50, "Unable to load package", explain=0), None, sys.exc_info()[2] payload_stream.seek(0, 0) if header.packaging == "mpm" or header.packaging == "deb": header.header_start = header.header_end = 0 (header_start, header_end) = (0, 0) else: (header_start, header_end) = get_header_byte_range(payload_stream) payload_stream.seek(0, 0) return header, payload_stream, header_start, header_end
def upload(self, file, FileChecksumType, FileChecksum): """ Uploads a file. Returns (http_error_code, error_message) Sets: self.package_name self.package_epoch self.package_version self.package_release self.package_arch """ f = open(file) try: header, payload_stream = rhn_mpm.load(file=f) except rhn_mpm.InvalidPackageError: return -1, "Not an RPM: %s" % file # Set some package data members self.package_name = header['name'] self.package_epoch = header['epoch'] self.package_version = header['version'] self.package_release = header['release'] if header.is_source: if 1051 in header.keys(): self.package_arch = 'nosrc' else: self.package_arch = 'src' else: self.package_arch = header['arch'] self.packaging = header.packaging nvra = [self.package_name, self.package_version, self.package_release, self.package_arch] if isinstance(nvra[3], IntType): # Old rpm format return -1, "Deprecated RPM format: %s" % file self.nvra = nvra # use the precomputed passed checksum self.checksum_type = FileChecksumType self.checksum = FileChecksum # Set headers self.set_header("Content-Type", "application/x-rpm") self.set_header("User-Agent", self.user_agent) # Custom RHN headers prefix = self.header_prefix self.set_header("%s-%s" % (prefix, "Package-Name"), nvra[0]) self.set_header("%s-%s" % (prefix, "Package-Version"), nvra[1]) self.set_header("%s-%s" % (prefix, "Package-Release"), nvra[2]) self.set_header("%s-%s" % (prefix, "Package-Arch"), nvra[3]) self.set_header("%s-%s" % (prefix, "Packaging"), self.packaging) if self.checksum_type == 'md5': self.set_header("%s-%s" % (prefix, "File-MD5sum"), self.checksum) else: self.set_header("%s-%s" % (prefix, "File-Checksum-Type"), self.checksum_type) self.set_header("%s-%s" % (prefix, "File-Checksum"), self.checksum) self._response = self.send_http('POST', stream_body=f) f.close() payload_stream.close() retval = self.process_response() self.connection.close() return retval
def packages(self): self.setForce() # set the org self.setOrg() # set the URL self.setURL() # set the channels self.setChannels() # set the server self.setServer() # 12/22/05 wregglej 173287 authenticate the session. self.authenticate() # Do we have the new-style handler available? # ping the server for status self.warn(2, "url is", self.url_v2) ping = rhnpush_v2.PingPackageUpload(self.url_v2, self.options.proxy) self.ping_status, errmsg, headerinfo = ping.ping() self.warn(2, "Result codes:", self.ping_status, errmsg) # move patch clusters to the end because all the patches in the cluster # have to be pushed before the cluster itself files1 = [] files2 = [] for file in self.files: if file.startswith("patch-cluster-"): files2.append(file) else: files1.append(file) self.files = files1 + files2 channel_packages = [] # a little fault tolarence is in order random.seed() checkpkgflag = 0 tries = 3 # pkilambi:check if the Sat version we are talking to has this capability. # If not use the normal way to talk to older satellites(< 4.1.0). if headerinfo.getheader("X-RHN-Check-Package-Exists"): checkpkgflag = 1 (server_digest_hash, pkgs_info, digest_hash) = self.check_package_exists() for pkg in self.files: ret = None # pkilambi:errors off as not initialized.this fixes it. # temporary fix for picking pkgs instead of full paths pkg_key = (pkg.strip()).split("/")[-1] if checkpkgflag: # it's newer satellite, compute checksum checks on client. if not server_digest_hash.has_key(pkg_key): continue checksum_type, checksum = digest = digest_hash[pkg_key] server_digest = tuple(server_digest_hash[pkg_key]) # compare checksums for existance check if server_digest == digest and not self.options.force: channel_packages.append(pkgs_info[pkg_key]) self.warn(1, "Package %s already exists on the RHN Server-- Skipping Upload...." % pkg) continue elif server_digest == (): self.warn(1, "Package %s Not Found on RHN Server -- Uploading" % pkg) elif server_digest == "on-disk" and not self.options.force: channel_packages.append(pkgs_info[pkg_key]) self.warn(0, "Package on disk but not on db -- Skipping Upload " % pkg) continue elif server_digest != digest: if self.options.force: self.warn(1, "Package checksum %s mismatch -- Forcing Upload" % pkg) else: msg = ( """Error: Package %s already exists on the server with a different checksum. Skipping upload to prevent overwriting existing package. (You may use rhnpush with the --force option to force this upload if the force_upload option is enabled on your server.)\n""" % pkg ) if not self.options.tolerant: self.die(-1, msg) self.warn(0, msg) continue else: # it's an older satellite(< 4.1.0). Just do the push the usual old way, # without checksum pre-check. try: f = open(pkg) header, payload_stream = rhn_mpm.load(file=f) checksum_type = header.checksum_type() except rhn_mpm.InvalidPackageError, e: if not self.options.tolerant: self.die(-1, "ERROR: %s: This file doesn't appear to be a package" % pkg) self.warn(2, "ERROR: %s: This file doesn't appear to be a package" % pkg) continue except IOError: if not self.options.tolerant: self.die(-1, "ERROR: %s: No such file or directory available" % pkg) self.warn(2, "ERROR: %s: No such file or directory available" % pkg) continue checksum = getFileChecksum(checksum_type, file=payload_stream) f.close()