Ask a Question

Trying to restart docker images from ReadyAPI Groovy script

SOLVED
jcomber
Occasional Contributor

Trying to restart docker images from ReadyAPI Groovy script

Is it possible to have a Groovy script within a ReadyAPI test suite that will restart docker image(s)?  I have an existing Groovy script that works but copying/pasting into a ReadyAPI Groovy script test step doesn't seem to work.  Am I expecting functionality from ReadyAPI that isn't supported with Groovy?  If it's possible to attain this, how is it done - not finding much information online.

7 REPLIES 7
KarelHusa
Super Contributor

@jcomber,

If you have a running Groovy script, it should be feasible to accommodate and execute it from within ReadyAPI. You need to resolve dependencies (imports) and sometimes also privileges.

 

Usually, it works fine, though you may encounter library conflicts for dependencies.

 

Karel@apimate.eu
https://apimate.eu
jcomber
Occasional Contributor

 

                def dockerTemp = 'docker restart query'.execute()
//                def dockerRestartTest = 'docker restart ' + s
//                def dockerProc = dockerRestartTest.execute()

 

I've tried both versions of the offensive '.execute()' above (the commented 2 lines are the version that works in intelliJ) - both versions yield this in ReadyAPI:  ERROR: An error occurred [java.io.IOException: Cannot run program "docker": error=2, No such file or directory], see error log for details.  I'm able to run docker within a terminal and within intelliJ.  


 

KarelHusa
Super Contributor

@jcomber, it seems your ReadyAPI has different PATH environment variable setup than terminal or Idea.

You can try to execute docker with full path, e.g.:

 

/usr/bin/docker restart query

 

Karel@apimate.eu
https://apimate.eu
jcomber
Occasional Contributor

I've tried that suggestion (>which docker gives: /usr/bin/docker) to no avail.  I'm able to run ReadyAPI scripts against that server if the Groovy test step is disabled, so it appears to be directly Docker related.  Manually, I'm able to execute the docker cmd on that server just fine.  At a loss...

jcomber
Occasional Contributor

This should be possible, correct?  A Groovy script, running within a ReadyAPI test suite, ought to be able to SSH into a server and execute a 'docker restart' command I would think.  Any ideas how to implement this?  

KarelHusa
Super Contributor

@jcomber,

don't give it up; running docker from a Groovy script works; I just tried it in my ReadyAPI (see screenshot below).

 

There has to be some issue in your environment; try executing other commands, logging your PATH variable, etc., to debug the issue. Let us know then what the issue was.

 

KarelHusa_0-1666250272190.png

 

Karel@apimate.eu
https://apimate.eu
jcomber
Occasional Contributor

Thanks Karel - got it working!!  The issue was that I needed a proper key-pair and then my Groovy script had to be of the form (splitting it in the following fashion worked):
def dockerRestartTest = "ssh username@hostname docker restart "
def dockerProc = dockerRestartTest.execute()

cancel
Showing results for 
Search instead for 
Did you mean: