From 7fd15284c122e4132c2b02ebb83dcfb619f0a392 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 15 Dec 2015 16:39:47 -0800 Subject: [PATCH] test_multi.py: wait for meta sync Signed-off-by: Yehuda Sadeh --- src/test/rgw/test-rgw-meta-sync.sh | 11 ++- src/test/rgw/test-rgw-multisite.sh | 2 +- src/test/rgw/test_multi.py | 139 +++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 src/test/rgw/test_multi.py diff --git a/src/test/rgw/test-rgw-meta-sync.sh b/src/test/rgw/test-rgw-meta-sync.sh index fe3ace2de5461..18d65fa0389fe 100755 --- a/src/test/rgw/test-rgw-meta-sync.sh +++ b/src/test/rgw/test-rgw-meta-sync.sh @@ -6,8 +6,9 @@ set -e function get_metadata_sync_status { id=$1 + realm=$2 - meta_sync_status_json=`$(rgw_admin $id) metadata sync status` + meta_sync_status_json=`$(rgw_admin $id) --rgw-realm=$realm metadata sync status` global_sync_status=$(json_extract sync_status.info.status $meta_sync_status_json) num_shards=$(json_extract sync_status.info.num_shards $meta_sync_status_json) @@ -26,8 +27,9 @@ function get_metadata_sync_status { function get_metadata_log_status { master_id=$1 + realm=$2 - master_mdlog_status_json=`$(rgw_admin $master_id) mdlog status` + master_mdlog_status_json=`$(rgw_admin $master_id) --rgw_realm=$realm mdlog status` master_meta_status=$(json_extract "" $master_mdlog_status_json) eval master_status=$(project_python_array_field marker $master_meta_status) @@ -36,12 +38,13 @@ function get_metadata_log_status { function wait_for_meta_sync { master_id=$1 id=$2 + realm=$3 - get_metadata_log_status $master_id + get_metadata_log_status $master_id $realm echo "master_status=${master_status[*]}" while true; do - get_metadata_sync_status $id + get_metadata_sync_status $id $realm echo "secondary_status=${secondary_status[*]}" diff --git a/src/test/rgw/test-rgw-multisite.sh b/src/test/rgw/test-rgw-multisite.sh index 32d3648de7909..cbb30f5bcf917 100755 --- a/src/test/rgw/test-rgw-multisite.sh +++ b/src/test/rgw/test-rgw-multisite.sh @@ -50,6 +50,6 @@ done i=2 while [ $i -le $num_clusters ]; do - wait_for_meta_sync 1 $i + wait_for_meta_sync 1 $i $realm_name done diff --git a/src/test/rgw/test_multi.py b/src/test/rgw/test_multi.py new file mode 100644 index 0000000000000..dd79fc001a3d1 --- /dev/null +++ b/src/test/rgw/test_multi.py @@ -0,0 +1,139 @@ +import subprocess +import os + + +mstart_path = os.getenv('MSTART_PATH') +if mstart_path is None: + mstart_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + '/../..') + '/' + +test_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__))) + '/' + +def mpath(bin, *params): + s = mstart_path + bin + for p in params: + s += ' ' + str(p) + + return s + +def tpath(bin, *params): + s = test_path + bin + for p in params: + s += ' ' + str(p) + + return s + +def bash(cmd, check_retcode = True): + print 'cmd:', cmd + process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) + s = process.communicate()[0] + print s + if check_retcode: + assert(process.returncode == 0) + return s + +def mstart(cluster_id, is_new): + cmd = mpath('mstart.sh', cluster_id) + if is_new: + cmd += ' -n' + + bash(cmd) + +def mstop(cluster_id, entity = None): + cmd = mpath('mstop.sh', cluseter_id) + if entity is not None: + cmd += ' ' + entity + bash(cmd) + +def mrgw(cluster_id, port, extra_cmd = None): + cmd = mpath('mrgw.sh', port) + if extra_cmd is not None: + cmd += ' ' + extra_cmd + bash(cmd) + +def init_multi_site(num_clusters): + bash(tpath('test-rgw-multisite.sh', num_clusters)) + + +class RGWRealmCredentials: + def __init__(self, access_key, secret): + self.access_key = access_key + self.secret = secret + +class RGWCluster: + def __init__(self, cluster_num): + self.cluster_num = cluster_num + self.cluster_id = 'c' + str(cluster_num) + self.needs_reset = True + + def start(self): + mstart(self.cluster_id, self.needs_reset) + self.needs_reset = False + + def stop(self): + mstop(self.cluster_id) + + def start_rgw(port): + mrgw(self.cluster_id, port) + + def stop_rgw(self): + mstop(self.cluster_id, 'radosgw') + + def rgw_admin(self, cmd): + print bash(tpath('test-rgw-call.sh', 'call_rgw_admin', self.cluster_num, cmd)) + +class RGWRealm: + def __init__(self, realm, credentials, master_index): + self.realm = realm + self.credentials = credentials + self.master_index = master_index + + def init_zone(self, cluster, zg, zone_name, port, first_zone_port=0): + if first_zone_port == 0: + bash(tpath('test-rgw-call.sh', 'init_first_zone', cluster.cluster_num, + self.realm, zg, zone_name, port, + self.credentials.access_key, self.credentials.secret)) + else: + bash(tpath('test-rgw-call.sh', 'init_zone_in_existing_zg', cluster.cluster_num, + self.realm, zg, zone_name, first_zone_port, port, + self.credentials.access_key, self.credentials.secret)) + + def meta_checkpoint(self, cluster_index): + if cluster_index == self.master_index: + return + + bash(tpath('test-rgw-call.sh', 'wait_for_meta_sync', self.master_index + 1, cluster_index + 1, self.realm)) + + + +class RGWMulti: + def __init__(self, num_clusters): + self.num_clusters = num_clusters + + self.clusters = {} + for i in xrange(num_clusters): + self.clusters[i] = RGWCluster(i + 1) + + self.base_port = 8000 + + def setup(self): + credentials = RGWRealmCredentials('1234567890', 'pencil') + realm = RGWRealm('earth', credentials, 0) + + self.clusters[0].start() + realm.init_zone(self.clusters[0], 'us', 'us-1', self.base_port) + + for i in xrange(1, self.num_clusters): + self.clusters[i].start() + realm.init_zone(self.clusters[i], 'us', 'us-' + str(i + 1), self.base_port + i, first_zone_port=self.base_port) + + for i in xrange(1, self.num_clusters): + realm.meta_checkpoint(i) + + +def main(): + rgw_multi = RGWMulti(2) + + rgw_multi.setup() + +if __name__ == "__main__": + main() -- 2.39.5