Skip to content

Commit

Permalink
Cephfilesystem creation test based on bug (#9851)
Browse files Browse the repository at this point in the history
* Adding test to see if the cephfilesystem can not be created with the same name if it already exists

Signed-off-by: Shivam Durgbuns <[email protected]>
  • Loading branch information
shivamdurgbuns authored Jun 7, 2024
1 parent e464737 commit 9482269
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 17 deletions.
41 changes: 24 additions & 17 deletions ocs_ci/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,30 +605,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, namespace
), f"File system {cephfs_data.name} does not exist"
return cephfs_data


def default_storage_class(
Expand Down Expand Up @@ -1041,7 +1050,7 @@ def get_cephfs_data_pool_name():
return out[0]["data_pools"][0]


def validate_cephfilesystem(fs_name):
def validate_cephfilesystem(fs_name, namespace=config.ENV_DATA["cluster_namespace"]):
"""
Verify CephFileSystem exists at Ceph and OCP
Expand All @@ -1052,9 +1061,7 @@ def validate_cephfilesystem(fs_name):
bool: True if CephFileSystem is created at Ceph and OCP side else
will return False with valid msg i.e Failure cause
"""
cfs = ocp.OCP(
kind=constants.CEPHFILESYSTEM, namespace=config.ENV_DATA["cluster_namespace"]
)
cfs = ocp.OCP(kind=constants.CEPHFILESYSTEM, namespace=namespace)
ct_pod = pod.get_ceph_tools_pod()
ceph_validate = False
ocp_validate = False
Expand Down
63 changes: 63 additions & 0 deletions tests/internal/test_cephfilesystem_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import logging
import pytest

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

logger = logging.getLogger(__name__)


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

@tier2
@green_squad
@pytest.mark.polarion_id("OCS-5793")
def test_Cephfilesystem_creation(self):
"""
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:
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")
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)
logger.info("Creating CephFileSystem in the namespace")
new_cephFS_obj = create_ceph_file_system(
cephfs_name="test-ceph-fs", label={"use": "test"}
)
logger.info(
f"Not able to create a new ceph fs using same name {new_cephFS_obj}"
)

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 9482269

Please sign in to comment.