bind10_control.py 2.13 KB
Newer Older
Jelte Jansen's avatar
Jelte Jansen committed
1
2
from lettuce import *
import subprocess
3
import re
Jelte Jansen's avatar
Jelte Jansen committed
4

5
6
7
8
9
def check_lines(output, lines):
    for line in lines:
        if output.find(line) != -1:
            return line

10
11
12
@step('start bind10(?: with configuration (\S+))?' +\
      '(?: with cmdctl port (\d+))?(?: as (\S+))?')
def start_bind10(step, config_file, cmdctl_port, process_name):
Jelte Jansen's avatar
Jelte Jansen committed
13
14
    args = [ 'bind10', '-v' ]
    if config_file is not None:
15
16
        args.append('-p')
        args.append("configurations/")
Jelte Jansen's avatar
Jelte Jansen committed
17
        args.append('-c')
18
        args.append(config_file)
19
    if cmdctl_port is None:
20
        args.append('--cmdctl-port=47805')
21
22
    else:
        args.append('--cmdctl-port=' + cmdctl_port)
23
24
    if process_name is None:
        process_name = "bind10"
25
26
27
    else:
        args.append('-m')
        args.append(process_name + '_msgq.socket')
Jelte Jansen's avatar
Jelte Jansen committed
28

29
30
    world.processes.add_process(step, process_name, args)

Jelte Jansen's avatar
Jelte Jansen committed
31
32
    # check output to know when startup has been completed
    # TODO what to do on failure?
33
34
35
36
    message = world.processes.wait_for_stderr_str(process_name,
                                                  ["BIND10_STARTUP_COMPLETE",
                                                   "BIND10_STARTUP_ERROR"])
    assert message == "BIND10_STARTUP_COMPLETE", "Got: " + str(message)
Jelte Jansen's avatar
Jelte Jansen committed
37

38
39
40
41
@step('wait for bind10 auth (?:of (\w+) )?to start')
def wait_for_auth(step, process_name):
    if process_name is None:
        process_name = "bind10"
42
    world.processes.wait_for_stderr_str(process_name, ['AUTH_SERVER_STARTED'])
Jelte Jansen's avatar
Jelte Jansen committed
43

44
45
46
47
48
49
@step('have bind10 running(?: with configuration ([\w.]+))?')
def have_bind10_running(step, config_file):
    step.given('start bind10 with configuration ' + config_file)
    step.given('wait for bind10 auth to start')

@step('set bind10 configuration (\S+) to (.*)')
Jelte Jansen's avatar
Jelte Jansen committed
50
def set_config_command(step, name, value):
51
52
    args = ['bindctl', '-p', '47805']
    bindctl = subprocess.Popen(args, 1, None, subprocess.PIPE,
Jelte Jansen's avatar
Jelte Jansen committed
53
54
55
56
                               subprocess.PIPE, None)
    bindctl.stdin.write("config set " + name + " " + value + "\n")
    bindctl.stdin.write("config commit\n")
    bindctl.stdin.write("quit\n")
57
58
    result = bindctl.wait()
    assert result == 0, "bindctl exit code: " + str(result)
Jelte Jansen's avatar
Jelte Jansen committed
59
60