cephfs: fix tracevol.py to work with dynamic value of fsname

tracevol.py takes 'myfs' as default fsname, changed it so that it can work with
dynamic values of fsname.

Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
This commit is contained in:
Mudit Agarwal 2020-07-29 16:41:29 +05:30 committed by mergify[bot]
parent 6814f598ce
commit 5fa1be586a

View File

@ -165,8 +165,9 @@ def format_table(arg, pvc_data, pvdata, table, is_rbd):
if is_rbd:
present_in_cluster = check_image_in_cluster(arg, image_id, pool_name, volname_prefix)
else:
fsname = get_fsname_from_pvdata(arg, pvdata)
subvolname = volname_prefix + image_id
present_in_cluster = check_subvol_in_cluster(arg, subvolname)
present_in_cluster = check_subvol_in_cluster(arg, subvolname, fsname)
image_name = volname_prefix + image_id
table.add_row([pvcname, pvname, image_name, pv_present,
uuid_present, present_in_cluster])
@ -406,7 +407,7 @@ def get_pool_name(arg, vol_id, is_rbd):
return pool['metadata_pool']
return ""
def check_subvol_in_cluster(arg, subvol_name):
def check_subvol_in_cluster(arg, subvol_name, fsname):
"""
Checks if subvolume exists in cluster or not.
"""
@ -415,14 +416,14 @@ def check_subvol_in_cluster(arg, subvol_name):
if subvol_group == "":
# default subvolumeGroup
subvol_group = "csi"
return check_subvol_path(arg, subvol_name, subvol_group)
return check_subvol_path(arg, subvol_name, subvol_group, fsname)
def check_subvol_path(arg, subvol_name, subvol_group):
def check_subvol_path(arg, subvol_name, subvol_group, fsname):
"""
Returns True if subvolume path exists in the cluster.
"""
cmd = ['ceph', 'fs', 'subvolume', 'getpath',
'myfs', subvol_name, subvol_group]
fsname, subvol_name, subvol_group]
if not arg.userkey:
cmd += ["--id", arg.userid, "--key", arg.userkey]
if arg.toolboxdeployed is True:
@ -539,6 +540,25 @@ def get_volname_prefix(arg, pvdata):
volname_prefix = volume_attr[key]
return volname_prefix
def get_fsname_from_pvdata(arg, pvdata):
"""
Returns fsname stored in pv data
"""
fsname = 'myfs'
if not pvdata:
if arg.debug:
print("failed to get pv data")
sys.exit()
volume_attr = pvdata['spec']['csi']['volumeAttributes']
key = 'fsName'
if key in volume_attr.keys():
fsname = volume_attr[key]
else:
if arg.debug:
print("fsname is not set in storageclass/pv")
sys.exit()
return fsname
if __name__ == "__main__":
ARGS = PARSER.parse_args()
if ARGS.command not in ["kubectl", "oc"]: