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.
 
 

243 lines
5.2 KiB

#!/bin/bash
exname=$(basename $0)
prefix_cmd="
. /etc/shlib
include common
include parse
. ../lib/common
"
[ "$DEBUG" ] && echo "Loading testlib..."
if ! . ./libtest ; then
echo 'libtest failed to load.'
exit 1
fi
export COLUMNS=50
test_pid_file="$tmp_dir/test.$$pid.tmp"
rm -f "$test_pid_file"
##
## Mocks
##
relation-get() {
local key="$1"
echo "$CFG" | shyaml get-value "$key" 2>/dev/null
}
export -f relation-get
file_put() {
echo "file_put $1"
cat - | prefix " | "
}
export -f file_put
docker() {
echo "docker" "$@"
echo stdin:
cat - | prefix " | "
}
export -f docker
config-add() {
echo "config-add"
echo "$1" | prefix " | "
}
export -f config-add
mkdir() {
echo "called: $FUNCNAME $@" >&2
}
export -f mkdir
setfacl() {
echo "called: $FUNCNAME $@" >&2
}
export -f setfacl
chgrp() {
echo "called: $FUNCNAME $@" >&2
}
export -f chgrp
chmod() {
echo "called: $FUNCNAME $@" >&2
}
export -f chmod
cached_cmd_on_base_image() {
echo "called: $FUNCNAME $@" >&2
echo "stdout:" >&2
echo "<GID>" | prefix " | " >&2
echo "<GID>"
}
export -f cached_cmd_on_base_image
##
## apache_vhost_create
##
try "
export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
DOMAIN=www.example.com
DOCKER_SITE_PATH=/var/www/\$DOMAIN
apache_vhost_create"
noerror
is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/www.example.com.conf'
try "
export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
DOMAIN=www.example.com
DOCKER_SITE_PATH=/var/www/\$DOMAIN
CFG='
ssl: true
'
apache_vhost_create"
noerror
is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/www.example.com.conf'
is err ''
try "
export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
export CONFIGSTORE='\$CONFIGSTORE'
export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
DOMAIN=www.example.com
DOCKER_SITE_PATH=/var/www/\$DOMAIN
CFG='
ssl:
key: |
a
b
cert: c
'
apache_vhost_create"
noerror
is out part 'file_put $CONFIGSTORE/$BASE_CHARM_NAME/etc/ssl/certs/www.example.com.pem
| c'
is out part 'file_put $CONFIGSTORE/$BASE_CHARM_NAME/etc/ssl/private/www.example.com.key
| a
| b'
is out reg 'config-add'
is out reg ' - \$CONFIGSTORE/\$BASE_CHARM_NAME/etc/ssl/certs/www.example.com.pem:/etc/ssl/certs/www.example.com.pem:ro'
is out reg ' - \$CONFIGSTORE/\$BASE_CHARM_NAME/etc/ssl/private/www.example.com.key:/etc/ssl/private/www.example.com.key:ro'
try "
export DOCKER_BASE_IMAGE=docker/apache
export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
export CONFIGSTORE='\$CONFIGSTORE'
export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
DOMAIN=www.example.com
DOCKER_SITE_PATH=/var/www/\$DOMAIN
export CFG='
creds:
toto: xxx
'
apache_vhost_create"
noerror
is out reg "htpasswd -bc '/etc/apache2/sites-enabled/www.example.com.passwd' 'toto' 'xxx'"
is out reg 'docker run -i --entrypoint /bin/bash .* docker/apache'
##
## apache_proxy_dir
##
try "
export DOCKER_BASE_IMAGE=docker/apache
export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
export CONFIGSTORE='\$CONFIGSTORE'
export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
export CFG='
creds:
toto: xxx
'
apache_publish_dir"
is errlvl 1 ## no domain
try "
export DATASTORE='\$DATASTORE'
export DOCKER_BASE_IMAGE=docker/apache
export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
export CONFIGSTORE='\$CONFIGSTORE'
export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
export CFG='
domain: www.example.com
creds:
toto: xxx
'
apache_publish_dir"
is errlvl 0
is err reg 'setfacl -R -m g:<GID>:rx \$DATASTORE/\$BASE_CHARM_NAME/var/www/www.example.com'
is err reg 'cached_cmd_on_base_image apache id -g www-data'
try "
export DATASTORE='\$DATASTORE'
export DOCKER_BASE_IMAGE=docker/apache
export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
export CONFIGSTORE='\$CONFIGSTORE'
export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
export CFG='
domain: www.example.com
creds:
toto: xxx
data-dirs:
- a
- b
- c
'
apache_publish_dir"
is errlvl 0
is err reg 'setfacl -R -m g:<GID>:rwx \$DATASTORE/\$BASE_CHARM_NAME/var/www/www.example.com/a \$DATASTORE/\$BASE_CHARM_NAME/var/www/www.example.com/b \$DATASTORE/\$BASE_CHARM_NAME/var/www/www.example.com/c'
is err reg 'setfacl -R -d -m g:<GID>:rwx \$DATASTORE/\$BASE_CHARM_NAME/var/www/www.example.com/a \$DATASTORE/\$BASE_CHARM_NAME/var/www/www.example.com/b \$DATASTORE/\$BASE_CHARM_NAME/var/www/www.example.com/c'
try "
export DATASTORE='\$DATASTORE'
export DOCKER_BASE_IMAGE=docker/apache
export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
export CONFIGSTORE='\$CONFIGSTORE'
export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
export MASTER_BASE_CHARM_NAME='\$MASTER_BASE_CHARM_NAME'
export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
export CFG='
domain: www.example.com
location: /opt/apps/newlocation
creds:
toto: xxx
data-dirs:
- a
- b
- c
'
apache_publish_dir"
is errlvl 0
is err reg 'mkdir -p /opt/apps/newlocation'
is err reg 'setfacl -R -m g:<GID>:rx /opt/apps/newlocation'
is out part ' | $MASTER_BASE_CHARM_NAME:
| volumes:
| - /opt/apps/newlocation:/var/www/www.example.com'
summary