def verify_volume_count(self): metrics = get_heketi_metrics(self.heketi_client_node, self.heketi_server_url) self.assertTrue(metrics['heketi_volumes_count']) for vol_count in metrics['heketi_volumes_count']: self.assertTrue(vol_count['cluster']) cluster_info = heketi_cluster_info(self.heketi_client_node, self.heketi_server_url, vol_count['cluster'], json=True) self.assertEqual(vol_count['value'], len(cluster_info['volumes']))
def verify_volume_count(self): metrics = get_heketi_metrics( self.heketi_client_node, self.heketi_server_url) self.assertTrue(metrics['heketi_volumes_count']) for vol_count in metrics['heketi_volumes_count']: self.assertTrue(vol_count['cluster']) cluster_info = heketi_cluster_info( self.heketi_client_node, self.heketi_server_url, vol_count['cluster'], json=True) self.assertEqual(vol_count['value'], len(cluster_info['volumes']))
def test_heketi_metrics_validating_existing_node_count(self): """Validate existing 'node count' in heketi metrics""" metrics = get_heketi_metrics( self.heketi_client_node, self.heketi_server_url) self.assertTrue(metrics) self.assertTrue(metrics.get('heketi_nodes_count')) for cluster in metrics['heketi_nodes_count']: cluster_info = heketi_cluster_info( self.heketi_client_node, self.heketi_server_url, cluster['cluster'], json=True) self.assertTrue(cluster_info) self.assertTrue(cluster_info.get('nodes')) self.assertEqual(len(cluster_info['nodes']), cluster['value'])
def test_heketi_metrics_validating_existing_node_count(self): """Validate existing 'node count' in heketi metrics""" metrics = get_heketi_metrics(self.heketi_client_node, self.heketi_server_url) self.assertTrue(metrics) self.assertTrue(metrics.get('heketi_nodes_count')) for cluster in metrics['heketi_nodes_count']: cluster_info = heketi_cluster_info(self.heketi_client_node, self.heketi_server_url, cluster['cluster'], json=True) self.assertTrue(cluster_info) self.assertTrue(cluster_info.get('nodes')) self.assertEqual(len(cluster_info['nodes']), cluster['value'])
def test_heketi_cluster_info(self): """Test and validateheketi cluster info operation""" # Create heketi cluster cluster_info = heketi_ops.heketi_cluster_create( self.heketi_client_node, self.heketi_server_url, json=True) self.addCleanup(heketi_ops.heketi_cluster_delete, self.heketi_client_node, self.heketi_server_url, cluster_info["id"]) # Get newly created heketi cluster info get_cluster_info = heketi_ops.heketi_cluster_info( self.heketi_client_node, self.heketi_server_url, cluster_info["id"], json=True) # Validate newly created heketi cluster info params = (("id", cluster_info["id"]), ("block", True), ("file", True), ("blockvolumes", []), ("volumes", []), ("nodes", [])) for param, value in params: self.assertEqual(get_cluster_info[param], value)
def test_create_heketi_cluster_and_add_node(self): """Test heketi node add to a newly created cluster""" storage_host_info = g.config.get("additional_gluster_servers") if not storage_host_info: self.skipTest( "Skip test case as 'additional_gluster_servers' option is " "not provided in config file") storage_host_info = list(storage_host_info.values())[0] try: storage_hostname = storage_host_info["manage"] storage_ip = storage_host_info["storage"] storage_device = storage_host_info["devices"][0] except KeyError: msg = ("Config options 'additional_gluster_servers.manage' " "'additional_gluster_servers.storage' and " "'additional_gluster_servers.devices' " "must be set.") g.log.error(msg) raise exceptions.ConfigError(msg) h_client, h_server = self.heketi_client_node, self.heketi_server_url storage_zone = 1 cluster_id = heketi_ops.heketi_cluster_create(self.heketi_client_node, self.heketi_server_url, json=True)["id"] self.addCleanup(heketi_ops.heketi_cluster_delete, self.heketi_client_node, self.heketi_server_url, cluster_id) self.configure_node_to_run_gluster(storage_hostname) heketi_node_info = heketi_ops.heketi_node_add(h_client, h_server, storage_zone, cluster_id, storage_hostname, storage_ip, json=True) heketi_node_id = heketi_node_info["id"] self.addCleanup(heketi_ops.heketi_node_delete, h_client, h_server, heketi_node_id) self.addCleanup(heketi_ops.heketi_node_remove, h_client, h_server, heketi_node_id) self.addCleanup(heketi_ops.heketi_node_disable, h_client, h_server, heketi_node_id) self.assertEqual( heketi_node_info["cluster"], cluster_id, "Node got added in unexpected cluster exp: %s, act: %s" % (cluster_id, heketi_node_info["cluster"])) heketi_ops.heketi_device_add(h_client, h_server, storage_device, heketi_node_id) heketi_node_info = heketi_ops.heketi_node_info(h_client, h_server, heketi_node_id, json=True) device_id = None for device in heketi_node_info["devices"]: if device["name"] == storage_device: device_id = device["id"] break err_msg = ("Failed to add device %s on node %s" % (storage_device, heketi_node_id)) self.assertTrue(device_id, err_msg) self.addCleanup(heketi_ops.heketi_device_delete, h_client, h_server, device_id) self.addCleanup(heketi_ops.heketi_device_remove, h_client, h_server, device_id) self.addCleanup(heketi_ops.heketi_device_disable, h_client, h_server, device_id) cluster_info = heketi_ops.heketi_cluster_info(h_client, h_server, cluster_id, json=True) self.assertIn( heketi_node_info["id"], cluster_info["nodes"], "Newly added node %s not found in cluster %s, cluster info %s" % (heketi_node_info["id"], cluster_id, cluster_info)) topology_info = heketi_ops.heketi_topology_info(h_client, h_server, json=True) cluster_details = [ cluster for cluster in topology_info["clusters"] if cluster["id"] == cluster_id ] err_msg = "Cluster details for id '%s' not found" % cluster_id self.assertTrue(cluster_details, err_msg) err_msg = ("Multiple clusters with same id '%s' found %s" % (cluster_id, cluster_details)) self.assertEqual(len(cluster_details), 1, err_msg) node_details = [ node for node in cluster_details[0]["nodes"] if node["id"] == heketi_node_id ] err_msg = "Node details for id '%s' not found" % heketi_node_id self.assertTrue(node_details, err_msg) err_msg = ("Multiple nodes with same id '%s' found %s" % (heketi_node_id, node_details)) self.assertEqual(len(node_details), 1, err_msg) err_msg = "Unexpected %s found '%s', expected '%s'" exp_storage_hostname = node_details[0]["hostnames"]["manage"][0] self.assertEqual( exp_storage_hostname, storage_hostname, err_msg % ( "hostname", exp_storage_hostname, storage_hostname, )) exp_storage_ip = node_details[0]["hostnames"]["storage"][0] self.assertEqual(exp_storage_ip, storage_ip, err_msg % ("IP address", exp_storage_ip, storage_ip)) zone = node_details[0]["zone"] self.assertEqual(zone, storage_zone, err_msg % ("zone", zone, storage_zone))