7 EteGatherDataListener implements the ROBOT listener API version 2 and is
8 instantiated via the robot cammmand line option
10 --listener EteGatherDataListener:<jobbumber>:<key filename>
12 The purpose is to gather and preserve debugging data from each of the application
13 VMs when an ETE test fails.
15 This listener counts the number of test
16 cases that have failed and, if > 0 at then end of the robot exection (close()),
17 will connect to each application vm and
19 2. upload the gather_data.sh
20 2. execute gather_data.sh
21 3. Transfer the resulting zip file to the Robot reports folder
23 This will enable the Jenkins job to retrieve the debug data along with the
24 Robot logs and reports and archive it with the failed job for later retreival.
26 Note that the gather_data.sh depends upon the application providing
27 a /opt/gather_application_data.sh on their respective VMs for the zip file
32 class EteGatherDataListener(object):
33 ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
34 ROBOT_LISTENER_API_VERSION = 2
42 "policy" : "10.0.6.1",
45 "portal" : "10.0.9.1",
46 "message_router" : "10.0.11.1",
47 "dcae_pstg00" : "10.0.4.101",
48 "dcae_coll00" : "10.0.4.102",
49 "dcae_cdap00" : "10.0.4.103",
50 "dcae_cdap01" : "10.0.4.104",
51 "dcae_cdap02" : "10.0.4.105"
55 local_gather_data_sh = ""
57 def __init__(self, job='10', keyfile='/share/config/key.pvt', shell="gather_data.sh"):
60 self.output_folder = ''
63 self.keyfile = keyfile
64 self.local_gather_data_sh = shell
65 print "EteGatherDataListener instantiated"
67 def end_test(self, name, attrs):
68 if attrs['status'] == 'PASS':
73 def output_file(self, path):
74 if (self.folder != ''):
76 self.folder = os.path.dirname(path)
80 print "EteGatherDataListener tests failed=" + str(self.tests_failed)
81 if (self.tests_failed > 0):
82 self.gather_debug_data()
84 def gather_debug_data(self):
86 for application in self.APPLICATIONS.keys():
87 self.gather_application_data(application, self.APPLICATIONS.get(application))
89 def gather_application_data(self, application, ip):
90 extra = {"_threadid" : 1}
91 paramiko.util.log_to_file(self.folder + "/paramiko.log", level=0)
92 log = logging.getLogger("paramiko")
93 ssh = paramiko.SSHClient()
95 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
96 ssh.connect(ip,username="root", key_filename=self.keyfile)
97 except paramiko.SSHException:
98 log.error("Connection Failed to " + ip, extra=extra)
101 gather_data_sh = "/tmp/gather_data.sh"
102 ftp = ssh.open_sftp()
103 ftp.put(self.local_gather_data_sh, gather_data_sh)
105 stdin, stdout, stderr = ssh.exec_command("/bin/bash "+ gather_data_sh + " " + application + " " + self.job)
106 error = stderr.read()
108 log.info("stderr:" + error, extra=extra)
111 # No error? ASsume we have a file to download.
113 log.info("stdout:" + out, extra=extra)
114 filename = application + "_" + self.job + ".tar.gz"
115 localzip = self.folder + "/" + filename
116 remotezip = "/tmp/gather_data/" + filename
117 ftp = ssh.open_sftp()
118 ftp.get(remotezip, localzip)
120 stdin, stdout, stderr = ssh.exec_command("rm -rf " + remotezip);
122 except paramiko.SSHException: