summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSri Vignesh <sselvan@redhat.com>2020-01-27 15:29:04 +0530
committerSri Vignesh <sselvan@redhat.com>2020-01-28 15:09:23 +0530
commit38ba8b796bda281144bf21a40cab1ea27341d57b (patch)
tree50540398d310a9d079271d7e6606ef01f0385ce5
parentdb8c543a366934c087031695ca679af4c8be9463 (diff)
[LibFix][TestFix] Add function get_unique_lv_list_from_all_servers
Added library to cleanup lv created after snapshot clone and made modifications with cleanup. Change-Id: I71a437bf99eac1170895510475ddb30748771672 Signed-off-by: Sri Vignesh <sselvan@redhat.com>
-rw-r--r--glustolibs-gluster/glustolibs/gluster/gluster_base_class.py51
-rw-r--r--tests/functional/snapshot/test_snap_delete_original_volume.py18
2 files changed, 55 insertions, 14 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py
index e8ade17..7cd128f 100644
--- a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py
+++ b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018 Red Hat, Inc. <http://www.redhat.com>
+# Copyright (C) 2018-2020 Red Hat, Inc. <http://www.redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -32,7 +32,10 @@ from unittest import TestCase
from glusto.core import Glusto as g
-from glustolibs.gluster.exceptions import ConfigError
+from glustolibs.gluster.exceptions import (
+ ConfigError,
+ ExecutionError,
+)
from glustolibs.gluster.lib_utils import inject_msg_in_logs
from glustolibs.gluster.mount_ops import create_mount_objs
from glustolibs.gluster.nfs_libs import export_volume_through_nfs
@@ -434,6 +437,24 @@ class GlusterBaseClass(TestCase):
return True
@classmethod
+ def get_unique_lv_list_from_all_servers(cls):
+ """Get all unique lv path from all servers
+
+ Returns: List of all unique lv path in all servers. None otherwise.
+ """
+ cmd = "lvs --noheadings -o lv_path | awk '{if ($1) print $1}'"
+ lv_list = []
+ for server in cls.servers:
+ ret, out, _ = g.run(server, cmd, "root")
+ current_lv_list = out.splitlines()
+ if current_lv_list:
+ lv_list.extend(current_lv_list)
+ if ret:
+ g.log.error("failed to execute command %s" % cmd)
+ raise ExecutionError("Failed to execute %s cmd" % cmd)
+ return list(set(lv_list))
+
+ @classmethod
def cleanup_volume(cls):
"""Cleanup the volume
@@ -450,7 +471,28 @@ class GlusterBaseClass(TestCase):
g.log.info("Log Volume %s Info and Status", cls.volname)
log_volume_info_and_status(cls.mnode, cls.volname)
- return ret
+ # compare and remove additional lv created, skip otherwise
+ new_lv_list = cls.get_unique_lv_list_from_all_servers()
+ if cls.lv_list != new_lv_list:
+ cmd = ("for mnt in `mount | grep 'run/gluster/snaps' |"
+ "awk '{print $3}'`; do umount $mnt; done")
+ for server in cls.servers:
+ ret, _, err = g.run(server, cmd, "root")
+ if ret:
+ g.log.error("Failed to remove snap "
+ "bricks from mountpoint %s" % err)
+ return False
+ new_lv_list = cls.get_unique_lv_list_from_all_servers()
+ lv_remove_list = list(set(new_lv_list) - set(cls.lv_list))
+ for server in cls.servers:
+ for lv in lv_remove_list:
+ cmd = ("lvremove %s --force" % lv)
+ ret, _, err = g.run(server, cmd, "root")
+ if ret:
+ g.log.error("failed to remove lv: %s" % err)
+ g.log.info("Expected error msg '%s'" % err)
+ g.log.info("Successfully cleaned-up volumes")
+ return True
@classmethod
def unmount_volume_and_cleanup_volume(cls, mounts):
@@ -522,6 +564,9 @@ class GlusterBaseClass(TestCase):
raise ConfigError("'clients_info' not defined in the global "
"config")
+ # get lv list
+ cls.lv_list = cls.get_unique_lv_list_from_all_servers()
+
# Set mnode : Node on which gluster commands are executed
cls.mnode = cls.all_servers[0]
diff --git a/tests/functional/snapshot/test_snap_delete_original_volume.py b/tests/functional/snapshot/test_snap_delete_original_volume.py
index cf21061..b103551 100644
--- a/tests/functional/snapshot/test_snap_delete_original_volume.py
+++ b/tests/functional/snapshot/test_snap_delete_original_volume.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2018 Red Hat, Inc. <http://www.redhat.com>
+# Copyright (C) 2017-2020 Red Hat, Inc. <http://www.redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -33,7 +33,6 @@ from glustolibs.gluster.volume_libs import cleanup_volume
from glustolibs.gluster.volume_ops import (get_volume_info, volume_status,
volume_list, volume_start)
from glustolibs.io.utils import validate_io_procs
-from glustolibs.gluster.mount_ops import umount_volume
from glustolibs.gluster.snap_ops import (snap_create,
snap_list,
snap_activate,
@@ -199,12 +198,9 @@ class SnapshotSelfheal(GlusterBaseClass):
raise ExecutionError("Failed to delete the cloned volume")
g.log.info("Successful in deleting Cloned volume")
- # Unmount Volume
- g.log.info("Starting to Unmount Volume")
- for mount_obj in self.mounts:
- ret = umount_volume(mount_obj.client_system, self.mpoint,
- self.mount_type)
- if not ret:
- raise ExecutionError("Failed to umount the vol "
- "& cleanup Volume")
- g.log.info("Successful in umounting the volume and Cleanup")
+ # Unmount and cleanup-volume
+ g.log.info("Starting to Unmount and cleanup-volume")
+ ret = self.unmount_volume_and_cleanup_volume(mounts=self.mounts)
+ if not ret:
+ raise ExecutionError("Failed to Unmount and Cleanup Volume")
+ g.log.info("Successful in Unmount Volume and Cleanup Volume")