Skip to content

Commit

Permalink
Adding test to see if the cephfilesystem can not be created with the …
Browse files Browse the repository at this point in the history
…same name if it already exists

Signed-off-by: Shivam Durgbuns <[email protected]>
  • Loading branch information
shivamdurgbuns committed May 23, 2024
1 parent 16c9c5f commit edb710c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 13 deletions.
35 changes: 22 additions & 13 deletions ocs_ci/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,30 +606,39 @@ def create_ceph_block_pool(
return cbp_obj


def create_ceph_file_system(pool_name=None):
def create_ceph_file_system(
cephfs_name=None, label=None, namespace=constants.OPENSHIFT_STORAGE_NAMESPACE
):
"""
Create a Ceph file system
** This method should not be used anymore **
** This method is for internal testing only **
Args:
pool_name (str): The pool name to create
cephfs_name (str): The ceph FS name to create
label (dict): The label to give to pool
namespace (str): The name space in which the ceph FS has to be created
Returns:
OCS: An OCS instance for the Ceph file system
"""
cfs_data = templating.load_yaml(constants.CEPHFILESYSTEM_YAML)
cfs_data["metadata"]["name"] = (
pool_name if pool_name else create_unique_resource_name("test", "cfs")
cephfs_data = templating.load_yaml(constants.CEPHFILESYSTEM_YAML)
cephfs_data["metadata"]["name"] = (
cephfs_name if cephfs_name else create_unique_resource_name("test", "cfs")
)
cfs_data["metadata"]["namespace"] = config.ENV_DATA["cluster_namespace"]
cfs_data = create_resource(**cfs_data)
cfs_data.reload()
cephfs_data["metadata"]["namespace"] = namespace
if label:
cephfs_data["metadata"]["labels"] = label

try:
cephfs_data = create_resource(**cephfs_data)
cephfs_data.reload()
except Exception as e:
logger.error(e)
raise e

assert validate_cephfilesystem(
cfs_data.name
), f"File system {cfs_data.name} does not exist"
return cfs_data
cephfs_data.name
), f"File system {cephfs_data.name} does not exist"
return cephfs_data


def default_storage_class(
Expand Down
59 changes: 59 additions & 0 deletions tests/internal/test_cephfilesystem_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import pytest
import logging

from ocs_ci.helpers.helpers import (
create_ceph_file_system,
)
from ocs_ci.ocs.exceptions import CommandFailed
from ocs_ci.framework.testlib import tier2
import ocs_ci.ocs.resources.pod as pod


logger = logging.getLogger(__name__)


class TestCephFileSystemCreation:
"""
Testing Creation of a filesystem and checking its existence.
Also checking if the same filesystem can't be created twice.
"""

@pytest.fixture()
def cephFileSystem(self, request):
"""
Creating the CephFileSystem test-ceph-fs for the test.
"""
logger.info("Creating CephFileSystem in the namespace")
cephFS_obj = create_ceph_file_system(
cephfs_name="test-ceph-fs", label={"use": "test"}
)

if cephFS_obj:
logger.info("CephFile System Created. : test-ceph-fs")
else:
logger.error("Unable to create the Ceph File System")

@tier2
def test_Cephfilesystem_creation(self, cephFileSystem):
"""
Trying to create more cephfilesystem using the same name.
Expected Result: It should not create the filesystem and throw error.
"""
logger.info("Starting test of Ceph Filesystem Creation")
try:
ct_pod = pod.get_ceph_tools_pod()
cmd1 = "ceph fs fail test-ceph-fs"
ct_pod.exec_cmd_on_pod(cmd1)
cmd2 = "ceph fs rm test-ceph-fs --yes-i-really-mean-it"
ct_pod.exec_cmd_on_pod(cmd2)
create_ceph_file_system(cephfs_name="test-ceph-fs", label={"use": "test"})

except CommandFailed as e:
if "Error from server (AlreadyExists)" in str(e):
logger.info("Test success!")
assert "Error from server (AlreadyExists)" in str(e)
else:
logger.error(
f"Command Failed, while creating the ceph file system.\n{str(e)}"
)
raise CommandFailed

0 comments on commit edb710c

Please sign in to comment.