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 copy_build_repo(self, host, conf_dict): """copy the brew build repo to all the existing nodes""" self.build_repo_file = self.build_repo_tag + ".repo" self.build_repo_url = os.environ.get("BUILD_REPO_URL") logger.log.info("Copying %s to %s" % (self.build_repo_file, host)) repo = open(self.build_repo_file, "w") repo.write("[" + self.build_repo_tag + "]\n") repo.write("name=" + self.build_repo_tag + "\n") repo.write("baseurl=" + self.build_repo_url + "\n") repo.write("enabled=1\n") repo.write("gpgcheck=0\n") repo.write("skip_if_unavailable=1\n") repo.close() source = self.build_repo_file destination = "/etc/yum.repos.d/" + source logger.log.info("source file is %s" % source) logger.log.info("destination file is %s" % destination) ssh_c = SSHClient(hostname = host, username = \ self.username, password = self.password) ssh_c.CopyFiles(source, destination)
def my_build_repo(self, host, conf_dict): source = self.build_repo destination = "/etc/yum.repos.d/my_build.repo" logger.log.info("Copying %s to %s on %s" % (source, destination, host)) ssh_c = SSHClient(hostname = host, username = \ self.username, password = self.password) ssh_c.CopyFiles(source, destination)
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 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 restraint_setup(self, host, conf_dict): """ wget appropriate restraint repo to respective nodes. Install restraint rpms and start its service. """ logger.log.info("Checking platform.dist of %s" % host) ssh_c = SSHClient(hostname = host, username = \ self.username, password = self.password) stdin, stdout, stderr = ssh_c.ExecuteCmd('python -c "import platform; \ print platform.dist()"') dist = stdout.read() dist = str(dist).replace('(','').replace(')','').replace("'", "").\ replace(',','') dist = dist.split() logger.log.info("Platform distribution for host %s is %s" % (host, dist)) repo_out = "/etc/yum.repos.d/restraint.repo" restraint_repo = conf_dict['restraint'][dist[1]] wget_cmd = "wget " + restraint_repo + " -O " + repo_out logger.log.info("%s to %s" % (host, wget_cmd)) stdin, stdout, stderr = ssh_c.ExecuteCmd(wget_cmd) for line in stdout.read().splitlines(): logger.log.info(line) restraint_remove_rpms = conf_dict['restraint']['remove_rpm'] remove_cmd = "yum remove -y " + restraint_remove_rpms logger.log.info("%s to %s" % (host, remove_cmd)) stdin, stdout, stderr = ssh_c.ExecuteCmd(remove_cmd) for line in stdout.read().splitlines(): logger.log.info(line) restraint_install_rpms = conf_dict['restraint']['install_rpm'] install_cmd = "yum install -y " + restraint_install_rpms logger.log.info("%s to %s" % (host, install_cmd)) stdin, stdout, stderr = ssh_c.ExecuteCmd(install_cmd) for line in stdout.read().splitlines(): logger.log.info(line) service = ("restraintd") start_service_cmd = ("service %s start; chkconfig %s on" % (service, \ service)) logger.log.info("%s to %s" % (host, start_service_cmd)) stdin, stdout, stderr = ssh_c.ExecuteCmd(start_service_cmd) for line in stdout.read().splitlines(): logger.log.info(line)
def copy_async_updates_repo(self, host, conf_dict): """copy the async updates repo to all the existing nodes""" try: logger.log.info( "Checking platform.dist of %s to get the right batched repo" % host) ssh_c = SSHClient(hostname = host, username = \ self.username, password = self.password) stdin, stdout, stderr = ssh_c.ExecuteCmd( 'python -c "import platform; \ print platform.dist()"') dist = stdout.read() dist = str(dist).replace('(','').replace(')','').replace("'", "").\ replace(',','') dist = dist.split() logger.log.info("Platform distribution for host %s is %s" % (host, dist)) self.async_updates_url = conf_dict['async_repos'][dist[1]] self.build_repo_file = "async_updates_" + host + ".repo" logger.log.info("Creating async updates build repo file %s" % self.build_repo_file) repo = open(self.build_repo_file, "w") repo.write("[" + "async_updates" + "]\n") repo.write("name=" + "async_updates" + "\n") repo.write("baseurl=" + self.async_updates_url + "\n") repo.write("enabled=1\n") repo.write("gpgcheck=0\n") repo.write("skip_if_unavailable=1\n") repo.close() source = self.build_repo_file destination = "/etc/yum.repos.d/" + source logger.log.info("source file is %s" % source) logger.log.info("destination file is %s" % destination) ssh_c = SSHClient(hostname = host, username = \ self.username, password = self.password) ssh_c.CopyFiles(source, destination) except KeyError, e: logger.log.error( "%s key for async_updates_url does not exists in conf." % e)
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()