Skip to content

Commit

Permalink
Merge pull request #550 from armosec/testrunningpods
Browse files Browse the repository at this point in the history
Refactor cluster state logging to join output lines for better readab…
  • Loading branch information
kooomix authored Jan 1, 2025
2 parents 5946418 + ebd613c commit bf43de4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests_scripts/kubernetes/base_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ def verify_running_pods(self, namespace: str, replicas: int = None, name: str =
if comp_operator(len(running_pods), replicas): # and len(running_pods) == len(total_pods):
Logger.logger.info(f"all pods are running after {delta_t} seconds")
result = subprocess.run("kubectl get pods -A", timeout=300, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = " ".join(result.stdout.splitlines())
Logger.logger.info(f"cluster state {result}")
return
delta_t = (datetime.now() - start).total_seconds()
Expand All @@ -779,6 +780,7 @@ def verify_running_pods(self, namespace: str, replicas: int = None, name: str =
KubectlWrapper.convert_workload_to_dict(non_running_pods, f_json=True, indent=2)))

result = subprocess.run("kubectl get pods -A", timeout=300, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = " ".join(result.stdout.splitlines())
Logger.logger.info(f"cluster state {result}")
raise Exception("wrong number of pods are running after {} seconds. expected: {}, running: {}, pods:{}"
.format(delta_t, replicas, len(running_pods), running_pods)) # , len(total_pods)))
Expand Down
12 changes: 11 additions & 1 deletion tests_scripts/workflows/teams_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def start(self):
workflow_body = self.build_compliance_workflow_body(name=COMPLIANCE_WORKFLOW_NAME_TEAMS + self.cluster, channel_name=TEAMS_CHANNEL_NAME, channel_guid=channel_guid, cluster=self.cluster, namespace=namespace, category=COMPLIANCE, driftPercentage=15, webhook_url=get_env("CHANNEL_WEBHOOK"))
self.create_and_assert_workflow(workflow_body, EXPECTED_CREATE_RESPONSE, update=False)
before_test_message_ts = time.time()
Logger.logger.info(f"before_test_message_ts: {before_test_message_ts}")

Logger.logger.info("Stage 4: Validate workflows created successfully")
self.validate_workflow(VULNERABILITIES_WORKFLOW_NAME_TEAMS + self.cluster, TEAMS_CHANNEL_NAME)
Expand Down Expand Up @@ -194,9 +195,18 @@ def assert_vulnerability_message_sent(self, messages, cluster):

def assert_misconfiguration_message_sent(self, messages, cluster):
found = 0
found_compliance = False
found_cluster = False
for message in messages:
message_string = str(message)
if "Your compliance score has decreased by" in message_string and cluster in message_string:
# split message check for debug
if "Your compliance score has decreased by" in message_string:
Logger.logger.info("Compliance message found")
found_compliance = True
if cluster in message_string:
Logger.logger.info(f"Cluster {cluster} found in message")
found_cluster = True
if found_compliance and found_cluster:
found += 1
assert found > 0, f"expected to have exactly one new misconfiguration message, found {found}"

Expand Down

0 comments on commit bf43de4

Please sign in to comment.