Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top