def _push_package_v2(self, package, fileChecksumType, fileChecksum): self.warn(1, "Using POST request") pu = rhnpush_v2.PackageUpload(self.url_v2, self.options.proxy) pu.set_session(self.session.getSessionString()) pu.set_force(self.options.force) pu.set_null_org(self.options.nullorg) pu.set_timeout(self.options.timeout) status, msgstr = pu.upload(package, fileChecksumType, fileChecksum) ret = {} for tag in ('name', 'version', 'release', 'epoch', 'arch'): val = getattr(pu, "package_%s" % tag) if val is None: val = '' ret[tag] = val ret['checksum_type'] = fileChecksumType ret['checksum'] = fileChecksum if status == 400: # Bad request - something bad happened try: data = rpclib.xmlrpclib.loads(msgstr) except: # Raise the exception instead of silently dying raise uploadLib.UploadError( "Error pushing %s: %s (%s)" % (package, msgstr, status)), None, sys.exc_info()[2] (diff_dict, ), methodname = data del methodname diff_level = diff_dict['level'] pdict = diff_dict['diff'] raise uploadLib.UploadError(ret, diff_level, pdict) if status == 403: # auth expired raise an exception to grab one raise AuthenticationRequired() if status != 200: self.die(1, "Error pushing %s: %s (%s)" % (package, msgstr, status)) return ret
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) ping_status, errmsg, headerinfo = ping.ping() self.warn(2, "Result codes:", 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 filename in self.files: if filename.startswith('patch-cluster-'): files2.append(filename) else: files1.append(filename) self.files = files1 + files2 channel_packages = [] # a little fault tolarence is in order random.seed() tries = 3 # satellites < 4.1.0 are no more supported if not headerinfo.getheader('X-RHN-Check-Package-Exists'): self.die(-1, "Pushing to Satellite < 4.1.0 is not supported.") (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 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 for _t in range(0, tries): try: ret = self.package(pkg, checksum_type, checksum) if ret is None: raise uploadLib.UploadError() # TODO: Revisit this. We throw this error all over the place, # but doing so will cause us to skip the --tolerant logic # below. I don't think we really want this behavior. # There are some cases where we don't want to retry 3 # times, but not at the expense of disabling the tolerant # flag, IMHO. This loop needs some lovin'. -- pav #FIX: it checks for tolerant flag and aborts only if the flag is #not specified except uploadLib.UploadError, ue: if not self.options.tolerant: self.die(1, ue) self.warn(2, ue) except AuthenticationRequired: #session expired so we re-authenticate for the process to complete #this uses the username and password from memory if available #else it prompts for one. self.authenticate() except:
try: h = uploadLib.get_header(package, source=self.options.source) except uploadLib.InvalidPackageError, e: # GS: MALFORMED PACKAGE print "Unable to load package", package return None if hasattr(h, 'packaging'): packaging = h.packaging else: packaging = 'rpm' if packaging == 'rpm' and self.options.nosig is None and not h.is_signed( ): #pkilambi:bug#173886:force exit to check for sig if --nosig raise uploadLib.UploadError( "ERROR: %s: unsigned rpm (use --nosig to force)" % package) try: ret = self._push_package_v2(package, fileChecksumType, fileChecksum) except uploadLib.UploadError, e: ret, diff_level, pdict = e.args[:3] severities = { 1: 'path changed', 2: 'package resigned', 3: 'differing build times or hosts', 4: 'package recompiled', } if severities.has_key(diff_level): strmsg = \ "Error: Package with same name already exists on " + \