def validate_block_volumes_count(self, h_node, h_server, node_ip):

        # get list of block volumes using heketi
        h_blockvol_list = heketi_blockvolume_list(
            h_node, h_server, json=True)
        # Get existing BHV list
        bhv_list = list(
            get_block_hosting_volume_list(h_node, h_server).keys())
        for vol in bhv_list:
            bhv_info = heketi_volume_info(h_node, h_server, vol, json=True)
            bhv_name = bhv_info['name']
        gluster_block_list = get_block_list(node_ip, volname=bhv_name)
        self.assertIsNotNone(
            gluster_block_list, "Failed to get gluster block list")
        self.assertEqual(
            len(h_blockvol_list['blockvolumes']), len(gluster_block_list),
            "Failed to verify blockvolume count Expected:'{}', "
            "Actual:'{}'".format(
                len(h_blockvol_list['blockvolumes']), len(gluster_block_list)))
    def test_create_max_num_blockhostingvolumes(self):
        num_of_bv = 10
        new_bhv_list, bv_list, g_nodes = [], [], []
        free_space, nodenum = get_total_free_space(self.heketi_client_node,
                                                   self.heketi_server_url)
        if nodenum < 3:
            self.skipTest("Skip the test case since number of"
                          "online nodes is less than 3.")
        free_space_available = int(free_space / nodenum)
        default_bhv_size = get_default_block_hosting_volume_size(
            self.heketi_client_node, self.heketi_dc_name)
        # Get existing list of BHV's
        existing_bhv_list = get_block_hosting_volume_list(
            self.heketi_client_node, self.heketi_server_url)

        # Skip the test if available space is less than default_bhv_size
        if free_space_available < default_bhv_size:
            self.skipTest("Skip the test case since free_space_available %s"
                          "is less than space_required_for_bhv %s ." %
                          (free_space_available, default_bhv_size))

        # Create BHV's
        while free_space_available > default_bhv_size:
            block_host_create_info = heketi_volume_create(
                self.heketi_client_node,
                self.heketi_server_url,
                default_bhv_size,
                json=True,
                block=True)
            if block_host_create_info["id"] not in existing_bhv_list.keys():
                new_bhv_list.append(block_host_create_info["id"])
            self.addCleanup(heketi_volume_delete,
                            self.heketi_client_node,
                            self.heketi_server_url,
                            block_host_create_info["id"],
                            raise_on_error=False)
            block_vol_size = int(
                block_host_create_info["blockinfo"]["freesize"] / num_of_bv)

            # Create specified number of BV's in BHV's created
            for i in range(0, num_of_bv):
                block_vol = heketi_blockvolume_create(self.heketi_client_node,
                                                      self.heketi_server_url,
                                                      block_vol_size,
                                                      json=True,
                                                      ha=3,
                                                      auth=True)
                self.addCleanup(heketi_blockvolume_delete,
                                self.heketi_client_node,
                                self.heketi_server_url,
                                block_vol["id"],
                                raise_on_error=False)
                bv_list.append(block_vol["id"])
            free_space_available = int(free_space_available - default_bhv_size)

        # Get gluster node ips
        h_nodes_ids = heketi_node_list(self.heketi_client_node,
                                       self.heketi_server_url)
        for h_node in h_nodes_ids[:2]:
            g_node = heketi_node_info(self.heketi_client_node,
                                      self.heketi_server_url,
                                      h_node,
                                      json=True)
            g_nodes.append(g_node['hostnames']['manage'][0])

        # Check if there is no crash in gluster related services & heketi
        services = (("glusterd", "running"), ("gluster-blockd", "running"),
                    ("tcmu-runner", "running"), ("gluster-block-target",
                                                 "exited"))
        for g_node in g_nodes:
            for service, state in services:
                wait_for_service_status_on_gluster_pod_or_node(
                    self.ocp_client[0],
                    service,
                    'active',
                    state,
                    g_node,
                    raise_on_error=False)
            out = hello_heketi(self.heketi_client_node, self.heketi_server_url)
            self.assertTrue(
                out, "Heketi server %s is not alive" % self.heketi_server_url)

        # Delete all the BHV's and BV's created
        for bv_volume in bv_list:
            heketi_blockvolume_delete(self.heketi_client_node,
                                      self.heketi_server_url, bv_volume)

        # Check if any blockvolume exist in heketi & gluster
        for bhv_volume in new_bhv_list[:]:
            heketi_vol_info = heketi_volume_info(self.heketi_client_node,
                                                 self.heketi_server_url,
                                                 bhv_volume,
                                                 json=True)
            self.assertNotIn("blockvolume",
                             heketi_vol_info["blockinfo"].keys())
            gluster_vol_info = get_block_list('auto_get_gluster_endpoint',
                                              volname="vol_%s" % bhv_volume)
            self.assertIsNotNone(gluster_vol_info,
                                 "Failed to get volume info %s" % bhv_volume)
            new_bhv_list.remove(bhv_volume)
            for blockvol in gluster_vol_info:
                self.assertNotIn("blockvol_", blockvol)
                heketi_volume_delete(self.heketi_client_node,
                                     self.heketi_server_url, bhv_volume)

        # Check if all blockhosting volumes are deleted from heketi
        self.assertFalse(new_bhv_list)
    def test_heket_block_volume_info_with_gluster_block_volume_info(self):
        """Verify heketi block volume info with the backend gluster
        block volume info
        """
        h_node, h_server = self.heketi_client_node, self.heketi_server_url
        vol_size = 1
        h_block_vol = heketi_blockvolume_create(h_node,
                                                h_server,
                                                vol_size,
                                                auth=True,
                                                json=True)
        self.addCleanup(heketi_blockvolume_delete, h_node, h_server,
                        h_block_vol["id"])

        h_block_vol["blockvolume"]["hosts"].sort()
        h_block_vol_gbid = h_block_vol["blockvolume"]["username"]
        h_block_vol_name = h_block_vol["name"]
        h_block_vol_paswd = h_block_vol["blockvolume"]["password"]
        h_block_vol_hosts = h_block_vol["blockvolume"]["hosts"]
        h_block_host_vol_id = h_block_vol["blockhostingvolume"]
        h_block_vol_ha = h_block_vol["hacount"]

        # Fetch heketi blockhostingvolume info
        h_bhv_info = heketi_volume_info(h_node,
                                        h_server,
                                        h_block_host_vol_id,
                                        json=True)
        err_msg = "Failed to get heketi blockhostingvolume info for {}"
        self.assertTrue(h_bhv_info, err_msg.format(h_block_host_vol_id))
        h_bhv_name = h_bhv_info['name']
        err_msg = "Failed to get heketi BHV name for heketi blockvolume Id {}"
        self.assertTrue(h_bhv_name, err_msg.format(h_block_host_vol_id))

        # Get gluster blockvolume list
        g_block_vol_list = get_block_list('auto_get_gluster_endpoint',
                                          h_bhv_name)
        err_msg = ("Failed to get gluter blockvolume list {}".format(
            g_block_vol_list))
        self.assertTrue(g_block_vol_list, err_msg)

        err_msg = (
            "Heketi block volume {} not present in gluster blockvolumes {}".
            format(h_block_vol_name, g_block_vol_list))
        self.assertIn(h_block_vol_name, g_block_vol_list, err_msg)

        g_block_info = get_block_info('auto_get_gluster_endpoint', h_bhv_name,
                                      h_block_vol_name)
        g_block_info["EXPORTED ON"].sort()

        g_block_vol_hosts = g_block_info["EXPORTED ON"]
        g_block_vol_gbid = g_block_info["GBID"]
        g_block_vol_name = g_block_info["NAME"]
        g_block_vol_paswd = g_block_info["PASSWORD"]
        g_block_vol_id = g_block_info["VOLUME"][4:]
        g_block_vol_ha = g_block_info["HA"]

        # verfiy block device info and glusterblock volume info
        err_msg = ("Did not match {} from heketi {} and gluster {} side")
        self.assertEqual(
            h_block_vol_gbid, g_block_vol_gbid,
            err_msg.format("GBID", h_block_vol_gbid, g_block_vol_gbid,
                           err_msg))
        self.assertEqual(
            h_block_vol_name, g_block_vol_name,
            err_msg.format("blockvolume", h_block_vol_name, g_block_vol_name,
                           err_msg))
        self.assertEqual(
            h_block_vol_paswd, g_block_vol_paswd,
            err_msg.format("password", h_block_vol_paswd, g_block_vol_paswd,
                           err_msg))
        self.assertEqual(
            h_block_vol_hosts, g_block_vol_hosts,
            err_msg.format("hosts", h_block_vol_hosts, g_block_vol_hosts,
                           err_msg))
        self.assertEqual(
            h_block_host_vol_id, g_block_vol_id,
            err_msg.format("blockhost vol id", h_block_host_vol_id,
                           g_block_vol_id, err_msg))
        self.assertEqual(
            h_block_vol_ha, g_block_vol_ha,
            err_msg.format("ha", h_block_vol_ha, g_block_vol_ha, err_msg))
Пример #4
0
    def test_dev_path_block_volume_delete(self):
        """Validate device path name changes the deletion of
           already existing file volumes
        """

        pvc_size, pvc_amount = 2, 5
        pvc_names, gluster_block_list, vol_details = [], [], []

        # Fetch BHV list
        h_bhv_list_before = heketi_ops.get_block_hosting_volume_list(
            self.h_node, self.h_server).keys()

        # Create storage class
        sc_name = self.create_storage_class()

        # Delete created BHV and BV as cleanup during failures
        self.addCleanup(self._cleanup_heketi_volumes, h_bhv_list_before)

        # Create PVC's
        for i in range(0, pvc_amount):
            pvc_name = openshift_ops.oc_create_pvc(self.node,
                                                   sc_name,
                                                   pvc_size=pvc_size)
            pvc_names.append(pvc_name)
            self.addCleanup(openshift_ops.wait_for_resource_absence, self.node,
                            'pvc', pvc_name)
            self.addCleanup(openshift_ops.oc_delete,
                            self.node,
                            'pvc',
                            pvc_name,
                            raise_on_absence=False)

        # Wait for PVC's to be bound
        openshift_ops.wait_for_pvc_be_bound(self.node, pvc_names)

        # Get volume name list
        for pvc_name in pvc_names:
            pv_name = openshift_ops.get_pv_name_from_pvc(self.node, pvc_name)
            volume_name = openshift_ops.get_vol_names_from_pv(self.node,
                                                              pv_name,
                                                              vol_type='block')
            vol_details.append(volume_name)

        # Get BHV list after BV creation
        h_bhv_list_after = heketi_ops.get_block_hosting_volume_list(
            self.h_node, self.h_server).keys()
        self.assertTrue(h_bhv_list_after, "Failed to get the BHV list")

        # Validate BV's count
        self.validate_block_volumes_count(self.h_node, self.h_server,
                                          self.node_ip)

        # Collect pvs info and detach disks and collect pvs info
        pvs_info_before = openshift_storage_libs.get_pvs_info(
            self.node, self.node_ip, self.devices_list, raise_on_error=False)
        self.detach_and_attach_vmdk(self.vm_name, self.node_hostname,
                                    self.devices_list)
        pvs_info_after = openshift_storage_libs.get_pvs_info(
            self.node, self.node_ip, self.devices_list, raise_on_error=False)

        # Compare pvs info before and after
        for (path, uuid, vg_name), (_path, _uuid,
                                    _vg_name) in zip(pvs_info_before[:-1],
                                                     pvs_info_after[1:]):
            self.assertEqual(
                uuid, _uuid, "pv_uuid check failed. Expected:{},"
                "Actual: {}".format(uuid, _uuid))
            self.assertEqual(
                vg_name, _vg_name, "vg_name check failed. Expected:"
                "{}, Actual:{}".format(vg_name, _vg_name))

        # Delete created PVC's
        for pvc_name in pvc_names:
            openshift_ops.oc_delete(self.node, 'pvc', pvc_name)

        # Wait for pvc to get deleted
        openshift_ops.wait_for_resources_absence(self.node, 'pvc', pvc_names)

        # Get existing BHV list
        for bhv_name in h_bhv_list_after:
            b_list = block_libs.get_block_list(self.node_ip, volname=bhv_name)
            self.assertIsNotNone(gluster_block_list,
                                 "Failed to get gluster block list")
            gluster_block_list.append(b_list)

        # Get list of block volumes using heketi
        h_blockvol_list = heketi_ops.heketi_blockvolume_list(self.h_node,
                                                             self.h_server,
                                                             json=True)

        # Validate volumes created are not present
        for vol in vol_details:
            self.assertNotIn(vol, gluster_block_list,
                             "Failed to delete volume {}".format(vol))
            self.assertNotIn(vol, h_blockvol_list['blockvolumes'],
                             "Failed to delete blockvolume '{}'".format(vol))