Python script launched from Jenkins hangs - java

I have a python script which launches a java tool to run regression tests. If I run these commands on directly on command line they work fine , If I run this script from Jenkins the java tool will be in hanged state till I close the jenkins job. Once I close Jenkins job I see the tool running.
Following is the command generated from the python script:
export DISPLAY=:0;/home/tools/executor/bin/executor -J-Xms128m -J-Xmx1024m -a/home/ExecutorSuites/FWVerification/Platform/update_firmware_polaris.e.xml -r744 <uname> <passwrd>
Is there any issue running python scripts from Jenkins? I really appreciate any help on this. I am a FW engineer, do not know much about java and Jenkins.
Here is the python script:
import paramiko
import sys
import os
class Unbuffered:
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
sys.stdout=Unbuffered(sys.stdout)
hostname = os.environ['J_TESTMACHINE_IP']
username = os.environ['J_TESTMACHINE_UNAME']
password = os.environ['J_TESTMACHINE_PASSWD']
vapor_username = os.environ['J_VAPOR_UNAME']
vapor_password = os.environ['J_VAPOR_PASSWD']
executor_path = os.environ['J_EXECUTOR_PATH']
vapor_revid = os.environ['J_VAPOR_REVID']
test_results_path = os.environ['J_VAPOR_TESTRESULTS_FILEPATH']
es_home_dir = os.environ['J_ES_HOME_DIR']
testsuites_string = os.environ['J_TEST_SUITE']
testsuites = [x.strip() for x in testsuites_string.split(',')]
localfile = "C:\Jenkins\localfile.txt"
def create_client(hostname, username, password):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(hostname,username=username, password=password)
except BadHostKeyException:
print "The server's host key could not be verified"
except AuthenticationException:
print "if authentication failed"
except SSHException:
print "There were other errors connecting or establishing an SSH session"
except socket.error:
print "a socket error occurred while connecting"
return client
def destroy_client(client):
client.close()
def form_executor_cmd(testsuite):
executor_cmd = "export DISPLAY=:0;";
executor_cmd += executor_path;
executor_cmd += " -J-Xms128m -J-Xmx1024m";
executor_cmd += " -a" + es_home_dir + testsuite;
executor_cmd += " -r" + vapor_revid;
executor_cmd += " -u" + vapor_username + " -p" + vapor_password;
return executor_cmd
def run_remote_cmd(client, remote_cmd):
try:
stdin, stdout, stderr = client.exec_command(remote_cmd)
except SSHException:
print "When executing command "+remote_cmd+", there were other errors connecting or establishing an SSH session"
channel = stdout.channel
status = channel.recv_exit_status()
print "\n Executing remote command "+remote_cmd+" ...\n";
print "Exit Status " + str(status)
return status, stdin, stdout, stderr
def clear_testresults(client, filepath):
print "clearing test results at " + filepath
status, stdin, stdout, stderr = run_remote_cmd(client, "rm "+filepath)
def did_it_pass(client):
ftp = client.open_sftp()
ftp.get(test_results_path, localfile)
f = open(localfile,"a+")
lines = f.readlines()
print lines
f.close()
ftp.close()
os.remove(localfile)
if "Failed" in lines:
return 1
else:
return 0
os.remove('localfile.txt')
###########################################################
# hostname = 'sclab-sfmfv-avatar'
# username = 'root'
# password = 'pmcsfm'
# ssh connection created
client = create_client(hostname, username, password)
#executor_cmd = "export DISPLAY=:0;/home/tools/executor/bin/executor -a/home/ExecutorSuites/FWVerification/Platform/update_firmware_avatar.e.xml -r342 -uSfmFwTest1 -pSfmFWbot01"
failed = 0
for testsuite in testsuites:
print testsuite
clear_testresults(client, test_results_path)
print "\n Executing suite "+testsuite+" ...\n";
executor_cmd = form_executor_cmd(testsuite)
status, stdin, stdout, stderr = run_remote_cmd(client, executor_cmd)
if did_it_pass(client):
print "Testsuite "+ testsuite +"failed"
data = stderr.read();
print data
failed = 1
else:
print "Testsuite "+ testsuite +"succeeded"
data = stdout.read();
print data
if failed == 1 :
sys.exit (1)
# ssh connection destroyed
destroy_client(client)

Related

Why does a variable of type com.ibm.jms.JMSTextMessage print truncated content and ellipses (...)?

I would like to understand why a variable of type com.ibm.jms.JMSTextMessage is printed with truncated content and ellipses (...) when converted to string.
I have this code in a JSR223 Sampler in JMeter:
import com.ibm.msg.client.jms.JmsConnectionFactory
import com.ibm.msg.client.jms.JmsFactoryFactory
import com.ibm.msg.client.wmq.WMQConstants
import javax.jms.Session
import javax.jms.TextMessage
def hostName = "127.0.0.1"
def hostPort = 1414
def channelName = "DEV.APP.SVRCONN"
def queueManagerName = "QM1"
def queueName = "DEV.QUEUE.1"
def ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER)
def cf = ff.createConnectionFactory()
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, hostName)
cf.setIntProperty(WMQConstants.WMQ_PORT, hostPort)
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channelName)
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT)
def connInboundQueue = cf.createConnection("user", "password")
def sessInboundQueue = connInboundQueue.createSession(false, Session.AUTO_ACKNOWLEDGE)
def payload = "AAA:+.? '\n" +
"ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'\n" +
"DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'\n" +
"GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'\n" +
"JKL+745'\n" +
"HHH+TN:IIAA891011213531235BNM422244:::001'\n" +
"CCC+NT+++ABCDEFGHIJKLMNOPQRS'\n" +
"STU+00123456789012:UF+0000000000:GY'\n" +
"VXY+50+MI1234+++MI'\n" +
"AAA+235+ABC'\n" +
"BBB+200:3202062000:301'\n" +
"FFF+90+USA'\n" +
"BBB+232:2101051135:201'\n" +
"CCC+FF+++AaBaBa001:TEST1'\n" +
"DDD+3++G'\n" +
"EEE+329:711013'\n" +
"FFF+178+XXX'\n" +
"FFF+179+YYY'\n" +
"GGG+2+ZZZ'\n" +
"HHH+BXG:ABCDEF'\n" +
"HHH+ABC:12AB3E01234E8UD8'\n" +
"III+P:110:111+100000001'\n" +
"EEE+36:281105'\n" +
"FFF+91+ASD'\n" +
"VVV+50:2'\n" +
"XXX+0011+1'\n" +
"YYY+1+U0123456'\n" +
"ZZZ+1+U1234560002'\n"
TextMessage msg = sessInboundQueue.createTextMessage()
msg.setText(payload)
log.info(msg.toString())
log.info(msg.getClass().toString())
log.info(msg.getText())
I would like to understand why log.info(msg.toString()) does not print the whole text content and show ellipses after some point (...)
If I do log.info(msg.getText()), I can see the whole text message.
Here is the print outcome in jmeter's console:
2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue:
JMSMessage class: jms_text
JMSType: null
JMSDeliveryMode: 2
JMSDeliveryDelay: 0
JMSDeliveryTime: 1635710725481
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d5120514d312020202020202020201f537d6101c31040
JMSTimestamp: 1635710725481
JMSCorrelationID: 1757416553
JMSDestination: queue:///DEV.QUEUE.1
JMSReplyTo: null
JMSRedelivered: false
JMSXAppID: 4.1\bin\ApacheJMeter.jar
JMSXDeliveryCount: 0
JMSXUserID: mquser1
JMS_IBM_PutApplType: 28
JMS_IBM_PutDate: 20211031
JMS_IBM_PutTime: 20052548
AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:20 ...
2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue: class com.ibm.jms.JMSTextMessage
2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue: AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'
GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'
JKL+745'
HHH+TN:IIAA891011213531235BNM422244:::001'
CCC+NT+++ABCDEFGHIJKLMNOPQRS'
STU+00123456789012:UF+0000000000:GY'
VXY+50+MI1234+++MI'
AAA+235+ABC'
BBB+200:3202062000:301'
FFF+90+USA'
BBB+232:2101051135:201'
CCC+FF+++AaBaBa001:TEST1'
DDD+3++G'
EEE+329:711013'
FFF+178+XXX'
FFF+179+YYY'
GGG+2+ZZZ'
HHH+BXG:ABCDEF'
HHH+ABC:12AB3E01234E8UD8'
III+P:110:111+100000001'
EEE+36:281105'
FFF+91+ASD'
VVV+50:2'
XXX+0011+1'
YYY+1+U0123456'
ZZZ+1+U1234560002'
According to the IBM documentation com.ibm.jms.JMSTextMessage inherits the toString() implementation from com.ibm.jms.JMSMessage and the JavaDoc for that method says:
Gets a String containing a formatted version of the message header.
My guess is that the body is cut off simply because toString() is really just meant to give you the header. However, only IBM would know for sure why it works that way. To be clear, there is no guarantee that toString() will (or should) return the entire body of the message.
If you really want to inspect the body of the text message you should invoke getText(). This method is required to return the body of the text-message according to the JMS JavaDoc as well as IBM's own JavaDoc. Both state:
Gets the String containing this message's data. The default value is null.

ASE is terminating this process when trying to install the jar file (Msg 5702, Level 10, State 1)

I have an SAP ASE 16 server on a Windows OS.
I have enabled the java service:
sp_configure 'enable java'
Parameter Name Default Memory Used Config Value Run Value Unit Type
-------------- ----------- ----------- ------------ ------------ ------ ------
enable java 0 0 1 1 switch static
Rows affected (1) Time (0.094 s)
I have created a basic class to test the service (JDBCExamples.java):
import java.sql.*; // JDBC
public class JDBCExamples {
public static void main(String args[]){
if (args.length != 2) {
System.out.println("\n Usage: " + "name secondName \n");
return;
}
try {
String name = args[0];
String secondName = args[1].toLowerCase();
System.out.println("\n HOLA " + name + " " + secondName +" FUNCIONO!!!\n");
} catch (Exception e) {
System.out.println("\n Exception: ");
e.printStackTrace();
}
}
}
I have the class file JDBCExamples.class and I make a file JDBCExamples.jar.
When I try to install the jar file it shows the error message:
instjava -f JDBCExamples.jar -SDEFAULT -Uuser -Ppassword -Ddatabase -new
Server Message: - Msg 5702, Level 10, State 1:
ASE is terminating this process.
I don't see any in log database.
Any idea what the problem is?
Update:
I posted the same problem in https://answers.sap.com/questions/13241081/ase-is-terminating-this-process-when-trying-to-ins.html
In this post suspect the issue is caused by an ASE bug fixed in PL06:
2687973 - NTPCI__exit(1); Native Thread failed to unwind - SAP ASE http://service.sap.com/sap/support/notes/2687973
I have a trial version and I can not download a newer patch (PL06 at least but recommend PL09 as most recent)
Does anyone have this patch?

Updating module version when updating version in dependencies (multi-module maven )

My problem: versions-maven-plugin helps me to up version in some module (let's call it A) in my multi-module maven project.
Some modules (let's call it B and C) in this project have in dependencies module A. I need to up versions for this modules (B and C) too. Sometimes, i also need to up version in other module (B-parent) where B (or C) in dependencies (A version up -> B version up -> B-parent version up). Other problem is the modules can be at different levels of nesting.
Example:
root:
---B-parent:
---B (A in dependencies)
---C-parent
---C (A in dependencies)
---A-parent:
---A
Process: A version up -> A-parent version up, C version-up -> C-parent version-up, B version-up -> B-parent version up.
This plugin can't do this.
Is there any idea how this can be done?
Or my strategy of updating versions is not good enough?
I've made a script for increasing version numbers in all dependent modules recursively with a versions-maven-plugin.
Algorithm is as follows:
Run versions:set in target module
Run versions:set in all modules which have been updated by versions:set from previous step. If the module has been already processed - skip it.
Repeat step 2
Python 2.7 code
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
# How To
#
# Run script and pass module path as a first argument.
# Or run it without arguments in module dir.
#
# Script will request the new version number for each module.
# If no version provided - last digit will be incremented (1.0.0 -> 1.0.1).
# cd <module-path>
# <project-dir>/increment-version.py
# ...
# review changes and commit
from subprocess import call, Popen, PIPE, check_output
import os
import re
import sys
getVersionCommand = "mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate " \
"-Dexpression=project.version 2>/dev/null | grep -v '\['"
def getCurrentModuleVersion():
return check_output(getVersionCommand, shell=True).decode("utf-8").split("\n")[0]
def incrementLastDigit(version):
digits = version.split(".")
lastDigit = int(digits[-1])
digits[-1] = str(lastDigit+1)
return ".".join(digits)
def isUpdatedVersionInFile(version, file):
return "<version>" + version + "</version>" in \
check_output("git diff HEAD --no-ext-diff --unified=0 --exit-code -a --no-prefix {} "
"| egrep \"^\\+\"".format(file), shell=True).decode("utf-8")
def runVersionSet(version):
process = Popen(["mvn", "versions:set", "-DnewVersion="+version, "-DgenerateBackupPoms=false"], stdout=PIPE)
(output, err) = process.communicate()
exitCode = process.wait()
if exitCode is not 0:
print "Error setting the version"
exit(1)
return output, err, exitCode
def addChangedPoms(version, dirsToVisit, visitedDirs):
changedFiles = check_output(["git", "ls-files", "-m"]) \
.decode("utf-8").split("\n")
changedPoms = [f for f in changedFiles if f.endswith("pom.xml")]
changedDirs = [os.path.dirname(os.path.abspath(f)) for f in changedPoms if isUpdatedVersionInFile(version, f)]
changedDirs = [d for d in changedDirs if d not in visitedDirs and d not in dirsToVisit]
print "New dirs to visit:", changedDirs
return changedDirs
if __name__ == "__main__":
visitedDirs = []
dirsToVisit = []
if len(sys.argv) > 1:
if os.path.exists(os.path.join(sys.argv[1], "pom.xml")):
dirsToVisit.append(os.path.abspath(sys.argv[1]))
else:
print "Error. No pom.xml file in dir", sys.argv[1]
exit(1)
else:
dirsToVisit.append(os.path.abspath(os.getcwd()))
pattern = re.compile("aggregation root: (.*)")
while len(dirsToVisit) > 0:
dirToVisit = dirsToVisit.pop()
print "Visiting dir", dirToVisit
os.chdir(dirToVisit)
currentVersion = getCurrentModuleVersion()
defaultVersion = incrementLastDigit(currentVersion)
version = raw_input("New version for {}:{} ({}):".format(dirToVisit, currentVersion, defaultVersion))
if not version.strip():
version = defaultVersion
print "New version:", version
output, err, exitcode = runVersionSet(version)
rootDir = pattern.search(output).group(1)
visitedDirs = visitedDirs + [dirToVisit]
os.chdir(rootDir)
print "Adding new dirs to visit"
dirsToVisit = dirsToVisit + addChangedPoms(version, dirsToVisit, visitedDirs)

Unable to resolve class com.cloudbees.hudson.plugins.folder.Folder

I am trying to gather data from jenkins using groovy script and getting an error:
unable to resolve class com.cloudbees.hudson.plugins.folder.Folder
Below is the code:
import jenkins.model.*
import hudson.model.*
import groovy.time.TimeCategory
use ( TimeCategory ) {
// e.g. find jobs not run in last 1 year
sometimeago = (new Date() - 1.year)
}
jobs = Jenkins.instance.getAllItems()
lastabort = null
jobs.each { j ->
if (j instanceof com.cloudbees.hudson.plugins.folder.Folder) { return }
numbuilds = j.builds.size()
if (numbuilds == 0) {
println 'JOB: ' + j.fullName
println ' -> no build'
return
}
lastbuild = j.builds[numbuilds - 1]
if (lastbuild.timestamp.getTime() < sometimeago) {
println 'JOB: ' + j.fullName
println ' -> lastbuild: ' + lastbuild.displayName + ' = ' + lastbuild.result + ', time: ' + lastbuild.timestampString2
}
}
The error is:
rg.codehaus.groovy.control.MultipleCompilationErrorsExceptio‌​n:
startup failed: Script1.groovy: 12: unable to resolve class
com.cloudbees.hudson.plugins.folder.Folder # line 12, column 20. if (j
instanceof com.cloudbees.hudson.plugins.folder.Folder) { return } ^ 1
error at
org.codehaus.groovy.control.ErrorCollector.failIfErrors(Erro‌​rCollector.java:302)
I see Folder.java in jenkinsci/cloudbees-folder-plugin.
That means you need to:
check if you do have JENKINS/CloudBees Folders Plugin installed, or your groovy script would not be able to resolve that dependency.
Add "import com.cloudbees.hudson.plugins.folder.*" to be sure the script is able to make the instanceOf work.
When running groovy scripts that import libraries in Jenkins, check that your Jenkins build step is an "Execute system Groovy script", not a plain old "Execute Groovy script".
The 'system' scripts run on the existing JVM, as opposed to spawning a new one and therefore losing access to the shared libraries available to the original Jenkins JVM instance.
Groovy Script vs System Groovy Script - https://plugins.jenkins.io/groovy/

Why zabbix do not show a value received from java code?

Consider a java code:
String host = "zabbixHost";
int port = 10051;
ZabbixSender zabbixSender = new ZabbixSender(host, port);
DataObject dataObject = new DataObject();
dataObject.setHost("testHost");
dataObject.setKey("test.ping.count");
dataObject.setValue("10");
// TimeUnit is SECONDS.
dataObject.setClock(System.currentTimeMillis()/1000);
SenderResult result = zabbixSender.send(dataObject);
System.out.println("result:" + result);
if (result.success()) {
System.out.println("send success.");
} else {
System.err.println("sned fail!");
}
The result is {"failed":0,"processed":1,"spentSeconds":0.001715,"total":1}
Then I send a request by zabbix_sender tool from command line:
zabbix_sender -z zabbixHost -p 10051 -s testHost -k test.ping.count -o 8 -v
The output is:
info from server: "processed: 1; failed: 0; total: 1; seconds spent: 0.002052"
sent: 1; skipped: 0; total: 1
For now 2 values were sent into Zabbix. But when I got to the monitoring graphic for test.ping.count and only 8 value is shown. E.g. value from java code was not received even when response was successful.
What is going on? How to fix such situation?
Note
The library is - io.github.hengyunabc:zabbix-sender:0.0.3
Zabbix version is 3.0
The problem was with timestamps, zabbix-sender with version 0.0.1 set request (not dataobject) clock in milliseconds while version 0.0.3 in seconds. So using right version fix issues.
maven sample (source):
<dependency>
<groupId>io.github.hengyunabc</groupId>
<artifactId>zabbix-sender</artifactId>
<version>0.0.3</version>
</dependency>

Categories

Resources