Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cephfilesystem creation test based on bug #9851

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we checked regression for this? i.e. Is there any TC which is consuming this function with pool_name param defined in the function call?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got clarity from Shivam that its validated and based on the output added Verified label.

):
"""
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
Comment on lines +633 to +635
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope this part of code is validated with failure message, if required do add required exception message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is added if any unknown error has is thrown by create resource function while creating the object


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add this TC in polarion and update the polarion ID here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added polarian id

@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
Loading