Forum Discussion

jcomber's avatar
jcomber
Occasional Contributor
3 years ago

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.

  • 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's avatar
    KarelHusa
    Champion Level 1

    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.

     

    • jcomber's avatar
      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's avatar
        KarelHusa
        Champion Level 1

        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

         

  • jcomber's avatar
    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's avatar
      KarelHusa
      Champion Level 1

      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.

       

       

  • jcomber's avatar
    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()