Skip to content

Commit 28a6f50

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

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
@rgw
27+
@red_squad
28+
@skipif_no_lso
29+
class TestRGWReadAffinityMode:
30+
"""
31+
Test the RGW Read Affinity value in an ODF cluster
32+
33+
"""
34+
35+
@pytest.fixture(scope="class", autouse=True)
36+
def revert_read_affinity_mode(self, request):
37+
"""
38+
Reverts the RGW readAffinity mode to localize state.
39+
"""
40+
41+
def teardown():
42+
patch = '\'{"spec": {"gateway": {"readAffinity": {"type": "localize"}}}}\''
43+
patch_cmd = (
44+
f"oc patch cephObjectStore/{CEPH_OBJECT_STORE.data['items'][0]['metadata'].get('name')} "
45+
f"-n openshift-storage --type merge --patch {patch}"
46+
)
47+
run_cmd(patch_cmd)
48+
sample = TimeoutSampler(
49+
timeout=60,
50+
sleep=10,
51+
func=self.get_read_affinity_from_ceph,
52+
)
53+
sample.wait_for_func_value(DEFAULT_READ_AFFINITY)
54+
55+
request.addfinalizer(teardown)
56+
57+
def get_read_affinity_from_ceph(self):
58+
"""
59+
Returns current readAffinity set in ceph cluster
60+
Returns :
61+
ceph_read_affinity_mode (String)
62+
"""
63+
cmd = "ceph config show client.rgw.ocs.storagecluster.cephobjectstore.a"
64+
ceph_pod = pod.get_ceph_tools_pod()
65+
ceph_op = ceph_pod.exec_ceph_cmd(cmd)
66+
for val in ceph_op:
67+
if val["name"] == "rados_replica_read_policy":
68+
log.info(val["value"])
69+
return val["value"]
70+
else:
71+
return None
72+
73+
@tier1
74+
def test_rgw_read_affinity_mode(self):
75+
"""
76+
Test default ReadAffinity mode of RGW in an ODF cluster
77+
step #1. Validate readAffinity mode is set to ""local"" for RGW
78+
step #2. Validate the status of RGW pod
79+
step #3. Validate readAffinity value from ceph cluster
80+
step #4: Change current mode to "balanced" and validate it along with RGW pod status
81+
step #5: Change current mode to "default" and validate it along with RGW pod status
82+
"""
83+
rgw_pod_count = len(get_rgw_pods())
84+
# 1. Validate readAffinity mode is set to "localize" for RGW
85+
current_read_affinity = CEPH_OBJECT_STORE.data["items"][0]["spec"]["gateway"][
86+
"readAffinity"
87+
]["type"]
88+
assert (
89+
DEFAULT_READ_AFFINITY == current_read_affinity
90+
), f"Default ReadAffinity for RGW is {current_read_affinity}. Expected value is {DEFAULT_READ_AFFINITY}"
91+
# 2. Validate the status of RGW pod
92+
assert OCP_OBJ.wait_for_resource(
93+
condition=constants.STATUS_RUNNING,
94+
resource_count=rgw_pod_count,
95+
selector=constants.RGW_APP_LABEL,
96+
)
97+
# 3. Validate readAffinity value from ceph cluster
98+
sample = TimeoutSampler(
99+
timeout=60,
100+
sleep=10,
101+
func=self.get_read_affinity_from_ceph,
102+
)
103+
sample.wait_for_func_value(DEFAULT_READ_AFFINITY)
104+
105+
# 4 and 5. Change current mode to all available mode and validate it along with RGW pod status
106+
READ_AFFINITY_LIST = ["balance", "default"]
107+
for val in READ_AFFINITY_LIST:
108+
patch = f'\'{{"spec": {{"gateway": {{"readAffinity": {{"type": "{val}"}}}}}}}}\''
109+
patch_cmd = (
110+
f"oc patch cephObjectStore/{CEPH_OBJECT_STORE.data['items'][0]['metadata'].get('name')} "
111+
f"-n openshift-storage --type merge --patch {patch}"
112+
)
113+
run_cmd(patch_cmd)
114+
CEPH_OBJECT_STORE.reload_data()
115+
current_read_affinity = CEPH_OBJECT_STORE.data["items"][0]["spec"][
116+
"gateway"
117+
]["readAffinity"]["type"]
118+
assert (
119+
current_read_affinity == val
120+
), f"Failed to change ReadAffinity for RGW. Current value: {current_read_affinity}. Expected value: {val}"
121+
122+
# Validate RGW POD status
123+
assert OCP_OBJ.wait_for_resource(
124+
condition=constants.STATUS_RUNNING,
125+
resource_count=rgw_pod_count,
126+
selector=constants.RGW_APP_LABEL,
127+
)
128+
sample = TimeoutSampler(
129+
timeout=60,
130+
sleep=10,
131+
func=self.get_read_affinity_from_ceph,
132+
)
133+
sample.wait_for_func_value(val)

0 commit comments

Comments
 (0)