Exemple #1
0
def run(ceph_cluster, **kw):
    """
    Pre-requisites:
    1. Create 3 cephfs volume
       creats fs volume create <vol_name>
       ceph orch apply mds <fs_name> --placement='<no. of mds> <mds_nodes...>'

    Test operation:
    1. Create client1 restricted to first cephfs
       ceph fs authorize <fs_name> client.<client_id> <path-in-cephfs> rw
    2. Create client2 restricted to second cephfs
    3. Create client3 restricted to third cephfs
    4. Get filesystem information using client1
    5. Ensure only first cephfs info is shown
    6. Get filesystem information using client2
    7. Ensure only second cephfs info is shown
    8. Get filesystem information using client3
    9. Ensure only third cephfs info is shown

    Clean-up:
    1. Remove third cephfs
    2. Remove all the cephfs mounts
    3. Remove all the clients
    """
    try:
        tc = "CEPH-83573875"
        log.info(f"Running cephfs {tc} test case")

        config = kw["config"]
        build = config.get("build", config.get("rhbuild"))
        mdss = ceph_cluster.get_ceph_objects("mds")

        fs_util = FsUtils(ceph_cluster)
        clients = ceph_cluster.get_ceph_objects("client")
        client1 = clients[0]
        mds1 = mdss[0].node.hostname
        mds2 = mdss[1].node.hostname
        fs_util.prepare_clients(clients, build)
        fs_util.auth_list(clients)
        mon_node_ip = fs_util.get_mon_node_ips()
        mon_node_ip = ",".join(mon_node_ip)
        fs1 = "cephfs"
        fs2 = "cephfs-ec"
        fs3 = "Ceph_fs_new"
        commands = [
            f"ceph fs volume create {fs3}",
            f"ceph orch apply mds {fs3} --placement='2 {mds1} {mds2}'",
        ]
        for command in commands:
            _, err = clients[0].exec_command(sudo=True,
                                             cmd=command,
                                             long_running=True)
            if err:
                return 1
            wait_for_process(client=clients[0],
                             process_name=fs3,
                             ispresent=True)
        log.info(f"Creating client authorized to {fs1}")
        fs_util.fs_client_authorize(client1, fs1, "client1", "/", "rw")
        log.info(f"Creating client authorized to {fs2}")
        fs_util.fs_client_authorize(client1, fs2, "client2", "/", "rw")
        log.info(f"Creating client authorized to {fs3}")
        fs_util.fs_client_authorize(client1, fs3, "client3", "/", "rw")
        log.info("Verifying file system information for client1")
        command = (
            "ceph auth get client.client1 -o /etc/ceph/ceph.client.client1.keyring"
        )
        client1.exec_command(sudo=True, cmd=command)
        command = "ceph fs ls -n client.client1 -k /etc/ceph/ceph.client.client1.keyring --format json"
        out, rc = client1.exec_command(sudo=True, cmd=command)
        output = json.loads(out.read().decode())
        validate_fs_info(fs1, output)
        log.info("Verifying file system information for client2")
        command = (
            "ceph auth get client.client2 -o /etc/ceph/ceph.client.client2.keyring"
        )
        client1.exec_command(sudo=True, cmd=command)
        command = "ceph fs ls -n client.client2 -k /etc/ceph/ceph.client.client2.keyring --format json"
        out, rc = client1.exec_command(sudo=True, cmd=command)
        output = json.loads(out.read().decode())
        validate_fs_info(fs2, output)
        log.info("Verifying file system information for client3")
        command = (
            "ceph auth get client.client3 -o /etc/ceph/ceph.client.client3.keyring"
        )
        client1.exec_command(sudo=True, cmd=command)
        command = "ceph fs ls -n client.client3 -k /etc/ceph/ceph.client.client3.keyring --format json"
        out, rc = client1.exec_command(sudo=True, cmd=command)
        output = json.loads(out.read().decode())
        validate_fs_info(fs3, output)
        return 0

    except Exception as e:
        log.info(e)
        log.info(traceback.format_exc())
        return 1
    finally:
        log.info("Cleaning up the system")
        commands = [
            "ceph config set mon mon_allow_pool_delete true",
            f"ceph fs volume rm {fs3} --yes-i-really-mean-it",
        ]
        for command in commands:
            client1.exec_command(sudo=True, cmd=command)

        for num in range(1, 4):
            client1.exec_command(sudo=True,
                                 cmd=f"ceph auth rm client.client{num}")
def run(ceph_cluster, **kw):
    try:
        tc = "CEPH-83574483"
        log.info("Running cephfs %s test case" % (tc))

        config = kw.get("config")
        rhbuild = config.get("rhbuild")
        from tests.cephfs.cephfs_utilsV1 import FsUtils

        fs_util = FsUtils(ceph_cluster)
        client = ceph_cluster.get_ceph_objects("client")
        mon_node_ip = fs_util.get_mon_node_ips()
        mon_node_ip = ",".join(mon_node_ip)
        fs_count = 1
        fs_name = "cephfs"
        client_number = 1
        """
        Testing multiple cephfs client authorize for 5.x and
        Testing single cephfs client authorize for 4.x
        """
        while fs_count != 3:
            """
            Setting fs name for 4.x and
            Setting "Cephfs name" parameter for kernel & fuse mount for 5.x
            Leaving "Cephfs name" parameter empty for 4.x as parameter not supported in 4.x
            """
            if "4." in rhbuild:
                fs_name = "cephfs_new"
                kernel_fs_para = ""
                fuse_fs_para = ""
            else:
                kernel_fs_para = f",fs={fs_name}"
                fuse_fs_para = f" --client_fs {fs_name}"
            log.info(f"Testing client authorize for {fs_name}")
            # Create client with read-write permission on "/" directory
            mount_points = []
            client_name = "Client_" + str(client_number)
            kernel_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_uppercase + string.digits) for i in range(5)
            )
            fuse_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_lowercase + string.digits) for i in range(5)
            )
            mount_points.extend([kernel_mount_dir, fuse_mount_dir])
            log.info(
                f"Testing {client_name} with read-write permission on root directory"
            )
            fs_util.fs_client_authorize(client[0], fs_name, client_name, "/", "rw")
            # Mount cephfs on kernel & fuse client
            fs_util.kernel_mount(
                client,
                kernel_mount_dir,
                mon_node_ip,
                new_client_hostname=client_name,
                extra_params=kernel_fs_para,
            )
            fs_util.fuse_mount(
                client,
                fuse_mount_dir,
                new_client_hostname=client_name,
                extra_params=fuse_fs_para,
            )
            # Create directories & files inside them for this & next test scenarios
            for num in range(1, 4):
                log.info("Creating Directories")
                out, rc = client[0].exec_command(
                    sudo=True, cmd="mkdir %s/%s_%d" % (kernel_mount_dir, "dir", num)
                )
                out, rc = client[0].exec_command(
                    sudo=True,
                    cmd=f"dd if=/dev/zero of={kernel_mount_dir}/dir_{num}/file_{num} bs=10M count=10",
                )
            # Test read & write opearions on "/" directory on both kernel & fuse mount
            rc = test_read_write_op(
                client[0], kernel_mount_dir, fuse_mount_dir, client_name
            )
            if rc == 1:
                return 1
            log.info(f"Permissions set for client {client_name} is working")
            client_number += 1
            # Create client with read permission on "/" directory & read-write permission on "dir1" directory
            client_name = "Client_" + str(client_number)
            kernel_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_uppercase + string.digits) for i in range(5)
            )
            fuse_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_lowercase + string.digits) for i in range(5)
            )
            mount_points.extend([kernel_mount_dir, fuse_mount_dir])
            log.info(
                f"Testing {client_name} with read permission on root & read-write permission on /dir_1"
            )
            fs_util.fs_client_authorize(
                client[0], fs_name, client_name, "/", "r", extra_params=" /dir_1 rw"
            )
            # Mount cephfs on kernel & fuse client
            fs_util.kernel_mount(
                client,
                kernel_mount_dir,
                mon_node_ip,
                new_client_hostname=client_name,
                extra_params=kernel_fs_para,
            )
            fs_util.fuse_mount(
                client,
                fuse_mount_dir,
                new_client_hostname=client_name,
                extra_params=fuse_fs_para,
            )
            # Verify write operation on "/" directory fails
            rc = verify_write_failure(
                client[0], kernel_mount_dir, fuse_mount_dir, client_name
            )
            if rc == 1:
                return 1
            # Test read operation "/" directory & read-write operation on "dir1" directory
            commands = [
                f"dd if={fuse_mount_dir}/file of={fuse_mount_dir}/dir_1/file_copy_2 bs=10M count=10",
                f"dd if={kernel_mount_dir}/file of={kernel_mount_dir}/dir_1/file_copy_3 bs=10M count=10",
            ]
            for command in commands:
                _, err = client[0].exec_command(
                    sudo=True, cmd=command, long_running=True
                )
                if err:
                    log.error(
                        f"Permissions set for client {client_name} is not working"
                    )
                    return 1
            log.info(f"Permissions set for client {client_name} is working")
            client_number += 1
            # Create client with read permission on "dir_2" directory
            client_name = "Client_" + str(client_number)
            kernel_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_uppercase + string.digits) for i in range(5)
            )
            fuse_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_lowercase + string.digits) for i in range(5)
            )
            mount_points.extend([kernel_mount_dir, fuse_mount_dir])
            log.info(
                f"Testing {client_name} with read-write permission on /dir_2 directory"
            )
            fs_util.fs_client_authorize(client[0], fs_name, client_name, "/dir_2", "rw")
            # Mount cephfs on kernel & fuse client on sub_directory "dir_2"
            fs_util.kernel_mount(
                client,
                kernel_mount_dir,
                mon_node_ip,
                new_client_hostname=client_name,
                sub_dir="/dir_2",
                extra_params=kernel_fs_para,
            )
            fs_util.fuse_mount(
                client,
                fuse_mount_dir,
                new_client_hostname=client_name,
                extra_params=f" -r /dir_2 {fuse_fs_para}",
            )
            # Verify mount on root directory fails
            kernel_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_uppercase + string.digits) for i in range(5)
            )
            fuse_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_lowercase + string.digits) for i in range(5)
            )
            try:
                fs_util.kernel_mount(
                    client,
                    kernel_mount_dir,
                    mon_node_ip,
                    new_client_hostname=client_name,
                    extra_params=kernel_fs_para,
                )
            except AssertionError as e:
                log.info(e)
                log.info(
                    f"Permissions set for client {client_name} is working for kernel mount"
                )
            except CommandFailed as e:
                log.info(e)
                err = str(e)
                err = err.split()
                if "mount" in err:
                    log.info(
                        f"Permissions set for client {client_name} is working for kernel mount"
                    )
                else:
                    log.info(traceback.format_exc())
                    return 1
            except Exception as e:
                log.info(e)
                log.info(traceback.format_exc())
                return 1
            else:
                log.error(
                    f"Permissions set for client {client_name} is not working for kernel mount"
                )
                return 1
            try:
                fs_util.fuse_mount(
                    client,
                    fuse_mount_dir,
                    new_client_hostname=client_name,
                    extra_params=fuse_fs_para,
                )
            except AssertionError as e:
                log.info(e)
                log.info(
                    f"Permissions set for client {client_name} is working for fuse mount"
                )
            except CommandFailed as e:
                log.info(e)
                err = str(e)
                err = err.split()
                if "mount" in err:
                    log.info(
                        f"Permissions set for client {client_name} is working for fuse mount"
                    )
                else:
                    log.info(traceback.format_exc())
                    return 1
            except Exception as e:
                log.info(e)
                log.info(traceback.format_exc())
                return 1
            else:
                log.error(
                    f"Permissions set for client {client_name} is not working for fuse mount"
                )
                return 1
            # Test read & write opearions on kernel & fuse mount
            commands = [
                f"python3 /home/cephuser/smallfile/smallfile_cli.py --operation create --threads 10 --file-size 4 "
                f"--files 1000 --files-per-dir 10 --dirs-per-dir 2 --top {kernel_mount_dir}",
                f"python3 /home/cephuser/smallfile/smallfile_cli.py --operation read --threads 10 --file-size 4 "
                f"--files 1000 --files-per-dir 10 --dirs-per-dir 2 --top {kernel_mount_dir}",
                f"dd if=/dev/zero of={fuse_mount_dir}/file bs=10M count=10",
                f"dd if={fuse_mount_dir}/file of={fuse_mount_dir}/file bs=10M count=10",
            ]
            for command in commands:
                _, err = client[0].exec_command(
                    sudo=True, cmd=command, long_running=True
                )
                if err:
                    log.error(
                        f"Permissions set for client {client_name} is not working"
                    )
                    return 1
            log.info(f"Permissions set for client {client_name} is working")
            client_number += 1
            # Create client with read permission on "dir_3" directory
            client_name = "Client_" + str(client_number)
            kernel_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_uppercase + string.digits) for i in range(5)
            )
            fuse_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_lowercase + string.digits) for i in range(5)
            )
            log.info(f"Testing {client_name} with read permission on /dir_3 directory")
            fs_util.fs_client_authorize(client[0], fs_name, client_name, "/dir_3", "r")
            # Verify mount on root directory fails
            try:
                fs_util.kernel_mount(
                    client,
                    kernel_mount_dir,
                    mon_node_ip,
                    new_client_hostname=client_name,
                    extra_params=kernel_fs_para,
                )
            except AssertionError as e:
                log.info(e)
                log.info(
                    f"Permissions set for client {client_name} is working for kernel mount"
                )
            except CommandFailed as e:
                log.info(e)
                err = str(e)
                err = err.split()
                if "mount" in err:
                    log.info(
                        f"Permissions set for client {client_name} is working for kernel mount"
                    )
                else:
                    log.info(traceback.format_exc())
                    return 1
            except Exception as e:
                log.info(e)
                log.info(traceback.format_exc())
                return 1
            else:
                log.error(f"Permissions set for client {client_name} is not working")
                return 1
            try:
                fs_util.fuse_mount(
                    client,
                    fuse_mount_dir,
                    new_client_hostname=client_name,
                    extra_params=fuse_fs_para,
                )
            except AssertionError as e:
                log.info(e)
                log.info(
                    f"Permissions set for client {client_name} is working for fuse mount"
                )
            except CommandFailed as e:
                log.info(e)
                err = str(e)
                err = err.split()
                if "mount" in err:
                    log.info(
                        f"Permissions set for client {client_name} is working for fuse mount"
                    )
                else:
                    log.info(traceback.format_exc())
                    return 1
            except Exception as e:
                log.info(e)
                log.info(traceback.format_exc())
                return 1
            else:
                log.error(f"Permissions set for client {client_name} is not working")
                return 1
            # Mount cephfs on kernel & fuse client on sub_directory "dir_3"
            kernel_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_uppercase + string.digits) for i in range(5)
            )
            fuse_mount_dir = "/mnt/" + "".join(
                secrets.choice(string.ascii_lowercase + string.digits) for i in range(5)
            )
            mount_points.extend([kernel_mount_dir, fuse_mount_dir])
            fs_util.kernel_mount(
                client,
                kernel_mount_dir,
                mon_node_ip,
                new_client_hostname=client_name,
                sub_dir="/dir_3",
                extra_params=kernel_fs_para,
            )
            fs_util.fuse_mount(
                client,
                fuse_mount_dir,
                new_client_hostname=client_name,
                extra_params=f" -r /dir_3 {fuse_fs_para}",
            )
            # Verify write opearions on kernel & fuse mount fails
            rc = verify_write_failure(
                client[0], kernel_mount_dir, fuse_mount_dir, client_name
            )
            if rc == 1:
                return 1
            # Verify read opearions on kernel & fuse mount
            commands = [
                f"dd if={fuse_mount_dir}/file_3 of=~/file_3 bs=10M count=10",
                f"dd if={kernel_mount_dir}/file_3 of=~/file_33 bs=10M count=10",
            ]
            for command in commands:
                _, err = client[0].exec_command(
                    sudo=True, cmd=command, long_running=True
                )
                if err:
                    log.error(
                        f"Permissions set for client {client_name} is not working"
                    )
                    return 1
            log.info(f"Permissions set for client {client_name} is working")
            log.info(f"Clean up the system for {fs_name}")
            out, rc = client[0].exec_command(
                sudo=True, cmd=f"rm -rf {mount_points[1]}/*"
            )
            for mount_point in mount_points:
                out, rc = client[0].exec_command(sudo=True, cmd=f"umount {mount_point}")
                if "5." in rhbuild:
                    out, err = client[1].exec_command(
                        sudo=True, cmd=f"umount {mount_point}"
                    )
            for mount_point in mount_points:
                out, rc = client[0].exec_command(
                    sudo=True, cmd=f"rm -rf {mount_point}/"
                )
                if "5." in rhbuild:
                    out, err = client[1].exec_command(
                        sudo=True, cmd=f"rm -rf {mount_point}/"
                    )
            if "4." in rhbuild:
                break
            fs_name = "cephfs-ec"
            fs_count += 1
            client_number += 1
        for num in range(1, 5):
            out, err = client[0].exec_command(
                sudo=True, cmd=f"ceph auth rm client.client_{num}"
            )
        if "5." in rhbuild:
            for num in range(5, 9):
                out, err = client[0].exec_command(
                    sudo=True, cmd=f"ceph auth rm client.client_{num}"
                )
        return 0

    except CommandFailed as e:
        log.info(e)
        log.info(traceback.format_exc())
        return 1
    except Exception as e:
        log.info(e)
        log.info(traceback.format_exc())
        return 1
Exemple #3
0
def run(ceph_cluster, **kw):
    """
    Pre-requisites:
    1. Create 2 cephfs volume
       creats fs volume create <vol_name>

    Test operation:
    1. Create client1 restricted to first cephfs
       ceph fs authorize <fs_name> client.<client_id> <path-in-cephfs> rw
    2. Create client2 restricted to second cephfs
    3. Mount first cephfs with client1
    4. Verify mounting second cephfs with client1 fails
    5. Mount second cephfs with client2
    6. Verify mounting first cephfs with client2 fails

    Clean-up:
    1. Remove all the cephfs mounts
    2. Remove all the created clients
    """
    try:
        tc = "CEPH-83573869"
        log.info(f"Running cephfs {tc} test case")

        config = kw["config"]
        build = config.get("build", config.get("rhbuild"))

        fs_util = FsUtils(ceph_cluster)
        clients = ceph_cluster.get_ceph_objects("client")
        client1 = clients[0]
        fs_util.prepare_clients(clients, build)
        fs_util.auth_list(clients)
        mon_node_ip = fs_util.get_mon_node_ips()
        mon_node_ip = ",".join(mon_node_ip)
        mount_points = []
        fs1 = "cephfs"
        fs2 = "cephfs-ec"
        log.info(f"Creating client authorized to {fs1}")
        fs_util.fs_client_authorize(client1, fs1, "client1", "/", "rw")
        log.info(f"Creating client authorized to {fs2}")
        fs_util.fs_client_authorize(client1, fs2, "client2", "/", "rw")
        kernel_mount_dir = "/mnt/kernel" + "".join(
            secrets.choice(string.ascii_uppercase + string.digits)
            for i in range(5))
        fuse_mount_dir = "/mnt/fuse" + "".join(
            secrets.choice(string.ascii_lowercase + string.digits)
            for i in range(5))
        mount_points.extend([kernel_mount_dir, fuse_mount_dir])
        log.info(f"Mounting {fs1} with client1")
        fs_util.kernel_mount(
            clients,
            kernel_mount_dir,
            mon_node_ip,
            new_client_hostname="client1",
            extra_params=f",fs={fs1}",
        )
        fs_util.fuse_mount(
            clients,
            fuse_mount_dir,
            new_client_hostname="client1",
            extra_params=f" --client_fs {fs1}",
        )
        log.info(f"Verifying mount failure for client1 for {fs2}")
        rc = verify_mount_failure_on_root(
            fs_util,
            clients,
            kernel_mount_dir + "_dir1",
            fuse_mount_dir + "_dir1",
            "client1",
            mon_node_ip,
            fs_name=f"{fs2}",
        )
        if rc == 1:
            log.error(f"Mount success on {fs2} with client1")
            return 1
        kernel_mount_dir = "/mnt/kernel" + "".join(
            secrets.choice(string.ascii_uppercase + string.digits)
            for i in range(5))
        fuse_mount_dir = "/mnt/fuse" + "".join(
            secrets.choice(string.ascii_lowercase + string.digits)
            for i in range(5))
        mount_points.extend([kernel_mount_dir, fuse_mount_dir])
        log.info(f"Mounting {fs2} with client2")
        fs_util.kernel_mount(
            clients,
            kernel_mount_dir,
            mon_node_ip,
            new_client_hostname="client2",
            extra_params=f",fs={fs2}",
        )
        fs_util.fuse_mount(
            clients,
            fuse_mount_dir,
            new_client_hostname="client2",
            extra_params=f" --client_fs {fs2}",
        )
        rc = verify_mount_failure_on_root(
            fs_util,
            clients,
            kernel_mount_dir + "_dir2",
            fuse_mount_dir + "_dir2",
            "client2",
            mon_node_ip,
            fs_name=f"{fs1}",
        )
        log.info(f"Verifying mount failure for client2 for {fs1}")
        if rc == 1:
            log.error(f"Mount success on {fs1} with client2")
            return 1
        return 0

    except Exception as e:
        log.info(e)
        log.info(traceback.format_exc())
        return 1
    finally:
        log.info("Cleaning up the system")
        for client in clients:
            for mount_point in mount_points:
                client.exec_command(sudo=True, cmd=f"umount {mount_point}")
        for num in range(1, 4):
            client1.exec_command(sudo=True,
                                 cmd=f"ceph auth rm client.client{num}")