bind10_control.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from lettuce import *
  2. import subprocess
  3. @world.absorb
  4. def shutdown_server():
  5. if world.bind10 is not None:
  6. world.bind10.terminate()
  7. world.bind10.wait()
  8. world.bind10 = None
  9. @world.absorb
  10. def wait_for_output_lines(lines):
  11. assert world.bind10 is not None
  12. found = False
  13. while not found:
  14. output = world.bind10.stderr.readline()
  15. for line in lines:
  16. if output.find(line) != -1:
  17. return line
  18. @step(u'start bind10(?: with configuration ([\w.]+))?')
  19. def start_bind10(step, config_file):
  20. args = [ 'bind10', '-v' ]
  21. if config_file is not None:
  22. args.append('-c')
  23. args.append("configurations/" + config_file)
  24. world.bind10 = subprocess.Popen(args, 1, None, subprocess.PIPE,
  25. subprocess.PIPE, subprocess.PIPE)
  26. # check output to know when startup has been completed
  27. # TODO what to do on failure?
  28. message = world.wait_for_output_lines(["BIND10_STARTUP_COMPLETE",
  29. "BIND10_STARTUP_ERROR"])
  30. assert message == "BIND10_STARTUP_COMPLETE"
  31. @step(u'wait for bind10 auth to start')
  32. def wait_for_auth(step):
  33. world.wait_for_output_lines(['AUTH_SERVER_STARTED'])
  34. @step(u'stop bind10')
  35. def stop_the_server(step):
  36. world.shutdown_server()
  37. @step(u'set bind10 configuration (\S+) to (.*)')
  38. def set_config_command(step, name, value):
  39. bindctl = subprocess.Popen(['bindctl'], 1, None, subprocess.PIPE,
  40. subprocess.PIPE, None)
  41. bindctl.stdin.write("config set " + name + " " + value + "\n")
  42. bindctl.stdin.write("config commit\n")
  43. bindctl.stdin.write("quit\n")
  44. bindctl.wait()