def copy_testout_junit(self, options, conf_dict): """ Copy junit file from first node to Jenkins slave """ master = self.existing_nodes[0] ssh_c = SSHClient(hostname = master, username = \ self.username, password = self.password) remote_file = conf_dict['pytest']['pytest_junit_loc'] scp = SCPClient(ssh_c.get_transport()) scp.get(remote_file) # Executing script that would convert the test case name in junit # output xml to use docstrings. self.junit_convert_script = conf_dict['pytest']['junit_convert_script'] self.junit_new_out = conf_dict['pytest']['pytest_new_junit_loc'] self.team = conf_dict['pytest']['team'] tests_base = conf_dict['pytest']['tests_base'] self.package = tests_base.replace("-", "_") tests_to_run = conf_dict['pytest']['tests_to_run'] self.test_suite = tests_to_run.rsplit('/', 1)[1] massage_junit = "python " + self.junit_convert_script + " -i " + \ remote_file + " -o " + self.junit_new_out + " -t " + self.team + \ " -p " + self.package + " -s " + self.test_suite stdin, stdout, stderr = ssh_c.ExecuteCmd(massage_junit) for line in stdout.read().splitlines(): logger.log.info(line) scp = SCPClient(ssh_c.get_transport()) scp.get(self.junit_new_out)
def get_reports(self, options, conf_dict): master = self.existing_nodes[0] ssh_c = SSHClient(hostname = master, username = \ self.username, password = self.password) coverage_data = conf_dict['coverage']['coverage_data'] scp = SCPClient(ssh_c.get_transport()) scp.get(coverage_data) coverage_xml = conf_dict['coverage']['coverage_xml'] scp = SCPClient(ssh_c.get_transport()) scp.get(coverage_xml) remotepath = conf_dict['coverage']['coverage_html'] cmd = 'scp -r ' + master + ':' + remotepath + ' .' p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) output = p.stdout.read() print output
def get_reports(self, options, conf_dict): master = self.existing_nodes[0] ssh_c = SSHClient(hostname = master, username = \ self.username, password = self.password) coverage_xml = conf_dict['coverage']['coverage_xml'] scp = SCPClient(ssh_c.get_transport()) scp.get(coverage_xml)
def copy_test_out_junit(self): """ Getting Junit files""" print("pytest node =",self.pytest_node) ssh_c = SSHClient( hostname=self.pytest_node, username = self.username, password = self.password) logger.log.info("Getting pytest results") cwd = os.environ.get('PWD') remote_file = self.conf_dict['pytest']['pytest_junit_loc'] sftp = paramiko.SFTPClient.from_transport(ssh_c.get_transport()) sftp.get(remote_file, '%s/junit.xml'%(cwd))
def deploy_ssh_keys(self): """ Copy ssh keys to all existing nodes """ print("In ssh keys function ",self.existing_nodes) for host in self.existing_nodes: print("ssh host = ",host) ssh_c = SSHClient(hostname=host, username=self.username, password=self.password) stdin, stdout, stderr = ssh_c.ExecuteCmd("mkdir -p /root/.ssh/") stdout.close() stderr.close() ssh_c = SSHClient( hostname=self.pytest_node, username = self.username, password = self.password) logger.log.info("Generate ssh keys") stdin, stdout, stderr = ssh_c.ExecuteCmd("ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ''") ssh_c = SSHClient( hostname=self.pytest_node, username = self.username, password = self.password) logger.log.info("Create authorized_keys") stdin, stdout, stderr = ssh_c.ExecuteCmd("cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys") ssh_c = SSHClient( hostname=self.pytest_node, username = self.username, password = self.password) logger.log.info("Set permissions to authorized_keys") stdin, stdout, stderr = ssh_c.ExecuteCmd("chmod 600 /root/.ssh/authorized_keys") ssh_c = SSHClient( hostname=self.pytest_node, username = self.username, password = self.password) scp = SCPClient(ssh_c.get_transport()) cwd = os.environ.get('PWD') logger.log.info("Get the ssh keys and authorized_keys file to jslave") sftp = paramiko.SFTPClient.from_transport(ssh_c.get_transport()) sftp.get('/root/.ssh/authorized_keys', '%s/authorized_keys'%(cwd)) sftp.get('/root/.ssh/id_rsa', '%s/id_rsa'%(cwd)) sftp.get('/root/.ssh/id_rsa.pub','%s/id_rsa.pub'%(cwd)) if os.path.isfile('%s/authorized_keys'%(cwd)): logger.log.info("authorized_keys file exist") else: logger.log.info("authorized_keys file doesn't exist") if os.path.isfile('%s/id_rsa.pub'%(cwd)): logger.log.info("id_rsa.pub exists") else: logger.log.info("id_rsa.pub doesn't exists") if os.path.isfile('%s/id_rsa'%(cwd)): logger.log.info("id_rsa file exists") else: logger.log.info("id_rsa file doesn't exist") for host in self.existing_nodes: if host is not self.pytest_node: ssh_c = SSHClient(hostname=host, username=self.username, password=self.password) stdout, stderr, exit_status = ssh_c.ExecuteScript('ls -l /root/.ssh') logger.log.info("Output = %s"%(stdout.getvalue())) logger.log.info("Command status = %s"%(exit_status)) sftp = paramiko.SFTPClient.from_transport(ssh_c.get_transport()) sftp.put('%s/authorized_keys'%(cwd),'/root/.ssh/authorized_keys') sftp.put('%s/id_rsa.pub'%(cwd),'/root/.ssh/id_rsa.pub') sftp.put('%s/id_rsa'%(cwd), '/root/.ssh/id_rsa') #ssh_c.CopyFiles('%s/authorized_keys'%(cwd),'/root/.ssh/authorized_keys') #ssh_c.CopyFiles('%s/id_rsa.pub'%(cwd),'/root/.ssh/id_rsa.pub') #ssh_c.CopyFiles('%s/id_rsa'%(cwd), '/root/.ssh/id_rsa') #remove files files = ['authorized_keys', 'id_rsa.pub', 'id_rsa'] for ssh_f in files: logger.log.info('removing %s/%s'%(cwd,ssh_f)) os.remove('%s/%s'%(cwd,ssh_f)) for host in self.existing_nodes: ssh_c = SSHClient(hostname=host, username=self.username, password=self.password) ssh_c.ExecuteCmd('chmod 600 /root/.ssh/authorized_keys') ssh_c.ExecuteCmd('chmod 600 /root/.ssh/id_rsa') ssh_c.ExecuteCmd('echo "StrictHostKeyChecking no" >> /root/.ssh/config') stdout.close() stderr.close()