<s> import itertools <EOL> import paramiko <EOL> import prettytable <EOL> import re <EOL> import subprocess <EOL> import sys <EOL> def sshconnect ( hostname , user , passwd ) : <EOL> sshclient = paramiko . SSHClient ( ) <EOL> sshclient . set_missing_host_key_policy ( paramiko . AutoAddPolicy ( ) ) <EOL> try : <EOL> sshclient . connect ( hostname , username = user , password = passwd ) <EOL> except Exception : <EOL> raise <EOL> return sshclient <EOL> def report_table ( suite_name ) : <EOL> ps = subprocess . Popen ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % ( suite_name ) ] , <EOL> stdout = subprocess . PIPE ) <EOL> output = ps . communicate ( ) [ <NUM_LIT:0> ] <EOL> output = output . splitlines ( ) <EOL> line = <NUM_LIT:0> <EOL> tc_dict = { } <EOL> while line < len ( output ) : <EOL> find1 = re . search ( '<STR_LIT>' , output [ line ] , re . I ) <EOL> if find1 is not None : <EOL> line += <NUM_LIT:1> <EOL> if line <= len ( output ) - <NUM_LIT:1> : <EOL> find2 = re . search ( <EOL> '<STR_LIT>' % <EOL> ( find1 . group ( <NUM_LIT:1> ) ) , output [ line ] , re . I ) <EOL> if find2 is not None : <EOL> tc_dict [ find1 . group ( <NUM_LIT:1> ) ] = find2 . group ( <NUM_LIT:1> ) , find1 . group ( <NUM_LIT:2> ) <EOL> line += <NUM_LIT:1> <EOL> table = prettytable . PrettyTable ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> table . padding_width = <NUM_LIT:1> <EOL> for key , val in tc_dict . iteritems ( ) : <EOL> table . add_row ( [ "<STR_LIT:%s>" % ( key ) , "<STR_LIT:%s>" % ( val [ <NUM_LIT:0> ] ) , "<STR_LIT:%s>" % ( val [ <NUM_LIT:1> ] ) ] ) <EOL> return table <EOL> def report_results ( suite_name , txt_file ) : <EOL> orig_stdout = sys . stdout <EOL> f = open ( '<STR_LIT:%s>' % ( txt_file ) , '<STR_LIT:a>' ) <EOL> sys . stdout = f <EOL> report = report_table ( suite_name ) <EOL> print ( report ) <EOL> sys . stdout = orig_stdout <EOL> f . close ( ) <EOL> def gen_tc_header ( ) : <EOL> comb_list = [ <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , [ <EOL> '<STR_LIT>' , '<STR_LIT>' ] , [ <EOL> '<STR_LIT>' , '<STR_LIT>' ] , [ <EOL> '<STR_LIT>' , '<STR_LIT>' ] , [ <EOL> '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> out_hdr_list = list ( itertools . product ( * comb_list ) ) <EOL> out_headers = [ ] <EOL> for hdr in out_hdr_list : <EOL> header = '<STR_LIT>' + '<STR_LIT:_>' . join ( str ( i ) for i in hdr ) <EOL> out_headers . append ( header ) <EOL> proto = list ( itertools . combinations ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <NUM_LIT:2> ) ) <EOL> proto_hdrs = [ ] <EOL> for hdr in proto : <EOL> proto_header = '<STR_LIT:_>' . join ( str ( i ) for i in hdr ) <EOL> proto_hdrs . append ( proto_header ) <EOL> in_hdrs = list ( itertools . product ( out_headers , proto_hdrs ) ) <EOL> final_headers = [ ] <EOL> for hdr in in_hdrs : <EOL> tc_header = '<STR_LIT:_>' . join ( str ( i ) for i in hdr ) <EOL> final_headers . append ( tc_header ) <EOL> table = prettytable . PrettyTable ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> table . padding_width = <NUM_LIT:1> <EOL> for i in range ( len ( final_headers ) ) : <EOL> table . add_row ( [ "<STR_LIT>" % <EOL> ( i + <NUM_LIT:1> ) , "<STR_LIT>" , "<STR_LIT:%s>" % <EOL> ( final_headers [ i ] ) ] ) <EOL> print ( table ) </s>
