summaryrefslogtreecommitdiffstats
path: root/src/test/rgw/test-rgw-common.sh
blob: 838169aa8e750ba49253b257661b04a974eb8b83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash

function var_to_python_json_index {
  echo "['$1']" | sed "s/\./'\]\['/g"
}

function json_extract {
var=$(var_to_python_json_index $1)
shift
python - <<END
import json
s='$@'
data = json.loads(s) 
print data$var
END
}

x() {
  echo "x " "$@"
  eval "$@"
}


script_dir=`dirname $0`
root_path=`(cd $script_dir/../..; pwd)`

mstart=$root_path/mstart.sh
mstop=$root_path/mstop.sh
mrun=$root_path/mrun

function start_ceph_cluster {
  [ $# -ne 1 ] && echo "start_ceph_cluster() needs 1 param" && exit 1

  echo "$mstart c$1"
}

function rgw_admin {
  [ $# -ne 1 ] && echo "rgw_admin() needs 1 param" && exit 1

  echo "$mrun c$1 radosgw-admin"
}

function rgw {
  [ $# -ne 2 ] && echo "rgw() needs 2 params" && exit 1

  echo "$root_path/mrgw.sh c$1 $2"
}

function init_first_zone {
  [ $# -ne 7 ] && echo "init_first_zone() needs 7 params" && exit 1

  id=$1
  realm=$2
  zg=$3
  zone=$4
  port=$5

  access_key=$6
  secret=$7

# initialize realm
  x $(rgw_admin $id) realm create --rgw-realm=$realm

# create zonegroup, zone
  x $(rgw_admin $id) zonegroup create --rgw-zonegroup=$zg --endpoints=http://localhost:$port --master --default
  x $(rgw_admin $id) zone create --rgw-zonegroup=$zg --rgw-zone=$zone --access-key=${access_key} --secret=${secret} --endpoints=http://localhost:$port --default
  x $(rgw_admin $id) user create --uid=zone.user --display-name="Zone User" --access-key=${access_key} --secret=${secret} --system

  x $(rgw_admin $id) period update --commit

  x $(rgw $id $port) --rgw-zone=$zone
}

function init_zone_in_existing_zg {
  [ $# -ne 7 ] && echo "init_zone_in_existing_zg() needs 7 params" && exit 1

  id=$1
  realm=$2
  zg=$3
  zone=$4
  port=$5

  access_key=$6
  secret=$7

  x $(rgw_admin $id) realm pull --url=http://localhost:$zone1_port --access-key=${system_access_key} --secret=${system_secret} --default
  x $(rgw_admin $id) zonegroup default --rgw-zonegroup=$zg
  x $(rgw_admin $id) zone create --rgw-zonegroup=$zg --rgw-zone=$zone2 --access-key=${system_access_key} --secret=${system_secret} --endpoints=http://localhost:$zone2_port
  x $(rgw_admin $id) period update --commit

  x $(rgw $id $zone2_port) --rgw-zone=$zone2
}