2

I don't seem to be getting the expected workings. I can't seem to actually catch the prompt.

Here is what I have:

with settings(hide('commands', 'warnings') , warn_only=True):
   prompts = expect('Are you sure you want to perform this operation? [Y/N]:', 'N')
   with expecting(prompts):
      run(sudo("/something.sh apply /some.file" , user="someuser"))

I'm pretty sure I'm doing something wrong.

Jasper van den Bosch
  • 3,169
  • 4
  • 32
  • 55
Ecogeek
  • 23
  • 3
  • Can you post the code of `something.sh`? – Jasper van den Bosch Nov 21 '12 at 16:14
  • 1
    something.sh is actually a Blackboard patching script. Looking at it, I see that it basically sets up it's environment then drops into a Java command line script. I'm guessing that's why it's not working. Can't pass the value through two steps... – Ecogeek Nov 21 '12 at 16:32
  • I don't think that should be a problem. Try 3. below and the corrected import statement. – Jasper van den Bosch Nov 21 '12 at 16:33
  • 1
    That did it! I really appreciate the help and this awesome tool. This is going to make deployments a lot faster! – Ecogeek Nov 21 '12 at 16:55

1 Answers1

0

I have edited your code with some minor things:

  1. expecting requires a list
  2. Fabric/Fexpect sudo() and run() cannot be nested. You probably just need sudo()
  3. You have to escape regexp symbols, such as [] with a slash \[ or just make the 'expectation' shorter:

    prompts = []
    prompts += expect('Are you sure.*', 'N')
    with expecting(prompts):
        sudo("/something.sh apply /some.file" , user="someuser")
    

Also, perhaps you should not hide('commands'), depending on what prompt something.sh uses.

Jasper van den Bosch
  • 3,169
  • 4
  • 32
  • 55
  • 1
    The fabric script is still pausing waiting for input. Not sure what's wrong... This is the output: out: Performing pre-apply validation... out: Are you sure you want to perform this operation? [Y/N]: I've tried with and without the "out:" – Ecogeek Nov 21 '12 at 16:08
  • Did you properly import the fexpect version of sudo? `from ilogue.fexpect import run`? – Jasper van den Bosch Nov 21 '12 at 16:11
  • Run includes sudo, I take it? This is what I have: import time from fabric.api import env,roles,settings,sudo,puts,task,hide,execute,abort,local,runs_once from fabric.contrib.console import confirm from fabric.state import output from ilogue.fexpect import expect, expecting, run – Ecogeek Nov 21 '12 at 16:16
  • No, I think you should just import sudo: `from ilogue.fexpect import sudo` – Jasper van den Bosch Nov 21 '12 at 16:18