bind10_control.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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('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('-p')
  34. args.append("configurations/")
  35. args.append('-c')
  36. args.append(config_file)
  37. world.bind10 = subprocess.Popen(args, 1, None, subprocess.PIPE,
  38. subprocess.PIPE, subprocess.PIPE)
  39. # check output to know when startup has been completed
  40. # TODO what to do on failure?
  41. message = world.wait_for_output_lines(["BIND10_STARTUP_COMPLETE",
  42. "BIND10_STARTUP_ERROR"])
  43. assert message == "BIND10_STARTUP_COMPLETE"
  44. @step('wait for bind10 auth to start')
  45. def wait_for_auth(step):
  46. world.wait_for_output_lines(['AUTH_SERVER_STARTED'])
  47. @step('have bind10 running(?: with configuration ([\w.]+))?')
  48. def have_bind10_running(step, config_file):
  49. step.given('start bind10 with configuration ' + config_file)
  50. step.given('wait for bind10 auth to start')
  51. @step('wait for log message (\w+)')
  52. def wait_for_message(step, message):
  53. world.wait_for_output_lines([message], False)
  54. @step('stop bind10')
  55. def stop_the_server(step):
  56. world.shutdown_server()
  57. @step('set bind10 configuration (\S+) to (.*)')
  58. def set_config_command(step, name, value):
  59. bindctl = subprocess.Popen(['bindctl'], 1, None, subprocess.PIPE,
  60. subprocess.PIPE, None)
  61. bindctl.stdin.write("config set " + name + " " + value + "\n")
  62. bindctl.stdin.write("config commit\n")
  63. bindctl.stdin.write("quit\n")
  64. result = bindctl.wait()
  65. assert result == 0, "bindctl exit code: " + str(result)