forked from 0k/0k-charms
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
4.2 KiB
171 lines
4.2 KiB
#!/bin/bash
|
|
|
|
exname=$(basename $0)
|
|
|
|
compose_core=$(which compose-core) || {
|
|
echo "Requires compose-core executable to be in \$PATH." >&2
|
|
exit 1
|
|
}
|
|
|
|
fetch-def() {
|
|
local path="$1" fname="$2"
|
|
( . "$path" 1>&2 || {
|
|
echo "Failed to load '$path'." >&2
|
|
exit 1
|
|
}
|
|
declare -f "$fname"
|
|
)
|
|
}
|
|
|
|
prefix_cmd="
|
|
. /etc/shlib
|
|
|
|
include common
|
|
include parse
|
|
|
|
. ../lib/common
|
|
|
|
$(fetch-def "$compose_core" yaml_get_values)
|
|
$(fetch-def "$compose_core" yaml_get_interpret)
|
|
$(fetch-def "$compose_core" read-0-err)
|
|
$(fetch-def "$compose_core" p-err)
|
|
$(fetch-def "$compose_core" expand_vars)
|
|
|
|
SERVICE_NAME='bar'
|
|
|
|
" || {
|
|
echo "Couldn't build prefix cmd" >&2
|
|
exit 1
|
|
}
|
|
|
|
# mock
|
|
cfg-get-value() {
|
|
local key="$1"
|
|
shyaml get-value "$key" 2>/dev/null
|
|
}
|
|
export -f cfg-get-value
|
|
|
|
get_top_master_service_for_service() {
|
|
local service="$1"
|
|
echo "$service"
|
|
}
|
|
export -f get_top_master_service_for_service
|
|
|
|
get_service_charm() {
|
|
local service="$1"
|
|
echo "$service"
|
|
}
|
|
export -f get_service_charm
|
|
|
|
charm.get_dir() {
|
|
local charm="$1"
|
|
echo "/path/to/charm-store/$charm"
|
|
}
|
|
export -f charm.get_dir
|
|
|
|
export CACHEDIR=$(mktemp -d -t tmp.XXXXXXXXXX)
|
|
export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
|
|
trap "rm -rf \"$state_tmpdir\"" EXIT
|
|
trap "rm -rf \"$CACHEDIR\"" EXIT
|
|
|
|
##
|
|
## Tests
|
|
##
|
|
|
|
try "
|
|
cron:entries_from_service 'foo' ''"
|
|
is errlvl 1
|
|
is err reg "Error:.*ailed to get.*."
|
|
is err reg "Error:.*empty.*."
|
|
is out '' TRIM
|
|
|
|
try "
|
|
cron:entries_from_service 'foo' '
|
|
(0 0 * * *) {XX} dc run --rm foo
|
|
'" "wrong lock args"
|
|
is errlvl 1
|
|
is err reg "Error:.*lock argument.*."
|
|
is err reg "Error:.*parse lock.*."
|
|
is out '' TRIM
|
|
|
|
|
|
try "
|
|
cron:entries_from_service 'foo' '
|
|
(0 0 * * * *) {} dc run --rm foo
|
|
'" "wrong schedule"
|
|
is errlvl 1
|
|
is err reg "Error:.*schedule.*"
|
|
is out '' TRIM
|
|
|
|
|
|
try "
|
|
cron:entries_from_service 'foo' '
|
|
(0 0 * * *) {}
|
|
'" "wrong command"
|
|
is errlvl 1
|
|
is err reg "Error:.*empty command.*"
|
|
is out '' TRIM
|
|
|
|
|
|
try "
|
|
set -o pipefail &&
|
|
cron:entries_from_service 'foo' '
|
|
(0 0 * * *) {-p 10 -k} dc run --rm foo
|
|
' | tr '\0' '\n'" "one command no label"
|
|
noerror
|
|
is out "\
|
|
0 0 * * * lock launch-foo -p 10 -k -c \"dc run --rm foo\" 2>&1 | awk '{ print strftime(\"%Y-%m-%d %H:%M:%S %Z\"), \$0; fflush(); }' >> /var/log/cron/launch-foo_script.log\
|
|
" TRIM
|
|
|
|
|
|
try "
|
|
set -o pipefail &&
|
|
cron:entries_from_service 'foo' '
|
|
wiz: (0 0 * * *) {-p 10 -k} dc run --rm foo
|
|
' | tr '\0' '\n'" "one command with label"
|
|
noerror
|
|
is out "\
|
|
0 0 * * * lock launch-foo-wiz -p 10 -k -c \"dc run --rm foo\" 2>&1 | awk '{ print strftime(\"%Y-%m-%d %H:%M:%S %Z\"), \$0; fflush(); }' >> /var/log/cron/launch-foo-wiz_script.log\
|
|
" TRIM
|
|
|
|
|
|
|
|
try "
|
|
set -o pipefail &&
|
|
cron:entries_from_service 'foo' '
|
|
wiz: (0 0 * * *) {-p 10 -k} dc run --rm foo
|
|
bam: (@daily) {-p 10 -D -k} dc run --rm foo --hop
|
|
|
|
' | tr '\0' '\n'" "multi command with label"
|
|
noerror
|
|
is out "\
|
|
0 0 * * * lock launch-foo-wiz -p 10 -k -c \"dc run --rm foo\" 2>&1 | awk '{ print strftime(\"%Y-%m-%d %H:%M:%S %Z\"), \$0; fflush(); }' >> /var/log/cron/launch-foo-wiz_script.log
|
|
@daily lock launch-foo-bam -p 10 -D -k -c \"dc run --rm foo --hop\" 2>&1 | awk '{ print strftime(\"%Y-%m-%d %H:%M:%S %Z\"), \$0; fflush(); }' >> /var/log/cron/launch-foo-bam_script.log\
|
|
" TRIM
|
|
|
|
|
|
|
|
try "
|
|
set -o pipefail &&
|
|
cron:entries_from_service 'foo' '!var-expand
|
|
(0 0 * * *) {-p 10 -k} dc run --rm \$BASE_SERVICE_NAME \$MASTER_BASE_SERVICE_NAME
|
|
' | tr '\0' '\n'" "using relation's var"
|
|
noerror
|
|
is out "\
|
|
0 0 * * * lock launch-foo -p 10 -k -c \"dc run --rm foo foo\" 2>&1 | awk '{ print strftime(\"%Y-%m-%d %H:%M:%S %Z\"), \$0; fflush(); }' >> /var/log/cron/launch-foo_script.log" TRIM
|
|
|
|
|
|
try "
|
|
set -o pipefail &&
|
|
cfg='!var-expand
|
|
(0 0 * * *) {-p 10 -k} dc run --rm \$BASE_SERVICE_NAME \$MASTER_BASE_SERVICE_NAME
|
|
'
|
|
cron:entries_from_service 'foo1' \"\$cfg\" | tr '\0' '\n'
|
|
cron:entries_from_service 'foo2' \"\$cfg\" | tr '\0' '\n'
|
|
" "using relation's var, same conf, different env"
|
|
noerror
|
|
is out "\
|
|
0 0 * * * lock launch-foo1 -p 10 -k -c \"dc run --rm foo1 foo1\" 2>&1 | awk '{ print strftime(\"%Y-%m-%d %H:%M:%S %Z\"), \$0; fflush(); }' >> /var/log/cron/launch-foo1_script.log
|
|
0 0 * * * lock launch-foo2 -p 10 -k -c \"dc run --rm foo2 foo2\" 2>&1 | awk '{ print strftime(\"%Y-%m-%d %H:%M:%S %Z\"), \$0; fflush(); }' >> /var/log/cron/launch-foo2_script.log\
|
|
" TRIM
|
|
|