Exemple #1
0
    def run_exthandlers(self, debug=False):
        """
        Run the update and extension handler
        """
        logger.set_prefix("ExtHandler")
        threading.current_thread().setName("ExtHandler")

        #
        # Agents < 2.2.53 used to echo the log to the console. Since the extension handler could have been started by
        # one of those daemons, output a message indicating that output to the console will stop, otherwise users
        # may think that the agent died if they noticed that output to the console stops abruptly.
        #
        # Feel free to remove this code if telemetry shows there are no more agents <= 2.2.53 in the field.
        #
        if conf.get_logs_console(
        ) and get_daemon_version() < FlexibleVersion("2.2.53"):
            self.__add_console_appender(logger.LogLevel.INFO)
            try:
                logger.info(
                    u"The agent will now check for updates and then will process extensions. Output to /dev/console will be suspended during those operations."
                )
            finally:
                logger.disable_console_output()

        from azurelinuxagent.ga.update import get_update_handler
        update_handler = get_update_handler()
        update_handler.run(debug)
Exemple #2
0
    def test_telemetry_logger_add_log_event(self, mock_lib_dir, *_):
        mock_lib_dir.return_value = self.lib_dir
        __event_logger__.event_dir = self.event_dir
        prefix = "YoloLogger"

        logger.add_logger_appender(logger.AppenderType.TELEMETRY,
                                   logger.LogLevel.WARNING,
                                   path=add_log_event)
        logger.set_prefix(prefix)

        logger.warn('Test Log - Warning')

        event_files = os.listdir(__event_logger__.event_dir)
        self.assertEqual(1, len(event_files))

        log_file_event = os.path.join(__event_logger__.event_dir,
                                      event_files[0])
        try:
            with open(log_file_event) as logfile:
                logcontent = logfile.read()
                # Checking the contents of the event file.
                self.assertIn("Test Log - Warning", logcontent)
        except Exception as e:
            self.assertFalse(
                True,
                "The log file looks like it isn't correctly setup for this test. Take a look. "  # pylint: disable=redundant-unittest-assert
                "{0}".format(e))
Exemple #3
0
 def run_exthandlers(self):
     """
     Run the update and extension handler
     """
     logger.set_prefix("Upd/Ext-Handler")
     from azurelinuxagent.ga.update import get_update_handler
     update_handler = get_update_handler()
     update_handler.run()
Exemple #4
0
 def run_exthandlers(self, debug=False):
     """
     Run the update and extension handler
     """
     logger.set_prefix("ExtHandler")
     from azurelinuxagent.ga.update import get_update_handler
     update_handler = get_update_handler()
     update_handler.run(debug)
Exemple #5
0
 def run_exthandlers(self, debug=False):
     """
     Run the update and extension handler
     """
     logger.set_prefix("ExtHandler")
     from azurelinuxagent.ga.update import get_update_handler
     update_handler = get_update_handler()
     update_handler.run(debug)
Exemple #6
0
    def daemon(self):
        """
        Run agent daemon
        """
        logger.set_prefix("Daemon")
        child_args = None \
            if self.conf_file_path is None \
                else "-configuration-path:{0}".format(self.conf_file_path)

        from azurelinuxagent.daemon import get_daemon_handler
        daemon_handler = get_daemon_handler()
        daemon_handler.run(child_args=child_args)
Exemple #7
0
    def daemon(self):
        """
        Run agent daemon
        """
        logger.set_prefix("Daemon")
        child_args = None \
            if self.conf_file_path is None \
                else "-configuration-path:{0}".format(self.conf_file_path)

        from azurelinuxagent.daemon import get_daemon_handler
        daemon_handler = get_daemon_handler()
        daemon_handler.run(child_args=child_args)
Exemple #8
0
    def test_telemetry_logger_check_all_file_logs_written_when_events_gt_MAX_NUMBER_OF_EVENTS(
            self, mock_lib_dir, *_):
        mock_lib_dir.return_value = self.lib_dir
        __event_logger__.event_dir = self.event_dir
        no_of_log_statements = MAX_NUMBER_OF_EVENTS + 100
        exception_caught = False
        prefix = "YoloLogger"

        logger.add_logger_appender(logger.AppenderType.FILE,
                                   logger.LogLevel.INFO,
                                   path=self.log_file)
        logger.add_logger_appender(logger.AppenderType.TELEMETRY,
                                   logger.LogLevel.WARNING,
                                   path=add_log_event)
        logger.set_prefix(prefix)

        # Calling logger.warn no_of_log_statements times would cause the telemetry appender to writing
        # 1000 events into the events dir, and then drop the remaining events. It should not generate the RuntimeError
        try:
            for i in range(0, no_of_log_statements):
                logger.warn('Test Log - {0} - 1 - Warning'.format(i))
        except RuntimeError:
            exception_caught = True

        self.assertFalse(
            exception_caught,
            msg="Caught a Runtime Error. This should not have been raised.")
        self.assertEqual(MAX_NUMBER_OF_EVENTS,
                         len(os.listdir(__event_logger__.event_dir)))

        try:
            with open(self.log_file) as logfile:
                logcontent = logfile.readlines()

                # Checking the last log entry.
                # Subtracting 1 as range is exclusive of the upper bound
                self.assertIn(
                    "WARNING {1} Test Log - {0} - 1 - Warning".format(
                        no_of_log_statements - 1, prefix), logcontent[-1])

                # Checking the 1001st log entry. We know that 1001st entry would generate a PERIODIC message of too many
                # events, which should be captured in the log file as well.
                self.assertRegex(
                    logcontent[1001],
                    r"(.*WARNING\s*{0}\s*\[PERIODIC\]\s*Too many files under:.*{1}, "
                    r"current count\:\s*\d+,\s*removing oldest\s*.*)".format(
                        prefix, self.event_dir))
        except Exception as e:
            self.assertFalse(
                True,
                "The log file looks like it isn't correctly setup for this test. "  # pylint: disable=redundant-unittest-assert
                "Take a look. {0}".format(e))
Exemple #9
0
 def daemon(self):
     """
     Run agent daemon
     """
     set_daemon_version(AGENT_VERSION)
     logger.set_prefix("Daemon")
     threading.current_thread().setName("Daemon")
     child_args = None \
         if self.conf_file_path is None \
             else "-configuration-path:{0}".format(self.conf_file_path)
     from azurelinuxagent.daemon import get_daemon_handler
     daemon_handler = get_daemon_handler()
     daemon_handler.run(child_args=child_args)
Exemple #10
0
    def test_nested_logger(self, mock_file_write, mock_console_write,
                           mock_telem_write, mock_stdout_write):
        """
        The purpose of this test is to see if the logger gets correctly created when passed it another logger and also
        if the appender correctly gets the messages logged. This is how the ExtHandlerInstance logger works.

        I initialize the default logger(logger), then create a new logger(lg) from it, and then log using logger & lg.
        See if both logs are flowing through or not.
        """

        parent_prefix = "ParentLogger"
        child_prefix = "ChildLogger"

        logger.add_logger_appender(logger.AppenderType.FILE,
                                   logger.LogLevel.INFO,
                                   path=self.log_file)
        logger.add_logger_appender(logger.AppenderType.TELEMETRY,
                                   logger.LogLevel.WARNING,
                                   path=add_log_event)
        logger.add_logger_appender(logger.AppenderType.CONSOLE,
                                   logger.LogLevel.WARNING,
                                   path="/dev/null")
        logger.add_logger_appender(logger.AppenderType.STDOUT,
                                   logger.LogLevel.WARNING)
        logger.set_prefix(parent_prefix)

        lg = logger.Logger(logger.DEFAULT_LOGGER, child_prefix)

        lg.error("Test Log")
        self.assertEqual(1, mock_file_write.call_count)
        self.assertEqual(1, mock_console_write.call_count)
        self.assertEqual(1, mock_telem_write.call_count)
        self.assertEqual(1, mock_stdout_write.call_count)

        self.assertIn(child_prefix, mock_file_write.call_args[0][1])
        self.assertIn(child_prefix, mock_console_write.call_args[0][1])
        self.assertIn(child_prefix, mock_telem_write.call_args[0][1])
        self.assertIn(child_prefix, mock_stdout_write.call_args[0][1])

        logger.error("Test Log")
        self.assertEqual(2, mock_file_write.call_count)
        self.assertEqual(2, mock_console_write.call_count)
        self.assertEqual(2, mock_telem_write.call_count)
        self.assertEqual(2, mock_stdout_write.call_count)

        self.assertIn(parent_prefix, mock_file_write.call_args[0][1])
        self.assertIn(parent_prefix, mock_console_write.call_args[0][1])
        self.assertIn(parent_prefix, mock_telem_write.call_args[0][1])
        self.assertIn(parent_prefix, mock_stdout_write.call_args[0][1])