def test_log_init_default_log_level(self): self.rhsm_config.set("logging", "default_log_level", "WARNING") logutil.init_logger() sm_logger = logging.getLogger("subscription_manager") rhsm_logger = logging.getLogger("rhsm-app") self.assertEqual(sm_logger.getEffectiveLevel(), logging.WARNING) self.assertEqual(rhsm_logger.getEffectiveLevel(), logging.WARNING)
def func_wrapper(*args, **kwargs): global injected if not injected: logutil.init_logger() from subscription_manager.injectioninit import init_dep_injection init_dep_injection() injected = True return func(*args, **kwargs)
def test_set_invalid_logger_level(self): test_logger_name = 'foobar' initial_level = logging.ERROR test_logger = logging.getLogger(test_logger_name) test_logger.setLevel(initial_level) config_level = logging.DEBUG self.rhsm_config.set('logging', test_logger_name, config_level) logutil.init_logger() self.assertNotEqual(test_logger.getEffectiveLevel(), config_level)
def test_set_valid_logger_level(self): logging_conf = [ ('subscription_manager.managercli', "ERROR"), ('rhsm', "WARNING"), ('rhsm-app', "CRITICAL"), ('rhsm-app.rhsmd', "DEBUG") ] for logger_name, log_level in logging_conf: self.rhsm_config.set('logging', logger_name, log_level) logutil.init_logger() for logger_name, log_level in logging_conf: real_log_level = logging.getLogger(logger_name).getEffectiveLevel() self.assertEqual(real_log_level, logging._checkLevel(log_level))
def main(): logutil.init_logger() log = logging.getLogger('rhsm-app.' + __name__) parser = OptionParser(usage=USAGE, formatter=WrappedIndentedHelpFormatter()) parser.add_option("--autoheal", dest="autoheal", action="store_true", default=False, help="perform an autoheal check") (options, args) = parser.parse_args() try: _main(options, log) except SystemExit as se: # sys.exit triggers an exception in older Python versions, which # in this case we can safely ignore as we do not want to log the # stack trace. We need to check the code, since we want to signal # exit with failure to the caller. Otherwise, we will exit with 0 if se.code: sys.exit(-1) except Exception as e: log.error("Error while updating certificates using daemon") print(_('Unable to update entitlement certificates and repositories')) log.exception(e) sys.exit(-1)
except connection.ExpiredIdentityCertException, e: log.critical(_("Your identity certificate has expired")) raise e except connection.GoneException, ge: uuid = ConsumerIdentity.read().getConsumerId() if ge.deleted_id == uuid: log.critical(_("This consumer's profile has been deleted from the server. Its local certificates will now be archived")) managerlib.clean_all_data() log.critical(_("Certificates archived to '/etc/pki/consumer.old'. Contact your system administrator if you need more information.")) raise ge if __name__ == '__main__': logutil.init_logger() log = logging.getLogger('rhsm-app.' + __name__) parser = OptionParser(usage=USAGE, formatter=WrappedIndentedHelpFormatter()) parser.add_option("--autoheal", dest="autoheal", action="store_true", default=False, help="perform an autoheal check") (options, args) = parser.parse_args() try: main(options, log) except SystemExit, se: # sys.exit triggers an exception in older Python versions, which # in this case we can safely ignore as we do not want to log the # stack trace. We need to check the code, since we want to signal # exit with failure to the caller. Otherwise, we will exit with 0 if se.code:
def test_do_not_modify_root_logger(self): root_handlers = logging.getLogger().handlers logutil.init_logger() self.assert_items_equals(logging.getLogger().handlers, root_handlers)
def test_log_init(self): logutil.init_logger() sm_logger = logging.getLogger("subscription_manager") rhsm_logger = logging.getLogger("rhsm-app") self.assertEqual(sm_logger.getEffectiveLevel(), logging.DEBUG) self.assertEqual(rhsm_logger.getEffectiveLevel(), logging.DEBUG)
# granted to use or replicate Red Hat trademarks that are incorporated # in this software or its documentation. # import syslog import gobject import dbus import dbus.service import dbus.glib import logging import sys sys.path.append("/usr/share/rhsm") from subscription_manager.logutil import init_logger init_logger() log = logging.getLogger('rhsm-app.' + __name__) from subscription_manager.injectioninit import init_dep_injection init_dep_injection() from subscription_manager.certlib import ConsumerIdentity from subscription_manager.branding import get_branding from subscription_manager.injection import require, CERT_SORTER from subscription_manager.hwprobe import ClassicCheck from subscription_manager.i18n_optparse import OptionParser, \ WrappedIndentedHelpFormatter, USAGE from subscription_manager.cert_sorter import RHSM_VALID, \ RHSM_EXPIRED, RHSM_WARNING, RHSM_PARTIALLY_VALID, \ RHN_CLASSIC, RHSM_REGISTRATION_REQUIRED
def test_init_logger_debug(self): with mock.patch.dict('os.environ', {'SUBMAN_DEBUG': '1'}): logutil.init_logger() debug_logger = logging.getLogger() self.assertEqual(debug_logger.getEffectiveLevel(), logging.DEBUG)
def test_init_logger(self): logutil.init_logger() sm_logger = logging.getLogger("subscription_manager") rhsm_logger = logging.getLogger("rhsm") self.assertEqual(sm_logger.getEffectiveLevel(), logutil.LOG_LEVEL) self.assertEqual(rhsm_logger.getEffectiveLevel(), logutil.LOG_LEVEL)
# # However... If we get a GoneException and it's deleted_id does not match the current # consumer uuid, we do not delete the consumer. That would require using a valid consumer # cert, but making a request for a different consumer uuid, so unlikely. Could register # with --consumerid get there? if ge.deleted_id == uuid: log.critical("Consumer profile \"%s\" has been deleted from the server. Its local certificates will now be archived", uuid) managerlib.clean_all_data() log.critical("Certificates archived to '/etc/pki/consumer.old'. Contact your system administrator if you need more information.") raise ge if __name__ == '__main__': logutil.init_logger() log = logging.getLogger('rhsm-app.' + __name__) parser = OptionParser(usage=USAGE, formatter=WrappedIndentedHelpFormatter()) parser.add_option("--autoheal", dest="autoheal", action="store_true", default=False, help="perform an autoheal check") (options, args) = parser.parse_args() try: main(options, log) except SystemExit as se: # sys.exit triggers an exception in older Python versions, which # in this case we can safely ignore as we do not want to log the # stack trace. We need to check the code, since we want to signal # exit with failure to the caller. Otherwise, we will exit with 0 if se.code: