Esempio n. 1
0
    def test_restart_gluster_block_provisioner_pod(self):
        """Restart gluster-block provisioner pod
        """

        # create heketi block volume
        vol_info = heketi_blockvolume_create(self.heketi_client_node,
                                             self.heketi_server_url,
                                             size=5,
                                             json=True)
        self.assertTrue(vol_info, "Failed to create heketi block"
                        "volume of size 5")
        self.addCleanup(heketi_blockvolume_delete, self.heketi_client_node,
                        self.heketi_server_url, vol_info['id'])

        # restart gluster-block-provisioner-pod
        dc_name = "glusterblock-%s-provisioner-dc" % self.storage_project_name
        pod_name = get_pod_name_from_dc(self.ocp_master_node, dc_name)
        oc_delete(self.ocp_master_node, 'pod', pod_name)
        wait_for_resource_absence(self.ocp_master_node, 'pod', pod_name)

        # new gluster-pod name
        pod_name = get_pod_name_from_dc(self.ocp_master_node, dc_name)
        wait_for_pod_be_ready(self.ocp_master_node, pod_name)

        # create new heketi block volume
        vol_info = heketi_blockvolume_create(self.heketi_client_node,
                                             self.heketi_server_url,
                                             size=2,
                                             json=True)
        self.assertTrue(vol_info, "Failed to create heketi block"
                        "volume of size 2")
        heketi_blockvolume_delete(self.heketi_client_node,
                                  self.heketi_server_url, vol_info['id'])
    def test_block_volume_delete(self):
        """Validate deletion of gluster-block volume and capacity of used pool
        """
        block_vol = heketi_blockvolume_create(self.heketi_client_node,
                                              self.heketi_server_url,
                                              1,
                                              json=True)
        self.addCleanup(heketi_blockvolume_delete,
                        self.heketi_client_node,
                        self.heketi_server_url,
                        block_vol["id"],
                        raise_on_error=False)

        heketi_blockvolume_delete(self.heketi_client_node,
                                  self.heketi_server_url,
                                  block_vol["id"],
                                  json=True)

        volume_list = heketi_blockvolume_list(self.heketi_client_node,
                                              self.heketi_server_url,
                                              json=True)
        self.assertNotIn(
            block_vol["id"], volume_list["blockvolumes"],
            "The block volume has not been successfully deleted,"
            " ID is %s" % block_vol["id"])
    def test_create_block_vol_after_host_vol_creation(self):
        """Validate block-device after manual block hosting volume creation
           using heketi
        """
        block_host_create_info = heketi_volume_create(self.heketi_client_node,
                                                      self.heketi_server_url,
                                                      5,
                                                      json=True,
                                                      block=True)
        self.addCleanup(heketi_volume_delete, self.heketi_client_node,
                        self.heketi_server_url, block_host_create_info["id"])

        block_vol = heketi_blockvolume_create(self.heketi_client_node,
                                              self.heketi_server_url,
                                              1,
                                              json=True)
        self.addCleanup(heketi_blockvolume_delete, self.heketi_client_node,
                        self.heketi_server_url, block_vol["id"])
 def test_create_block_vol_after_host_vol_creation(self):
     """Validate block-device after manual block hosting volume creation
        using heketi
     """
     block_host_create_info = heketi_volume_create(self.heketi_client_node,
                                                   self.heketi_server_url,
                                                   5,
                                                   json=True,
                                                   block=True)
     self.assertNotEqual(block_host_create_info, False,
                         "Block host volume creation failed")
     block_hosting_vol_id = block_host_create_info["id"]
     self.addCleanup(self.delete_volumes, block_hosting_vol_id)
     block_vol = heketi_blockvolume_create(self.heketi_client_node,
                                           self.heketi_server_url,
                                           1,
                                           json=True)
     self.assertNotEqual(block_vol, False, "Block volume creation failed")
     self.addCleanup(self.delete_block_volumes, block_vol["id"])
 def test_block_volume_list(self):
     """Validate heketi blockvolume list command works as expected"""
     created_vol_ids = []
     for count in range(3):
         block_vol = heketi_blockvolume_create(self.heketi_client_node,
                                               self.heketi_server_url,
                                               1,
                                               json=True)
         self.assertNotEqual(block_vol, False,
                             "Block volume creation has failed")
         self.addCleanup(self.delete_block_volumes, block_vol["id"])
         created_vol_ids.append(block_vol["id"])
     volumes = heketi_blockvolume_list(self.heketi_client_node,
                                       self.heketi_server_url,
                                       json=True)
     existing_vol_ids = volumes.values()[0]
     for vol_id in created_vol_ids:
         self.assertIn(
             vol_id, existing_vol_ids,
             "Block vol with '%s' ID is absent in the "
             "list of block volumes." % vol_id)
    def test_blockvolume_create_no_free_space(self):
        """Validate error is returned when free capacity is exhausted"""

        # Create first small blockvolume
        blockvol1 = heketi_blockvolume_create(self.heketi_client_node,
                                              self.heketi_server_url,
                                              1,
                                              json=True)
        self.assertTrue(blockvol1, "Failed to create block volume.")
        self.addCleanup(heketi_blockvolume_delete, self.heketi_client_node,
                        self.heketi_server_url, blockvol1['id'])

        # Get info about block hosting volumes
        file_volumes = heketi_volume_list(self.heketi_client_node,
                                          self.heketi_server_url,
                                          json=True)
        self.assertTrue(file_volumes)
        self.assertIn("volumes", file_volumes)
        self.assertTrue(file_volumes["volumes"])
        max_block_hosting_vol_size, file_volumes_debug_info = 0, []
        for vol_id in file_volumes["volumes"]:
            vol = heketi_volume_info(self.heketi_client_node,
                                     self.heketi_server_url,
                                     vol_id,
                                     json=True)
            current_block_hosting_vol_size = vol.get('size', 0)
            if current_block_hosting_vol_size > max_block_hosting_vol_size:
                max_block_hosting_vol_size = current_block_hosting_vol_size
            if current_block_hosting_vol_size:
                file_volumes_debug_info.append(
                    six.text_type({
                        'id': vol.get('id', '?'),
                        'name': vol.get('name', '?'),
                        'size': current_block_hosting_vol_size,
                        'blockinfo': vol.get('blockinfo', '?'),
                    }))
        self.assertGreater(max_block_hosting_vol_size, 0)

        # Try to create blockvolume with size bigger than available
        too_big_vol_size = max_block_hosting_vol_size + 1
        try:
            blockvol2 = heketi_blockvolume_create(self.heketi_client_node,
                                                  self.heketi_server_url,
                                                  too_big_vol_size,
                                                  json=True)
        except ExecutionError:
            return

        if blockvol2 and blockvol2.get('id'):
            self.addCleanup(heketi_blockvolume_delete, self.heketi_client_node,
                            self.heketi_server_url, blockvol2['id'])
        block_hosting_vol = heketi_volume_info(
            self.heketi_client_node,
            self.heketi_server_url,
            blockvol2.get('blockhostingvolume'),
            json=True)
        self.assertGreater(
            block_hosting_vol.get('size', -2), blockvol2.get('size', -1),
            ("Block volume unexpectedly was created. "
             "Calculated 'max free size' is '%s'.\nBlock volume info is: %s \n"
             "File volume info, which hosts block volume: \n%s,"
             "Block hosting volumes which were considered: \n%s" %
             (max_block_hosting_vol_size, blockvol2, block_hosting_vol,
              '\n'.join(file_volumes_debug_info))))