Skip to content

Commit 67c2264

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

File tree

1 file changed

+127
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)