|
| 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") |
0 commit comments