def takeSnapshotFromOnlyHost(self):
        run_result = CommonVariables.success
        run_status = 'success'
        all_failed = False
        is_inconsistent = False
        unable_to_sleep = False
        blob_snapshot_info_array = None
        self.logger.log('Taking Snapshot through Host')
        HandlerUtil.HandlerUtility.add_to_telemetery_data(
            CommonVariables.snapshotCreator, CommonVariables.backupHostService)

        if self.g_fsfreeze_on:
            run_result, run_status = self.freeze()
        if (run_result == CommonVariables.success):
            snap_shotter = HostSnapshotter(self.logger, self.hostIp)
            self.logger.log('T:S doing snapshot now...')
            time_before_snapshot = datetime.datetime.now()
            blob_snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep = snap_shotter.snapshotall(
                self.para_parser, self.freezer, self.g_fsfreeze_on,
                self.taskId)
            time_after_snapshot = datetime.datetime.now()
            snapshotTimeTaken = time_after_snapshot - time_before_snapshot
            self.logger.log('T:S takeSnapshotFromHost, time_before_snapshot=' +
                            str(time_before_snapshot) +
                            ", time_after_snapshot=" +
                            str(time_after_snapshot) + ", snapshotTimeTaken=" +
                            str(snapshotTimeTaken))
            HandlerUtil.HandlerUtility.add_to_telemetery_data(
                "snapshotTimeTaken", str(snapshotTimeTaken))
            self.logger.log('T:S snapshotall ends...', True)

        return run_result, run_status, blob_snapshot_info_array, all_failed, unable_to_sleep, is_inconsistent
    def takeSnapshotFromOnlyHost(self):
        all_failed= False
        is_inconsistent =  False
        snapshot_info_array = None
        self.logger.log('Taking Snapshot through Host')
        HandlerUtil.HandlerUtility.add_to_telemetery_data("snapshotCreator", "backupHostService")
        if self.g_fsfreeze_on :
            run_result, run_status = self.freeze()
        if(run_result == CommonVariables.success):
            snap_shotter = HostSnapshotter(self.logger)
            self.logger.log('T:S doing snapshot now...')
            time_before_snapshot = datetime.datetime.now()
            snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep  = snap_shotter.snapshotall(self.para_parser, self.freezer, self.g_fsfreeze_on)
            time_after_snapshot = datetime.datetime.now()
            HandlerUtil.HandlerUtility.add_to_telemetery_data("snapshotTimeTaken", str(time_after_snapshot-time_before_snapshot))
            self.logger.log('T:S snapshotall ends...', True)
            if(all_failed or self.check_snapshot_array_fail(snapshot_info_array)):
                run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                run_status = 'error'
                if self.takeSnapshotFrom == CommonVariables.onlyHost:
                    self.hutil.SetExtErrorCode(ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedNoNetwork)
                    error_msg = error_msg + ExtensionErrorCodeHelper.ExtensionErrorCodeHelper.StatusCodeStringBuilder(self.hutil.ExtErrorCode)
                error_msg = 'Enable failed in taking snapshot through host'
                self.logger.log("T:S " + error_msg, True)

        return run_result, run_status, snapshot_info_array, all_failed
    def takeSnapshotFromFirstHostThenGuest(self):

        run_result = CommonVariables.success
        run_status = 'success'

        all_failed = False
        is_inconsistent = False
        unable_to_sleep = False
        blob_snapshot_info_array = None
        snap_shotter = HostSnapshotter(self.logger, self.hostIp)
        pre_snapshot_statuscode = snap_shotter.pre_snapshot(
            self.para_parser, self.taskId)

        if (pre_snapshot_statuscode == 200 or pre_snapshot_statuscode == 201):
            run_result, run_status, blob_snapshot_info_array, all_failed, unable_to_sleep, is_inconsistent = self.takeSnapshotFromOnlyHost(
            )
        else:
            run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed, unable_to_sleep, is_inconsistent = self.takeSnapshotFromGuest(
            )

            if all_snapshots_failed and run_result != CommonVariables.success:
                self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedNoNetwork
            elif run_result != CommonVariables.success:
                self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedRestrictedNetwork

        return run_result, run_status, blob_snapshot_info_array, all_failed, unable_to_sleep, is_inconsistent
    def takeSnapshotFromFirstHostThenGuest(self):

        run_result = CommonVariables.success
        run_status = 'success'

        all_failed = False
        is_inconsistent = False
        blob_snapshot_info_array = None
        snap_shotter = HostSnapshotter(self.logger, self.hostIp)
        pre_snapshot_statuscode = snap_shotter.pre_snapshot(
            self.para_parser, self.taskId)

        if (pre_snapshot_statuscode == 200 or pre_snapshot_statuscode == 201):
            run_result, run_status, blob_snapshot_info_array, all_failed = self.takeSnapshotFromOnlyHost(
            )
            if (all_failed and run_result != CommonVariables.success):
                run_result = CommonVariables.error
                run_status = 'error'
                error_msg = 'T:S Enable failed with error in transient error from xstore'
                self.logger.log(
                    "Marking retryble error when presnapshot succeeds but dosnapshot fails through host",
                    True, 'Warning')
        else:
            run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed = self.takeSnapshotFromGuest(
            )

            if all_snapshots_failed and run_result != CommonVariables.success:
                self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedNoNetwork
            elif run_result != CommonVariables.success:
                self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedRestrictedNetwork

        return run_result, run_status, blob_snapshot_info_array, all_failed
示例#5
0
    def is_command_timedout(self, para_parser):
        result = False
        dateTimeNow = datetime.datetime.utcnow()
        try:
            try:
                snap_shotter = HostSnapshotter(self.logger, self.hostIp)
                pre_snapshot_statuscode, responseBody = snap_shotter.pre_snapshot(
                    self.para_parser, self.taskId)

                if (int(pre_snapshot_statuscode) == 200
                        or int(pre_snapshot_statuscode) == 201) and (
                            responseBody != None and responseBody != ""):
                    resonse = json.loads(responseBody)
                    dateTimeNow = datetime.datetime(
                        resonse['responseTime']['year'],
                        resonse['responseTime']['month'],
                        resonse['responseTime']['day'],
                        resonse['responseTime']['hour'],
                        resonse['responseTime']['minute'],
                        resonse['responseTime']['second'])
                    self.logger.log(
                        'Date and time extracted from pre-snapshot request: ' +
                        str(dateTimeNow))
            except Exception as e:
                self.logger.log(
                    'Error in getting Host time falling back to using system time. Exception %s, stack trace: %s'
                    % (str(e), traceback.format_exc()))

            if (para_parser is not None
                    and para_parser.commandStartTimeUTCTicks is not None
                    and para_parser.commandStartTimeUTCTicks != ""):
                utcTicksLong = int(para_parser.commandStartTimeUTCTicks)
                self.logger.log('utcTicks in long format' + str(utcTicksLong))
                commandStartTime = self.convert_time(utcTicksLong)
                self.logger.log('command start time is ' +
                                str(commandStartTime) + " and utcNow is " +
                                str(dateTimeNow))
                timespan = dateTimeNow - commandStartTime
                MAX_TIMESPAN = 140 * 60  # in seconds
                total_span_in_seconds = self.timedelta_total_seconds(timespan)
                self.logger.log('timespan: ' + str(timespan) +
                                ', total_span_in_seconds: ' +
                                str(total_span_in_seconds) +
                                ', MAX_TIMESPAN: ' + str(MAX_TIMESPAN))

                if total_span_in_seconds > MAX_TIMESPAN:
                    self.logger.log(
                        'CRP timeout limit has reached, should abort.')
                    result = True
        except Exception as e:
            self.logger.log(
                'T:S is_command_timedout : Exception %s, stack trace: %s' %
                (str(e), traceback.format_exc()))

        return result
示例#6
0
    def takeSnapshotFromOnlyHost(self):
        run_result = CommonVariables.success
        run_status = 'success'
        all_failed = False
        is_inconsistent = False
        unable_to_sleep = False
        blob_snapshot_info_array = None
        self.logger.log('Taking Snapshot through Host')
        HandlerUtil.HandlerUtility.add_to_telemetery_data(
            CommonVariables.snapshotCreator, CommonVariables.backupHostService)

        if self.g_fsfreeze_on:
            run_result, run_status = self.freeze()

        if (self.para_parser is not None
                and self.is_command_timedout(self.para_parser) == True):
            self.hutil.SetExtErrorCode(
                ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.
                FailedGuestAgentInvokedCommandTooLate)
            run_result = CommonVariables.FailedGuestAgentInvokedCommandTooLate
            run_status = 'error'
            all_failed = True
            self.logger.log(
                'T:S takeSnapshotFromOnlyHost : Thawing as failing due to CRP timeout',
                True, 'Error')
            self.freezer.thaw_safe()
        elif (run_result == CommonVariables.success
              or self.takeCrashConsistentSnapshot == True):
            snap_shotter = HostSnapshotter(self.logger, self.hostIp)
            self.logger.log('T:S doing snapshot now...')
            time_before_snapshot = datetime.datetime.now()
            blob_snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep = snap_shotter.snapshotall(
                self.para_parser, self.freezer, self.g_fsfreeze_on,
                self.taskId)
            time_after_snapshot = datetime.datetime.now()
            snapshotTimeTaken = time_after_snapshot - time_before_snapshot
            self.logger.log('T:S takeSnapshotFromHost, time_before_snapshot=' +
                            str(time_before_snapshot) +
                            ", time_after_snapshot=" +
                            str(time_after_snapshot) + ", snapshotTimeTaken=" +
                            str(snapshotTimeTaken))
            HandlerUtil.HandlerUtility.add_to_telemetery_data(
                "snapshotTimeTaken", str(snapshotTimeTaken))
            self.logger.log('T:S snapshotall ends...', True)

        return run_result, run_status, blob_snapshot_info_array, all_failed, unable_to_sleep, is_inconsistent
    def takeSnapshotFromFirstHostThenGuest(self):

        run_result = CommonVariables.success
        run_status = 'success'

        all_failed= False
        is_inconsistent =  False
        blob_snapshot_info_array = None
        snap_shotter = HostSnapshotter(self.logger, self.hostIp)
        pre_snapshot_statuscode = snap_shotter.pre_snapshot(self.para_parser, self.taskId)

        if(pre_snapshot_statuscode == 200 or pre_snapshot_statuscode == 201):
            run_result, run_status, blob_snapshot_info_array, all_failed = self.takeSnapshotFromOnlyHost()
        else:
            run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed  = self.takeSnapshotFromGuest()

            if all_snapshots_failed and run_result != CommonVariables.success:
                self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedNoNetwork
            elif run_result != CommonVariables.success :
                self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedRestrictedNetwork

        return run_result, run_status, blob_snapshot_info_array, all_failed
    def takeSnapshotFromOnlyHost(self):
        run_result = CommonVariables.success
        run_status = 'success'
        all_failed= False
        is_inconsistent =  False
        blob_snapshot_info_array = None
        self.logger.log('Taking Snapshot through Host')
        HandlerUtil.HandlerUtility.add_to_telemetery_data(CommonVariables.snapshotCreator, CommonVariables.backupHostService)

        if self.g_fsfreeze_on :
            run_result, run_status = self.freeze()
        if(run_result == CommonVariables.success):
            snap_shotter = HostSnapshotter(self.logger, self.hostIp)
            self.logger.log('T:S doing snapshot now...')
            time_before_snapshot = datetime.datetime.now()
            blob_snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep  = snap_shotter.snapshotall(self.para_parser, self.freezer, self.g_fsfreeze_on, self.taskId)
            time_after_snapshot = datetime.datetime.now()
            HandlerUtil.HandlerUtility.add_to_telemetery_data("snapshotTimeTaken", str(time_after_snapshot-time_before_snapshot))
            self.logger.log('T:S snapshotall ends...', True)

        return run_result, run_status, blob_snapshot_info_array, all_failed