def add_heketi_node_to_cluster(self, cluster_id):
        """Add new node to a 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"]
        except KeyError:
            msg = ("Config options 'additional_gluster_servers.manage' "
                   "and 'additional_gluster_servers.storage' 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

        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"]))

        return storage_hostname, storage_ip
Beispiel #2
0
    def __init__(self):
        try:
            self.hostname = g.config['cloud_provider']['vmware']['hostname']
            self.username = g.config['cloud_provider']['vmware']['username']
            self.password = g.config['cloud_provider']['vmware']['password']
            self.port = g.config['cloud_provider']['vmware'].get('port', 443)
        except KeyError:
            msg = ("Config file doesn't have values related to vmware Cloud"
                   " Provider.")
            g.log.error(msg)
            raise exceptions.ConfigError(msg)

        # Connect vsphere client
        try:
            self.vsphere_client = connect.ConnectNoSSL(self.hostname,
                                                       self.port,
                                                       self.username,
                                                       self.password)
        except Exception as e:
            g.log.error(e)
            raise exceptions.CloudProviderError(e)
Beispiel #3
0
def _get_cloud_provider():
    """Gather cloud provider facts"""

    global CLOUD_PROVIDER
    if CLOUD_PROVIDER:
        return CLOUD_PROVIDER

    try:
        cloud_provider_name = g.config['cloud_provider']['name']
    except KeyError:
        msg = "Incorrect config file. Cloud provider name is missing."
        g.log.error(msg)
        raise exceptions.ConfigError(msg)

    if cloud_provider_name == 'vmware':
        CLOUD_PROVIDER = VmWare()
    else:
        msg = "Cloud Provider %s is not supported." % cloud_provider_name
        g.log.error(msg)
        raise NotImplementedError(msg)

    return CLOUD_PROVIDER
    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))