Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Mahesh Shetty <[email protected]>
  • Loading branch information
mashetty330 committed Aug 9, 2024
1 parent 8406b44 commit cdc6601
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
40 changes: 35 additions & 5 deletions ocs_ci/deployment/cnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,27 @@ def disable_multicluster_engine(self):
return
logger.info(cmd_res.stdout.decode("utf-8").splitlines())

def check_if_any_vm_instances(self, namespace=None):
"""
Checks if any VMs or VM instances are running
Args:
namespace (str): namespace to check
Returns:
True if any VMs or VMi else False
"""

vm_obj = OCP(kind=constants.VIRTUAL_MACHINE, namespace=namespace)
vmi_obj = OCP(kind=constants.VIRTUAL_MACHINE_INSTANCE, namespace=namespace)

return vm_obj.get(
out_yaml_format=False, all_namespaces=not namespace, dont_raise=True
) or vmi_obj.get(
out_yaml_format=False, all_namespaces=not namespace, dont_raise=True
)

def remove_hyperconverged(self):
"""
Remove HyperConverged CR
Expand Down Expand Up @@ -705,22 +726,31 @@ def remove_namespace(self):
Remove openshift virtualization namespace
"""
cnv_namespace = OCP(
kind=constants.NAMESPACE, resource_name=constants.CNV_NAMESPACE
)
cnv_namespace.delete(resource_name=constants.CNV_NAMESPACE)
cnv_namespace = OCP()
cnv_namespace.delete_project(constants.CNV_NAMESPACE)
logger.info(f"Deleted the namespace {constants.CNV_NAMESPACE}")

def cleanup_cnv(self, check_cnv_installed=False):
def uninstall_cnv(self, check_cnv_installed=True):
"""
Uninstall CNV deployment
Args:
check_cnv_installed (Bool): True if want to check if CNV installed
"""
if check_cnv_installed:
if not self.cnv_hyperconverged_installed():
logger.info("CNV is not installed, skipping the cleanup...")
return

assert not self.check_if_any_vm_instances(), (
"Vm or Vmi instances are found in the cluster,"
"Please make sure all VMs and VM instances are removed"
)
logger.info(
"No VM or VM instances are found in the cluster, proceeding with the uninstallation"
)

logger.info("Removing the virtualization hyperconverged")
self.remove_hyperconverged()

Expand Down
11 changes: 9 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7956,21 +7956,28 @@ def finalizer():
"""
if cnv_obj.cnv_hyperconverged_installed():
cnv_obj.cleanup_cnv()
cnv_obj.uninstall_cnv()

request.addfinalizer(finalizer)


@pytest.fixture()
def setup_vms_standalone_pvc(request, project_factory, setup_cnv):
def setup_vms_standalone_pvc(request, project_factory):
"""
This fixture will setup VM using standalone PVC
"""
vm_obj = None

def factory():
"""
Factory method to setup VM using standalone PVC
"""
nonlocal vm_obj
assert (
CNVInstaller().cnv_hyperconverged_installed
), "CNV is not installed in the cluster. please install CNV."
project_obj = project_factory()
log.info(f"Created project {project_obj.namespace} for VMs")
vm_obj = create_vm_using_standalone_pvc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def test_netsplit(
init_sanity,
reset_conn_score,
setup_vms_standalone_pvc,
setup_cnv,
):
"""
This test will test the netsplit scenarios (BC, AB, AB-AC, AB-BC) when CephFS, RBD and VM workloads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def test_zone_shutdowns(
setup_logwriter_rbd_workload_factory,
logreader_workload_factory,
setup_vms_standalone_pvc,
setup_cnv,
):
"""
This test will test the shutdown scenarios when CephFS, RBD and VM workloads
Expand Down Expand Up @@ -399,6 +400,7 @@ def test_zone_crashes(
logreader_workload_factory,
nodes,
setup_vms_standalone_pvc,
setup_cnv,
):
"""
This test will test the crash scenarios when CephFS, RBD and VM workloads
Expand Down

0 comments on commit cdc6601

Please sign in to comment.