daily pastebin goal
95%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. set -e
  3.  
  4. CONTAINER="ds-test"
  5.  
  6. echo "Test setup"
  7. # Set up some data segments (these are just plain objects)
  8. TOKEN="`swift stat -v | grep "Auth Token" | cut -d : -f 2`"
  9. STORAGE_URL="`swift stat -v | grep "StorageURL" | cut -d : -f 2,3,4,5,6`"
  10.  
  11. pushd ${TMPDIR:-/tmp}
  12. echo "normal segment 1" > ns1
  13. echo "normal segment 2" > ns2
  14. echo "normal segment 3" > ns3
  15. echo "normal segment 4" > ns4
  16. echo "normal segment 5" > ns5
  17. echo "normal segment 6" > ns6
  18. echo "normal segment 7" > ns7
  19. echo "normal segment 8" > ns8
  20. echo "normal segment 9" > ns9
  21.  
  22. echo "submanifest segment 1" > sub1
  23. echo "submanifest segment 2" > sub2
  24. echo "submanifest segment 3" > sub3
  25. echo "submanifest segment 4" > sub4
  26.  
  27. swift upload "$CONTAINER" ns1 ns2 ns3 ns4 ns5 ns6 ns7 ns8 ns9 sub1 sub2 sub3 sub4 > /dev/null
  28.  
  29. cat <<EOF >submanifest
  30. [
  31.     {"data": "c3VibWFuaWZlc3QgaW50cm8gZGF0YQo="},
  32.     {"path": "$CONTAINER/sub1"},
  33.     {"path": "$CONTAINER/sub2"},
  34.     {"data": "c3VibWFuaWZlc3QgZGF0YSBzZWdtZW50Cg=="},
  35.     {"path": "$CONTAINER/sub3"},
  36.     {"path": "$CONTAINER/sub4"},
  37.     {"data": "c3VibWFuaWZlc3Qgb3V0cm8gZGF0YQo="}
  38. ]
  39. EOF
  40.  
  41. python -mjson.tool submanifest >/dev/null || echo "JSON not ok"
  42. curl -q -X PUT --data-binary @submanifest -H "X-Auth-Token: $TOKEN" $STORAGE_URL/$CONTAINER/submanifest?multipart-manifest=put
  43.  
  44.  
  45. function run_test() {
  46.     MANIFEST="$1"
  47.  
  48.     # It's 2018, but trailing commas in JSON are still not allowed.
  49.     python -mjson.tool $MANIFEST >/dev/null || echo "JSON not ok"
  50.     curl -q -X PUT --data-binary @$MANIFEST -H "X-Auth-Token: $TOKEN" $STORAGE_URL/$CONTAINER/$MANIFEST?multipart-manifest=put
  51.     curl -i -X GET -H "X-Auth-Token: $TOKEN" $STORAGE_URL/$CONTAINER/$MANIFEST
  52. }
  53.  
  54. echo
  55. echo "Manifest containing both path/data segments"
  56. cat <<EOF >manifest
  57. [
  58.     {"data": "ZGF0YSBwcmUgMQo="},
  59.     {"data": "ZGF0YSBwcmUgMgo="},
  60.     {"path": "$CONTAINER/ns1"},
  61.     {"data": "ZGF0YSAxCg=="},
  62.     {"path": "$CONTAINER/ns2"},
  63.     {"data": "ZGF0YSAyCg=="},
  64.     {"path": "$CONTAINER/ns3"},
  65.     {"data": "ZGF0YSAzCg=="},
  66.     {"path": "$CONTAINER/ns4"},
  67.     {"data": "ZGF0YSA0Cg=="},
  68.     {"path": "$CONTAINER/ns5"},
  69.     {"data": "ZGF0YSA1Cg=="},
  70.     {"path": "$CONTAINER/ns6"},
  71.     {"data": "ZGF0YSA2Cg=="},
  72.     {"path": "$CONTAINER/ns7"},
  73.     {"data": "ZGF0YSA3Cg=="},
  74.     {"path": "$CONTAINER/ns8"},
  75.     {"data": "ZGF0YSA4Cg=="},
  76.     {"path": "$CONTAINER/ns9"},
  77.     {"data": "ZGF0YSBwb3N0IDEK"},
  78.     {"data": "ZGF0YSBwb3N0IDIK"}
  79. ]
  80. EOF
  81. run_test "manifest"
  82.  
  83. echo
  84. echo "Manifest with ranges"
  85. cat <<EOF >manifest-range
  86. [
  87.     {"data": "ZGF0YSBwcmUgMQo="},
  88.     {"data": "ZGF0YSBwcmUgMgo="},
  89.     {"path": "$CONTAINER/ns1", "range": "0-6"},
  90.     {"path": "$CONTAINER/ns1", "range": "-2"},
  91.     {"data": "ZGF0YSAxCg=="},
  92.     {"path": "$CONTAINER/ns2", "range": "0-4"},
  93.     {"path": "$CONTAINER/ns2", "range": "-1"},
  94.     {"path": "$CONTAINER/ns3"},
  95.     {"data": "ZGF0YSBwb3N0IDEK"},
  96.     {"data": "ZGF0YSBwb3N0IDIK"}
  97. ]
  98. EOF
  99. run_test "manifest-range"
  100.  
  101. echo
  102. echo "Manifest with submanifest after normal segment"
  103. cat <<EOF >manifest-sub-after-normal
  104. [
  105.     {"data": "ZGF0YSBwcmUgMQo="},
  106.     {"data": "ZGF0YSBwcmUgMgo="},
  107.     {"path": "$CONTAINER/ns1"},
  108.     {"path": "$CONTAINER/submanifest"},
  109.     {"path": "$CONTAINER/ns2"},
  110.     {"data": "ZGF0YSBwb3N0IDEK"},
  111.     {"data": "ZGF0YSBwb3N0IDIK"}
  112. ]
  113. EOF
  114. run_test "manifest-sub-after-normal"
  115.  
  116.  
  117. echo
  118. echo "Manifest with submanifest after data segment"
  119. cat <<EOF >manifest-sub-after-data
  120. [
  121.     {"data": "ZGF0YSBwcmUgMQo="},
  122.     {"data": "ZGF0YSBwcmUgMgo="},
  123.     {"path": "$CONTAINER/ns1"},
  124.     {"data": "ZGF0YSBiZWZvcmUgc3VibWFuaWZlc3QK"},
  125.     {"path": "$CONTAINER/submanifest"},
  126.     {"data": "ZGF0YSBhZnRlciBzdWJtYW5pZmVzdAo="},
  127.     {"path": "$CONTAINER/ns2"},
  128.     {"data": "ZGF0YSBwb3N0IDEK"},
  129.     {"data": "ZGF0YSBwb3N0IDIK"}
  130. ]
  131. EOF
  132. run_test "manifest-sub-after-data"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top