Skip to content

Commit

Permalink
[ISSUE-1186]: cr notes
Browse files Browse the repository at this point in the history
Co-authored-by: korzepadawwid <[email protected]>
Co-authored-by: mdutka-dell <[email protected]>
Signed-off-by: Dawid Korzepa <[email protected]>
  • Loading branch information
korzepadawid and mdutka-dell committed Jul 12, 2024
1 parent e0cfbf7 commit 8f44288
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 55 deletions.
57 changes: 29 additions & 28 deletions tests/e2e-test-framework/framework/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,48 +341,49 @@ def get_pod_node_ip(self, pod_name: str, namespace: str) -> str:
node = self.core_v1_api.read_node(name=node_name)
return node.status.addresses[0].address

def get_events_by_reason(
def get_events_by_reason_for_cr(
self,
plural: str,
resource_name: str,
namespace: Optional[str] = None,
reason: Optional[str] = None,
reason: str,
) -> List[CoreV1Event]:
"""
Retrieves events related to a specific resource by reason.
Retrieves a list of events filtered by the given resource name and reason.
Args:
plural (str): The plural name of the resource.
resource_name (str): The name of the resource.
namespace: (Optional[str], optional): The namespace of the resource.
reason (Optional[str], optional): The reason for filtering events. Defaults to None.
reason (str): The reason for filtering events.
Returns:
List[CoreV1Event]: A list of events related to the resource by reason.
List[CoreV1Event]: A list of Kubernetes CoreV1Event objects.
"""
if namespace:
cr = self.custom_objects_api.get_namespaced_custom_object(
const.CR_GROUP,
const.CR_VERSION,
namespace,
plural,
resource_name,
)
else:
cr = self.custom_objects_api.get_cluster_custom_object(
const.CR_GROUP, const.CR_VERSION, plural, resource_name
)
uid = cr["metadata"]["uid"]
field_selector = f"involvedObject.uid={uid}"
field_selector = f"involvedObject.name={resource_name},reason={reason}"
events_list = self.core_v1_api.list_event_for_all_namespaces(
field_selector=field_selector
).items

if reason:
events_list = [e for e in events_list if e.reason == reason]

return events_list

def event_in(self, resource_name: str, reason: str) -> bool:
"""
Checks if an event with the given resource name and reason exists in the Kubernetes API.
Args:
resource_name (str): The name of the resource.
reason (str): The reason for the event.
Returns:
bool: True if the event exists, False otherwise.
"""
events = self.get_events_by_reason_for_cr(
resource_name=resource_name,
reason=reason,
)
if len(events) > 0:
logging.info(f"event {reason} found")
return True
logging.warning(f"event {reason} not found")
return False

def wait_volume(
self,
name: str,
Expand Down Expand Up @@ -690,8 +691,8 @@ def recreate_pod(self, name: str, namespace: str) -> V1Pod:
logging.info(f"pod {name} is ready")

return pod
def get_pod_node_ip(self, pod_name: str, namespace:str) -> str:

def get_pod_node_ip(self, pod_name: str, namespace: str) -> str:
"""
Retrieves the IP address of the node associated with the given pod name and namespace.
Expand Down
33 changes: 6 additions & 27 deletions tests/e2e-test-framework/tests/test_fake_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setup_class(
cls.drive_utils = drive_utils_executors
cls.sts = STS(cls.namespace, cls.name, cls.replicas)
cls.sts.delete()
cls.sts.create(storage_classes=[const.HDD_SC])
cls.sts.create(storage_classes=[const.SSD_SC])

yield

Expand Down Expand Up @@ -77,14 +77,10 @@ def test_5808_fake_attach_without_dr(self):
)
logging.info(f"drive {drive_name} went {const.STATUS_OFFLINE}")

pod = self.utils.recreate_pod(
name=pod.metadata.name, namespace=self.namespace
)
pod = self.utils.recreate_pod(pod)
volume_name = volume["metadata"]["name"]
assert self.event_in(
plural="volumes",
resource_name=volume_name,
reason=const.FAKE_ATTACH_INVOLVED,
assert self.utils.event_in(
resource_name=volume_name, reason=const.FAKE_ATTACH_INVOLVED
), f"event {const.FAKE_ATTACH_INVOLVED} not found"

self.drive_utils[node_ip].restore(host_num=host_num)
Expand All @@ -95,25 +91,8 @@ def test_5808_fake_attach_without_dr(self):
name=drive_name, expected_status=const.STATUS_ONLINE
)

self.utils.recreate_pod(
name=pod.metadata.name, namespace=self.namespace
)
assert self.event_in(
plural="volumes",
self.utils.recreate_pod(pod)
assert self.utils.event_in(
resource_name=volume_name,
reason=const.FAKE_ATTACH_CLEARED,
), f"event {const.FAKE_ATTACH_CLEARED} not found"

def event_in(self, plural: str, resource_name: str, reason: str) -> bool:
events = self.utils.get_events_by_reason(
plural=plural,
resource_name=resource_name,
reason=reason,
namespace=self.namespace,
)
for event in events:
if event.reason == reason:
logging.info(f"event {reason} found")
return True
logging.warning(f"event {reason} not found")
return False

0 comments on commit 8f44288

Please sign in to comment.