Skip to content

Commit

Permalink
bz2260550 automation
Browse files Browse the repository at this point in the history
Signed-off-by: nagendra202 <nagreddy@redhat.com>
  • Loading branch information
nagendra202 committed Jan 6, 2025
1 parent 8333f51 commit 9897bfb
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
52 changes: 52 additions & 0 deletions ocs_ci/ocs/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3200,6 +3200,58 @@ def apply_node_affinity_for_ceph_toolbox(node_name):
return True


def apply_node_affinity_for_noobaa_pod(node_name):
resource_name = constants.DEFAULT_CLUSTERNAME
if config.DEPLOYMENT["external_mode"]:
resource_name = constants.DEFAULT_CLUSTERNAME_EXTERNAL_MODE

storagecluster_obj = ocp.OCP(
resource_name=resource_name,
namespace=config.ENV_DATA["cluster_namespace"],
kind=constants.STORAGECLUSTER,
)
nodeaffinity = {
"noobaa-standalone": {
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{"key": f"{node_name}", "operator": "Exists"}
]
}
]
}
}
}
}

# (
# f'{{"toolbox": {{"nodeAffinity": {{"requiredDuringSchedulingIgnoredDuringExecution": '
# f'{{"nodeSelectorTerms": [{{"matchExpressions": [{{"key": "kubernetes.io/hostname",'
# f'"operator": "In",'
# f'"values": ["{node_name}"]}}]}}]}}}}}}}}'
# )
param = f'{{"spec": {{"placement": {nodeaffinity}}}}}'
ct_pod = pod.get_ceph_tools_pod(skip_creating_pod=True)
ct_pod_name = ct_pod.name
storagecluster_obj.patch(params=param, format_type="merge")
log.info(
f"Successfully applied node affinity for ceph toolbox pod with {node_name}"
)
ct_pod.ocp.wait_for_delete(ct_pod_name)
log.info(
"Identify on which node the ceph toolbox is running after failover due to node affinity"
)
ct_new_pod_running_node_name = get_ceph_tools_running_node()
if node_name == ct_new_pod_running_node_name:
log.info(
f"ceph toolbox pod failovered to the new node {ct_new_pod_running_node_name}"
f" given in node affinity successfully "
)
return True


def get_ceph_tools_running_node():
"""
Get node name where the ceph tools pod is currently running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
taint_nodes,
unschedule_nodes,
untaint_nodes,
apply_node_affinity_for_noobaa_pod,
)
from ocs_ci.ocs.resources.pod import wait_for_pods_to_be_running
from ocs_ci.ocs.resources.pod import (
wait_for_pods_to_be_running,
get_pod_obj,
get_pod_node,
)
from ocs_ci.helpers.helpers import apply_custom_taint_and_toleration

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -120,3 +126,18 @@ def test_nodeaffinity_to_ceph_toolbox_with_default_taints(self):
assert apply_node_affinity_for_ceph_toolbox(
other_node_name
), "Failed to apply nodeaffinity with default taints"

def test_tolerations_on_standalone_noobaa(self):
worker_nodes = get_worker_nodes()
log.info(f"Current available worker nodes are {worker_nodes}")
taint_nodes(worker_nodes)
log.info("Applied default taints on all the worker nodes")
noobaa_operator_pod_obj = get_pod_obj(
"noobaa-operator", namespace="openshift-storage"
)
noobaa_running_node = get_pod_node(noobaa_operator_pod_obj)

other_nodes = [node for node in worker_nodes if node != noobaa_running_node]
other_node_name = random.choice(other_nodes)
apply_custom_taint_and_toleration()
apply_node_affinity_for_noobaa_pod(other_node_name)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import logging
import pytest
import random

from ocs_ci.framework import config
from ocs_ci.ocs import ocp, constants
from ocs_ci.ocs.node import (
check_taint_on_nodes,
get_worker_nodes,
taint_nodes,
untaint_nodes,
apply_node_affinity_for_noobaa_pod,
)
from ocs_ci.ocs.resources.pod import (
get_pod_node,
get_pods_having_label,
)
from ocs_ci.helpers.helpers import apply_custom_taint_and_toleration

log = logging.getLogger(__name__)


class TestNoobaaPodNodeAffinity:
@pytest.fixture(scope="session", autouse=True)
def teardown(self, request):
def finalizer():
"""
Finalizer will take care of below activities:
1. Untaint the nodes: remove taints from nodes
2. Removes nodeaffinity to bring storage cluster with default values.
"""
if check_taint_on_nodes():
untaint_nodes()
resource_name = constants.DEFAULT_CLUSTERNAME
if config.DEPLOYMENT["external_mode"]:
resource_name = constants.DEFAULT_CLUSTERNAME_EXTERNAL_MODE
storagecluster_obj = ocp.OCP(
resource_name=resource_name,
namespace=config.ENV_DATA["cluster_namespace"],
kind=constants.STORAGECLUSTER,
)
params = '[{"op": "remove", "path": "/spec/placement/noobaa-standalone"},]'
storagecluster_obj.patch(params=params, format_type="json")
log.info("Patched storage cluster back to the default")
# assert (
# wait_for_pods_to_be_running()
# ), "some of the pods didn't came up running"

request.addfinalizer(finalizer)

def test_tolerations_on_standalone_noobaa(self):
worker_nodes = get_worker_nodes()
log.info(f"Current available worker nodes are {worker_nodes}")
taint_nodes(worker_nodes)
log.info("Applied default taints on all the worker nodes")
# noobaa_operator_pod_obj = get_pod_obj("noobaa-operator",namespace= "openshift-storage")
noobaa_operator_pod_obj = get_pods_having_label(
label=constants.NOOBAA_OPERATOR_POD_LABEL
)
noobaa_running_node = get_pod_node(noobaa_operator_pod_obj[0])

other_nodes = [node for node in worker_nodes if node != noobaa_running_node]
other_node_name = random.choice(other_nodes)
apply_custom_taint_and_toleration()
apply_node_affinity_for_noobaa_pod(other_node_name)

0 comments on commit 9897bfb

Please sign in to comment.