Skip to content

Commit

Permalink
Assertion Error for datetime format of 'last sync time'
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed Feb 13, 2024
1 parent f9e5fc6 commit 783323d
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions robottelo/host_helpers/capsule_mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime
import time

from dateutil.parser import parse

from robottelo.constants import PUPPET_CAPSULE_INSTALLER, PUPPET_COMMON_INSTALLER_OPTS
from robottelo.logging import logger
from robottelo.utils.installer import InstallerCommand
Expand Down Expand Up @@ -67,19 +69,31 @@ def wait_for_sync(self, timeout=600, start_time=None):
# is started (or finished already)
if start_time is None:
start_time = datetime.utcnow().replace(microsecond=0)
start_time = start_time.strftime('%Y-%m-%d %H:%M:%S UTC')
logger.info(f"Waiting for capsule {self.hostname} sync to finish ...")
sync_status = self.nailgun_capsule.content_get_sync()
logger.info(f"Active tasks {sync_status['active_sync_tasks']}")
assert (
len(sync_status['active_sync_tasks'])
or datetime.strptime(sync_status['last_sync_time'], '%Y-%m-%d %H:%M:%S UTC')
>= start_time
)
active_sync = False
if not sync_status['last_sync_time']:
# if last sync is None, we must have some in-progress sync task started
assert len(sync_status['active_sync_tasks'])
active_sync = True
else:
try:
# assert the last sync started at or after the start_time
assert parse(sync_status['last_sync_time']) >= parse(start_time)
except AssertionError:
# time of last sync was older than start_time, assert an active sync
assert len(sync_status['active_sync_tasks'])
active_sync = True

# Wait till capsule sync finishes and assert the sync task succeeded
for task in sync_status['active_sync_tasks']:
self.satellite.api.ForemanTask(id=task['id']).poll(timeout=timeout)
sync_status = self.nailgun_capsule.content_get_sync()
# after any in-progress sync task(s) finished, the most recent sync was at or after the start_time
if active_sync:
assert parse(sync_status['last_sync_time']) >= parse(start_time)
assert len(sync_status['last_failed_sync_tasks']) == 0

def get_published_repo_url(self, org, prod, repo, lce=None, cv=None):
Expand Down

0 comments on commit 783323d

Please sign in to comment.