Skip to content

Commit 86327ec

Browse files
authored
Merge pull request #249 from VasishtaShastry/rbd_12047
Automated rbd cli tests
2 parents a5a66b1 + 4b63722 commit 86327ec

File tree

2 files changed

+140
-1
lines changed

2 files changed

+140
-1
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import argparse
2+
import os
3+
import sys
4+
5+
sys.path.append(os.path.abspath(os.path.join(__file__, "../../..")))
6+
import utils.log as log
7+
import utils.utils
8+
9+
rbd_util = utils.utils.RbdUtils()
10+
11+
12+
def mirror_image_enable():
13+
"""
14+
CEPH-10247 - CLI Validation (+ve cases): rbd mirror image enable
15+
"""
16+
log.info(
17+
"Executing CEPH-10247 - CLI Validation (+ve cases): rbd mirror image enable"
18+
)
19+
20+
poolname = "mirror_image_enable"
21+
image_name = [f"ceph_10247_{i}" for i in range(3)]
22+
rbd_util.create_pool(poolname=poolname)
23+
for image in image_name:
24+
rbd_util.create_image(
25+
image_name=poolname + "/" + image, features="exclusive-lock,journaling"
26+
)
27+
28+
rbd_util.exec_cmd(f"rbd mirror pool enable {poolname} image")
29+
base_cmd = "rbd mirror image enable "
30+
31+
step_cmds = []
32+
step_cmds.append(base_cmd + f"{poolname}/{image_name[0]}")
33+
step_cmds.append(base_cmd + f"--pool {poolname} --image {image_name[1]}")
34+
step_cmds.append(base_cmd + f"-p {poolname} --image {image_name[2]}")
35+
36+
for image, step in zip(image_name, step_cmds):
37+
if rbd_util.exec_cmd(step) == False:
38+
log.error(f"Test case failed executing: {step}")
39+
exit(1)
40+
if not rbd_util.exec_cmd(
41+
f'rbd info {poolname}/{image}|grep \\"mirroring state: enabled\\"'
42+
):
43+
log.error(f"command not worked: {step}")
44+
exit(1)
45+
46+
log.info("Test case Passed")
47+
48+
49+
def mirror_pool_enable():
50+
"""
51+
CEPH-10249 - CLI Validation (+ve cases): rbd mirror pool enable
52+
"""
53+
log.info(
54+
"Executing CEPH-10249 - CLI Validation (+ve cases): rbd mirror pool enable"
55+
)
56+
poolname = "mirror_pool_enable"
57+
base_cmd = "rbd mirror pool enable"
58+
rbd_util.create_pool(poolname=poolname)
59+
60+
step_cmds = []
61+
step_cmds.append(base_cmd + f" {poolname}")
62+
step_cmds.append(base_cmd + f" -p {poolname}")
63+
step_cmds.append(base_cmd + f" --pool {poolname}")
64+
65+
for step in step_cmds:
66+
for mode in [" image", " pool"]:
67+
rbd_util.exec_cmd("rbd mirror pool disable {poolname}")
68+
if rbd_util.exec_cmd(step + mode) == False:
69+
log.error(f"Test case Failed executing: {step}{mode}")
70+
exit(1)
71+
if not rbd_util.exec_cmd(
72+
f'rbd mirror pool info {poolname}|grep \\"Mode:{mode}\\"'
73+
):
74+
log.error(f"command not worked: {step}{mode}")
75+
exit(1)
76+
77+
log.info("Test Case Passed")
78+
79+
80+
def mirror_pool_disable():
81+
"""
82+
CEPH-10250 - CLI Validation (+ve cases): rbd mirror pool disable
83+
"""
84+
log.info(
85+
"Executing CEPH-10250 - CLI Validation (+ve cases): rbd mirror pool disable"
86+
)
87+
poolname = "mirror_pool_disable"
88+
base_cmd = "rbd mirror pool disable"
89+
rbd_util.create_pool(poolname=poolname)
90+
91+
step_cmds = []
92+
step_cmds.append(base_cmd + f" {poolname}")
93+
step_cmds.append(base_cmd + f" -p {poolname}")
94+
step_cmds.append(base_cmd + f" --pool {poolname}")
95+
96+
for step in step_cmds:
97+
rbd_util.exec_cmd(f"rbd mirror pool enable {poolname} pool")
98+
if rbd_util.exec_cmd(step) == False:
99+
log.error(f"Test case Failed executing: {step}")
100+
exit(1)
101+
if not rbd_util.exec_cmd(
102+
f'rbd mirror pool info {poolname}|grep \\"Mode: disabled\\"'
103+
):
104+
log.error(f"command not worked: {step}")
105+
exit(1)
106+
107+
log.info("Test Case Passed")
108+
109+
110+
if __name__ == "__main__":
111+
112+
parser = argparse.ArgumentParser(description="RBD CLI Test")
113+
parser.add_argument("-e", "--ec-pool-k-m", required=False)
114+
parser.add_argument("--test-case", required=True)
115+
116+
args = parser.parse_args()
117+
118+
try:
119+
globals()[args.test_case]()
120+
rbd_util.delete_pool(poolname=args.test_case)
121+
except KeyError:
122+
log.error(f"{args.test_case} not yet implemented")

rbd/utils/utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ def get_ceph_version(self):
2222
return 5
2323

2424
def exec_cmd(self, cmd):
25-
25+
"""
26+
Command executor for rbd TCs
27+
Args:
28+
cmd: Command to be executed
29+
Returns: success -> output, failure -> False
30+
"""
2631
try:
2732
cmd = " ".join(shlex.split(cmd))
2833

@@ -107,3 +112,15 @@ def rm_ec_profile(self, **kw):
107112
self.exec_cmd(
108113
cmd="ceph osd erasure-code-profile rm {}".format(kw.get("profile"))
109114
)
115+
116+
def create_image(self, **kw):
117+
"""
118+
Create images with mentioned size and features
119+
Args:
120+
input: name of the image to be created -> pool_name/image_name
121+
features: arguments for --image-feature
122+
"""
123+
cmd = "rbd create " + kw.get("image_name") + " -s 1G"
124+
if kw.get("features"):
125+
cmd = cmd + " --image-feature " + kw["features"]
126+
self.exec_cmd(cmd)

0 commit comments

Comments
 (0)