bind10_control.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Copyright (C) 2011 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. from lettuce import *
  16. import subprocess
  17. import re
  18. @step('start bind10(?: with configuration (\S+))?' +\
  19. '(?: with cmdctl port (\d+))?(?: as (\S+))?')
  20. def start_bind10(step, config_file, cmdctl_port, process_name):
  21. """
  22. Start BIND 10 with the given optional config file, cmdctl port, and
  23. store the running process in world with the given process name.
  24. Parameters:
  25. config_file ('with configuration <file>', optional): this configuration
  26. will be used. The path is relative to the base lettuce
  27. directory.
  28. cmdctl_port ('with cmdctl port <portnr>', optional): The port on which
  29. b10-cmdctl listens for bindctl commands. Defaults to 47805.
  30. process_name ('as <name>', optional). This is the name that can be used
  31. in the following steps of the scenario to refer to this
  32. BIND 10 instance. Defaults to 'bind10'.
  33. This call will block until BIND10_STARTUP_COMPLETE or BIND10_STARTUP_ERROR
  34. is logged. In the case of the latter, or if it times out, the step (and
  35. scenario) will fail.
  36. It will also fail if there is a running process with the given process_name
  37. already.
  38. """
  39. args = [ 'bind10', '-v' ]
  40. if config_file is not None:
  41. args.append('-p')
  42. args.append("configurations/")
  43. args.append('-c')
  44. args.append(config_file)
  45. if cmdctl_port is None:
  46. args.append('--cmdctl-port=47805')
  47. else:
  48. args.append('--cmdctl-port=' + cmdctl_port)
  49. if process_name is None:
  50. process_name = "bind10"
  51. else:
  52. args.append('-m')
  53. args.append(process_name + '_msgq.socket')
  54. world.processes.add_process(step, process_name, args)
  55. # check output to know when startup has been completed
  56. message = world.processes.wait_for_stderr_str(process_name,
  57. ["BIND10_STARTUP_COMPLETE",
  58. "BIND10_STARTUP_ERROR"])
  59. assert message == "BIND10_STARTUP_COMPLETE", "Got: " + str(message)
  60. @step('wait for bind10 auth (?:of (\w+) )?to start')
  61. def wait_for_auth(step, process_name):
  62. """Wait for b10-auth to run. This is done by blocking until the message
  63. AUTH_SERVER_STARTED is logged.
  64. Parameters:
  65. process_name ('of <name', optional): The name of the BIND 10 instance
  66. to wait for. Defaults to 'bind10'.
  67. """
  68. if process_name is None:
  69. process_name = "bind10"
  70. world.processes.wait_for_stderr_str(process_name, ['AUTH_SERVER_STARTED'],
  71. False)
  72. @step('have bind10 running(?: with configuration ([\w.]+))?')
  73. def have_bind10_running(step, config_file):
  74. """
  75. Compound convenience step for running bind10, which consists of
  76. start_bind10 and wait_for_auth.
  77. Currently only supports the 'with configuration' option.
  78. """
  79. step.given('start bind10 with configuration ' + config_file)
  80. step.given('wait for bind10 auth to start')
  81. @step('set bind10 configuration (\S+) to (.*)(?: with cmdctl port (\d+))?')
  82. def set_config_command(step, name, value, cmdctl_port):
  83. """
  84. Run bindctl, set the given configuration to the given value, and commit it.
  85. Parameters:
  86. name ('configuration <name>'): Identifier of the configuration to set
  87. value ('to <value>'): value to set it to.
  88. cmdctl_port ('with cmdctl port <portnr>', optional): cmdctl port to send
  89. the command to. Defaults to 47805.
  90. Fails if cmdctl does not exit with status code 0.
  91. """
  92. if cmdctl_port is None:
  93. cmdctl_port = '47805'
  94. args = ['bindctl', '-p', cmdctl_port]
  95. bindctl = subprocess.Popen(args, 1, None, subprocess.PIPE,
  96. subprocess.PIPE, None)
  97. bindctl.stdin.write("config set " + name + " " + value + "\n")
  98. bindctl.stdin.write("config commit\n")
  99. bindctl.stdin.write("quit\n")
  100. result = bindctl.wait()
  101. assert result == 0, "bindctl exit code: " + str(result)