def test_push_log_to_kvp(self, publish_event):
        reporter = HyperVKvpReportingHandler(kvp_file_path=self.tmp_file_path)
        try:
            instantiated_handler_registry.register_item("telemetry", reporter)
            log_file = self.tmp_path("cloud-init.log")
            azure.MAX_LOG_TO_KVP_LENGTH = 100
            azure.LOG_PUSHED_TO_KVP_INDEX_FILE = self.tmp_path(
                'log_pushed_to_kvp')
            with open(log_file, "w") as f:
                log_content = "A" * 50 + "B" * 100
                f.write(log_content)
            azure.push_log_to_kvp(log_file)

            with open(log_file, "a") as f:
                extra_content = "C" * 10
                f.write(extra_content)
            azure.push_log_to_kvp(log_file)

            for call_arg in publish_event.call_args_list:
                event = call_arg[0][0]
                self.assertNotEqual(
                    event.event_type, azure.COMPRESSED_EVENT_TYPE)
            self.validate_compressed_kvps(
                reporter, 2,
                [log_content[-azure.MAX_LOG_TO_KVP_LENGTH:].encode(),
                 extra_content.encode()])
        finally:
            instantiated_handler_registry.unregister_item("telemetry",
                                                          force=False)
Exemple #2
0
    def test_report_compressed_event(self):
        reporter = HyperVKvpReportingHandler(kvp_file_path=self.tmp_file_path)
        try:
            instantiated_handler_registry.register_item("telemetry", reporter)
            event_desc = b"test_compressed"
            azure.report_compressed_event("compressed event", event_desc)

            self.validate_compressed_kvps(reporter, 1, [event_desc])
        finally:
            instantiated_handler_registry.unregister_item("telemetry",
                                                          force=False)
Exemple #3
0
    def test_push_log_to_kvp_exception_handling(self, m_subp, m_diag, m_com):
        reporter = HyperVKvpReportingHandler(kvp_file_path=self.tmp_file_path)
        try:
            instantiated_handler_registry.register_item("telemetry", reporter)
            log_file = self.tmp_path("cloud-init.log")
            azure.MAX_LOG_TO_KVP_LENGTH = 100
            azure.LOG_PUSHED_TO_KVP_INDEX_FILE = self.tmp_path(
                "log_pushed_to_kvp")
            with open(log_file, "w") as f:
                log_content = "A" * 50 + "B" * 100
                f.write(log_content)

            m_com.side_effect = Exception("Mock Exception")
            azure.push_log_to_kvp(log_file)

            # exceptions will trigger diagnostic reporting calls
            self.assertEqual(m_diag.call_count, 3)
        finally:
            instantiated_handler_registry.unregister_item("telemetry",
                                                          force=False)