Skip to content

Commit 45d07d4

Browse files
committed
Adds happy path testing for RGW ReadAffinity feature
Signed-off-by: Uday Kurundwade <[email protected]>
1 parent c44df30 commit 45d07d4

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import logging
2+
import pytest
3+
4+
from ocs_ci.framework import config
5+
from ocs_ci.framework.pytest_customization.marks import (
6+
red_squad,
7+
tier1,
8+
rgw,
9+
skipif_no_lso,
10+
)
11+
from ocs_ci.ocs.resources.pod import get_rgw_pods
12+
from ocs_ci.ocs.ocp import OCP
13+
import ocs_ci.ocs.resources.pod as pod
14+
from ocs_ci.ocs import constants
15+
from ocs_ci.utility.utils import TimeoutSampler, run_cmd
16+
17+
log = logging.getLogger(__name__)
18+
19+
CEPH_OBJECT_STORE = OCP(
20+
kind="CephObjectStore", namespace=config.ENV_DATA["cluster_namespace"]
21+
)
22+
OCP_OBJ = OCP(kind=constants.POD, namespace=config.ENV_DATA["cluster_namespace"])
23+
DEFAULT_READ_AFFINITY = "localize"
24+
25+
26+
27+
@rgw
28+
@red_squad
29+
@skipif_no_lso
30+
class TestRGWReadAffinityMode:
31+
"""
32+
Test the RGW Read Affinity value in an ODF cluster
33+
34+
"""
35+
36+
@pytest.fixture(scope="class", autouse=True)
37+
def revert_read_affinity_mode(self, request):
38+
"""
39+
Reverts the RGW readAffinity mode to localize state.
40+
"""
41+
42+
def teardown():
43+
patch = '\'{{"spec": {{"gateway": {{"readAffinity": {{"type": "localize"}}}}}}}}\''
44+
patch_cmd = (
45+
f"oc patch cephObjectStore/{CEPH_OBJECT_STORE.data['items'][0]['metadata'].get('name')} "
46+
f"-n openshift-storage --type merge --patch {patch}"
47+
)
48+
run_cmd(patch_cmd)
49+
50+
request.addfinalizer(teardown)
51+
52+
def get_read_affinity_from_ceph(self):
53+
"""
54+
Returns current readAffinity set in ceph cluster
55+
Returns :
56+
ceph_read_affinity_mode (String)
57+
"""
58+
cmd = "ceph config show client.rgw.ocs.storagecluster.cephobjectstore.a | grep rados_replica_read_policy"
59+
ceph_pod = pod.get_ceph_tools_pod()
60+
ceph_read_affinity_mode = ceph_pod.exec_ceph_cmd(cmd)
61+
return ceph_read_affinity_mode
62+
63+
@tier1
64+
def test_rgw_rear_affinity_mode(self):
65+
"""
66+
Test default ReadAffinity mode of RGW in an ODF cluster
67+
step #1. Validate readAffinity mode is set to ""local"" for RGW
68+
step #2. Validate the status of RGW pod
69+
step #3: Change current mode to "balanced" and validate it along with RGW pod status
70+
step #4: Change current mode to "default" and validate it along with RGW pod status
71+
"""
72+
rgw_pod_count = len(get_rgw_pods())
73+
# 1. Validate readAffinity mode is set to "localize" for RGW
74+
current_read_affinity = CEPH_OBJECT_STORE.data["items"][0]["spec"]["gateway"][
75+
"readAffinity"
76+
]["type"]
77+
assert (
78+
DEFAULT_READ_AFFINITY == current_read_affinity
79+
), f"Default ReadAffinity for RGW is {current_read_affinity}. Expected value is {DEFAULT_READ_AFFINITY}"
80+
# 2. Validate the status of RGW pod
81+
assert OCP_OBJ.wait_for_resource(
82+
condition=constants.STATUS_RUNNING,
83+
resource_count=rgw_pod_count,
84+
selector=constants.RGW_APP_LABEL,
85+
)
86+
sample = TimeoutSampler(
87+
timeout=60,
88+
sleep=10,
89+
func=self.get_read_affinity_from_ceph,
90+
)
91+
sample.wait_for_func_value(val)
92+
93+
# 3 and 4. Change current mode to all available mode and validate it along with RGW pod status
94+
READ_AFFINITY_LIST = ["balance", "default"]
95+
for val in READ_AFFINITY_LIST:
96+
patch = f'\'{{"spec": {{"gateway": {{"readAffinity": {{"type": "{val}"}}}}}}}}\''
97+
patch_cmd = (
98+
f"oc patch cephObjectStore/{CEPH_OBJECT_STORE.data['items'][0]['metadata'].get('name')} "
99+
f"-n openshift-storage --type merge --patch {patch}"
100+
)
101+
run_cmd(patch_cmd)
102+
CEPH_OBJECT_STORE.reload_data()
103+
current_read_affinity = CEPH_OBJECT_STORE.data["items"][0]["spec"][
104+
"gateway"
105+
]["readAffinity"]["type"]
106+
assert (
107+
current_read_affinity == val
108+
), f"Failed to change ReadAffinity for RGW. Current value: {current_read_affinity}. Expected value: {val}"
109+
110+
# Validate RGW POD status
111+
assert OCP_OBJ.wait_for_resource(
112+
condition=constants.STATUS_RUNNING,
113+
resource_count=rgw_pod_count,
114+
selector=constants.RGW_APP_LABEL,
115+
)
116+
sample = TimeoutSampler(
117+
timeout=60,
118+
sleep=10,
119+
func=self.get_read_affinity_from_ceph,
120+
)
121+
sample.wait_for_func_value(val)

0 commit comments

Comments
 (0)