def set_handler_status(self, status="NotReady", message="", code=0): state_dir = self.get_conf_dir() handler_status = ExtHandlerStatus() handler_status.name = self.ext_handler.name handler_status.version = self.ext_handler.properties.version handler_status.message = message handler_status.code = code handler_status.status = status status_file = os.path.join(state_dir, "HandlerStatus") try: fileutil.write_file(status_file, json.dumps(get_properties(handler_status))) except (IOError, ValueError, ProtocolError) as e: self.logger.error("Failed to save handler status: {0}", e)
def set_handler_status(self, status="NotReady", message="", code=0): state_dir = self.get_conf_dir() handler_status = ExtHandlerStatus() handler_status.name = self.ext_handler.name handler_status.version = str(self.ext_handler.properties.version) handler_status.message = message handler_status.code = code handler_status.status = status status_file = os.path.join(state_dir, "HandlerStatus") try: handler_status_json = json.dumps(get_properties(handler_status)) if handler_status_json is not None: fileutil.write_file(status_file, handler_status_json) else: self.logger.error("Failed to create JSON document of handler status for {0} version {1}".format( self.ext_handler.name, self.ext_handler.properties.version)) except (IOError, ValueError, ProtocolError) as e: fileutil.clean_ioerror(e, paths=[status_file]) self.logger.error("Failed to save handler status: {0}, {1}", ustr(e), traceback.format_exc())
def test_add_extension_observation(self): handler_status = ExtHandlerStatus() handler_status.name = "Name" handler_status.version = "1.0" handler_status.code = 0 handler_status.status = "Unresponsive" healthObserver = ExtensionHealthObserver() healthObserver.add_extension_observation(handler_status, []) # validate that 2 observations were made - one for the handler version, and one for the handler being in a failed state self.assertEqual(2, len(healthObserver.partial_observations)) self.assertEqual( ExtensionHealthObserver.CONTEXT_OBSERVATION + handler_status.name, healthObserver.partial_observations[0].name) self.assertEqual(handler_status.version, healthObserver.partial_observations[0].value) self.assertEqual(True, healthObserver.partial_observations[0].is_healthy) # unhealthy handler self.assertEqual(handler_status.name, healthObserver.partial_observations[1].name) self.assertEqual(False, healthObserver.partial_observations[1].is_healthy) handler_status.status = "Ready" healthObserver = ExtensionHealthObserver() healthObserver.add_extension_observation(handler_status, []) # validate that 2 observations were made - one for the handler version, and one for the handler being in a failed state self.assertEqual(2, len(healthObserver.partial_observations)) self.assertEqual( ExtensionHealthObserver.CONTEXT_OBSERVATION + handler_status.name, healthObserver.partial_observations[0].name) self.assertEqual(handler_status.version, healthObserver.partial_observations[0].value) self.assertEqual(True, healthObserver.partial_observations[0].is_healthy) # healthy handler self.assertEqual(handler_status.name, healthObserver.partial_observations[1].name) self.assertEqual(True, healthObserver.partial_observations[1].is_healthy) # add in an extension status ext_status = ExtensionStatus(seq_no=0) ext_status.status = "Error" ext_status.code = 0 healthObserver = ExtensionHealthObserver() healthObserver.add_extension_observation(handler_status, [ext_status]) # validate that 3 observations were made - one for the handler version, and one for the handler being in a success state, and one for # the extension self.assertEqual(3, len(healthObserver.partial_observations)) # unhealthy extension self.assertEqual( handler_status.name + ExtensionHealthObserver.STATUS_SUFFIX, healthObserver.partial_observations[2].name) self.assertEqual(False, healthObserver.partial_observations[2].is_healthy) ext_status.status = "Succeeded" healthObserver = ExtensionHealthObserver() healthObserver.add_extension_observation(handler_status, [ext_status]) # validate that 3 observations were made - one for the handler version, and one for the handler being in a success state, and one for # the extension self.assertEqual(3, len(healthObserver.partial_observations)) # healthy extension self.assertEqual( handler_status.name + ExtensionHealthObserver.STATUS_SUFFIX, healthObserver.partial_observations[2].name) self.assertEqual(True, healthObserver.partial_observations[2].is_healthy) substatus = ExtensionSubStatus() substatus.code = 0 substatus.status = "Error" ext_status.substatusList.append(substatus) healthObserver = ExtensionHealthObserver() healthObserver.add_extension_observation(handler_status, [ext_status]) # validate that 4 observations were made - one for the handler version, and one for the handler being in a success state, and one for # the extension self.assertEqual(4, len(healthObserver.partial_observations)) # unhealthy extension substatus self.assertEqual( handler_status.name + ExtensionHealthObserver.SUBSTATUS_SUFFIX, healthObserver.partial_observations[3].name) self.assertEqual(False, healthObserver.partial_observations[3].is_healthy) substatus.status = "Succeeded" ext_status.substatusList.append(substatus) healthObserver = ExtensionHealthObserver() healthObserver.add_extension_observation(handler_status, [ext_status]) # validate that 4 observations were made - one for the handler version, and one for the handler being in a success state, and one for # the extension self.assertEqual(4, len(healthObserver.partial_observations)) # unhealthy extension substatus self.assertEqual( handler_status.name + ExtensionHealthObserver.SUBSTATUS_SUFFIX, healthObserver.partial_observations[3].name) self.assertEqual(True, healthObserver.partial_observations[3].is_healthy)