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

[cherry-pick-9177][Release 4.12] Replacing crypt device check from pod to node. #10042

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
42 changes: 42 additions & 0 deletions ocs_ci/ocs/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2784,3 +2784,45 @@ def is_node_rack_or_zone_exist(failure_domain, node_name):
"""
node_obj = get_node_objs([node_name])[0]
return get_node_rack_or_zone(failure_domain, node_obj) is not None


def list_encrypted_rbd_devices_on_node(node):
"""
Get rbd crypt devices from the node

Args:
node: node name

Returns:
List of encrypted osd device names
"""
node_obj = OCP(kind="node")
crypt_devices_out = node_obj.exec_oc_debug_cmd(
node=node,
cmd_list=["lsblk | grep crypt | awk '{print $1}'"],
).split("\n")
crypt_devices = [device.strip() for device in crypt_devices_out if device != ""]
return crypt_devices


def verify_crypt_device_present_on_node(node, vol_handle):
"""
Find the crypt device maching for given volume handle.
paraggit marked this conversation as resolved.
Show resolved Hide resolved

Args:
node : node name
vol_handle : volumen handle name.

Returns:
bool: True if volume handle device found on the node, False otherwise
"""
device_list = list_encrypted_rbd_devices_on_node(node)
crypt_device = [device for device in device_list if vol_handle in device]
if not crypt_device:
log.error(
f"crypt device for volume handle {vol_handle} not present on node : {node}"
)
return False

log.info(f"Crypt device for volume handle {vol_handle} present on the node: {node}")
return True
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
from ocs_ci.utility import kms
from semantic_version import Version
from ocs_ci.ocs.node import verify_crypt_device_present_on_node


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -160,14 +161,11 @@ def test_pvc_to_pvc_clone(self, kv_version, kms_provider, pod_factory):

log.info("Checking for encrypted device and running IO on all pods")
for vol_handle, pod_obj in zip(self.vol_handles, self.pod_objs):
if pod_obj.exec_sh_cmd_on_pod(
command=f"lsblk | grep {vol_handle} | grep crypt"
):
log.info(f"Encrypted device found in {pod_obj.name}")
else:
raise ResourceNotFoundError(
f"Encrypted device not found in {pod_obj.name}"
)
node = pod_obj.get_node()
assert verify_crypt_device_present_on_node(
node, vol_handle
), f"Crypt devicve {vol_handle} not found on node:{node}"

log.info(f"File created during IO {pod_obj.name}")
pod_obj.run_io(
storage_type="block",
Expand Down Expand Up @@ -242,14 +240,10 @@ def test_pvc_to_pvc_clone(self, kv_version, kms_provider, pod_factory):
)
# Verify encrypted device is present and md5sum on all pods
for vol_handle, pod_obj in zip(cloned_vol_handles, cloned_pod_objs):
if pod_obj.exec_sh_cmd_on_pod(
command=f"lsblk | grep {vol_handle} | grep crypt"
):
log.info(f"Encrypted device found in {pod_obj.name}")
else:
raise ResourceNotFoundError(
f"Encrypted device not found in {pod_obj.name}"
)
node = pod_obj.get_node()
assert verify_crypt_device_present_on_node(
node, vol_handle
), f"Crypt devicve {vol_handle} not found on node:{node}"

log.info(f"Verifying md5sum on pod {pod_obj.name}")
pod.verify_data_integrity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from ocs_ci.utility import kms
from semantic_version import Version
from ocs_ci.ocs.node import verify_crypt_device_present_on_node

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -169,15 +170,10 @@ def test_encrypted_rbd_block_pvc_snapshot(
)
for vol_handle, pod_obj in zip(self.vol_handles, self.pod_objs):

# Verify whether encrypted device is present inside the pod
if pod_obj.exec_sh_cmd_on_pod(
command=f"lsblk | grep {vol_handle} | grep crypt"
):
log.info(f"Encrypted device found in {pod_obj.name}")
else:
raise ResourceNotFoundError(
f"Encrypted device not found in {pod_obj.name}"
)
node = pod_obj.get_node()
assert verify_crypt_device_present_on_node(
node, vol_handle
), f"Crypt devicve {vol_handle} not found on node:{node}"

# Find initial md5sum
pod_obj.md5sum_before_io = cal_md5sum(
Expand Down Expand Up @@ -329,14 +325,10 @@ def test_encrypted_rbd_block_pvc_snapshot(

# Verify encrypted device is present and md5sum on all pods
for vol_handle, pod_obj in zip(restore_vol_handles, restore_pod_objs):
if pod_obj.exec_sh_cmd_on_pod(
command=f"lsblk | grep {vol_handle} | grep crypt"
):
log.info(f"Encrypted device found in {pod_obj.name}")
else:
raise ResourceNotFoundError(
f"Encrypted device not found in {pod_obj.name}"
)
node = pod_obj.get_node()
assert verify_crypt_device_present_on_node(
node, vol_handle
), f"Crypt devicve {vol_handle} not found on node:{node}"

log.info(f"Verifying md5sum on pod {pod_obj.name}")
verify_data_integrity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
create_pods,
)
from ocs_ci.ocs import constants
from ocs_ci.ocs.node import verify_crypt_device_present_on_node


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -101,12 +102,10 @@ def test_rbd_pv_encryption_kmip(

# Verify whether encrypted device is present inside the pod and run IO
for vol_handle, pod_obj in zip(vol_handles, pod_objs):
if pod_obj.exec_sh_cmd_on_pod(
command=f"lsblk | grep {vol_handle} | grep crypt"
):
log.info(f"Encrypted device found in {pod_obj.name}")
else:
log.error(f"Encrypted device not found in {pod_obj.name}")
node = pod_obj.get_node()
assert verify_crypt_device_present_on_node(
node, vol_handle
), f"Crypt devicve {vol_handle} not found on node:{node}"

pod_obj.run_io(
storage_type="block",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from ocs_ci.utility import kms
from semantic_version import Version
from ocs_ci.ocs.node import verify_crypt_device_present_on_node


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -159,12 +160,10 @@ def test_rbd_pv_encryption(

# Verify whether encrypted device is present inside the pod and run IO
for vol_handle, pod_obj in zip(vol_handles, pod_objs):
if pod_obj.exec_sh_cmd_on_pod(
command=f"lsblk | grep {vol_handle} | grep crypt"
):
log.info(f"Encrypted device found in {pod_obj.name}")
else:
log.error(f"Encrypted device not found in {pod_obj.name}")
node = pod_obj.get_node()
assert verify_crypt_device_present_on_node(
node, vol_handle
), f"Crypt devicve {vol_handle} not found on node:{node}"

pod_obj.run_io(
storage_type="block",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ResourceNotFoundError,
)
from ocs_ci.utility import kms
from ocs_ci.ocs.node import verify_crypt_device_present_on_node

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -146,14 +147,10 @@ def test_rbd_pv_encryption_vaulttenantsa(

# Verify whether encrypted device is present inside the pod and run IO
for vol_handle, pod_obj in zip(vol_handles, pod_objs):
if pod_obj.exec_sh_cmd_on_pod(
command=f"lsblk | grep {vol_handle} | grep crypt"
):
log.info(f"Encrypted device found in {pod_obj.name}")
else:
raise ResourceNotFoundError(
f"Encrypted device not found in {pod_obj.name}"
)
node = pod_obj.get_node()
assert verify_crypt_device_present_on_node(
node, vol_handle
), f"Crypt devicve {vol_handle} not found on node:{node}"

pod_obj.run_io(
storage_type="block",
Expand Down
11 changes: 5 additions & 6 deletions tests/ui/test_pv_encryption_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ocs_ci.utility.utils import get_vault_cli, get_ocp_version
from ocs_ci.ocs import constants
from ocs_ci.utility import version
from ocs_ci.ocs.node import verify_crypt_device_present_on_node

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -225,12 +226,10 @@ def test_for_encrypted_pv_ui(
"Verify whether encrypted device is present inside the pod and run IO"
)
for vol_handle, pod_obj in zip(vol_handles, pod_objs):
if pod_obj.exec_sh_cmd_on_pod(
command=f"lsblk | grep {vol_handle} | grep crypt"
):
logger.info(f"Encrypted device found in {pod_obj.name}")
else:
logger.error(f"Encrypted device not found in {pod_obj.name}")
node = pod_obj.get_node()
assert verify_crypt_device_present_on_node(
node, vol_handle
), f"Crypt devicve {vol_handle} not found on node:{node}"

logger.info(f"Running FIO on Pod '{pod_obj.name}'")
pod_obj.run_io(
Expand Down
Loading