Пример #1
0
def parse_ext_substatus(substatus):
    # Check extension sub status format
    validate_has_key(substatus, "status", "substatus/status")
    validate_in_range(substatus["status"], VALID_EXTENSION_STATUS, "substatus/status")
    status = ExtensionSubStatus()
    status.name = substatus.get("name")
    status.status = substatus.get("status")
    status.code = substatus.get("code", 0)
    formatted_message = substatus.get("formattedMessage")
    status.message = parse_formatted_message(formatted_message)
    return status
Пример #2
0
def parse_ext_substatus(substatus):
    #Check extension sub status format
    validate_has_key(substatus, 'status', 'substatus/status')
    validate_in_range(substatus['status'], VALID_EXTENSION_STATUS,
                      'substatus/status')
    status = ExtensionSubStatus()
    status.name = substatus.get('name')
    status.status = substatus.get('status')
    status.code = substatus.get('code', 0)
    formatted_message = substatus.get('formattedMessage')
    status.message = parse_formatted_message(formatted_message)
    return status
Пример #3
0
def parse_ext_substatus(substatus):
    #Check extension sub status format
    validate_has_key(substatus, 'status', 'substatus/status')
    validate_in_range(substatus['status'], VALID_EXTENSION_STATUS,
                      'substatus/status')
    status = ExtensionSubStatus()
    status.name = substatus.get('name')
    status.status = substatus.get('status')
    status.code = substatus.get('code', 0)
    formatted_message = substatus.get('formattedMessage')
    status.message = parse_formatted_message(formatted_message)
    return status
Пример #4
0
    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)