|
2 | 2 |
|
3 | 3 | FS="xfs"
|
4 | 4 |
|
5 |
| -testSparseVolumeDoesNotTakeDiskSpace() { |
| 5 | +testRegularVolumeChecksDiskSpaceBeforeFormatting() { |
| 6 | + local error result count |
| 7 | + # setup |
| 8 | + |
| 9 | + ## attempt creating 10 GiB volume while we have only 2 GiB of space |
| 10 | + error=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=false -o size=10GiB 2>&1) |
| 11 | + result=$? |
| 12 | + |
| 13 | + ## because we shadow real data dir with our test volume we're sure there shouldn't be any volumes |
| 14 | + count=$(ls -1 "/var/lib/${DRIVER}/" | wc -l) |
| 15 | + |
| 16 | + # checks |
| 17 | + assertEquals "1" "${result}" |
| 18 | + assertEquals "0" "${count}" |
| 19 | +} |
| 20 | + |
| 21 | +testRegularVolumeReservesDiskSpace() { |
6 | 22 | local volume info allocated_size apparent_size
|
7 | 23 | # setup
|
8 |
| - local volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=true) |
| 24 | + local volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=false) |
9 | 25 | local info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${volume}.${FS}")
|
10 | 26 | local allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
|
11 | 27 | local apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
|
12 | 28 |
|
13 | 29 | # checks
|
14 |
| - assertTrue "Sparse ${FS} volume of ${apparent_size} MiB should take less space: ${allocated_size} MiB" "[ ${allocated_size} -lt ${apparent_size} ]" |
| 30 | + assertTrue "Regular ${FS} volume of ${apparent_size} MiB should take at least same space: ${allocated_size} MiB" "[ ${allocated_size} -ge ${apparent_size} ]" |
15 | 31 |
|
16 | 32 | # cleanup
|
17 | 33 | docker volume rm "${volume}" > /dev/null
|
18 | 34 | }
|
19 | 35 |
|
20 |
| -testRegularVolumeReservesDiskSpace() { |
| 36 | +testSparseVolumeDoesNotCheckAvailableDiskSpace() { |
| 37 | + local volume result info apparent_size |
| 38 | + # setup |
| 39 | + |
| 40 | + ## attempt creating 10 GiB volume while we have only 2 GiB of space |
| 41 | + volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=true -o size=10GiB) |
| 42 | + result=$? |
| 43 | + |
| 44 | + info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${volume}.${FS}") |
| 45 | + apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9') |
| 46 | + |
| 47 | + # checks |
| 48 | + assertEquals "0" "${result}" |
| 49 | + assertEquals "10240" "${apparent_size}" |
| 50 | + |
| 51 | + # cleanup |
| 52 | + docker volume rm "${volume}" > /dev/null |
| 53 | +} |
| 54 | + |
| 55 | +testSparseVolumeDoesNotTakeDiskSpace() { |
21 | 56 | local volume info allocated_size apparent_size
|
22 | 57 | # setup
|
23 |
| - local volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=false) |
| 58 | + local volume=$(docker volume create -d "${DRIVER}" -o fs=${FS} -o sparse=true) |
24 | 59 | local info=$(ls --block-size=M -ls "/var/lib/${DRIVER}/${volume}.${FS}")
|
25 | 60 | local allocated_size=$(echo ${info} | awk '{print $1}' | tr -dc '0-9')
|
26 | 61 | local apparent_size=$(echo ${info} | awk '{print $6}' | tr -dc '0-9')
|
27 | 62 |
|
28 | 63 | # checks
|
29 |
| - assertTrue "Regular ${FS} volume of ${apparent_size} MiB should take at least same space: ${allocated_size} MiB" "[ ${allocated_size} -ge ${apparent_size} ]" |
| 64 | + assertTrue "Sparse ${FS} volume of ${apparent_size} MiB should take less space: ${allocated_size} MiB" "[ ${allocated_size} -lt ${apparent_size} ]" |
30 | 65 |
|
31 | 66 | # cleanup
|
32 | 67 | docker volume rm "${volume}" > /dev/null
|
|
0 commit comments