Ejemplo n.º 1
0
    def takeSnapshotFromGuest(self):
        run_result = CommonVariables.success
        run_status = 'success'

        all_failed = False
        is_inconsistent = False
        blob_snapshot_info_array = None
        all_snapshots_failed = False
        try:
            if self.g_fsfreeze_on:
                run_result, run_status = self.freeze()
            if (self.para_parser.blobs == None
                    or len(self.para_parser.blobs) == 0):
                run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                run_status = 'error'
                error_msg = 'T:S taking snapshot failed as blobs are empty or none'
                self.logger.log(error_msg, True, 'Error')
            if (run_result == CommonVariables.success):
                HandlerUtil.HandlerUtility.add_to_telemetery_data(
                    CommonVariables.snapshotCreator,
                    CommonVariables.guestExtension)
                snap_shotter = GuestSnapshotter(self.logger, self.hutil)
                self.logger.log('T:S doing snapshot now...')
                time_before_snapshot = datetime.datetime.now()
                snapshot_result, blob_snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep, all_snapshots_failed = 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 (snapshot_result is not None
                        and len(snapshot_result.errors) > 0):
                    if unable_to_sleep:
                        run_result = CommonVariables.error
                        run_status = 'error'
                        error_msg = 'T:S Enable failed with error: ' + str(
                            snapshot_result)
                        self.logger.log(error_msg, True, 'Warning')
                    elif is_inconsistent == True:
                        run_result = CommonVariables.error
                        run_status = 'error'
                        error_msg = 'T:S Enable failed with error: ' + str(
                            snapshot_result)
                        self.logger.log(error_msg, True, 'Warning')
                elif self.check_snapshot_array_fail(
                        blob_snapshot_info_array) == True:
                    run_result = CommonVariables.error
                    run_status = 'error'
                    error_msg = 'T:S Enable failed with error in snapshot_array index'
                    self.logger.log(error_msg, True, 'Error')
        except Exception as e:
            errMsg = 'Failed to do the snapshot with error: %s, stack trace: %s' % (
                str(e), traceback.format_exc())
            self.logger.log(errMsg, True, 'Error')
            run_result = CommonVariables.error
            run_status = 'error'

        return run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed
    def takeSnapshotFromGuest(self):
        run_result = CommonVariables.success
        run_status = 'success'

        all_failed = False
        is_inconsistent = False
        unable_to_sleep = False
        blob_snapshot_info_array = None
        all_snapshots_failed = False
        try:
            if (self.para_parser.blobs == None
                    or len(self.para_parser.blobs) == 0):
                run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                run_status = 'error'
                error_msg = 'T:S taking snapshot failed as blobs are empty or none'
                self.logger.log(error_msg, True, 'Error')
                all_failed = True
                all_snapshots_failed = True
                return run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed, unable_to_sleep, is_inconsistent

            # populate metadata for all blobs
            blob_util = BlobUtil(self.logger)
            blob_metadata = blob_util.populate_blobMetadata_allblobs(
                self.para_parser)

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

            if (run_result == CommonVariables.success
                    or self.takeCrashConsistentSnapshot == True):
                HandlerUtil.HandlerUtility.add_to_telemetery_data(
                    CommonVariables.snapshotCreator,
                    CommonVariables.guestExtension)
                snap_shotter = GuestSnapshotter(self.logger, self.hutil)
                self.logger.log('T:S doing snapshot now...')
                time_before_snapshot = datetime.datetime.now()
                snapshot_result, blob_snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep, all_snapshots_failed = snap_shotter.snapshotall(
                    self.para_parser, self.freezer, self.g_fsfreeze_on,
                    blob_metadata)
                time_after_snapshot = datetime.datetime.now()
                snapshotTimeTaken = time_after_snapshot - time_before_snapshot
                self.logger.log(
                    'T:S ***** takeSnapshotFromGuest, 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)

        except Exception as e:
            errMsg = 'Failed to do the snapshot with error: %s, stack trace: %s' % (
                str(e), traceback.format_exc())
            self.logger.log(errMsg, True, 'Error')
            run_result = CommonVariables.error
            run_status = 'error'

        return run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed, unable_to_sleep, is_inconsistent
    def takeSnapshotFromGuest(self):
        run_result = CommonVariables.success
        run_status = 'success'

        all_failed= False
        is_inconsistent =  False
        blob_snapshot_info_array = None
        all_snapshots_failed = False
        try:
            if self.g_fsfreeze_on :
                run_result, run_status = self.freeze()
            if( self.para_parser.blobs == None or len(self.para_parser.blobs) == 0) :
                        run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                        run_status = 'error'
                        error_msg = 'T:S taking snapshot failed as blobs are empty or none'
                        self.logger.log(error_msg, True, 'Error')
            if(run_result == CommonVariables.success):
                HandlerUtil.HandlerUtility.add_to_telemetery_data(CommonVariables.snapshotCreator, CommonVariables.guestExtension)
                snap_shotter = GuestSnapshotter(self.logger)
                self.logger.log('T:S doing snapshot now...')
                time_before_snapshot = datetime.datetime.now()
                snapshot_result, blob_snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep, all_snapshots_failed  = 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(self.hutil.get_value_from_configfile('doseq') == '2'):
                    self.hutil.set_value_to_configfile('doseq', '0')
                if(snapshot_result is not None and len(snapshot_result.errors) > 0):
                    if unable_to_sleep:
                        run_result = CommonVariables.error
                        run_status = 'error'
                        error_msg = 'T:S Enable failed with error: ' + str(snapshot_result)
                        self.logger.log(error_msg, True, 'Warning')
                    elif is_inconsistent == True :
                        self.hutil.set_value_to_configfile('doseq', '1') 
                        run_result = CommonVariables.error
                        run_status = 'error'
                        error_msg = 'T:S Enable failed with error: ' + str(snapshot_result)
                        self.logger.log(error_msg, True, 'Warning')
                elif self.check_snapshot_array_fail(blob_snapshot_info_array) == True:
                    run_result = CommonVariables.error
                    run_status = 'error'
                    error_msg = 'T:S Enable failed with error in snapshot_array index'
                    self.logger.log(error_msg, True, 'Error')
        except Exception as e:
            if(self.hutil.get_value_from_configfile('doseq') == '2'):
                self.hutil.set_value_to_configfile('doseq', '0')
            errMsg = 'Failed to do the snapshot with error: %s, stack trace: %s' % (str(e), traceback.format_exc())
            self.logger.log(errMsg, True, 'Error')
            run_result = CommonVariables.error
            run_status = 'error'

        return run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed
    def takeSnapshotFromGuest(self):
        run_result = CommonVariables.success
        run_status = 'success'

        all_failed= False
        is_inconsistent =  False
        snapshot_info_array = None
        all_snapshots_failed = False
        try:
            if self.g_fsfreeze_on :
                run_result, run_status = self.freeze()
            if( self.para_parser.blobs == None or len(self.para_parser.blobs) == 0) :
                        run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                        run_status = 'error'
                        error_msg = 'T:S taking snapshot failed as blobs are empty or none'
                        self.logger.log(error_msg, True, 'Error')
            if(run_result == CommonVariables.success):
                HandlerUtil.HandlerUtility.add_to_telemetery_data("snapshotCreator", "guestExtension")
                snap_shotter = GuestSnapshotter(self.logger)
                self.logger.log('T:S doing snapshot now...')
                time_before_snapshot = datetime.datetime.now()
                snapshot_result,snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep, all_snapshots_failed  = 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(self.hutil.get_value_from_configfile('doseq') == '2'):
                    self.hutil.set_value_to_configfile('doseq', '0')
                if(snapshot_result is not None and len(snapshot_result.errors) > 0):
                    if unable_to_sleep:
                        run_result = CommonVariables.error
                        run_status = 'error'
                        error_msg = 'T:S Enable failed with error: ' + str(snapshot_result)
                        self.logger.log(error_msg, True, 'Warning')
                    elif is_inconsistent == True :
                        self.hutil.set_value_to_configfile('doseq', '1') 
                        run_result = CommonVariables.error
                        run_status = 'error'
                        error_msg = 'T:S Enable failed with error: ' + str(snapshot_result)
                        self.logger.log(error_msg, True, 'Warning')
                    else:
                        error_msg = 'T:S snapshot result: ' + str(snapshot_result)
                        run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                        if all_failed and self.takeSnapshotFrom == CommonVariables.onlyGuest:
                           self.hutil.SetExtErrorCode(ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedNoNetwork)
                           error_msg = error_msg + ExtensionErrorCodeHelper.ExtensionErrorCodeHelper.StatusCodeStringBuilder(self.hutil.ExtErrorCode)
                        elif self.takeSnapshotFrom == CommonVariables.onlyGuest:
                            self.hutil.SetExtErrorCode(ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedRestrictedNetwork)
                            error_msg = error_msg + ExtensionErrorCodeHelper.ExtensionErrorCodeHelper.StatusCodeStringBuilder(self.hutil.ExtErrorCode)
                        run_status = 'error'
                        self.logger.log(error_msg, True, 'Error')
                elif self.check_snapshot_array_fail(snapshot_info_array) == True:
                    run_result = CommonVariables.error
                    run_status = 'error'
                    error_msg = 'T:S Enable failed with error in snapshot_array index'
                    self.logger.log(error_msg, True, 'Error')
        except Exception as e:
            if(self.hutil.get_value_from_configfile('doseq') == '2'):
                self.hutil.set_value_to_configfile('doseq', '0')
            errMsg = 'Failed to do the snapshot with error: %s, stack trace: %s' % (str(e), traceback.format_exc())
            self.logger.log(errMsg, True, 'Error')
            run_result = CommonVariables.error
            run_status = 'error'

        return run_result, run_status, snapshot_info_array, all_failed, all_snapshots_failed
Ejemplo n.º 5
0
    def takeSnapshotFromGuest(self):
        run_result = CommonVariables.success
        run_status = 'success'

        all_failed = False
        is_inconsistent = False
        unable_to_sleep = False
        blob_snapshot_info_array = None
        all_snapshots_failed = False
        try:
            if (self.para_parser.blobs == None
                    or len(self.para_parser.blobs) == 0):
                run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                run_status = 'error'
                error_msg = 'T:S taking snapshot failed as blobs are empty or none'
                self.logger.log(error_msg, True, 'Error')
                all_failed = True
                all_snapshots_failed = True
                return run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed, unable_to_sleep, is_inconsistent

            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
                all_snapshots_failed = True
                self.logger.log(
                    'T:S takeSnapshotFromGuest : Thawing as failing due to CRP timeout',
                    True, 'Error')
                self.freezer.thaw_safe()
            elif (run_result == CommonVariables.success
                  or self.takeCrashConsistentSnapshot == True):
                HandlerUtil.HandlerUtility.add_to_telemetery_data(
                    CommonVariables.snapshotCreator,
                    CommonVariables.guestExtension)
                snap_shotter = GuestSnapshotter(self.logger, self.hutil)
                self.logger.log('T:S doing snapshot now...')
                time_before_snapshot = datetime.datetime.now()
                snapshot_result, blob_snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep, all_snapshots_failed = snap_shotter.snapshotall(
                    self.para_parser, self.freezer, self.g_fsfreeze_on)
                time_after_snapshot = datetime.datetime.now()
                snapshotTimeTaken = time_after_snapshot - time_before_snapshot
                self.logger.log(
                    'T:S ***** takeSnapshotFromGuest, 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)

        except Exception as e:
            errMsg = 'Failed to do the snapshot with error: %s, stack trace: %s' % (
                str(e), traceback.format_exc())
            self.logger.log(errMsg, True, 'Error')
            run_result = CommonVariables.error
            run_status = 'error'

        return run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed, unable_to_sleep, is_inconsistent
    def takeSnapshotFromGuest(self):
        run_result = CommonVariables.success
        run_status = 'success'

        all_failed = False
        is_inconsistent = False
        blob_snapshot_info_array = None
        all_snapshots_failed = False
        try:
            if self.g_fsfreeze_on:
                run_result, run_status = self.freeze()
            if (self.para_parser.blobs == None
                    or len(self.para_parser.blobs) == 0):
                run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                run_status = 'error'
                error_msg = 'T:S taking snapshot failed as blobs are empty or none'
                self.logger.log(error_msg, True, 'Error')
            if (run_result == CommonVariables.success):
                HandlerUtil.HandlerUtility.add_to_telemetery_data(
                    CommonVariables.snapshotCreator,
                    CommonVariables.guestExtension)
                snap_shotter = GuestSnapshotter(self.logger)
                self.logger.log('T:S doing snapshot now...')
                time_before_snapshot = datetime.datetime.now()
                snapshot_result, blob_snapshot_info_array, all_failed, is_inconsistent, unable_to_sleep, all_snapshots_failed = 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 (self.hutil.get_value_from_configfile('doseq') == '2'):
                    self.hutil.set_value_to_configfile('doseq', '0')
                if (snapshot_result is not None
                        and len(snapshot_result.errors) > 0):
                    if unable_to_sleep:
                        run_result = CommonVariables.error
                        run_status = 'error'
                        error_msg = 'T:S Enable failed with error: ' + str(
                            snapshot_result)
                        self.logger.log(error_msg, True, 'Warning')
                    elif is_inconsistent == True:
                        self.hutil.set_value_to_configfile('doseq', '1')
                        run_result = CommonVariables.error
                        run_status = 'error'
                        error_msg = 'T:S Enable failed with error: ' + str(
                            snapshot_result)
                        self.logger.log(error_msg, True, 'Warning')
                    else:
                        #making FailedSnapshotLimitReached error incase of "snapshot blob calls is exceeded"
                        if blob_snapshot_info_array != None:
                            for blob_snapshot_info in blob_snapshot_info_array:
                                if blob_snapshot_info != None and blob_snapshot_info.errorMessage != None:
                                    # if any blob-snapshot has failed with SnapshotRateExceeded with IsAnySnapshotFailed RegKey already true, assign StausCode FailedSnapshotLimitReached
                                    IsAnySnapshotFailedConfigValue = self.hutil.get_value_from_configfile(
                                        CommonVariables.IsAnySnapshotFailed)
                                    self.logger.log(
                                        'IsAnySnapshotFailedConfigValue : ' +
                                        str(IsAnySnapshotFailedConfigValue))
                                    if 'The rate of snapshot blob calls is exceeded' in blob_snapshot_info.errorMessage and (
                                            IsAnySnapshotFailedConfigValue
                                            == None
                                            or IsAnySnapshotFailedConfigValue
                                            == ''
                                            or IsAnySnapshotFailedConfigValue
                                            == 'False'):
                                        run_result = CommonVariables.error
                                        run_status = 'error'
                                        error_msg = 'Retrying when snapshot failed with SnapshotRateExceeded'
                                        self.logger.log(
                                            error_msg, True, 'Error')
                                        self.hutil.set_value_to_configfile(
                                            CommonVariables.
                                            IsAnySnapshotFailed, 'True')
                                        time.sleep(600)
                                        break
                                    elif 'The rate of snapshot blob calls is exceeded' in blob_snapshot_info.errorMessage or 'The snapshot count against this blob has been exceeded' in blob_snapshot_info.errorMessage:
                                        run_result = CommonVariables.FailedSnapshotLimitReached
                                        run_status = 'error'
                                        error_msg = 'T:S Enable failed with FailedSnapshotLimitReached errror'
                                        self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedSnapshotLimitReached
                                        error_msg = error_msg + ExtensionErrorCodeHelper.ExtensionErrorCodeHelper.StatusCodeStringBuilder(
                                            self.extensionErrorCode)
                                        self.hutil.set_value_to_configfile(
                                            CommonVariables.
                                            IsAnySnapshotFailed, 'False')
                                        break
                        if (run_result == CommonVariables.success):
                            error_msg = 'T:S snapshot result: ' + str(
                                snapshot_result)
                            run_result = CommonVariables.FailedRetryableSnapshotFailedNoNetwork
                            if all_failed and self.takeSnapshotFrom == CommonVariables.onlyGuest:
                                self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedNoNetwork
                                error_msg = error_msg + ExtensionErrorCodeHelper.ExtensionErrorCodeHelper.StatusCodeStringBuilder(
                                    self.extensionErrorCode)
                            else:
                                self.extensionErrorCode = ExtensionErrorCodeHelper.ExtensionErrorCodeEnum.FailedRetryableSnapshotFailedRestrictedNetwork
                                error_msg = error_msg + ExtensionErrorCodeHelper.ExtensionErrorCodeHelper.StatusCodeStringBuilder(
                                    self.extensionErrorCode)
                            run_status = 'error'

                        self.logger.log(error_msg, True, 'Error')
                elif self.check_snapshot_array_fail(
                        blob_snapshot_info_array) == True:
                    run_result = CommonVariables.error
                    run_status = 'error'
                    error_msg = 'T:S Enable failed with error in snapshot_array index'
                    self.logger.log(error_msg, True, 'Error')
        except Exception as e:
            if (self.hutil.get_value_from_configfile('doseq') == '2'):
                self.hutil.set_value_to_configfile('doseq', '0')
            errMsg = 'Failed to do the snapshot with error: %s, stack trace: %s' % (
                str(e), traceback.format_exc())
            self.logger.log(errMsg, True, 'Error')
            run_result = CommonVariables.error
            run_status = 'error'

        return run_result, run_status, blob_snapshot_info_array, all_failed, all_snapshots_failed