drone-wait-objectstore.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. function get_swift_token() {
  3. KEYSTONE_OUT=$(curl -s 'http://dockswift:5000/v2.0/tokens' -H 'Content-Type: application/json' -d '{"auth":{"passwordCredentials":{"username":"swift","password":"swift"},"tenantName":"service"}}')
  4. if (echo "$KEYSTONE_OUT" | grep -q 'object-store')
  5. then
  6. SWIFT_ENDPOINT=$(echo "$KEYSTONE_OUT" | php -r "echo array_values(array_filter(json_decode(file_get_contents('php://stdin'),true)['access']['serviceCatalog'], function(\$endpoint){return \$endpoint['type']==='object-store';}))[0]['endpoints'][0]['publicURL'];")
  7. SWIFT_TOKEN=$(echo "$KEYSTONE_OUT" | php -r "echo json_decode(file_get_contents('php://stdin'),true)['access']['token']['id'];")
  8. return 0
  9. else
  10. return -1
  11. fi
  12. }
  13. if [ "$OBJECT_STORE" == "swift" ]; then
  14. echo "waiting for keystone"
  15. until get_swift_token
  16. do
  17. sleep 2
  18. done
  19. echo "waiting for object store at $SWIFT_ENDPOINT"
  20. until curl -s -H "X-Auth-Token: $SWIFT_TOKEN" "$SWIFT_ENDPOINT"
  21. do
  22. sleep 2
  23. done
  24. echo "creating container"
  25. sleep 2
  26. while [ 1 ]
  27. do
  28. sleep 2
  29. respCode=$(curl -s -o /dev/null -w "%{http_code}" -X PUT -H "X-Auth-Token: $SWIFT_TOKEN" "$SWIFT_ENDPOINT/nextcloud")
  30. if [ "$respCode" == "201" ]
  31. then
  32. break
  33. fi
  34. done
  35. echo "creating test file"
  36. i=0
  37. while [ 1 ]
  38. do
  39. sleep 2
  40. respCode=$(curl -s -o /dev/null -w "%{http_code}" -X PUT -H "X-Auth-Token: $SWIFT_TOKEN" -H "Content-Type: text/html; charset=UTF-8" -d "Hello world" "$SWIFT_ENDPOINT/nextcloud/helloworld.txt")
  41. if [ "$respCode" == "201" ]
  42. then
  43. break
  44. fi
  45. i=$((i + 1))
  46. if [ "$i" == "20" ]
  47. then
  48. exit -1
  49. fi
  50. done
  51. echo "deleting test file"
  52. curl -s -o /dev/null -w "%{http_code}\n" -X DELETE -H "X-Auth-Token: $SWIFT_TOKEN" "$SWIFT_ENDPOINT/nextcloud/helloworld.txt"
  53. fi