Skip to content

Commit c13f7c3

Browse files
committed
export -A: fix the number of snapshots to 1
1 parent c8f51c5 commit c13f7c3

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2222
- start: overwrite /etc/hosts of a pot, adding all pots on the same bridge and custom entries added via set-hosts
2323
- flavorable commands: extend support to set-cmd and set-env
2424
- pot-rdr anchor: the name of the anchor is now a truncated pot name (the last 54 characters)
25-
- export: it's executed only if one snapshot is available. -F force execution, -A call purge-snapshots to reduce the number of shapshot to 1
25+
- export: it's executed only if one snapshot is available. -F force execution, -A fix the number of snapshots, via purge-snapshots or taking a shapshot automagically
2626
- start: using exec.start instead of command (it seems more predictable)
2727

2828
### Deprecated

share/pot/export.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export-help() {
1717
echo ' -D directory : where to store the compressed file with the pot'
1818
echo ' -l compression-level : from 0 (fast) to 9 (best). Defaul level 6. (man xz for more information)'
1919
echo ' -F : force exports of multiple snapshot (only 1 snapshot should be allowed)'
20-
echo ' -A : auto-purge older snapshots (only 1 snapshot should be allowed)'
20+
echo ' -A : auto-fix snapshots number (exactly 1 snapshot is allowed)'
2121
}
2222

2323
# $1 : pot name
@@ -131,8 +131,19 @@ pot-export()
131131
else
132132
_snap="$(_zfs_last_snap "${POT_ZFS_ROOT}/jails/$_pname" )"
133133
if [ -z "$_snap" ]; then
134-
_error "pot $_pname has no snapshots - please use pot snapshot for that"
135-
${EXIT} 1
134+
if [ "$_auto_purge" = "YES" ]; then
135+
_info "Taking a snapshot of $_pname"
136+
if ! pot-cmd snapshot -p "$_pname" ; then
137+
_error "Failed to take a snapshot of pot $_pname"
138+
${EXIT} 1
139+
else
140+
_snap="$(_zfs_last_snap "${POT_ZFS_ROOT}/jails/$_pname" )"
141+
_debug "A snapshot of $_pname has been automatically taken (@$_snap)"
142+
fi
143+
else
144+
_error "Pot $_pname has no snapshots - please use pot snapshot for that"
145+
${EXIT} 1
146+
fi
136147
fi
137148
fi
138149
if [ "$( _zfs_count_snap "${POT_ZFS_ROOT}/jails/$_pname" )" -gt 1 ]; then

tests/common-stub.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ EXIT="return"
1616
# test-pot-single no single 0 10.1.2.3 yes public-bridge
1717
# test-pot-single-run yes single 0 undef yes public-bridge
1818
# test-pot-single-2 no single 0 10.1.2.3 yes public-bridge
19+
# test-pot-single-0 no single 0 10.1.2.3 yes public-bridge
1920
# test-pot-3 no multi 1 10.1.2.3 no alias
2021

2122
# test-pot-multi-inherit no multi 1 no inherit
@@ -70,7 +71,7 @@ _is_pot()
7071
test-pot|test-pot-run|\
7172
test-pot-2|test-pot-run-2|\
7273
test-pot-0|test-pot-nosnap|test-pot-3|\
73-
test-pot-single|test-pot-single-run|test-pot-single-2|\
74+
test-pot-single|test-pot-single-run|test-pot-single-2|test-pot-single-0|\
7475
test-pot-multi-inherit|test-pot-multi-private|\
7576
${POT_DNS_NAME})
7677
return 0 # true
@@ -137,7 +138,8 @@ _get_conf_var()
137138
test-pot-2|test-pot-run-2)
138139
echo "2"
139140
;;
140-
test-pot-0|test-pot-single|test-pot-single-run|test-pot-single-2)
141+
test-pot-0|test-pot-single|test-pot-single-run|\
142+
test-pot-single-2|test-pot-single-0)
141143
echo "0"
142144
;;
143145
esac
@@ -158,7 +160,7 @@ _get_conf_var()
158160
echo ""
159161
;;
160162
test-pot-2|test-pot-3|\
161-
test-pot-single|test-pot-single-2)
163+
test-pot-single|test-pot-single-2|test-pot-single-0)
162164
echo "10.1.2.3"
163165
;;
164166
test-pot-multi-private)
@@ -176,7 +178,7 @@ _get_conf_var()
176178
echo "alias"
177179
;;
178180
test-pot-2|test-pot-single-run|\
179-
test-pot-single|test-pot-single-2)
181+
test-pot-single|test-pot-single-2|test-pot-single-0)
180182
echo "public-bridge"
181183
;;
182184
test-pot-multi-private)
@@ -192,14 +194,14 @@ _get_conf_var()
192194
test-pot-multi-inherit|test-pot-multi-private)
193195
echo "multi"
194196
;;
195-
test-pot-single|test-pot-single-run|test-pot-single-2)
197+
test-pot-single|test-pot-single-run|test-pot-single-2|test-pot-single-0)
196198
echo "single"
197199
esac
198200
;;
199201
"vnet")
200202
case $1 in
201203
test-pot-2|test-pot-single|test-pot-single-run|\
202-
test-pot-multi-private|test-pot-single-2)
204+
test-pot-multi-private|test-pot-single-2|test-pot-single-0)
203205
echo "true"
204206
;;
205207
test-pot-3|test-pot-multi-inherit)

tests/export1.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ _zfs_last_snap()
2626
echo 1234321
2727
elif [ "$1" = "/jails/test-pot-single-2" ]; then
2828
echo 4321234
29+
elif [ "$1" = "/jails/test-pot-single-0" ]; then
30+
if [ -e /tmp/pot_test_last_snap ]; then
31+
echo 123123123
32+
rm -f /tmp/pot_test_last_snap
33+
else
34+
touch /tmp/pot_test_last_snap
35+
fi
2936
fi
3037
}
3138

@@ -184,6 +191,15 @@ test_pot_export_031()
184191
assertEquals "_export calls" "0" "$EXPORTS_CALLS"
185192
}
186193

194+
test_pot_export_032()
195+
{
196+
# no snapshosts available
197+
pot-export -p test-pot-single-0
198+
assertEquals "Exit rc" "1" "$?"
199+
assertEquals "Error calls" "1" "$ERROR_CALLS"
200+
assertEquals "_export calls" "0" "$EXPORTS_CALLS"
201+
}
202+
187203
test_pot_export_040()
188204
{
189205
pot-export -p test-pot-single
@@ -282,12 +298,30 @@ test_pot_export_051()
282298
assertEquals "Error calls" "0" "$ERROR_CALLS"
283299
assertEquals "_is_zfs_pot_snap calls" "0" "$ISZFSSNAP_CALLS"
284300
assertEquals "pot-cmd calls" "1" "$POTCMD_CALLS"
301+
assertEquals "pot-cmd arg1" "purge-snapshots" "$POTCMD_CALL1_ARG1"
285302
assertEquals "_export calls" "1" "$EXPORTS_CALLS"
286303
assertEquals "_export arg1" "test-pot-single-2" "$EXPORTS_CALL1_ARG1"
287304
assertEquals "_export arg2" "4321234" "$EXPORTS_CALL1_ARG2"
288305
assertEquals "_export arg3" "1.0" "$EXPORTS_CALL1_ARG3"
289306
assertEquals "_export arg4" "." "$EXPORTS_CALL1_ARG4"
290307
}
308+
309+
test_pot_export_052()
310+
{
311+
pot-export -p test-pot-single-0 -t 1.0 -A
312+
assertEquals "Exit rc" "0" "$?"
313+
assertEquals "Help calls" "0" "$HELP_CALLS"
314+
assertEquals "Error calls" "0" "$ERROR_CALLS"
315+
assertEquals "_is_zfs_pot_snap calls" "0" "$ISZFSSNAP_CALLS"
316+
assertEquals "pot-cmd calls" "1" "$POTCMD_CALLS"
317+
assertEquals "pot-cmd arg1" "snapshot" "$POTCMD_CALL1_ARG1"
318+
assertEquals "_export calls" "1" "$EXPORTS_CALLS"
319+
assertEquals "_export arg1" "test-pot-single-0" "$EXPORTS_CALL1_ARG1"
320+
assertEquals "_export arg2" "123123123" "$EXPORTS_CALL1_ARG2"
321+
assertEquals "_export arg3" "1.0" "$EXPORTS_CALL1_ARG3"
322+
assertEquals "_export arg4" "." "$EXPORTS_CALL1_ARG4"
323+
}
324+
291325
setUp()
292326
{
293327
common_setUp
@@ -301,4 +335,9 @@ setUp()
301335
POTCMD_CALLS=0
302336
}
303337

338+
tearDown()
339+
{
340+
rm -f /tmp/pot_test_last_snap
341+
}
342+
304343
. shunit/shunit2

0 commit comments

Comments
 (0)