Skip to content

Commit

Permalink
Added testcases for improve storage allocation feature
Browse files Browse the repository at this point in the history
Signed-off-by: Amrita Mahapatra <[email protected]>
  • Loading branch information
amr1ta committed Jun 14, 2024
1 parent a140eb0 commit 44fa276
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 134 deletions.
11 changes: 2 additions & 9 deletions ocs_ci/deployment/provider_client/storage_client_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
verify_block_pool_exists,
)
from ocs_ci.ocs.exceptions import CommandFailed
from ocs_ci.helpers.managed_services import (
verify_storageclient,
# verify_storageclient_storageclass_claims,
)


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -228,12 +224,12 @@ def provider_and_native_client_installation(
constants.DEFAULT_BLOCKPOOL
), f"{constants.DEFAULT_BLOCKPOOL} is not created"
assert (
self.rados_utils.verify_cephblockpool_status()
verify_cephblockpool_status()
), "the cephblockpool is not in Ready phase"

# Validate radosnamespace created and in 'Ready' status
assert (
self.rados_utils.check_phase_of_rados_namespace()
check_phase_of_rados_namespace()
), "The radosnamespace is not in Ready phase"

# Validate storageclassrequests created
Expand Down Expand Up @@ -286,9 +282,6 @@ def verify_provider_mode_deployment(self):
"""
This method verifies provider mode deployment
Returns:
onboarding_token(str): client onboarding token
"""

# Check ux server pod, ocs-provider server pod and rgw pods are up and running
Expand Down
70 changes: 0 additions & 70 deletions ocs_ci/ocs/rados_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,76 +277,6 @@ def get_mgr_proxy_container(self, node, docker_image, proxy_container="mgr_proxy

return mgr_object

def verify_cephblockpool_status(
self,
pool_name=constants.DEFAULT_BLOCKPOOL,
namespace=None,
required_phase=constants.STATUS_READY,
):
"""
Verify the phase of cephblockpool
Args:
pool_name (str): The name of the Ceph block pool
Returns:
status: True if the Ceph block pool is in Ready status, False otherwise
"""
if not namespace:
namespace = config.ENV_DATA["cluster_namespace"]
cmd = (
f"oc get {constants.CEPHBLOCKPOOL} {pool_name} -n {namespace} "
"-o=jsonpath='{.status.phase}'"
)
# phase = run_cmd(cmd=cmd)

phase = retry((CommandFailed), tries=20, delay=10,)(
run_cmd
)(cmd=cmd)

logger.info(f"{pool_name} is in {phase} phase")
logger.info(f"Required phase is {required_phase}")
if phase == required_phase:
return True
else:
return False

def fetch_rados_namespaces(self, namespace=None):
"""
Verify if rados namespace exists
Returns:
bool: True if the radosnamespace exists, False otherwise
"""
logger.info("Fetch radosnamespaces exist")
if not namespace:
namespace = config.ENV_DATA["cluster_namespace"]
rados_ns_obj = ocp.OCP(kind=constants.CEPHBLOCKPOOLRADOSNS, namespace=namespace)
result = rados_ns_obj.get()
sample = result["items"]
rados_ns_list = [item.get("metadata").get("name") for item in sample]
return rados_ns_list

def check_phase_of_rados_namespace(
self, namespace=None, required_phase=constants.STATUS_READY
):
"""
Verify if rados namespace exists
Returns:
bool: True if the radosnamespace exists, False otherwise
"""
logger.info("Verifying if radosnamespace is in desired phase")
if not namespace:
namespace = config.ENV_DATA["cluster_namespace"]
for rados_namespace in self.fetch_rados_namespaces(namespace=namespace):
check_radosns_phase_cmd = (
f"oc get {constants.CEPHBLOCKPOOLRADOSNS} {rados_namespace} -n {namespace} "
"-o=jsonpath='{.status.phase}'"
)
phase = run_cmd(cmd=check_radosns_phase_cmd)
return True if phase == required_phase else False


def verify_cephblockpool_status(
pool_name=constants.DEFAULT_BLOCKPOOL,
Expand Down
48 changes: 40 additions & 8 deletions ocs_ci/ocs/resources/storage_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,59 @@ def odf_installation_on_client(
if enable_console:
enable_console_plugin(value="[odf-client-console]")

def check_storageclient_availability(self, storage_client_name):
"""
Check if the storage client exists
Returns:
bool: True if storage client exists, False otherwise
"""
return self.storage_client_obj.check_resource_existence(
timeout=120,
resource_name=storage_client_name,
should_exist=True,
)

def create_storage_client(
self,
storage_provider_endpoint=None,
onboarding_token=None,
native_client=False,
):
"""
This method creates storage clients
Inputs:
storage_provider_endpoint (str): storage provider endpoint details.
onboarding_token (str): onboarding token
native_client (bool): flag to indicate if the storageclient is nativeclient
"""

# Pull storage-client yaml data
log.info("Pulling storageclient CR data from yaml")
storage_client_data = templating.load_yaml(constants.STORAGE_CLIENT_YAML)
resource_name = storage_client_data["metadata"]["name"]
log.info(f"the resource name: {resource_name}")
if self.ocs_version < version.VERSION_4_16:
# Pull storage-client yaml data
log.info("Pulling storageclient CR data from yaml")
storage_client_data = templating.load_yaml(
constants.NATIVE_STORAGE_CLIENT_YAML
)
storage_client_name = storage_client_data["metadata"]["name"]
log.info(f"the resource name: {storage_client_name}")

else:
log.info("Pulling storageclient CR data from yaml")
storage_client_data = templating.load_yaml(
constants.PROVIDER_MODE_STORAGE_CLIENT
)
if native_client:
storage_client_data["metadata"]["name"] = "ocs-storagecluster"
storage_client_name = storage_client_data["metadata"]["name"]
else:
storage_client_name = storage_client_data["metadata"]["name"]
log.info(f"the resource name: {storage_client_name}")

# Check storageclient is available or not
is_available = self.storage_client_obj.is_exist(
resource_name=resource_name,
is_available = self.check_storageclient_availability(
storage_client_name=storage_client_name,
)

if not is_available:
Expand Down Expand Up @@ -467,10 +497,12 @@ def create_native_storage_client(
onboarding_token = storage_clients.generate_client_onboarding_ticket()

# Create ODF subscription for storage-client
self.odf_installation_on_client()
if self.ocs_version < version.VERSION_4_16:
self.odf_installation_on_client()
self.create_storage_client(
storage_provider_endpoint=storage_provider_endpoint,
onboarding_token=onboarding_token,
native_client=True,
)

if self.ocs_version < version.VERSION_4_16:
Expand Down
Loading

0 comments on commit 44fa276

Please sign in to comment.