Skip to content

Commit

Permalink
Added docstring, fixed typos
Browse files Browse the repository at this point in the history
Signed-off-by: Aviadp <[email protected]>
  • Loading branch information
AviadP committed May 30, 2024
1 parent 922ef04 commit 4227b01
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
51 changes: 45 additions & 6 deletions ocs_ci/ocs/ephernal_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,61 @@
log = getLogger(__name__)


class EphernalPodFactory:
class EphemeralPodFactory:
@staticmethod
def create_pod_dict(pod_name: str, storage_type: str, **kwargs):

if storage_type == CEPHFS_INTERFACE:
return EphernalPodFactory.create_cephfs_pod_dict(pod_name, **kwargs)
return EphemeralPodFactory.create_cephfs_pod_dict(pod_name, **kwargs)
elif storage_type == RBD_INTERFACE:
return EphernalPodFactory.create_rbd_pod_dict(pod_name, **kwargs)
return EphemeralPodFactory.create_rbd_pod_dict(pod_name, **kwargs)

@staticmethod
def create_cephfs_pod_dict(pod_name: str, **kwargs) -> dict:
"""
This method creates a dictionary representing a CephFS pod configuration.
Args:
pod_name (str): The name of the pod.
Returns:
pod_dict: A dictionary representing the CephFS pod configuration.
"""
pod_dict_path = EPHEMERAL_FS_POD_YAML
pod_dict = load_yaml(pod_dict_path)
return pod_dict

@staticmethod
def create_rbd_pod_dict(pod_name: str, **kwargs) -> dict:
"""
This method creates a dictionary representing a RBD pod configuration.
Args:
pod_name (str): The name of the pod.
Returns:
pod_dict: A dictionary representing the RBD pod configuration.
"""
pod_dict_path = EPHEMERAL_RBD_POD_YAML
pod_dict = load_yaml(pod_dict_path)
return pod_dict

@staticmethod
def create_ephmeral_pod(pod_name: str, storage_type: str, **kwargs) -> Pod:
pod_dict = EphernalPodFactory.create_pod_dict(pod_name, storage_type, **kwargs)
def create_ephemeral_pod(pod_name: str, storage_type: str, **kwargs) -> Pod:
"""
This method creates a new ephemeral pod based on the specified storage type.
Args:
pod_name (str): The name of the pod.
storage_type (str): The type of storage interface (CephFS or RBD).
Returns:
created_resources: A new ephemeral pod object.
"""
pod_dict = EphemeralPodFactory.create_pod_dict(pod_name, storage_type, **kwargs)
pod_dict["metadata"]["namespace"] = config.ENV_DATA["cluster_namespace"]
pod_obj = Pod(**pod_dict)

Expand All @@ -52,7 +83,15 @@ def create_ephmeral_pod(pod_name: str, storage_type: str, **kwargs) -> Pod:
return created_resource

@staticmethod
def delete_ephmeral_pod(pod_name: str, namespace: str) -> None:
def delete_ephemeral_pod(pod_name: str, namespace: str) -> None:
"""
This method deletes an existing ephemeral pod.
Args:
pod_name (str): The name of the pod.
namespace (str): The namespace of the pod.
"""
pod_dict = {
"metadata": {
"name": pod_name,
Expand Down
18 changes: 7 additions & 11 deletions tests/functional/pod_and_daemons/test_ephemeral_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@
from logging import getLogger

from ocs_ci.ocs.resources.pvc import get_all_pvcs
from ocs_ci.ocs.ephernal_storage import EphernalPodFactory
from ocs_ci.ocs.ephernal_storage import EphemeralPodFactory
from ocs_ci.ocs.constants import (
CEPHFS_INTERFACE,
RBD_INTERFACE,
)
from ocs_ci.framework import config
from ocs_ci.framework.pytest_customization.marks import (
tier1,
brown_squad,
)
from ocs_ci.framework.pytest_customization.marks import tier1, brown_squad, polarion_id

log = getLogger(__name__)


@tier1
@brown_squad
class TestEphernalPod:
@polarion_id("OCS-5792")
class TestEphemeralPod:
@pytest.mark.parametrize(
argnames=["interface"], argvalues=[[CEPHFS_INTERFACE], [RBD_INTERFACE]]
)
def test_ephernal_pod_creation(self, interface) -> None:
def test_ephemeral_pod_creation(self, interface) -> None:
pod_name = None
storage_type = interface
ephemeral_pod = EphernalPodFactory.create_ephmeral_pod(pod_name, storage_type)
ephemeral_pod = EphemeralPodFactory.create_ephemeral_pod(pod_name, storage_type)
log.info(f"Pods Created: {ephemeral_pod}")

# Test PVC Creation
Expand All @@ -49,10 +47,8 @@ def test_ephernal_pod_creation(self, interface) -> None:
log.info("Starting pod deletion validation")
p_name = ephemeral_pod.get("metadata").get("name")
log.info(f"P_NAME: {p_name}")

# Test delete pod
log.info("Start Deleting ephemeral pods")
EphernalPodFactory.delete_ephmeral_pod(
EphemeralPodFactory.delete_ephemeral_pod(
p_name, config.ENV_DATA["cluster_namespace"]
)

Expand Down

0 comments on commit 4227b01

Please sign in to comment.