示例#1
0
 def one_common(self,
                request,
                pk=None,
                ansi='pro_ansi_yml',
                extra_vars={},
                action='pull'):
     start_time = time.time()
     log_simple = []
     log_complex = []
     log_error = []
     log_name = ''
     try:
         ansi_yml = request.DATA[ansi]
         print ansi_yml
     except:
         ansi_yml = ansi
     try:
         excute = Ansi_Play(ansi_yml, extra_vars)
     except:
         excute = Ansi_Play(ansi_yml)
     report = excute.run()
     try:
         pro_name = request.DATA['pro_name']
     except:
         try:
             pro_name = request.DATA['pro_group_name']
         except:
             pro_name = request.DATA['name']
     log_simple.append(str(report[0]))
     try:
         log_complex.append(str(report[1].decode('ascii', 'ignore')))
     except:
         log_complex.append(unicode(report[1], errors='ignore'))
     self.file_log(str(report[1]), str(request.DATA['pro_group']), action)
     if str(''.join(report[2].split('\n'))) != '':
         log_name = pro_name + ' ' + ':' + ' ' + str(''.join(
             report[2].split('\n'))) + ' '
     else:
         log_name = ''
     end_time = time.time()
     cost_time = str(round(end_time - start_time, 2))
     for j in report[0]:
         if report[0][j]['failures'] >= 1 or report[0][j][
                 'unreachable'] >= 1:
             log_name += pro_name + ' ' + j + ' ' + 'failed\n'
         if re.search('but failed', cost_time):
             pass
         else:
             if report[0][j]['failures'] >= 1 or report[0][j][
                     'unreachable'] >= 1:
                 cost_time += ' but failed'
     log_error.append(str(''.join(log_name.split('\n'))))
     return Response([
         '\n'.join(log_simple), ''.join(''.join(log_complex).split('\\n')),
         cost_time, '\n'.join(log_error)
     ])
示例#2
0
 def multi_common(self, request, pk=None, ansi='pro_ansi_yml', action='pull'):
     start_time = time.time()
     log_simple = []
     log_complex = []
     log_error = []
     cost_time = {}
     log_name = ''
     for i in request.DATA:
         start_item_time = time.time()
         if action == 'process':
             ansi_yml = i['ansi']
         else:
             ansi_yml = i[ansi]
         try:
             extra_vars = {'version': i['version']}
             excute = Ansi_Play(ansi_yml, extra_vars)
         except:
             excute = Ansi_Play(ansi_yml)
         log = excute.run()
         log_simple.append(str(log[0]))
         try:
             log_complex.append(str(log[1].decode('ascii', 'ignore')))
         except:
             log_complex.append(unicode(log[1], errors='ignore'))
         self.file_log(str(log[1]), str(i['pro_group']), action)
         if str(''.join(log[2].split('\n'))) != '':
             try:
                 pro_name = i['pro_name']
                 log_error.append(pro_name + ':' + str(log[2]))
             except:
                 log_error.append(i['pro_group_name'] + ":" + str(log[2]))
         else:
             log_name = ''
         end_item_time = time.time()
         cost_time[i['pro_name']] = str(round(end_item_time - start_item_time, 2))
         print log[0]
         for j in log[0]:
             print j
             if log[0][j]['failures'] >= 1 or log[0][j]['unreachable'] >= 1:
                 log_name += i['pro_name'] + ' ' + j + ' failed\n'
             if re.search('but failed', cost_time[i['pro_name']]):
                 pass
             else:
                 print j
                 print log[0][j]['failures']
                 if log[0][j]['failures'] >= 1 or log[0][j]['unreachable'] >= 1:
                     cost_time[i['pro_name']] += ' but failed'
         log_error.append(str(log_name))
         print log_error
     end_time = time.time()
     cost_time['total'] = str(round(end_time - start_time, 2))
     return Response(['\n'.join(log_simple), ''.join(''.join(log_complex).split('\\n')), cost_time, '\n'.join(log_error) ])
示例#3
0
 def one_common(self, request, pk=None, ansi='pro_ansi_yml', extra_vars={}, action='pull'):
     start_time = time.time()
     log_simple = []
     log_complex = []
     log_error = []
     log_name = ''
     try:
         ansi_yml = request.DATA[ansi]
         print ansi_yml
     except:
         ansi_yml = ansi
     try:
         excute = Ansi_Play(ansi_yml, extra_vars)
     except:
         excute = Ansi_Play(ansi_yml)
     report = excute.run()
     try:
         pro_name = request.DATA['pro_name']
     except:
         try:
             pro_name = request.DATA['pro_group_name']
         except:
             pro_name = request.DATA['name']
     log_simple.append(str(report[0]))
     try:
         log_complex.append(str(report[1].decode('ascii', 'ignore')))
     except:
         log_complex.append(unicode(report[1], errors='ignore'))
     self.file_log(str(report[1]), str(request.DATA['pro_group']), action)
     if str(''.join(report[2].split('\n'))) != '':
         log_name = pro_name + ' ' + ':' + ' ' + str(''.join(report[2].split('\n'))) + ' '
     else:
         log_name = ''
     end_time = time.time()
     cost_time = str(round(end_time - start_time, 2))
     for j in report[0]:
         if report[0][j]['failures'] >= 1 or report[0][j]['unreachable'] >= 1:
             log_name += pro_name + ' ' + j + ' ' + 'failed\n'
         if re.search('but failed', cost_time):
             pass
         else:
             if report[0][j]['failures'] >= 1 or report[0][j]['unreachable'] >= 1:
                 cost_time += ' but failed'
     log_error.append(str(''.join(log_name.split('\n'))))
     return Response(['\n'.join(log_simple), ''.join(''.join(log_complex).split('\\n')), cost_time, '\n'.join(log_error)])