def test_he_restlib_exception_unicode(self): e = connection.RestlibException(404, "Ошибка при обновлении системных данных (см. /var/log/rhsm/rhsm.log") try: managercli.handle_exception("обновлении", e) except SystemExit, e: self.assertEquals(e.code, -1)
def test_he_unicode(self): e = Exception("Ошибка при обновлении системных данных (см. /var/log/rhsm/rhsm.log") # e = FakeException(msg="Ошибка при обновлении системных данных (см. /var/log/rhsm/rhsm.log") try: managercli.handle_exception("a: %s" % e, e) except SystemExit, e: self.assertEquals(e.code, -1)
def test_he_ssl_wrong_host(self): e = SSL.Checker.WrongHost("expectedHost.example.com", "actualHost.example.com", "subjectAltName") try: managercli.handle_exception("huh", e) except SystemExit, e: self.assertEquals(e.code, -1)
def test_he_socket_error(self): # these error messages are bare strings, so we need to update the tests # if those messages change expected_msg = 'Network error, unable to connect to server. Please see /var/log/rhsm/rhsm.log for more information.' managercli.log.set_expected_msg(expected_msg) try: managercli.handle_exception(self.msg, socket.error()) except SystemExit, e: self.assertEquals(e.code, -1)
def test_he_bad_certificate(self): e = connection.BadCertificateException("/road/to/nowhwere") try: managercli.handle_exception("huh", e) except SystemExit, e: self.assertEquals(e.code, -1)
except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except ImportError as err: system_exit( 2, "Unable to find Subscription Manager module.\n" "Error: %s" % err) def main(): # execute try: return managercli.ManagerCLI().main() except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") return 0 if __name__ == '__main__': try: sys.exit(abs(main() or 0)) except SystemExit as err: # This is a non-exceptional exception thrown by Python 2.4, just # re-raise, bypassing handle_exception raise err except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except Exception as e: handle_exception("exception caught in subscription-manager", e)
# NOTE: this will fail across filesystems. We could add a force # flag to for creation of a specific name with approriate # warnings. dest_dir_name = os.path.join(self.options.destination, archive_name) # create the dest dir, and set it's perms, this is atomic ish self._makedir(dest_dir_name) # try to rename the dir atomically # rename only works on the same filesystem, but it is atomic. os.rename(content_path, dest_dir_name) print _("Wrote: %s/%s") % (self.options.destination, archive_name) except Exception, e: managercli.handle_exception(_("Unable to create zip file of system information: %s") % e, e) sys.exit(-1) finally: if assemble_path and os.path.exists(assemble_path): shutil.rmtree(assemble_path, True) def _make_code(self): return datetime.now().strftime("%Y%m%d-%f") def _get_version_info(self): return { "server type": self.server_versions["server-type"], "subscription management server": self.server_versions["candlepin"], "subscription-manager": self.client_versions["subscription-manager"], "python-rhsm": self.client_versions["python-rhsm"], }
def _do_command(self): self.options.destination = os.path.expanduser(self.options.destination) self._validate_options() consumer = inj.require(inj.IDENTITY) if not consumer.is_valid(): system_exit(ERR_NOT_REGISTERED_CODE, ERR_NOT_REGISTERED_MSG) code = self._make_code() archive_name = "rhsm-debug-system-%s" % code tar_file_name = "%s.tar.gz" % archive_name # /var/spool/rhsm/debug/rhsm-debug-system-20131212-121234/ content_path = os.path.join(self.assemble_path, archive_name) # /var/spool/rhsm/debug/rhsm-debug-system-20131212-123413.tar.gz tar_file_path = os.path.join(self.assemble_path, tar_file_name) try: # assemble path is in the package, so should always exist self._makedir(content_path) owner = self.cp.getOwner(consumer.uuid) self._write_flat_file(content_path, "consumer.json", self.cp.getConsumer(consumer.uuid)) self._write_flat_file(content_path, "compliance.json", self.cp.getCompliance(consumer.uuid)) self._write_flat_file(content_path, "entitlements.json", self.cp.getEntitlementList(consumer.uuid)) self._write_flat_file( content_path, "pools.json", self.cp.getPoolsList(consumer.uuid, True, None, owner['key'])) self._write_flat_file(content_path, "version.json", self._get_version_info()) # FIXME: we need to anon proxy passwords? sos = self.options.sos defaults = conf.defaults() # sosreport collects /etc/rhsm/* and /var/*/rhsm/*, so these would # be redundant for sos if not sos: # copy rhsm.conf specifically self._copy_cert_directory("/etc/rhsm", content_path) self._copy_directory('/var/log/rhsm', content_path) self._copy_directory('/var/lib/rhsm', content_path) if not sos: self._copy_cert_directory(DEFAULT_PRODUCT_CERT_DIR, content_path) if defaults['productcertdir'] != conf['rhsm'][ 'productCertDir'] or not sos: self._copy_cert_directory(conf['rhsm']['productCertDir'], content_path) if defaults['entitlementcertdir'] != conf['rhsm'][ 'entitlementCertDir'] or not sos: self._copy_cert_directory(conf['rhsm']['entitlementCertDir'], content_path) if defaults['consumercertdir'] != conf['rhsm'][ 'consumerCertDir'] or not sos: self._copy_cert_directory(conf['rhsm']['consumerCertDir'], content_path) # If ca_cert_dir and pluginconfdif are configured as subdirs of /etc/rhsm # (as is the default) we will have already copied there contents, # so ignore directory exists errors try: if defaults['ca_cert_dir'] != conf['rhsm'][ 'ca_cert_dir'] or not sos: self._copy_cert_directory(conf['rhsm']['ca_cert_dir'], content_path) except EnvironmentError as e: if e.errno != errno.EEXIST: raise try: if defaults['pluginconfdir'] != conf['rhsm'][ 'pluginconfdir'] or not sos: self._copy_directory(conf['rhsm']['pluginconfdir'], content_path) except EnvironmentError as e: if e.errno != errno.EEXIST: raise # build an archive by default if self.options.archive: try: tf = tarfile.open(tar_file_path, "w:gz") tf.add(content_path, archive_name) finally: tf.close() final_path = os.path.join(self.options.destination, "rhsm-debug-system-%s.tar.gz" % code) self.final_destination_path = final_path sfm = SaferFileMove() sfm.move(tar_file_path, final_path) print(_("Wrote: %s") % final_path) else: # NOTE: this will fail across filesystems. We could add a force # flag to for creation of a specific name with approriate # warnings. dest_dir_name = os.path.join(self.options.destination, archive_name) # create the dest dir, and set it's perms, this is atomic ish self._makedir(dest_dir_name) # try to rename the dir atomically # rename only works on the same filesystem, but it is atomic. os.rename(content_path, dest_dir_name) print(_("Wrote: %s") % dest_dir_name) except Exception as e: managercli.handle_exception( _("Unable to create zip file of system information: %s") % e, e) sys.exit(os.EX_SOFTWARE) finally: if content_path and os.path.isdir(content_path): shutil.rmtree(content_path, True)
dest_dir_name = os.path.join(self.options.destination, archive_name) # create the dest dir, and set it's perms, this is atomic ish self._makedir(dest_dir_name) # try to rename the dir atomically # rename only works on the same filesystem, but it is atomic. os.rename(content_path, dest_dir_name) print _("Wrote: %s/%s") % (self.options.destination, archive_name) except Exception, e: managercli.handle_exception( _("Unable to create zip file of system information: %s") % e, e) sys.exit(-1) finally: if assemble_path and os.path.exists(assemble_path): shutil.rmtree(assemble_path, True) def _make_code(self): return datetime.now().strftime("%Y%m%d-%f") def _get_version_info(self): return { "server type": self.server_versions["server-type"], "subscription management server": self.server_versions["candlepin"], "subscription-manager":
def _do_command(self): self.options.destination = os.path.expanduser(self.options.destination) self._validate_options() consumer = inj.require(inj.IDENTITY) if not consumer.is_valid(): system_exit(ERR_NOT_REGISTERED_CODE, ERR_NOT_REGISTERED_MSG) code = self._make_code() archive_name = "rhsm-debug-system-%s" % code tar_file_name = "%s.tar.gz" % archive_name # /var/spool/rhsm/debug/rhsm-debug-system-20131212-121234/ content_path = os.path.join(self.assemble_path, archive_name) # /var/spool/rhsm/debug/rhsm-debug-system-20131212-123413.tar.gz tar_file_path = os.path.join(self.assemble_path, tar_file_name) try: # assemble path is in the package, so should always exist self._makedir(content_path) owner = self.cp.getOwner(consumer.uuid) self._write_flat_file(content_path, "consumer.json", self.cp.getConsumer(consumer.uuid)) self._write_flat_file(content_path, "compliance.json", self.cp.getCompliance(consumer.uuid)) self._write_flat_file(content_path, "entitlements.json", self.cp.getEntitlementList(consumer.uuid)) self._write_flat_file(content_path, "pools.json", self.cp.getPoolsList(consumer.uuid, True, None, owner['key'])) self._write_flat_file(content_path, "version.json", self._get_version_info()) # FIXME: we need to anon proxy passwords? sos = self.options.sos defaults = conf.defaults() # sosreport collects /etc/rhsm/* and /var/*/rhsm/*, so these would # be redundant for sos if not sos: # copy rhsm.conf specifically self._copy_cert_directory("/etc/rhsm", content_path) self._copy_directory('/var/log/rhsm', content_path) self._copy_directory('/var/lib/rhsm', content_path) if not sos: self._copy_cert_directory(DEFAULT_PRODUCT_CERT_DIR, content_path) if defaults['productcertdir'] != conf['rhsm']['productCertDir'] or not sos: self._copy_cert_directory(conf['rhsm']['productCertDir'], content_path) if defaults['entitlementcertdir'] != conf['rhsm']['entitlementCertDir'] or not sos: self._copy_cert_directory(conf['rhsm']['entitlementCertDir'], content_path) if defaults['consumercertdir'] != conf['rhsm']['consumerCertDir'] or not sos: self._copy_cert_directory(conf['rhsm']['consumerCertDir'], content_path) # If ca_cert_dir and pluginconfdif are configured as subdirs of /etc/rhsm # (as is the default) we will have already copied there contents, # so ignore directory exists errors try: if defaults['ca_cert_dir'] != conf['rhsm']['ca_cert_dir'] or not sos: self._copy_cert_directory(conf['rhsm']['ca_cert_dir'], content_path) except EnvironmentError as e: if e.errno != errno.EEXIST: raise try: if defaults['pluginconfdir'] != conf['rhsm']['pluginconfdir'] or not sos: self._copy_directory(conf['rhsm']['pluginconfdir'], content_path) except EnvironmentError as e: if e.errno != errno.EEXIST: raise # build an archive by default if self.options.archive: try: tf = tarfile.open(tar_file_path, "w:gz") tf.add(content_path, archive_name) finally: tf.close() final_path = os.path.join(self.options.destination, "rhsm-debug-system-%s.tar.gz" % code) self.final_destination_path = final_path sfm = SaferFileMove() sfm.move(tar_file_path, final_path) print(_("Wrote: %s") % final_path) else: # NOTE: this will fail across filesystems. We could add a force # flag to for creation of a specific name with approriate # warnings. dest_dir_name = os.path.join(self.options.destination, archive_name) # create the dest dir, and set it's perms, this is atomic ish self._makedir(dest_dir_name) # try to rename the dir atomically # rename only works on the same filesystem, but it is atomic. os.rename(content_path, dest_dir_name) print(_("Wrote: %s") % dest_dir_name) except Exception as e: managercli.handle_exception(_("Unable to create zip file of system information: %s") % e, e) sys.exit(os.EX_SOFTWARE) finally: if content_path and os.path.isdir(content_path): shutil.rmtree(content_path, True)
def test_he_network_exception(self): e = connection.NetworkException(1337) try: managercli.handle_exception("huh", e) except SystemExit, e: self.assertEquals(e.code, -1)
from subscription_manager.migrate import migrate from subscription_manager.managercli import handle_exception except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except ImportError as err: system_exit(2, "Unable to find Subscription Manager module.\n" "Error: %s" % err) def main(): # execute try: return migrate.main() except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") return 0 if __name__ == '__main__': try: sys.exit(abs(main() or 0)) except SystemExit as sys_err: # this is a non-exceptional exception thrown by Python 2.4, just # re-raise, bypassing handle_exception raise sys_err except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except Exception as err: handle_exception("Exception caught in rhm-migrate-classic-to-rhsm", err)
ga_loader.init_ga() except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except ImportError as err: system_exit(2, "Unable to find Subscription Manager module.\n" "Error: %s" % err) def main(): # execute try: return managercli.ManagerCLI().main() except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") return 0 if __name__ == '__main__': try: sys.exit(abs(main() or 0)) except SystemExit as err: # This is a non-exceptional exception thrown by Python 2.4, just # re-raise, bypassing handle_exception raise err except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except Exception as e: handle_exception("exception caught in subscription-manager", e)
def test_he_restlib_exception(self): e = connection.RestlibException(404, "this is a msg") try: managercli.handle_exception("huh", e) except SystemExit, e: self.assertEquals(e.code, -1)
def test_he(self): e = FakeException() try: managercli.handle_exception(self.msg, e) except SystemExit, e: self.assertEquals(e.code, -1)
except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except ImportError as err: system_exit( 2, "Unable to find Subscription Manager module.\n" "Error: %s" % err) def main(): # execute try: return migrate.main() except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") return 0 if __name__ == '__main__': try: sys.exit(abs(main() or 0)) except SystemExit as sys_err: # this is a non-exceptional exception thrown by Python 2.4, just # re-raise, bypassing handle_exception raise sys_err except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except Exception as err: handle_exception("Exception caught in rhm-migrate-classic-to-rhsm", err)
from subscription_manager.managercli import handle_exception except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except ImportError as err: system_exit(2, "Unable to find Subscription Manager module.\n" "Error: %s" % err) def main(): # execute try: return migrate.main(five_to_six_script=True) except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") return 0 if __name__ == '__main__': try: sys.exit(abs(main() or 0)) except SystemExit as e: # this is a non-exceptional exception thrown by Python 2.4, just # re-raise, bypassing handle_exception raise e except KeyboardInterrupt: system_exit(0, "\nUser interrupted process.") except Exception as e: handle_exception("Exception caught in sat5to6", e)
def test_he_remote_server_exception(self): e = connection.RemoteServerException(1984) try: managercli.handle_exception("huh", e) except SystemExit, e: self.assertEquals(e.code, -1)
def test_he_ssl_error(self): e = SSL.SSLError() try: managercli.handle_exception("huh", e) except SystemExit, e: self.assertEquals(e.code, -1)