Skip to content

Commit

Permalink
Merge pull request #187 from cita-cloud/adapt_cloud_op
Browse files Browse the repository at this point in the history
update testcase: backup, export
  • Loading branch information
rink1969 authored Mar 1, 2024
2 parents 019322c + 12868b0 commit ad5191e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion test/operator/scripts/2_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
util.check_node_running(name="{}-node0".format(os.getenv("CHAIN_NAME")), namespace=os.getenv("NAMESPACE"))

# exec backup
result = util.exec_retry("kubectl exec -n {} -it {}-node0-0 -c patch-op -- cloud-op backup -c /etc/cita-cloud/config/config.toml -n /data -b /backup {}".format(os.getenv("NAMESPACE"), os.getenv("CHAIN_NAME"), old_bn - 100))
result = util.exec_retry("kubectl exec -n {} -it {}-node0-0 -c patch-op -- cloud-op backup -c /etc/cita-cloud/config/config.toml -n /data -p /backup {}".format(os.getenv("NAMESPACE"), os.getenv("CHAIN_NAME"), old_bn - 100))
if "backup done!" not in result:
print("exec back error: ", result)
exit(20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
logger.info("the block number before backup is: {}".format(old_bn))

# create backpvc
with open("backup_pvc.yaml", 'w') as pvc_file:
with open("export_pvc.yaml", 'w') as pvc_file:
pvc_file.write('''
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {}-export-backup
name: {}-export
labels:
app.kubernetes.io/chain-name: {}
spec:
Expand All @@ -31,7 +31,7 @@
storage: 10G
'''.format(os.getenv("CHAIN_TYPE"), os.getenv("CHAIN_NAME"), os.getenv("SC")))

result = util.exec("kubectl apply -n {} -f backup_pvc.yaml".format(os.getenv("NAMESPACE")))
result = util.exec("kubectl apply -n {} -f export_pvc.yaml".format(os.getenv("NAMESPACE")))
if "created" not in result:
print("create pvc error: ", result)
exit(10)
Expand Down Expand Up @@ -76,8 +76,8 @@
"name": "node-localtime"
},
{
"mountPath": "/backup",
"name": "backup"
"mountPath": "/export",
"name": "export"
}
],
"workingDir": "/data"
Expand All @@ -88,9 +88,9 @@
"op" : "add" ,
"path" : "/spec/template/spec/volumes/-" ,
"value" : {
"name": "backup",
"name": "export",
"persistentVolumeClaim": {
"claimName": "xxx-export-backup"
"claimName": "xxx-export"
}
}
}
Expand All @@ -105,10 +105,16 @@
time.sleep(300)
util.check_node_running(name="{}-node0".format(os.getenv("CHAIN_NAME")), namespace=os.getenv("NAMESPACE"))

# exec backup
result = util.exec_retry("kubectl exec -n {} -it {}-node0-0 -c patch-op -- cloud-op backup -c /etc/cita-cloud/config/config.toml -n /data -b /backup {} --export".format(os.getenv("NAMESPACE"), os.getenv("CHAIN_NAME"), 200))
if "backup done!" not in result:
print("exec back error: ", result)
# exec export
result = util.exec_retry("kubectl exec -n {} -it {}-node0-0 -c patch-op -- cloud-op export -c /etc/cita-cloud/config/config.toml -n /data -p /export -b 0 -e 200".format(os.getenv("NAMESPACE"), os.getenv("CHAIN_NAME")))
if "export done!" not in result:
print("exec export error: ", result)
exit(20)

# exec incremental export
result = util.exec_retry("kubectl exec -n {} -it {}-node0-0 -c patch-op -- cloud-op export -c /etc/cita-cloud/config/config.toml -n /data -p /export -b 201 -e 300".format(os.getenv("NAMESPACE"), os.getenv("CHAIN_NAME")))
if "export done!" not in result:
print("exec incremental export error: ", result)
exit(20)

# undo patch
Expand Down Expand Up @@ -143,11 +149,11 @@
"name": "restore",
"image": "busybox",
"command": ["/bin/sh"],
"args": ["-c", "rm -rf /data/chain_data; rm -rf /data/data; cp -af /backup/nnn/chain_data /data; cp -af /backup/nnn/data /data"],
"args": ["-c", "rm -rf /data/chain_data; rm -rf /data/data; cp -af /export/chain_data /data; cp -af /export/data /data"],
"volumeMounts": [
{
"mountPath": "/backup",
"name": "backup"
"mountPath": "/export",
"name": "export"
},
{
"mountPath": "/data",
Expand All @@ -158,9 +164,9 @@
],
"volumes": [
{
"name": "backup",
"name": "export",
"persistentVolumeClaim": {
"claimName": "xxx-export-backup"
"claimName": "xxx-export"
}
},
{
Expand All @@ -173,7 +179,7 @@
}
}
'''
result = util.exec("kubectl run restore -n {} --overrides='{}' --image=busybox --restart=Never".format(os.getenv("NAMESPACE"), patch_json_template.replace("nnn", str(200)).replace("xxx", os.getenv("CHAIN_TYPE")).replace("zzz", os.getenv("CHAIN_NAME"))))
result = util.exec("kubectl run restore -n {} --overrides='{}' --image=busybox --restart=Never".format(os.getenv("NAMESPACE"), patch_json_template.replace("xxx", os.getenv("CHAIN_TYPE")).replace("zzz", os.getenv("CHAIN_NAME"))))
if "created" not in result:
print("create temp pod error: ", result)
exit(50)
Expand Down Expand Up @@ -203,5 +209,5 @@

init_height = node_status["init_block_number"]

if init_height != 200:
raise Exception("rollback not excepted block number: init_height is:{} should be {}".format(init_height, 200))
if init_height != 300:
raise Exception("rollback not excepted block number: init_height is:{} should be 300".format(init_height))

0 comments on commit ad5191e

Please sign in to comment.