storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/mint/run/core/s3select/utils.py (about)

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3  # MinIO Python Library for Amazon S3 Compatible Cloud Storage,
     4  # (C) 2015-2020 MinIO, Inc.
     5  #
     6  # Licensed under the Apache License, Version 2.0 (the "License");
     7  # you may not use this file except in compliance with the License.
     8  # You may obtain a copy of the License at
     9  #
    10  #     http://www.apache.org/licenses/LICENSE-2.0
    11  #
    12  # Unless required by applicable law or agreed to in writing, software
    13  # distributed under the License is distributed on an "AS IS" BASIS,
    14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  # See the License for the specific language governing permissions and
    16  # limitations under the License.
    17  
    18  import inspect
    19  import json
    20  import time
    21  import traceback
    22  import uuid
    23  
    24  
    25  class LogOutput(object):
    26      """
    27      LogOutput is the class for log output. It is required standard for all
    28      SDK tests controlled by mint.
    29      Here are its attributes:
    30              'name': name of the SDK under test, e.g. 's3select'
    31              'function': name of the method/api under test with its signature
    32                          The following python code can be used to
    33                          pull args information of a <method> and to
    34                          put together with the method name:
    35                          <method>.__name__+'('+', '.join(args_list)+')'
    36                          e.g. 'remove_object(bucket_name, object_name)'
    37              'args': method/api arguments with their values, in
    38                      dictionary form: {'arg1': val1, 'arg2': val2, ...}
    39              'duration': duration of the whole test in milliseconds,
    40                          defaults to 0
    41              'alert': any extra information user is needed to be alerted about,
    42                       like whether this is a Blocker/Gateway/Server related
    43                       issue, etc., defaults to None
    44              'message': descriptive error message, defaults to None
    45              'error': stack-trace/exception message(only in case of failure),
    46                       actual low level exception/error thrown by the program,
    47                       defaults to None
    48              'status': exit status, possible values are 'PASS', 'FAIL', 'NA',
    49                        defaults to 'PASS'
    50      """
    51  
    52      PASS = 'PASS'
    53      FAIL = 'FAIL'
    54      NA = 'NA'
    55  
    56      def __init__(self, meth, test_name):
    57          self.__args_list = inspect.getargspec(meth).args[1:]
    58          self.__name = 's3select:'+test_name
    59          self.__function = meth.__name__+'('+', '.join(self.__args_list)+')'
    60          self.__args = {}
    61          self.__duration = 0
    62          self.__alert = ''
    63          self.__message = None
    64          self.__error = None
    65          self.__status = self.PASS
    66          self.__start_time = time.time()
    67  
    68      @property
    69      def name(self): return self.__name
    70  
    71      @property
    72      def function(self): return self.__function
    73  
    74      @property
    75      def args(self): return self.__args
    76  
    77      @name.setter
    78      def name(self, val): self.__name = val
    79  
    80      @function.setter
    81      def function(self, val): self.__function = val
    82  
    83      @args.setter
    84      def args(self, val): self.__args = val
    85  
    86      def json_report(self, err_msg='', alert='', status=''):
    87          self.__args = {k: v for k, v in self.__args.items() if v and v != ''}
    88          entry = {'name': self.__name,
    89                   'function': self.__function,
    90                   'args': self.__args,
    91                   'duration': int(round((time.time() - self.__start_time)*1000)),
    92                   'alert': str(alert),
    93                   'message': str(err_msg),
    94                   'error': traceback.format_exc() if err_msg and err_msg != '' else '',
    95                   'status': status if status and status != '' else
    96                   self.FAIL if err_msg and err_msg != '' else self.PASS
    97                   }
    98          return json.dumps({k: v for k, v in entry.items() if v and v != ''})
    99  
   100  
   101  def generate_bucket_name():
   102      return "s3select-test-" + str(uuid.uuid4())
   103  
   104  
   105  def generate_object_name():
   106      return str(uuid.uuid4())