コード例 #1
0
ファイル: exthandlers.py プロジェクト: lingjunxu/WALinuxAgent
    def collect_ext_status(self, ext):
        self.logger.verbose("Collect extension status")

        seq_no = self.get_largest_seq_no()
        if seq_no == -1:
            return None

        status_dir = self.get_status_dir()
        ext_status_file = "{0}.status".format(seq_no)
        ext_status_file = os.path.join(status_dir, ext_status_file)

        ext_status = ExtensionStatus(seq_no=seq_no)
        try:
            data_str = fileutil.read_file(ext_status_file)
            data = json.loads(data_str)
            parse_ext_status(ext_status, data)
        except IOError as e:
            ext_status.message = u"Failed to get status file {0}".format(e)
            ext_status.code = -1
            ext_status.status = "error"
        except (ExtensionError, ValueError) as e:
            ext_status.message = u"Malformed status file {0}".format(e)
            ext_status.code = -1
            ext_status.status = "error"

        return ext_status
コード例 #2
0
    def collect_ext_status(self, ext):
        self.logger.verbose("Collect extension status")

        seq_no = self.get_largest_seq_no()
        if seq_no == -1:
            return None

        status_dir = self.get_status_dir()
        ext_status_file = "{0}.status".format(seq_no)
        ext_status_file = os.path.join(status_dir, ext_status_file)

        ext_status = ExtensionStatus(seq_no=seq_no)
        try:
            data_str = fileutil.read_file(ext_status_file)
            data = json.loads(data_str)
            parse_ext_status(ext_status, data)
        except IOError as e:
            ext_status.message = u"Failed to get status file {0}".format(e)
            ext_status.code = -1
            ext_status.status = "error"
        except (ExtensionError, ValueError) as e:
            ext_status.message = u"Malformed status file {0}".format(e)
            ext_status.code = -1
            ext_status.status = "error"

        return ext_status
コード例 #3
0
    def collect_ext_status(self, ext):
        self.logger.verbose("Collect extension status")

        seq_no, ext_status_file = self.get_status_file_path(ext)
        if seq_no == -1:
            return None

        ext_status = ExtensionStatus(seq_no=seq_no)
        try:
            data_str = fileutil.read_file(ext_status_file)
            data = json.loads(data_str)
            parse_ext_status(ext_status, data)
        except IOError as e:
            ext_status.message = u"Failed to get status file {0}".format(e)
            ext_status.code = -1
            ext_status.status = "error"
        except ExtensionError as e:
            ext_status.message = u"Malformed status file {0}".format(e)
            ext_status.code = e.code
            ext_status.status = "error"
        except ValueError as e:
            ext_status.message = u"Malformed status file {0}".format(e)
            ext_status.code = -1
            ext_status.status = "error"

        return ext_status
コード例 #4
0
    def collect_ext_status(self, ext):
        self.logger.verbose("Collect extension status")

        seq_no, ext_status_file = self.get_status_file_path(ext)
        if seq_no == -1:
            return None

        ext_status = ExtensionStatus(seq_no=seq_no)
        try:
            data_str = fileutil.read_file(ext_status_file)
            data = json.loads(data_str)
            parse_ext_status(ext_status, data)
        except IOError as e:
            ext_status.message = u"Failed to get status file {0}".format(e)
            ext_status.code = -1
            ext_status.status = "error"
        except ExtensionError as e:
            ext_status.message = u"Malformed status file {0}".format(e)
            ext_status.code = e.code
            ext_status.status = "error"
        except ValueError as e:
            ext_status.message = u"Malformed status file {0}".format(e)
            ext_status.code = -1
            ext_status.status = "error"

        return ext_status
コード例 #5
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)