summaryrefslogtreecommitdiff
path: root/yarns/900-implements.yarn
blob: 57f52aaf482b7c76c9331d01dd095e111e65d9cb (plain)
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
# Appendix: Scenario step implementations

## Configuration

Save the name of the server to be tested, so it doesn't need to be
repeated for every step.

    IMPLEMENTS GIVEN server name is (.+)
    echo "SERVER=$MATCH_1" >> "$DATADIR/config.sh"

Set account name to use on server.

    IMPLEMENTS GIVEN server has account (.+)
    echo "ACCOUNT=$MATCH_1" >> "$DATADIR/config.sh"

## Ping

Does the server respond to a ping?

    IMPLEMENTS THEN server responds to ping
    . "$DATADIR/config.sh"
    ping -c1 "$SERVER"

## Check server hostname

Does the server's hostname match its domain name?

    IMPLEMENTS THEN server hostname is as expected
    . "$DATADIR/config.sh"
    ssh "$ACCOUNT@$SERVER" hostname | grep -Fx "$SERVER"

## Ansible account

Does the server have an account `ansible` that has passwordless sudo
access to root?

    IMPLEMENTS THEN server account has sudo
    . "$DATADIR/config.sh"
    ssh "$ACCOUNT@$SERVER" sudo -n id -u > "$DATADIR/id.out"
    grep -F 0 "$DATADIR/id.out"

## Python 2 installed?

Does the server have Python 2 installed, by invoking `python`?

    IMPLEMENTS THEN server has python version 2 installed
    . "$DATADIR/config.sh"
    ssh "$ACCOUNT@$SERVER" python --version 2> "$DATADIR/python.out"
    grep "^Python 2\." "$DATADIR/python.out"

## Running command over ssh

Run a command on the server over ssh, capturing stdout and stderr and
exit code for later inspection.

    IMPLEMENTS WHEN running ssh (.*)
    if ssh $MATCH_1 > "$DATADIR/stdout" 2> "$DATADIR/stderr"
    then
        echo 0 > "$DATADIR/exit"
    else
        echo $? > "$DATADIR/exit"
    fi

## Access server over SFTP

Put and get a file over SFTP.

    IMPLEMENTS THEN server allows SFTP
    . "$DATADIR/config.sh"
    echo test.file > "$DATADIR/sftp.file"
    cat > "$DATADIR/sftp.commands" << EOF
    put $DATADIR/sftp.file sftp.file
    get sftp.file $DATADIR/sftp.file.copy
    rm sftp.file
    EOF
    sftp -b "$DATADIR/sftp.commands" "$ACCOUNT@$SERVER"
    cmp "$DATADIR/sftp.file"  "$DATADIR/sftp.file.copy"

## Inspect results of running a command

The stdout, stderr, and exit code have been saved. Inspect them.

    IMPLEMENTS THEN output matches (.+)
    cat "$DATADIR/stdout"
    grep "$MATCH_1" "$DATADIR/stdout"