243 lines
5.2 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. prefix_cmd="
  4. . /etc/shlib
  5. include common
  6. include parse
  7. . ../lib/common
  8. "
  9. [ "$DEBUG" ] && echo "Loading testlib..."
  10. if ! . ./libtest ; then
  11. echo 'libtest failed to load.'
  12. exit 1
  13. fi
  14. export COLUMNS=50
  15. test_pid_file="$tmp_dir/test.$$pid.tmp"
  16. rm -f "$test_pid_file"
  17. ##
  18. ## Mocks
  19. ##
  20. relation-get() {
  21. local key="$1"
  22. echo "$CFG" | shyaml get-value "$key" 2>/dev/null
  23. }
  24. export -f relation-get
  25. file_put() {
  26. echo "file_put $1"
  27. cat - | prefix " | "
  28. }
  29. export -f file_put
  30. docker() {
  31. echo "docker" "$@"
  32. echo stdin:
  33. cat - | prefix " | "
  34. }
  35. export -f docker
  36. config-add() {
  37. echo "config-add"
  38. echo "$1" | prefix " | "
  39. }
  40. export -f config-add
  41. mkdir() {
  42. echo "called: $FUNCNAME $@" >&2
  43. }
  44. export -f mkdir
  45. setfacl() {
  46. echo "called: $FUNCNAME $@" >&2
  47. }
  48. export -f setfacl
  49. chgrp() {
  50. echo "called: $FUNCNAME $@" >&2
  51. }
  52. export -f chgrp
  53. chmod() {
  54. echo "called: $FUNCNAME $@" >&2
  55. }
  56. export -f chmod
  57. cached_cmd_on_base_image() {
  58. echo "called: $FUNCNAME $@" >&2
  59. echo "stdout:" >&2
  60. echo "<GID>" | prefix " | " >&2
  61. echo "<GID>"
  62. }
  63. export -f cached_cmd_on_base_image
  64. ##
  65. ## apache_vhost_create
  66. ##
  67. try "
  68. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  69. DOMAIN=www.example.com
  70. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  71. apache_vhost_create"
  72. noerror
  73. is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/www.example.com.conf'
  74. try "
  75. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  76. DOMAIN=www.example.com
  77. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  78. CFG='
  79. ssl: true
  80. '
  81. apache_vhost_create"
  82. noerror
  83. is out reg '^file_put \$SERVICE_CONFIGSTORE/.*/www.example.com.conf'
  84. is err ''
  85. try "
  86. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  87. export CONFIGSTORE='\$CONFIGSTORE'
  88. export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
  89. export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
  90. DOMAIN=www.example.com
  91. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  92. CFG='
  93. ssl:
  94. key: |
  95. a
  96. b
  97. cert: c
  98. '
  99. apache_vhost_create"
  100. noerror
  101. is out part 'file_put $CONFIGSTORE/$BASE_CHARM_NAME/etc/ssl/certs/www.example.com.pem
  102. | c'
  103. is out part 'file_put $CONFIGSTORE/$BASE_CHARM_NAME/etc/ssl/private/www.example.com.key
  104. | a
  105. | b'
  106. is out reg 'config-add'
  107. is out reg ' - \$CONFIGSTORE/\$BASE_CHARM_NAME/etc/ssl/certs/www.example.com.pem:/etc/ssl/certs/www.example.com.pem:ro'
  108. is out reg ' - \$CONFIGSTORE/\$BASE_CHARM_NAME/etc/ssl/private/www.example.com.key:/etc/ssl/private/www.example.com.key:ro'
  109. try "
  110. export DOCKER_BASE_IMAGE=docker/apache
  111. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  112. export CONFIGSTORE='\$CONFIGSTORE'
  113. export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
  114. export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
  115. DOMAIN=www.example.com
  116. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  117. export CFG='
  118. creds:
  119. toto: xxx
  120. '
  121. apache_vhost_create"
  122. noerror
  123. is out reg "htpasswd -bc '/etc/apache2/sites-enabled/www.example.com.passwd' 'toto' 'xxx'"
  124. is out reg 'docker run -i --entrypoint /bin/bash .* docker/apache'
  125. ##
  126. ## apache_proxy_dir
  127. ##
  128. try "
  129. export DOCKER_BASE_IMAGE=docker/apache
  130. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  131. export CONFIGSTORE='\$CONFIGSTORE'
  132. export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
  133. export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
  134. export CFG='
  135. creds:
  136. toto: xxx
  137. '
  138. apache_publish_dir"
  139. is errlvl 1 ## no domain
  140. try "
  141. export DATASTORE='\$DATASTORE'
  142. export DOCKER_BASE_IMAGE=docker/apache
  143. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  144. export CONFIGSTORE='\$CONFIGSTORE'
  145. export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
  146. export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
  147. export CFG='
  148. domain: www.example.com
  149. creds:
  150. toto: xxx
  151. '
  152. apache_publish_dir"
  153. is errlvl 0
  154. is err reg 'setfacl -R -m g:<GID>:rx \$DATASTORE/\$BASE_CHARM_NAME/var/www/www.example.com'
  155. is err reg 'cached_cmd_on_base_image apache id -g www-data'
  156. try "
  157. export DATASTORE='\$DATASTORE'
  158. export DOCKER_BASE_IMAGE=docker/apache
  159. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  160. export CONFIGSTORE='\$CONFIGSTORE'
  161. export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
  162. export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
  163. export CFG='
  164. domain: www.example.com
  165. creds:
  166. toto: xxx
  167. data-dirs:
  168. - a
  169. - b
  170. - c
  171. '
  172. apache_publish_dir"
  173. is errlvl 0
  174. 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'
  175. 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'
  176. try "
  177. export DATASTORE='\$DATASTORE'
  178. export DOCKER_BASE_IMAGE=docker/apache
  179. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  180. export CONFIGSTORE='\$CONFIGSTORE'
  181. export BASE_CHARM_NAME='\$BASE_CHARM_NAME'
  182. export MASTER_BASE_CHARM_NAME='\$MASTER_BASE_CHARM_NAME'
  183. export MASTER_TARGET_CHARM_NAME='\$MASTER_TARGET_CHARM_NAME'
  184. export CFG='
  185. domain: www.example.com
  186. location: /opt/apps/newlocation
  187. creds:
  188. toto: xxx
  189. data-dirs:
  190. - a
  191. - b
  192. - c
  193. '
  194. apache_publish_dir"
  195. is errlvl 0
  196. is err reg 'mkdir -p /opt/apps/newlocation'
  197. is err reg 'setfacl -R -m g:<GID>:rx /opt/apps/newlocation'
  198. is out part ' | $MASTER_BASE_CHARM_NAME:
  199. | volumes:
  200. | - /opt/apps/newlocation:/var/www/www.example.com'
  201. summary