Skip to content

Commit

Permalink
Fix the test logic that finds a backup pod.
Browse files Browse the repository at this point in the history
  • Loading branch information
draghuram committed Jan 15, 2020
1 parent ef153a9 commit 16c22e5
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions tests/src/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,20 @@ def test_backup(globalconfig, resources):
pods = kubeclient.wait_for_pod_to_appear(label_selector)

# Since the backup runs every minute and we are waiting for more than a
# a minute, sometimes we find that a second backup has already started by the
# time we start checking the status here. To take care of such scenarios,
# check the status of the pod whose status is not "Running"
found_pod = False
for pod in pods.items:
if pod.status.phase == "Running":
continue

found_pod = True
pod_name = pod.metadata.name

print("Checking status for pod: {}".format(pod_name))
# a minute, there are several possibilities:
# - No backups started which is extremely unlikely.
# - A single backup started which either finished or is still running.
# - More than one backup started
# To take care of all these scenarios, we first look for completed backup
# and if we don't find one, we look for a running backup.

backup_pod = next((x for x in pods.items if x.status.phase != "Running"), None)
if not backup_pod:
backup_pod = next((x for x in pods.items if x.status.phase == "Running"), None)
if not backup_pod:
raise Exception("Could not find a completed or running backup")

if backup_pod.status.phase == "Running":
pod = kubeclient.wait_for_pod_to_be_done(pod_name)
assert pod.status.phase == "Succeeded"

if not found_pod:
raise Exception("Could not find a completed backup")



assert backup_pod.status.phase == "Succeeded"

0 comments on commit 16c22e5

Please # to comment.