Exemple #1
0
    def setUp(self):
        self.get_super_method(self, 'setUp')()

        # A single mount is enough for all the tests
        self.mounts = self.mounts[0:1]
        self.client = self.mounts[0].client_system
        self.m_point = self.mounts[0].mountpoint

        # Command to run minimal IO
        self.io_cmd = 'cat /dev/urandom | tr -dc [:space:][:print:] | head -c '

        if not self.setup_volume_and_mount_volume(mounts=self.mounts):
            raise ExecutionError('Failed to setup and mount '
                                 '{}'.format(self.volname))

        self.timeout = 5 if is_rhel7(self.mnode) else 2
def cluster_auth_setup(servers):
    """
    Configuring the Cluster Services

    Args:
        servers(list): Hostname of ganesha nodes
    Returns:
        True(bool): If configuration of cluster services is success
        False(bool): If failed to configure cluster services
    """
    for node in servers:
        # Enable pacemaker.service
        ret, _, _ = g.run(node, "systemctl enable pacemaker.service")
        if ret != 0:
            g.log.error("Failed to enable pacemaker service in %s", node)

        # Start pcsd
        ret, _, _ = g.run(node, "systemctl start pcsd")
        if ret != 0:
            g.log.error("failed to start pcsd on %s", node)
            return False

        # Enable pcsd on the system
        ret, _, _ = g.run(node, "systemctl enable pcsd")
        if ret != 0:
            g.log.error("Failed to enable pcsd in %s", node)

        # Set a password for the user 'hacluster' on all the nodes
        ret, _, _ = g.run(node, "echo hacluster | passwd --stdin hacluster")
        if ret != 0:
            g.log.error("unable to set password for hacluster on %s", node)
            return False

    # Perform cluster authentication between the nodes
    auth_type = 'cluster' if is_rhel7(servers) else 'host'
    for node in servers:
        ret, _, _ = g.run(node, "pcs %s auth %s -u hacluster -p hacluster"
                          % (auth_type, ' '.join(servers)))
        if ret:
            g.log.error("pcs %s auth command failed on %s",
                        auth_type, node)
            return False
    return True
Exemple #3
0
def bring_down_network_interface(mnode, timeout=150):
    """Brings the network interface down for a defined time

        Args:
            mnode (str): Node at which the interface has to be bought down
            timeout (int): Time duration (in secs) for which network has to
                           be down

        Returns:
            network_status(object): Returns a process object

        Example:
            >>> bring_down_network_interface("10.70.43.68", timout=100)
    """
    interface = "eth0" if is_rhel7(mnode) else "ens3"
    cmd = "ifconfig {0} down\nsleep {1}\nifconfig {0} up".format(
        interface, timeout)
    _, _, _ = g.run(mnode, "echo  \"{}\"> 'test.sh'".format(cmd))
    network_status = g.run_async(mnode, "sh test.sh")
    return network_status
def create_nfs_ganesha_cluster(servers, vips):
    """
    Creating a ganesha HA cluster

    Args:
        servers(list): Hostname of ganesha nodes
        vips(list): VIPs that has to be assigned for each nodes
    Returns:
        True(bool): If configuration of ganesha cluster is success
        False(bool): If failed to configure ganesha cluster
    """
    # pylint: disable=too-many-return-statements
    # pylint: disable=too-many-branches
    # pylint: disable=too-many-statements
    ganesha_mnode = servers[0]

    # Configure ports in ganesha servers for RHEL7
    if is_rhel7(servers):
        g.log.info("Defining statd service ports")
        ret = configure_ports_on_servers(servers)
        if not ret:
            g.log.error("Failed to set statd service ports on nodes.")
            return False

    # Firewall settings for nfs-ganesha
    ret = ganesha_server_firewall_settings(servers)
    if not ret:
        g.log.error("Firewall settings for nfs ganesha has failed.")
        return False
    g.log.info("Firewall settings for nfs ganesha was success.")

    # Do peer probe if not already done
    ret = peer_probe_servers(ganesha_mnode, servers, validate=True)
    if not ret:
        g.log.error("Peer probe failed")
        return False

    # Enable shared storage if not present
    ret, _, _ = g.run(ganesha_mnode,
                      "gluster v list | grep 'gluster_shared_storage'")
    if ret != 0:
        if not enable_shared_storage(ganesha_mnode):
            g.log.error("Failed to enable shared storage")
            return False
        g.log.info("Enabled gluster shared storage.")
    else:
        g.log.info("Shared storage is already enabled.")

    # Enable the glusterfssharedstorage.service and nfs-ganesha service
    for server in servers:
        cmd = "systemctl enable glusterfssharedstorage.service"
        ret, _, _ = g.run(server, cmd)
        if ret != 0:
            g.log.error("Failed to enable glusterfssharedstorage.service "
                        "on %s", server)
            return False

        ret, _, _ = g.run(server, "systemctl enable nfs-ganesha")
        if ret != 0:
            g.log.error("Failed to enable nfs-ganesha service on %s", server)
            return False

    # Password less ssh for nfs
    ret = create_nfs_passwordless_ssh(ganesha_mnode, servers)
    if not ret:
        g.log.error("Password less ssh between nodes failed.")
        return False
    g.log.info("Password less ssh between nodes successful.")

    # Create ganesha-ha.conf file
    tmp_ha_conf = "/tmp/ganesha-ha.conf"
    create_ganesha_ha_conf(servers, vips, tmp_ha_conf)

    # Check whether ganesha-ha.conf file is created
    if not os.path.isfile(tmp_ha_conf):
        g.log.error("Failed to create ganesha-ha.conf")
        return False

    # Cluster auth setup
    ret = cluster_auth_setup(servers)
    if not ret:
        g.log.error("Failed to configure cluster services")
        return False

    # Create nfs-ganesha directory in shared storage
    dpath = '/var/run/gluster/shared_storage/nfs-ganesha'
    mkdir(ganesha_mnode, dpath)

    # Copy the config files to shared storage
    cmd = 'cp -p /etc/ganesha/ganesha.conf %s/' % dpath
    ret, _, _ = g.run(ganesha_mnode, cmd)
    if ret != 0:
        g.log.error("Failed to copy ganesha.conf to %s/", dpath)
        return False

    g.upload(ganesha_mnode, tmp_ha_conf, '%s/' % dpath)

    # Create backup of ganesha-ha.conf file in ganesha_mnode
    g.upload(ganesha_mnode, tmp_ha_conf, '/etc/ganesha/')

    # setsebool ganesha_use_fusefs on
    cmd = "setsebool ganesha_use_fusefs on"
    for server in servers:
        ret, _, _ = g.run(server, cmd)
        if ret:
            g.log.error("Failed to 'setsebool ganesha_use_fusefs on' on %",
                        server)
            return False

        # Verify ganesha_use_fusefs is on
        _, out, _ = g.run(server, "getsebool ganesha_use_fusefs")
        if "ganesha_use_fusefs --> on" not in out:
            g.log.error("Failed to 'setsebool ganesha_use_fusefs on' on %",
                        server)
            return False

    # Enabling ganesha
    g.log.info("Enable nfs-ganesha")
    ret, _, _ = enable_nfs_ganesha(ganesha_mnode)

    if ret != 0:
        g.log.error("Failed to enable ganesha")
        return False

    g.log.info("Successfully created ganesha cluster")

    # pcs status output
    _, _, _ = g.run(ganesha_mnode, "pcs status")

    # pacemaker status output
    _, _, _ = g.run(ganesha_mnode, "systemctl status pacemaker")

    return True
Exemple #5
0
def setup_nfs_ganesha(cls):
    """
    Create nfs-ganesha cluster if not exists
    Set client configurations for nfs-ganesha

    Returns:
        True(bool): If setup is successful
        False(bool): If setup is failure
    """
    # pylint: disable = too-many-statements, too-many-branches
    # pylint: disable = too-many-return-statements
    cluster_exists = is_nfs_ganesha_cluster_exists(
        cls.servers_in_nfs_ganesha_cluster[0])
    if cluster_exists:
        is_healthy = is_nfs_ganesha_cluster_in_healthy_state(
            cls.servers_in_nfs_ganesha_cluster[0])

        if is_healthy:
            g.log.info("Nfs-ganesha Cluster exists and is in healthy "
                       "state. Skipping cluster creation...")
        else:
            g.log.info("Nfs-ganesha Cluster exists and is not in "
                       "healthy state.")
            g.log.info("Tearing down existing cluster which is not in "
                       "healthy state")
            ganesha_ha_file = ("/var/run/gluster/shared_storage/"
                               "nfs-ganesha/ganesha-ha.conf")
            g_node = cls.servers_in_nfs_ganesha_cluster[0]

            g.log.info("Collecting server details of existing "
                       "nfs ganesha cluster")

            # Check whether ganesha ha file exists
            cmd = "[ -f {} ]".format(ganesha_ha_file)
            ret, _, _ = g.run(g_node, cmd)
            if ret:
                g.log.error("Unable to locate %s", ganesha_ha_file)
                return False

            # Read contents of ganesha_ha_file
            cmd = "cat {}".format(ganesha_ha_file)
            ret, ganesha_ha_contents, _ = g.run(g_node, cmd)
            if ret:
                g.log.error("Failed to read %s", ganesha_ha_file)
                return False

            servers_in_existing_cluster = re.findall(r'VIP_(.*)\=.*',
                                                     ganesha_ha_contents)

            ret = teardown_nfs_ganesha_cluster(servers_in_existing_cluster,
                                               force=True)
            if not ret:
                g.log.error("Failed to teardown unhealthy ganesha " "cluster")
                return False

            g.log.info("Existing unhealthy cluster got teardown "
                       "successfully")

    if (not cluster_exists) or (not is_healthy):
        g.log.info("Creating nfs-ganesha cluster of %s nodes" %
                   str(cls.num_of_nfs_ganesha_nodes))
        g.log.info("Nfs-ganesha cluster node info: %s" %
                   cls.servers_in_nfs_ganesha_cluster)
        g.log.info("Nfs-ganesha cluster vip info: %s" %
                   cls.vips_in_nfs_ganesha_cluster)

        ret = create_nfs_ganesha_cluster(cls.ganesha_servers_hostname,
                                         cls.vips_in_nfs_ganesha_cluster)
        if not ret:
            g.log.error("Creation of nfs-ganesha cluster failed")
            return False

    if not is_nfs_ganesha_cluster_in_healthy_state(
            cls.servers_in_nfs_ganesha_cluster[0]):
        g.log.error("Nfs-ganesha cluster is not healthy")
        return False
    g.log.info("Nfs-ganesha Cluster exists is in healthy state")

    if is_rhel7(cls.clients):
        ret = configure_ports_on_clients(cls.clients)
        if not ret:
            g.log.error("Failed to configure ports on clients")
            return False

    ret = ganesha_client_firewall_settings(cls.clients)
    if not ret:
        g.log.error("Failed to do firewall setting in clients")
        return False

    for server in cls.servers:
        for client in cls.clients:
            cmd = ("if [ -z \"$(grep -R \"%s\" /etc/hosts)\" ]; then "
                   "echo \"%s %s\" >> /etc/hosts; fi" %
                   (client, socket.gethostbyname(client), client))
            ret, _, _ = g.run(server, cmd)
            if ret != 0:
                g.log.error("Failed to add entry of client %s in "
                            "/etc/hosts of server %s" % (client, server))

    for client in cls.clients:
        for server in cls.servers:
            cmd = ("if [ -z \"$(grep -R \"%s\" /etc/hosts)\" ]; then "
                   "echo \"%s %s\" >> /etc/hosts; fi" %
                   (server, socket.gethostbyname(server), server))
            ret, _, _ = g.run(client, cmd)
            if ret != 0:
                g.log.error("Failed to add entry of server %s in "
                            "/etc/hosts of client %s" % (server, client))
    return True