def _call_function(self): retries = self._max_retries if not retries: retries = 1 exp = None result = None traceback_text = None for retry_index in range(retries): exp = None traceback_text = None try: logger.info( 'calling shared function: {} - retry index: {}'.format( self._function_key, retry_index)) result = self._function(*self._function_args, **self._function_kwargs) break except Exception as err: exp = err result = None logger.exception(exp) _, _, traceback_ = sys.exc_info() traceback_text = ''.join(traceback.format_tb(traceback_)) return result, exp, traceback_text
def _cleanup(): try: module_target_sat.api.Subscription( organization=module_org).delete_manifest( data={'organization_id': module_org.id}) except Exception: logger.exception('Exception cleaning manifest:')
def class_hostgroup(class_org, class_location): """Create a hostgroup linked to specific org and location created at the class scope""" hostgroup = entities.HostGroup(organization=[class_org], location=[class_location]).create() yield hostgroup try: hostgroup.delete() except HTTPError: logger.exception('Exception while deleting class scope hostgroup entity in teardown')
def class_user_reader(self, class_user_password, class_org, class_location): try: reader_role = RoleEntity().search(query={'search': 'name="Discovery Reader"'})[0] except IndexError: pytest.fail('Discovery Manager role was not found, setup cannot continue') user = UserEntity( organization=[class_org], location=[class_location], password=class_user_password, role=[reader_role], ).create() yield user try: user.delete() except HTTPError: logger.exception('Exception while deleting class scope user entity in teardown')
def _check_deadlock(lock_file_path, process_id): """To prevent process deadlock, raise exception if the file content is the same as process_id note: this function is called before the lock :type lock_file_path: str :type process_id: str """ if os.path.exists(lock_file_path): try: lock_file_handler = open(lock_file_path) lock_file_content = lock_file_handler.read() except OSError as exp: # do nothing, but anyway log the exception logger.exception(exp) lock_file_content = None if lock_file_content and lock_file_content == process_id: raise FunctionLockerError( 'recursion detected: the function file already locked by the same process' )