~fcorrea/charms/trusty/landscape-client/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash -eu

source lib/test-helpers.sh

test_setup() {
    echo "INFO: Setup Test Environment"
    juju deploy ubuntu
    juju deploy --repository . local:landscape-client
    juju add-relation ubuntu landscape-client
}

teardown() {
    echo "INFO: Starting Teardown"
    juju destroy-service ubuntu || /bin/true
    juju destroy-service landscape-client || /bin/true
}

assert_command_on_unit() {
    # Assert the command succeeds on the unit
    # $1 = unit to contact
    # $2 = command
    if ! juju ssh $1 "$2"; then
        error "CMD: $2 failed in $(diagnose)"
        exit 1
    fi
}

run_command_on_unit() {
    juju ssh $1 "$2"
}

assert_config() {
    # $1 = config
    # $2 and on = list of strings to run through egrep
    config=$1
    shift
    while [ $# -gt 0 ]; do
        if ! echo "$config" | egrep "$1"; then
            error "Config incorrect or missing: $1\n$(diagnose)"
            exit 1
        fi
        shift
    done
}


start-test "landscape-client add relation verify deploy"

teardown
test_setup

# Ensure ubuntu started, and landscape-client is related without error
jitsu watch --failfast \
    ubuntu --state=started -r "ubuntu landscape-client" \
    landscape-client --state=started


# Ensure all ubuntu service units look as expected (unregistered)
for i in $(jitsu get-service-info ubuntu public-address); do
    unit=$(echo $i | cut -d: -f1)
    host=$(echo $i | cut -d: -f2)
    assert_command_on_unit $unit "ps -ef | grep -v /usr/bin/landscape-client"
    assert_command_on_unit $unit "test -e /etc/landscape/client.conf"
    assert_command_on_unit $unit "sudo cat /etc/landscape/client.conf"
    assert_command_on_unit $unit "sudo grep computer_title /etc/landscape/client.conf | grep $unit"
done

# Set appropriate config for testing
juju set --config lib/test-config.yaml landscape-client

# We expect error since we aren't actually going to register the client
jitsu watch \
    landscape-client --state=configure-error

# Ensure all ubuntu service units look as expected (registration-attempt)
for i in $(jitsu get-service-info ubuntu public-address); do
    unit=$(echo $i | cut -d: -f1)
    host=$(echo $i | cut -d: -f2)
    assert_command_on_unit $unit "ps -ef | grep -v /usr/bin/landscape-client"
    assert_command_on_unit $unit "test -e /etc/landscape/client.conf"
    config=$(run_command_on_unit $unit "sudo cat /etc/landscape/client.conf")
    assert_config "$config" \
        "ping_url = http://foo.example.com/ping" \
        "data_path = /var/lib/landscape/client" \
        "computer_title = $unit" \
        "tags = foo,bar,baz" \
        "registration_password = foo-registration-key" \
        "url = https://foo.example.com/message-system" \
        "include_manager_plugins = ScriptExecution" \
        "script_users = ALL" \
        "registration_key = foo-registration-key" \
        "account_name = foo-account-name"
done

end-test "Deployed Successfully"