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

create multiple cnv workloads #10673

Merged
merged 16 commits into from
Dec 19, 2024
108 changes: 107 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
)
from ocs_ci.ocs.longevity import start_app_workload
from ocs_ci.utility.decorators import switch_to_default_cluster_index_at_last

from ocs_ci.helpers.keyrotation_helper import PVKeyrotation

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -7092,6 +7092,112 @@ def teardown():
return factory


@pytest.fixture
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
def multi_cnv_workload(
pv_encryption_kms_setup_factory, storageclass_factory, cnv_workload
):
"""
Create a cnv factory. Calling this fixture Creates multiple VMs
with specified configurations using the cnv_workload fixture.
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
"""

def factory(namespace=None):
"""
Args:
namespace (str, optional): The namespace to create the vm on.

Returns:
lists: objects of cnv workload class with default comp and aggressive compression
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved

"""
vm_list_agg_compr = []
vm_list_default_compr = []

namespace = (
parikshithb marked this conversation as resolved.
Show resolved Hide resolved
namespace if namespace else create_unique_resource_name("vm", "namespace")
)

# Setup csi-kms-connection-details configmap
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
log.info("Setting up csi-kms-connection-details configmap")
kms = pv_encryption_kms_setup_factory(kv_version="v2")
log.info("csi-kms-connection-details setup successful")

# Create an encryption enabled storageclass for RBD
avd-sagare marked this conversation as resolved.
Show resolved Hide resolved
sc_obj_def_compr = storageclass_factory(
parikshithb marked this conversation as resolved.
Show resolved Hide resolved
interface=constants.CEPHBLOCKPOOL,
encrypted=True,
encryption_kms_id=kms.kmsid,
new_rbd_pool=True,
)

sc_obj_aggressive = storageclass_factory(
avd-sagare marked this conversation as resolved.
Show resolved Hide resolved
interface=constants.CEPHBLOCKPOOL,
encrypted=True,
encryption_kms_id=kms.kmsid,
compression="aggressive",
new_rbd_pool=True,
)
vm_configs = [
parikshithb marked this conversation as resolved.
Show resolved Hide resolved
hnallurv marked this conversation as resolved.
Show resolved Hide resolved
{
"volume_interface": constants.VM_VOLUME_PVC,
"access_mode": constants.ACCESS_MODE_RWX,
"sc_name": sc_obj_def_compr.name,
},
{
"volume_interface": constants.VM_VOLUME_PVC,
"access_mode": constants.ACCESS_MODE_RWX,
"sc_name": sc_obj_aggressive.name,
},
{
"volume_interface": constants.VM_VOLUME_PVC,
"access_mode": constants.ACCESS_MODE_RWO,
"sc_name": sc_obj_def_compr.name,
},
{
"volume_interface": constants.VM_VOLUME_DVT,
"access_mode": constants.ACCESS_MODE_RWX,
"sc_name": sc_obj_def_compr.name,
},
{
"volume_interface": constants.VM_VOLUME_DVT,
"access_mode": constants.ACCESS_MODE_RWX,
"sc_name": sc_obj_aggressive.name,
},
]

# Create ceph-csi-kms-token in the tenant namespace
kms.vault_path_token = kms.generate_vault_token()
kms.create_vault_csi_kms_token(namespace=namespace)

for sc_obj in [sc_obj_def_compr, sc_obj_aggressive]:
pvk_obj = PVKeyrotation(sc_obj)
pvk_obj.annotate_storageclass_key_rotation(schedule="*/3 * * * *")

# Loop through vm_configs and create the VMs using the cnv_workload fixture
for config in vm_configs:
vm_obj = cnv_workload(
volume_interface=config["volume_interface"],
access_mode=config["access_mode"],
storageclass=config["sc_name"],
pvc_size="30Gi", # Assuming pvc_size is fixed for all
source_url=constants.CNV_FEDORA_SOURCE, # Assuming source_url is the same for all VMs
namespace=namespace,
)
vm_obj = vm_obj[-1]
parikshithb marked this conversation as resolved.
Show resolved Hide resolved
if config["sc_name"] == sc_obj_aggressive.name:
vm_list_agg_compr.append(vm_obj)
else:
vm_list_default_compr.append(vm_obj)
return (
vm_list_default_compr,
vm_list_agg_compr,
sc_obj_aggressive,
sc_obj_def_compr,
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
)

return factory


@pytest.fixture(scope="class")
def lvm_storageclass_factory_class(request, storageclass_factory_class):
return lvm_storageclass_factory_fixture(request, storageclass_factory_class)
Expand Down
144 changes: 144 additions & 0 deletions tests/functional/cnv/test_vms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import logging
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
import pytest
import subprocess
import os
import hashlib
from ocs_ci.framework.testlib import E2ETest
avd-sagare marked this conversation as resolved.
Show resolved Hide resolved
from ocs_ci.framework.pytest_customization.marks import magenta_squad
from ocs_ci.helpers.cnv_helpers import cal_md5sum_vm
from ocs_ci.helpers.performance_lib import run_oc_command
from ocs_ci.helpers.keyrotation_helper import PVKeyrotation
from ocs_ci.utility.utils import run_cmd

logger = logging.getLogger(__name__)


class TestCNVVM(E2ETest):
parikshithb marked this conversation as resolved.
Show resolved Hide resolved
"""
Includes tests related to CNV workloads on MDR environment.
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved

"""

@pytest.fixture(autouse=True)
def setup(self, project_factory, multi_cnv_workload):

avd-sagare marked this conversation as resolved.
Show resolved Hide resolved
# Create a project
proj_obj = project_factory()
(
self.vm_objs_def,
self.vm_objs_aggr,
self.sc_obj_aggressive,
self.sc_obj_def_compr,
) = multi_cnv_workload(namespace=proj_obj.namespace)

logger.info("All vms created successfully")

def get_md5sum(self, file_path):
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
"""
Calculates the md5sum of the file
Args:
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
file_path (str): The name of the file for which md5sum to be calculated

Returns:
str: The md5sum of the file
"""
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
try:
hash_md5 = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved

except subprocess.CalledProcessError as e:
print(f"Error occurred while calculating MD5 checksum: {e}")
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
return None

PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
@magenta_squad
def test_cnv_vms(self, setup):
"""
Tests to verify configuration for non-GS like environment
avd-sagare marked this conversation as resolved.
Show resolved Hide resolved
Steps:
hnallurv marked this conversation as resolved.
Show resolved Hide resolved
1. Validate data integrity using md5sum.
a. create file locally and take md5sum
b. copy same file to vm and take md5sum
c. Validate both are same or not
2. Validate pvc level key rotation

PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved

"""

# To Do
# 1. if os is windows then check rxbounce enabled in sc yaml

# 2. Validate data integrity using md5sum.
file_name = "/tmp/dd_file"
vm_filepath = "/home/admin/dd_file1_copy"
avd-sagare marked this conversation as resolved.
Show resolved Hide resolved

# Create file locally
file_path = str(os.path.abspath(file_name))
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
cmd = f"dd if=/dev/zero of={file_path} bs=1M count=2048"
run_cmd(cmd)
avd-sagare marked this conversation as resolved.
Show resolved Hide resolved

# Calculate the MD5 checksum
if file_path:
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
md5sum_on_local = self.get_md5sum(file_path)
if md5sum_on_local:
print(f"MD5 checksum of the file: {md5sum_on_local}")
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved

# Copy local file to all vms
for vm_obj in self.vm_objs_aggr:
vm_obj.scp_to_vm(
local_path=file_path,
vm_username=None,
identity_file=None,
vm_dest_path=vm_filepath,
recursive=False,
)
for vm_obj in self.vm_objs_def:
vm_obj.scp_to_vm(
local_path=file_path,
vm_username=None,
identity_file=None,
vm_dest_path=vm_filepath,
recursive=False,
)

# Take md5sum of copied file and compare with md5sum taken locally
for vm_obj in self.vm_objs_aggr:
md5sum_on_vm = cal_md5sum_vm(vm_obj, vm_filepath, username=None)
assert (
md5sum_on_vm == md5sum_on_local
), f"md5sum has not changed after copying file on {vm_obj.name}"
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved

for vm_obj in self.vm_objs_def:
md5sum_on_vm = cal_md5sum_vm(vm_obj, vm_filepath, username=None)
assert (
md5sum_on_vm == md5sum_on_local
), f"md5sum has not changed after copying file on {vm_obj.name}"
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved

# 3.Verify PV Keyrotation.
for vm in self.vm_objs_def:
pvk_obj = PVKeyrotation(self.sc_obj_def_compr)
assert pvk_obj.wait_till_keyrotation(
vm.pvc_obj.get_pv_volume_handle_name
), f"Failed to rotate Key for the PVC {vm.pvc_obj.name}"

for vm in self.vm_objs_aggr:
pvk_obj = PVKeyrotation(self.sc_obj_aggressive)
volume_name = vm.pvc_obj.get().get("spec").get("volumeName")
for line in run_oc_command(
f"describe pv {volume_name}", namespace=vm.namespace
):
if "VolumeHandle:" in line:
volume_handle = line.split()[1]
break
if volume_handle is None:
logger.error(f"Cannot get volume handle for pv {volume_name}")
raise Exception("Cannot get volume handle")
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
assert pvk_obj.wait_till_keyrotation(
volume_handle
), f"Failed to rotate Key for the PVC {vm.pvc_obj.name}"

# 4.Stop all VMs
for vm_obj in self.vm_objs_def + self.vm_objs_aggr:
vm_obj.stop()
PrasadDesala marked this conversation as resolved.
Show resolved Hide resolved
Loading