From 2a0aa3727e81f4baae6ea4dce6ec7320b05ca539 Mon Sep 17 00:00:00 2001 From: Akarsha Rai Date: Tue, 23 Jan 2018 01:44:54 -0500 Subject: heketi automation cases Change-Id: Id5e3765940ba88ef6d41b52c3306ba45fe62a0f1 Signed-off-by: Akarsha Rai --- .../common/heketi/heketi_tests/test_check_entry.py | 128 +++++++++++++ .../test_create_heketi_volume_size_60.py | 199 ++++++++++++++++++++ .../heketi/heketi_tests/test_disabling_device.py | 123 +++++++++++++ .../heketi_tests/test_heketi_create_volume.py | 202 +++++++++++++++++++++ .../common/heketi/heketi_tests/test_node_info.py | 97 ++++++++++ 5 files changed, 749 insertions(+) create mode 100644 tests/functional/common/heketi/heketi_tests/test_check_entry.py create mode 100644 tests/functional/common/heketi/heketi_tests/test_create_heketi_volume_size_60.py create mode 100644 tests/functional/common/heketi/heketi_tests/test_disabling_device.py create mode 100644 tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py create mode 100644 tests/functional/common/heketi/heketi_tests/test_node_info.py diff --git a/tests/functional/common/heketi/heketi_tests/test_check_entry.py b/tests/functional/common/heketi/heketi_tests/test_check_entry.py new file mode 100644 index 00000000..16fbe085 --- /dev/null +++ b/tests/functional/common/heketi/heketi_tests/test_check_entry.py @@ -0,0 +1,128 @@ +#!/usr/bin/python + +from glusto.core import Glusto as g +from glustolibs.gluster.exceptions import ConfigError +from cnslibs.common.heketi_libs import HeketiClientSetupBaseClass +from cnslibs.common.heketi_ops import (heketi_volume_create, + heketi_volume_list, + heketi_volume_delete) +from cnslibs.common import heketi_ops, podcmd +from cnslibs.common.openshift_ops import oc_rsh, get_ocp_gluster_pod_names + + +class TestHeketiVolume(HeketiClientSetupBaseClass): + """ + Check /etc/fstab entry + """ + @classmethod + def setUpClass(cls): + super(TestHeketiVolume, cls).setUpClass() + cls.volume_size = cls.heketi_volume['size'] + + @podcmd.GlustoPod() + def test_to_check_entry_in_fstab_file(self): + """ + Create a heketi volume and check entry + in /etc/fstab and delete heketi volume + and check corresponding brick entry must + be removed + """ + + # Create heketi volume + g.log.info("Creating a heketi volume") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + self.volume_size, json=True) + self.assertTrue(out, ("Failed to create heketi volume " + "of size %s" % str(self.volume_size))) + g.log.info("Heketi volume successfully created" % out) + self.volume_id = out["bricks"][0]["volume"] + path = [] + for i in out["bricks"]: + path.append(i["path"].rstrip("/brick")) + + # Listing heketi volumes + g.log.info("List heketi volumes") + out = heketi_volume_list(self.heketi_client_node, + self.heketi_server_url) + self.assertTrue(out, ("Failed to list heketi volumes")) + g.log.info("Heketi volume successfully listed") + + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[1] + + cmd = "oc rsync "+ gluster_pod +":/var/lib/heketi/fstab /tmp" + out = g.run(self.heketi_client_node, cmd) + self.assertTrue(out, ("Failed to copy the file")) + g.log.info("Copied the file") + out = g.run_local("scp -r root@" +self.heketi_client_node+":/tmp/fstab /tmp/file.txt") + self.assertTrue(out, ("Failed to copy a file to /tmp/file.txt")) + g.log.info("Successfully copied to /tmp/file.txt") + out = g.run_local("ls /tmp") + self.assertTrue(out, ("Failed to list")) + g.log.info("Successfully listed") + + # open /tmp/fstab file + datafile = open("/tmp/file.txt") + # Check if the brick is mounted + for i in path: + string_to_search = i + rcode, rout, rerr = g.run_local('grep %s %s' % (string_to_search, "/tmp/file.txt")) + if rcode == 0: + g.log.info("Brick %s is mounted" % i) + datafile.close() + + out = g.run(self.heketi_client_node, "rm -rf /tmp/fstab") + self.assertTrue(out, ("Failed to delete a file /tmp/fstab")) + g.log.info("Successfully removed /tmp/fstab") + out = g.run_local("rm -rf /tmp/file.txt") + self.assertTrue(out, ("Failed to delete a file /tmp/file.txt")) + g.log.info("Successfully removed /tmp/file.txt") + + # Delete heketi volume + g.log.info("Deleting heketi volumes") + out = heketi_volume_delete(self.heketi_client_node, + self.heketi_server_url, + self.volume_id) + self.assertTrue(out, ("Failed to delete " + "heketi volume %s" % self.volume_id)) + g.log.info("Heketi volume successfully deleted %s" % self.volume_id) + + # Listing heketi volumes + g.log.info("List heketi volumes") + out = heketi_volume_list(self.heketi_client_node, + self.heketi_server_url) + self.assertTrue(out, ("Failed to list or No volumes to list")) + g.log.info("Heketi volume successfully listed") + + # Check entry /etc/fstab + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[0] + + cmd = "oc rsync "+ gluster_pod +":/var/lib/heketi/fstab /" + out = g.run(self.heketi_client_node, cmd) + self.assertTrue(out, ("Failed to copy the file")) + g.log.info("Copied the file") + out = g.run_local("scp -r root@" +self.heketi_client_node+":/fstab /tmp/newfile.txt") + self.assertTrue(out, ("Failed to copy to the file newfile.txt")) + g.log.info("Successfully copied to the file newfile.txt") + out = g.run_local("ls /tmp") + self.assertTrue(out, ("Failed to list")) + g.log.info("Successfully listed") + + # open /tmp/newfile.txt file + datafile = open("/tmp/newfile.txt") + # Check if the brick is mounted + for i in path: + string_to_search = i + rcode, rout, rerr = g.run_local('grep %s %s' % (string_to_search, "/tmp/newfile.txt")) + if rcode == 0: + raise ConfigError("Particular %s brick entry is found" % i) + datafile.close() + + out = g.run(self.heketi_client_node, "rm -rf /fstab") + self.assertTrue(out, ("Failed to delete a file /fstab")) + g.log.info("Successfully removed /fstab") + out = g.run_local("rm -rf /tmp/newfile.txt") + self.assertTrue(out, ("Failed to delete a file /tmp/newfile.txt")) + g.log.info("Successfully removed /tmp/file.txt") diff --git a/tests/functional/common/heketi/heketi_tests/test_create_heketi_volume_size_60.py b/tests/functional/common/heketi/heketi_tests/test_create_heketi_volume_size_60.py new file mode 100644 index 00000000..62448b92 --- /dev/null +++ b/tests/functional/common/heketi/heketi_tests/test_create_heketi_volume_size_60.py @@ -0,0 +1,199 @@ +#!/usr/bin/python + +from __future__ import division +import math + +from glusto.core import Glusto as g +from glustolibs.gluster.exceptions import ConfigError +from glustolibs.gluster.volume_ops import get_volume_list, get_volume_info +from cnslibs.common.heketi_libs import HeketiClientSetupBaseClass +from cnslibs.common.heketi_ops import (heketi_node_list, + heketi_node_info, + heketi_volume_create, + heketi_volume_list, + heketi_volume_info, + heketi_volume_delete, + heketi_topology_info) +from cnslibs.common import heketi_ops, podcmd +from cnslibs.common.openshift_ops import oc_rsh, get_ocp_gluster_pod_names + + +class TestHeketiVolume(HeketiClientSetupBaseClass): + + def get_free_space(self): + """ + Get free space in each devices + """ + free_spaces = [] + heketi_node_id_list = [] + device_list = [] + heketi_node_list_string = heketi_node_list( + self.heketi_client_node, self.heketi_server_url) + for line in heketi_node_list_string.strip().split("\n"): + heketi_node_id_list.append(line.strip().split( + "Cluster")[0].strip().split(":")[1]) + for node_id in heketi_node_id_list: + node_info_dict = heketi_node_info(self.heketi_client_node, + self.heketi_server_url, + node_id, json=True) + total_free_space = 0 + for device in node_info_dict["devices"]: + total_free_space += device["storage"]["free"] + free_spaces.append(total_free_space) + min_free_space = min(free_spaces) + total_free_space = sum(free_spaces)/(1024**2) + optimum_space = min_free_space / (1024 * 1024 * 10) + free_space = int(math.floor(optimum_space)) + total_free_space = int(math.floor(total_free_space)) + + return total_free_space, free_spaces + + @podcmd.GlustoPod() + def test_to_create_distribute_replicated_vol(self): + """ + Create distribute replicate heketi + volume and run heketi-cli volume info + """ + + hosts = [] + size = 610 + g.log.info("Creating a heketi volume") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + size, json=True) + self.assertTrue(out, ("Failed to create " + "heketi volume of size %s" % str(size))) + g.log.info("Successfully created heketi volume" + " of size %s" % str(size)) + volume_id = out["bricks"][0]["volume"] + self.addCleanup(self.delete_volumes, volume_id) + + # Correct the backupvol file servers are updated + gluster_servers = [] + g.log.info("Checking backupvol file servers are updated") + mount_node = (out["mount"]["glusterfs"] + ["device"].strip().split(":")[0]) + hosts.append(mount_node) + backup_volfile_server_list = (out["mount"]["glusterfs"]["options"] ["backup-volfile-servers"].strip().split(",")) + for backup_volfile_server in backup_volfile_server_list: + hosts.append(backup_volfile_server) + for gluster_server in g.config["gluster_servers"].keys(): + gluster_servers.append(g.config["gluster_servers"] + [gluster_server]["storage"]) + self.assertEqual(set(hosts), set(gluster_servers)) + g.log.info("Correctly updated backupvol file servers") + + # Retrieve heketi volume info + g.log.info("Retrieving heketi volume info") + out = heketi_ops.heketi_volume_info(self.heketi_client_node, + self.heketi_server_url, + volume_id, json=True) + self.assertTrue(out, ("Failed to get heketi volume info")) + g.log.info("Successfully got the heketi volume info") + name = out["name"] + + # Get gluster volume info + g.log.info("Get gluster volume info") + if self.deployment_type == "cns": + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[1] + p = podcmd.Pod(self.heketi_client_node, gluster_pod) + out = get_volume_info(p, volname=name) + else: + out = get_volume_info(self.heketi_client_node, + volname=name) + self.assertTrue(out, ("Failed to get volume info")) + g.log.info("Successfully got the volume info") + self.assertEqual(out[name]["typeStr"], "Distributed-Replicate", + "Not a Distributed-Replicate volume") + + @podcmd.GlustoPod() + def test_to_create_and_delete_dist_rep_vol(self): + """ + Create distribute replicate heketi + volume and delete it and check the available + space + """ + + size = 610 + g.log.info("Creating a heketi volume") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + size, json=True) + self.assertTrue(out, ("Failed to create " + "heketi volume of size %s" % str(size))) + g.log.info("Successfully created heketi volume" + " of size %s" % str(size)) + volume_id = out["bricks"][0]["volume"] + name = out["name"] + + # Get gluster volume info + g.log.info("Get gluster volume info") + if self.deployment_type == "cns": + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[1] + p = podcmd.Pod(self.heketi_client_node, gluster_pod) + out = get_volume_info(p, volname=name) + else: + out = get_volume_info(self.heketi_client_node, + volname=name) + self.assertTrue(out, ("Failed to get volume info")) + g.log.info("Successfully got the volume info") + self.assertEqual(out[name]["typeStr"], "Distributed-Replicate", + "Not a Distributed-Replicate volume") + + # Get the free space + # After creating heketi volume + free_space_after_creating_vol, _ = self.get_free_space() + + # Delete heketi volumes of size 60gb which was created + g.log.info("Deleting heketi volumes") + out = heketi_volume_delete(self.heketi_client_node, + self.heketi_server_url, + volume_id) + if not out: + raise ExecutionError("Failed to delete " + "heketi volume %s" % volume_id) + g.log.info("Heketi volume successfully deleted %s" % out) + + # Check the heketi volume list + g.log.info("List heketi volumes") + volumes = heketi_volume_list(self.heketi_client_node, + self.heketi_server_url, + json=True) + self.assertTrue(volumes, ("Failed to list heketi volumes")) + g.log.info("Heketi volumes successfully listed") + + # Check the gluster volume list + g.log.info("Get the gluster volume list") + if self.deployment_type == "cns": + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[1] + p = podcmd.Pod(self.heketi_client_node, gluster_pod) + out = get_volume_list(p) + else: + out = get_volume_list(self.heketi_client_node) + self.assertTrue(out, ("Unable to get volume list")) + g.log.info("Successfully got the volume list" % out) + + # Check the volume count are equal + if (len(volumes["volumes"]) != len(out)): + raise ExecutionError("Heketi volume list %s is" + " not equal to gluster" + " volume list %s" % ((volumes), (out))) + g.log.info("Heketi volumes list %s and" + " gluster volumes list %s" % ((volumes), (out))) + + # Get the used space + # After deleting heketi volume + free_space_after_deleting_vol, _ = self.get_free_space() + + # Compare the free size before and after deleting volume + g.log.info("Comparing the free space before and after" + " deleting volume") + self.assertTrue(free_space_after_creating_vol < free_space_after_deleting_vol) + g.log.info("Volume successfully deleted and space is" + " reallocated. Free space after creating" + " volume %s, Free space after deleting" + " volume %s" % ((free_space_after_creating_vol), + (free_space_after_deleting_vol))) diff --git a/tests/functional/common/heketi/heketi_tests/test_disabling_device.py b/tests/functional/common/heketi/heketi_tests/test_disabling_device.py new file mode 100644 index 00000000..1b293f4c --- /dev/null +++ b/tests/functional/common/heketi/heketi_tests/test_disabling_device.py @@ -0,0 +1,123 @@ +#!/usr/bin/python + +from __future__ import division +import math + +from glusto.core import Glusto as g +from glustolibs.gluster.exceptions import ExecutionError +from glustolibs.gluster.volume_ops import get_volume_info +from cnslibs.common.heketi_libs import HeketiClientSetupBaseClass +from cnslibs.common.heketi_ops import (heketi_volume_create, + heketi_device_disable, + heketi_device_enable, + heketi_device_info, + heketi_volume_delete) +from cnslibs.common import podcmd +from cnslibs.common.openshift_ops import oc_rsh, get_ocp_gluster_pod_names + + +class TestHeketiVolume(HeketiClientSetupBaseClass): + + @classmethod + def setUpClass(cls): + super(TestHeketiVolume, cls).setUpClass() + cls.volume_size = cls.heketi_volume['size'] + + @podcmd.GlustoPod() + def test_to_disable_device_and_create_vol(self): + """ + Disabling a device + """ + size = 610 + volume_id_list = [] + # Create heketi volume + g.log.info("Creating a heketi volume") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + self.volume_size, json=True) + self.assertTrue(out, ("Failed to create " + "heketi volume of size %s" % str(self.volume_size))) + g.log.info("Successfully created heketi volume of size %s" % str(self.volume_size)) + volume_id = out["bricks"][0]["volume"] + device_id = out["bricks"][0]["device"] + + # Disable device + g.log.info("Disabling a device") + out = heketi_device_disable(self.heketi_client_node, + self.heketi_server_url, + device_id) + self.assertTrue(out, ("Failed to disable " + "the device %s" % device_id)) + g.log.info("Successfully disabled device %s" % device_id) + + # Get device info + g.log.info("Retrieving device info") + out = heketi_device_info(self.heketi_client_node, + self.heketi_server_url, + device_id, json=True) + self.assertTrue(out, ("Failed to get device info %s" % device_id)) + g.log.info("Successfully retrieved device info %s" % device_id) + name = out["name"] + if out["state"] != "offline": + raise ExecutionError("Device %s is now online" % name) + g.log.info("Device %s is now offine" % name) + + # Try to create heketi volume + g.log.info("Creating heketi volume:" + " Expected to fail") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + size, json=True) + self.assertFalse(out, ("Successfully created " + "volume of size %s, Node" + " has more than one device" % str(size))) + g.log.info("Expected output: Failed to create a " + "volume of size %s since device " + "is disabled %s" % (str(size), device_id)) + + # Enable the device + g.log.info("Enable the device") + out = heketi_device_enable(self.heketi_client_node, + self.heketi_server_url, + device_id) + self.assertTrue(out, ("Failed to enable the " + "device %s" % device_id)) + g.log.info("Successfully enabled device %s" % device_id) + + # Get device info + g.log.info("Retrieving device info") + out = heketi_device_info(self.heketi_client_node, + self.heketi_server_url, + device_id, + json=True) + self.assertTrue(out, ("Failed to get device info %s" % device_id)) + g.log.info("Successfully retrieved device info %s" % device_id) + name = out["name"] + if out["state"] != "online": + raise ExecutionError("Device %s is now offline" % name) + g.log.info("Device %s is now online" % name) + + # Create heketi volume of size + g.log.info("Creating heketi volume") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + size, json=True) + self.assertTrue(out, ("Failed to create volume " + "of size %s" % str(size))) + g.log.info("Successfully created volume of size %s" % str(size)) + name = out["name"] + volume_id = out["bricks"][0]["volume"] + volume_id_list.append(volume_id) + self.addCleanup(self.delete_volumes, volume_id_list) + + # Get gluster volume info + if self.deployment_type == "cns": + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[1] + p = podcmd.Pod(self.heketi_client_node, gluster_pod) + out = get_volume_info(p, volname=name) + else: + out = get_volume_info(self.heketi_client_node, + volname=name) + self.assertTrue(out, ("Failed to get volume info")) + g.log.info("Successfully got the volume info") diff --git a/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py b/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py new file mode 100644 index 00000000..80b6e1b6 --- /dev/null +++ b/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py @@ -0,0 +1,202 @@ +#!/usr/bin/python + +from glustolibs.gluster.exceptions import ExecutionError, ConfigError +from glusto.core import Glusto as g +from glustolibs.gluster.volume_ops import get_volume_list, get_volume_info +from cnslibs.common.heketi_libs import HeketiClientSetupBaseClass +from cnslibs.common.heketi_ops import (heketi_volume_create, + heketi_volume_list, + heketi_volume_info, + heketi_volume_delete, + heketi_cluster_list, + heketi_cluster_delete, + heketi_node_list, + heketi_node_delete) +from cnslibs.common import heketi_ops, podcmd +from cnslibs.common.openshift_ops import oc_rsh, get_ocp_gluster_pod_names + +class TestHeketiVolume(HeketiClientSetupBaseClass): + """ + Class to test heketi volume create + """ + @classmethod + def setUpClass(cls): + super(TestHeketiVolume, cls).setUpClass() + cls.volume_size = cls.heketi_volume['size'] + + @podcmd.GlustoPod() + def test_volume_create_and_list_volume(self): + """ + Create a heketi volume and list the volume + compare the volume with gluster volume list + """ + g.log.info("Create a heketi volume") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + self.volume_size, json=True) + self.assertTrue(out, ("Failed to create heketi " + "volume of size %s" % str(self.volume_size))) + g.log.info("Heketi volume successfully created" % out) + volume_id = out["bricks"][0]["volume"] + self.addCleanup(self.delete_volumes, volume_id) + name = out["name"] + + g.log.info("List heketi volumes") + volumes = heketi_volume_list(self.heketi_client_node, + self.heketi_server_url, + json=True) + self.assertTrue(volumes, ("Failed to list heketi volumes")) + g.log.info("Heketi volumes successfully listed") + + g.log.info("List gluster volumes") + if self.deployment_type == "cns": + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[1] + p = podcmd.Pod(self.heketi_client_node, gluster_pod) + out = get_volume_list(p) + else: + out = get_volume_list(self.heketi_client_node) + self.assertTrue(out, ("Unable to get volumes list")) + g.log.info("Successfully got the volumes list") + + # Check the volume count are equal + if (len(volumes["volumes"]) != len(out)): + raise ExecutionError("Heketi volume list %s is" + " not equal to gluster" + " volume list %s" % ((volumes), (out))) + g.log.info("Heketi volumes list %s and" + " gluster volumes list %s" % ((volumes), (out))) + + @podcmd.GlustoPod() + def test_create_vol_and_retrieve_vol_info(self): + """ + Create a heketi volume and retrieve the volume info + and get gluster volume info + """ + + g.log.info("Create a heketi volume") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + self.volume_size, json=True) + self.assertTrue(out, ("Failed to create heketi " + "volume of size %s" % str(self.volume_size))) + g.log.info("Heketi volume successfully created" % out) + volume_id = out["bricks"][0]["volume"] + self.addCleanup(self.delete_volumes, volume_id) + + g.log.info("Retrieving heketi volume info") + out = heketi_ops.heketi_volume_info(self.heketi_client_node, + self.heketi_server_url, + volume_id, json=True) + self.assertTrue(out, ("Failed to get heketi volume info")) + g.log.info("Successfully got the heketi volume info") + name = out["name"] + + if self.deployment_type == "cns": + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[1] + p = podcmd.Pod(self.heketi_client_node, gluster_pod) + out = get_volume_info(p, volname=name) + else: + out = get_volume_info(self.heketi_client_node, + volname=name) + self.assertTrue(out, ("Failed to get volume info %s" % name)) + g.log.info("Successfully got the volume info %s" % name) + + def test_to_check_deletion_of_cluster(self): + """ + Deletion of a cluster with volumes + and/ or nodes should fail + """ + # List heketi volumes + g.log.info("List heketi volumes") + volumes = heketi_volume_list(self.heketi_client_node, + self.heketi_server_url, + json=True) + if (len(volumes["volumes"])== 0): + g.log.info("Creating heketi volume") + out = heketi_volume_create(self.heketi_client_node, + self.heketi_server_url, + self.volume_size, json=True) + self.assertTrue(out, ("Failed to create heketi " + "volume of size %s" % str(self.volume_size))) + g.log.info("Heketi volume successfully created" % out) + volume_id = out["bricks"][0]["volume"] + self.addCleanup(self.delete_volumes, volume_id) + + # List heketi cluster's + g.log.info("Listing heketi cluster list") + out = heketi_cluster_list(self.heketi_client_node, + self.heketi_server_url, + json=True) + self.assertTrue(out, ("Failed to list heketi cluster")) + g.log.info("All heketi cluster successfully listed") + cluster_id = out["clusters"][0] + + # Deleting a heketi cluster + g.log.info("Trying to delete a heketi cluster" + " which contains volumes and/or nodes:" + " Expected to fail") + out = heketi_cluster_delete(self.heketi_client_node, + self.heketi_server_url, + cluster_id) + self.assertFalse(out, ("Successfully deleted a " + "cluster %s" % cluster_id)) + g.log.info("Expected result: Unable to delete cluster %s" + " because it contains volumes " + " and/or nodes" % cluster_id) + + # To confirm deletion failed, check heketi cluster list + g.log.info("Listing heketi cluster list") + out = heketi_cluster_list(self.heketi_client_node, + self.heketi_server_url, + json=True) + self.assertTrue(out, ("Failed to list heketi cluster")) + g.log.info("All heketi cluster successfully listed") + + def test_to_check_deletion_of_node(self): + """ + Deletion of a node which contains devices + """ + + # List of heketi node + heketi_node_id_list = [] + g.log.info("List heketi nodes") + node_list = heketi_node_list(self.heketi_client_node, + self.heketi_server_url, + json=True) + self.assertTrue(node_list, ("Failed to list heketi nodes")) + g.log.info("Successfully got the list of nodes") + for line in node_list.strip().split("\n"): + heketi_node_id_list.append(line.strip().split( + "Cluster")[0].strip().split(":")[1]) + for node_id in heketi_node_id_list: + g.log.info("Retrieve the node info") + node_info_dict = heketi_ops.heketi_node_info( + self.heketi_client_node, self.heketi_server_url, + node_id, json=True) + if not(node_info_dict["devices"][1]["storage"]["used"]): + raise ConfigError("No device in node %s" % node_id) + g.log.info("Used space in device %s" % node_info_dict[ + "devices"][1]["storage"]["used"]) + node_id = heketi_node_id_list[0] + + # Deleting a node + g.log.info("Trying to delete a node which" + " contains devices in it:" + " Expected to fail") + out = heketi_node_delete(self.heketi_client_node, + self.heketi_server_url, + node_id) + self.assertFalse(out, ("Successfully deletes a " + "node %s" % str(node_id))) + g.log.info("Expected result: Unable to delete " + "node %s because it contains devices") + + # To confrim deletion failed, check node list + g.log.info("Listing heketi node list") + node_list = heketi_node_list(self.heketi_client_node, + self.heketi_server_url, + json=True) + self.assertTrue(node_list, ("Failed to list heketi nodes")) + g.log.info("Successfully got the list of nodes") diff --git a/tests/functional/common/heketi/heketi_tests/test_node_info.py b/tests/functional/common/heketi/heketi_tests/test_node_info.py new file mode 100644 index 00000000..94ac34b9 --- /dev/null +++ b/tests/functional/common/heketi/heketi_tests/test_node_info.py @@ -0,0 +1,97 @@ +#!/usr/bin/python + +from glusto.core import Glusto as g +from glustolibs.gluster.exceptions import ExecutionError +from glustolibs.gluster.peer_ops import (get_pool_list) +from cnslibs.common.heketi_libs import HeketiClientSetupBaseClass +from cnslibs.common.heketi_ops import (heketi_node_info, + heketi_node_list) +from cnslibs.common import heketi_ops, podcmd +from cnslibs.common.openshift_ops import oc_rsh, get_ocp_gluster_pod_names + + +class TestHeketiVolume(HeketiClientSetupBaseClass): + """ + Class to test heketi volume create + """ + + @podcmd.GlustoPod() + def test_to_get_list_of_nodes(self): + """ + Listing all nodes and compare the + node listed in previous step + """ + + # List all list + heketi_node_id_list = [] + ip = [] + g.log.info("Listing the node id") + node_list = heketi_node_list(self.heketi_client_node, + self.heketi_server_url) + self.assertTrue(node_list, ("Failed to list heketi nodes")) + g.log.info("Successfully listed the node") + for line in node_list.strip().split("\n"): + heketi_node_id_list.append(line.strip().split( + "Cluster")[0].strip().split(":")[1]) + + if (len(heketi_node_id_list) == 0): + raise ExecutionError("Node list empty") + + for node_id in heketi_node_id_list: + g.log.info("Retrieve the node info") + node_info = heketi_ops.heketi_node_info( + self.heketi_client_node, self.heketi_server_url, + node_id, json=True) + self.assertTrue(node_info, ("Failed to " + "retrieve the node info")) + g.log.info("Successfully retrieved the node info %s" % node_id) + ip.append(node_info["hostnames"]["storage"]) + + # Compare the node listed in previous step + hostname = [] + + g.log.info("Get the pool list") + if self.deployment_type == "cns": + gluster_pod = get_ocp_gluster_pod_names( + self.heketi_client_node)[1] + p = podcmd.Pod(self.heketi_client_node, gluster_pod) + list_of_pools = get_pool_list(p) + else: + list_of_pools = get_pool_list(self.heketi_client_node) + self.assertTrue(list_of_pools, ("Failed to get the " + "pool list from gluster pods/nodes")) + g.log.info("Successfully got the pool list from gluster pods/nodes") + for pool in list_of_pools: + hostname.append(pool["hostname"]) + + if (len(heketi_node_id_list) != len(list_of_pools)): + raise ExecutionError("Heketi volume list %s is not equal" + " to gluster volume list %s" % ((ip), (hostname))) + g.log.info("The node IP's from node info and list" + " is : %s/n and pool list from gluster" + " pods/nodes is %s" % ((ip), (hostname))) + + def test_to_retrieve_node_info(self): + """ + List and retrieve node related info + """ + + # List all list + heketi_node_id_list = [] + g.log.info("Listing the node id") + node_list = heketi_node_list(self.heketi_client_node, + self.heketi_server_url) + self.assertTrue(node_list, ("Failed to list heketi nodes")) + g.log.info("Successfully listed the node") + for line in node_list.strip().split("\n"): + heketi_node_id_list.append(line.strip().split( + "Cluster")[0].strip().split(":")[1]) + + for node_id in heketi_node_id_list: + g.log.info("Retrieve the node info") + node_info = heketi_ops.heketi_node_info( + self.heketi_client_node, self.heketi_server_url, + node_id, json=True) + self.assertTrue(node_info, ("Failed to " + "retrieve the node info")) + g.log.info("Successfully retrieved the node info %s" % node_id) -- cgit