summaryrefslogtreecommitdiff
path: root/yarns/900-implements.yarn
blob: 433c374ad19eb6dc33eb8289cebb91344ae1e03d (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Scenario step implementations

This chapter has implementations of scenario steps used elsewhere in
this document.


## Should a scenario be run?

We provide a way to control which classes of scenarios get run. This
is done by passing in an environment variable `TESTS` to vmdebootstrap
(`--env` option), with a comma-separated list of classes:

* `fast`---run fast tests
* `build`---run scenarios that do builds

If `TESTS` is not set, everything gets run.

Scenarios can use the ASSUMING statements defined here to let the user
to allow them to run or not to run.

    IMPLEMENTS ASSUMING (fast|build) tests are requested
    support_required
    test_requested "$MATCH_1"

if `MIRROR` is set, use the default http mirror

    IMPLEMENTS ASSUMING (local|http) tests are requested
    support_required
    build_support_required
    mirror_requested "$MATCH_1"

## Building an image, or attempting to

To keep individual steps shorter, we provide some steps to set common
parts, such as the name of the image being built.

    IMPLEMENTS GIVEN user wants to build an image (\S+) that is (\S+) in size
    remember_setting IMAGE "$MATCH_1"
    remember_setting IMAGE_SIZE "$(size_in_bytes "$MATCH_2")"

Actually build an image. This looks like it can invoke any command,
but it's actually restricted to vmdebootstrap in the source tree.

    IMPLEMENTS WHEN the user runs vmdebootstrap (.*)
    PYTHONPATH="$SRCDIR" "$SRCDIR/bin/vmdebootstrap" \
        --image "$IMAGE" \
        --mirror ${MIRROR:=http://httpredir.debian.org/debian/} \
        --size "$IMAGE_SIZE" \
        $MATCH_1

Attempt to run vmdebootstrap, but allow it it to fail. Capture exit
code and stderr.

    IMPLEMENTS WHEN user attempts to run vmdebootstrap (.*)
    if PYTHONPATH="$SRCDIR" "$SRCDIR/bin/vmdebootstrap" \
        $MATCH_1 2> vmdebootstrap.stderr 1>vmdebootstrap.stdout
    then
        echo 0 > vmdebootstrap.exit
    else
        echo $? > vmdebootstrap.exit
    fi

Check for whether the attempted vmdebootstrap run had the desired exit
code.

    IMPLEMENTS THEN vmdebootstrap exited with a non-zero exit code
    grep -vFx 0 vmdebootstrap.exit

    IMPLEMENTS THEN vmdebootstrap exited with a zero exit code
    grep -Fx 0 vmdebootstrap.exit

Check the stderr of the attempted vmdebootstrap run.

    IMPLEMENTS THEN vmdebootstrap wrote an error message matching (.+)
    grep -P -e "$MATCH_1" vmdebootstrap.stderr

Check the stdout of the dry-run vmdebootstrap run.

    IMPLEMENTS THEN vmdebootstrap wrote a message matching (.+)
    grep -P -e "$MATCH_1" vmdebootstrap.stdout

Exclude a pattern from the stdout of the dry-run vmdebootstrap run.

    IMPLEMENTS THEN vmdebootstrap wrote a message not matching (.+)
    grep -P -v -e "$MATCH_1" vmdebootstrap.stdout

## Static tests on disk images

The steps in this section do static tests of disk image. These all
operate on the image specified in the step "GIVEN user wants to
build...".

Test the size of an image. This tests the length, not disk usage, of
the image.

    IMPLEMENTS THEN the image has the correct size
    actual="$(stat -c %s "$IMAGE")"
    [ "$actual" = "$IMAGE_SIZE" ]

Check the partition table on the image.

    IMPLEMENTS THEN the partition count of the image is (\d+)
    parted --script "$IMAGE" print |
        sed '1,/^Number/d' |
        grep -c . |
        grep -Fx $MATCH_1

Check partition boot flag.

    IMPLEMENTS THEN partition (\d+) has the boot flag set
    parted --script "$IMAGE" print |
        awk -v "PART=$MATCH_1" '/^ [0-9]+ / && $1 == PART && $7 ~ "^boot,?$"' |
        grep .

    IMPLEMENTS THEN partition (\d+) has the lba flag set
    parted --script "$IMAGE" print |
        awk -v "PART=$MATCH_1" '/^ [0-9]+ / && $1 == PART && $8 ~ "^lba?$"' |
        grep .

Check filesystem on a partition. This checks the actual filesystem,
not a type declared in the partition table.

    IMPLEMENTS THEN partition (\d+) has an? (\S+) filesystem
    device="$(kpartx_image_partition "$IMAGE" "$MATCH_1")"
    trap "unkpartx_image \"$IMAGE\"" EXIT
    blkid "$device" | grep "TYPE=\"$MATCH_2\""

Check that the partition contains a file with some content matching a
regular expression.

    IMPLEMENTS THEN partition (\d+) has file (\S+) matching (.+)
    device="$(kpartx_image_partition "$IMAGE" "$MATCH_1")"
    trap "unkpartx_image \"$IMAGE\"" EXIT
    mp="$(mktemp -d)"
    mount -r "$device" "$mp"
    trap "umount \"$mp\"; unkpartx_image \"$IMAGE\"" EXIT
    grep -P -e "$MATCH_3" "$mp/$MATCH_2"

Check that the partition contains a specified symlink.

    IMPLEMENTS THEN partition (\d+) has symlink (\S+)
    device="$(kpartx_image_partition "$IMAGE" "$MATCH_1")"
    trap "unkpartx_image \"$IMAGE\"" EXIT
    mp="$(mktemp -d)"
    mount -r "$device" "$mp"
    trap "umount \"$mp\"; unkpartx_image \"$IMAGE\"" EXIT
    stat "$mp/$MATCH_2" |
    grep "symbolic link"

Check that the partition contains a specified path.

    IMPLEMENTS THEN partition (\d+) has filename (\S+)
    device="$(kpartx_image_partition "$IMAGE" "$MATCH_1")"
    trap "unkpartx_image \"$IMAGE\"" EXIT
    mp="$(mktemp -d)"
    mount -r "$device" "$mp"
    trap "umount \"$mp\"; unkpartx_image \"$IMAGE\"" EXIT
    stat "$mp/$MATCH_2" |
    grep "regular file"

Check the image output format

    IMPLEMENTS THEN image has file format matching (.+)
    qemu-img info $IMAGE |
        grep "file format" |
        grep $MATCH_1