Action hooks in python: no output - python

I've been working on an Openshift app where the action hooks are written in Python.
The action hooks run, and work, but I can not get any output to display when I create the app. So when I run rhc app create ... the app is successfully created, but none of the status or debug messages I try to output ever display.
The code gets called like this:
b = library.Object()
b.build()
I have tried:
Adding a logging function to the object and adding b.showlog() to the code above.
print "Message with value: {0}".format(variable) from inside the build hook script
print >>sys.stderr, "Something bad happened: '{0}'...".format(return_code) from inside the build hook script
When I've written action hooks in bash, echo ... works fine.
This exact question doesn't seem to have been answered before, though there are questions that are superficially similar.

You don't get any action hook output during an app create. You will only see it during a "git push" when you update code. I would suggest having the output write to a log file in your ~/app-root/data directory instead so that you can view it later. Also, if you catch it at the right time, you can ssh into your application while it is being created the first time.

Related

Use Robot Framework logging file at the end of test case execution

I am a new Robot Framework user and have a question regarding the log file that it makes at the end of executing testcases. I would like to use the html file it creates and upload it automatically to the correct ticket. I already have python code that works to upload the file and it can be used as a keyword, but I am not sure how I can call upon that keyword as a test teardown step as at that point the logging probably is not created yet..
Is this correct and if so: is there another way to automatically call a python function to upload the html file after executing a testcase?
Yes, you can use things as below:
Test Teardown Run keyword if test Passed/Failed Name_of_kw
Add this to your settings section of .robot file.
Now, define the kw: (Import Process Library first in your robot file)
Name_of_kw
Start Process <tab> python <tab> path_to_file.py<tab> alias=prog
Wait for Process prog #wait until it gets completed
Get Process Result prog stdout=yes #to make sure you have uploaded it
================
more details at -https://robotframework.org/robotframework/latest/libraries/Process.html#library-documentation-top
I've been facing the same problem and I've got an alternative solution for getting log files (log.html, report.html, output.xml) in same execution and upload them to a FTP Server.
I created a python script in Robot Framework's root project folder:
import subprocess
import os.path
import time
arguments = sys.argv
subprocess.run(arguments)
logs = ['log.html', 'report.html', 'output.xml']
while not os.path.exists(logs[0] and logs[1] and logs[2]):
time.sleep(1)
do_something()
Instead of running:
robot .\tests\...\suite
Run:
python script.py robot .\tests\...\suite
In that way, you will be able to work with output files when tests or suites are finished.
If you run robot's command with -d flag to save results on a different folder, consider using automatic variable from Robot Framework called ${OUTPUT DIR} to get full source path and save it to txt file on root folder. That's because you'll be able to read it and find the logs in your script.py.

python. How to redirect Maya history?

All Maya script logs and errors printed in history tab. This is output from all commands and python scripts.
For better debugging scripts I want all the logs were sent somewhere on the server. How to intercept and send the output to your script. Then I will do all that is necessary, and the output is either a remote console, or somewhere in the files on the server.
The task to intercept the output. How to do it?
You can also redirect Script Editor history using Maya's scriptEditorInfo command found here:
An example usage of this would be something like:
import maya.cmds as cmds
outfile = r'/path/to/your/outfile.txt'
# begin output capture
cmds.scriptEditorInfo(historyFilename=outfile, writeHistory=True)
# stop output capture
cmds.scriptEditorInfo(writeHistory=False)
There is also cmdFileOutput which you can either call interactively or enable/disable via a registry entry to MAYA_CMD_FILE_OUTPUT, documentation here
Lastly, you can augment Maya start using the -log flag to write the Output Window text to another location. With this however, you do not get the Script Editor output, but could be all you desire given what it is you are trying to log.
its sounds like that you need a real-time error tracker like Sentry
, in Sentry are logging modules that are maked exactly for this reason, communicate Server/Client logging with a richer error/debug handling
here a example for Rerouting the Maya Script Editor to a terminal

using twistd to run a twisted application but script run twice

sample code here
# main.py
from twisted.application import service, internet
application = service.Application("x")
service.IProcess(application).processName = "x"
print "some log...."
if I run this main.py with:
twistd -y main.py
I got 2 "some log...." lines.
If this code run twice?
The "process name" feature you're using works by re-executing the process with a new argv[0]. There is no completely reliable way to save an arbitrary object (like the Application) across this process re-execution. This means that the .py file has to be re-evaluated in the new process to recreate the Application object so twistd knows what you want it to do.
You might want to consider using setproctitle rather than twistd's built-in process title feature. (For that matter, maybe twistd should just use it if it's available...)

Android's MonkeyRunner occasionally throws exceptions

I am running an automated test using an Android emulator driving an app with a Monkey script written in Python.
The script is copying files onto the emulator, clicks buttons in the app and reacts depending on the activities that the software triggers during its operation. The script is supposed to be running the cycle a few thousand times so I have this in a loop to run the adb tool to copy the files, start the activities and see how the software is reacting by calling the getProperty method on the device with the parameter 'am.current.comp.class'.
So here is a very simplified version of my script:
for target in targets:
androidSDK.copyFile(emulatorName, target, '/mnt/sdcard')
# Runs the component
device.startActivity(component='com.myPackage/com.myPackage.myactivity')
while 1:
if device.getProperty('am.current.comp.class') == 'com.myPackage.anotheractivity':
time.sleep(1) # to allow the scree to display the new activity before I click on it
device.touch(100, 100, 'DOWN_AND_UP')
# Log the result of the operation somewhere
break
time.sleep(0.1)
(androidSDK is a small class I've written that wraps some utility functions to copy and delete files using the adb tool).
On occasions the script crashes with one of a number of exceptions, for instance (I am leaving out the full stack trace)
[com.android.chimpchat.adb.AdbChimpDevice]com.android.ddmlib.ShellCommandUnresponsiveException
or
[com.android.chimpchat.adb.AdbChimpDevice] Unable to get variable: am.current.comp.class
[com.android.chimpchat.adb.AdbChimpDevice]java.net.SocketException: Software caused connectionabort: socket write error
I have read that sometimes the socket connection to the device becomes unstable and may need a restart (adb start-server and adb kill-server come in useful).
The problem I'm having is that the tools are throwing Java exceptions (Monkey runs in Jython), but I am not sure how those can be trapped from within my Python script. I would like to be able to determine the exact cause of the failure inside the script and recover the situation so I can carry on with my iterations (re-establish the connection, for instance? Would for instance re-initialising my device with another call to MonkeyRunner.waitForConnection be enough?).
Any ideas?
Many thanks,
Alberto
EDIT. I thought I'd mention that I have discovered that it is possible to catch Java-specific exceptions in a Jython script, should anyone need this:
from java.net import SocketException
...
try:
...
except(SocketException):
...
It is possible to catch Java-specific exceptions in a Jython script:
from java.net import SocketException
...
try:
...
except(SocketException):
...
(Taken from OP's edit to his question)
This worked for me:
device.shell('exit')# Exit the shell

python,running command line servers - they're not listening properly

Im attempting to start a server app (in erlang, opens ports and listens for http requests) via the command line using pexpect (or even directly using subprocess.Popen()).
the app starts fine, logs (via pexpect) to the screen fine, I can interact with it as well via command line...
the issue is that the servers wont listen for incoming requests. The app listens when I start it up manually, by typing commands in the command line. using subprocess/pexpect stops the app from listening somehow...
when I start it manually "netstat -tlp" displays the app as listening, when I start it via python (subprocess/pexpect) netstat does not register the app...
I have a feeling it has something to do with the environemnt, the way python forks things, etc.
Any ideas?
thank you
basic example:
note:
"-pz" - just ads ./ebin to the modules path for the erl VM, library search path
"-run" - runs moduleName, without any parameters.
command_str = "erl -pz ./ebin -run moduleName"
child = pexpect.spawn(command_str)
child.interact() # Give control of the child to the user
all of this stuff works correctly, which is strange. I have logging inside my code and all the log messages output as they should. the server wouldnt listen even if I started up its process via a bash script, so I dont think its the python code thats causing it (thats why I have a feeling that its something regarding the way the new OS process is started).
It could be to do with the way that command line arguments are passed to the subprocess.
Without more specific code, I can't say for sure, but I had this problem working on sshsplit ( https://launchpad.net/sshsplit )
To pass arguments correctly (in this example "ssh -ND 3000"), you should use something like this:
openargs = ["ssh", "-ND", "3000"]
print "Launching %s" %(" ".join(openargs))
p = subprocess.Popen(openargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
This will not only allow you to see exactly what command you are launching, but should correctly pass the values to the executable. Although I can't say for sure without seeing some code, this seems the most likely cause of failure (could it also be that the program requires a specific working directory, or configuration file?).

Categories