bind10_control.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. def check_lines(output, lines):
  10. for line in lines:
  11. if output.find(line) != -1:
  12. return line
  13. @world.absorb
  14. def wait_for_output_lines(lines, examine_past = True):
  15. assert world.bind10 is not None
  16. if examine_past:
  17. for output in world.bind10_output:
  18. for line in lines:
  19. if output.find(line) != -1:
  20. return line
  21. found = False
  22. while not found:
  23. output = world.bind10.stderr.readline()
  24. # store any line, for examine_skipped
  25. world.bind10_output.append(output)
  26. for line in lines:
  27. if output.find(line) != -1:
  28. return line
  29. @step(u'start bind10(?: with configuration ([\w.]+))?')
  30. def start_bind10(step, config_file):
  31. args = [ 'bind10', '-v' ]
  32. if config_file is not None:
  33. args.append('-c')
  34. args.append("configurations/" + config_file)
  35. world.bind10 = subprocess.Popen(args, 1, None, subprocess.PIPE,
  36. subprocess.PIPE, subprocess.PIPE)
  37. # check output to know when startup has been completed
  38. # TODO what to do on failure?
  39. message = world.wait_for_output_lines(["BIND10_STARTUP_COMPLETE",
  40. "BIND10_STARTUP_ERROR"])
  41. assert message == "BIND10_STARTUP_COMPLETE"
  42. @step(u'wait for bind10 auth to start')
  43. def wait_for_auth(step):
  44. world.wait_for_output_lines(['AUTH_SERVER_STARTED'])
  45. @step(u'wait for log message (\w+)')
  46. def wait_for_message(step, message):
  47. world.wait_for_output_lines([message], False)
  48. @step(u'stop bind10')
  49. def stop_the_server(step):
  50. world.shutdown_server()
  51. @step(u'set bind10 configuration (\S+) to (.*)')
  52. def set_config_command(step, name, value):
  53. bindctl = subprocess.Popen(['bindctl'], 1, None, subprocess.PIPE,
  54. subprocess.PIPE, None)
  55. bindctl.stdin.write("config set " + name + " " + value + "\n")
  56. bindctl.stdin.write("config commit\n")
  57. bindctl.stdin.write("quit\n")
  58. result = bindctl.wait()
  59. assert result == 0, "bindctl exit code: " + str(result)