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 9949945
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions robottelo/host_helpers/capsule_mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from datetime import datetime
from datetime import (
datetime,
timedelta,
)
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,20 +72,49 @@ 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)
# 1s margin of safety for rounding
start_time = (start_time - timedelta(seconds=1)).strftime('%Y-%m-%d %H:%M:%S UTC')
active_sync = False
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
)

if not sync_status['last_sync_time']: # never synced
# we expect some in-progress sync task(s) ongoing
assert len(sync_status['active_sync_tasks']) > 0, (
f'last_sync_time for capsule {self.hostname} was None (never synced),'
' expected one or more ongoing sync task(s), but found none.'
)
else:
try:
# the last sync time was at or after start_time?
assert parse(sync_status['last_sync_time']) >= parse(start_time)
except AssertionError:
# time of last sync was older than start_time, we expect active sync task(s)
assert len(sync_status['active_sync_tasks']) > 0, (
f'last_sync_time ({sync_status["last_sync_time"]}), for capsule {self.hostname},'
' was older than start_time. Expected one or more ongoing sync task(s), but found none.'
)
# 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)
active_sync = True
# after any in-progress sync task(s) finished, sync_status updated:
# the most recent sync time was at or after the start_time
# there are no remaining active sync tasks from updated status
sync_status = self.nailgun_capsule.content_get_sync()
assert len(sync_status['last_failed_sync_tasks']) == 0
if active_sync:
assert parse(sync_status['last_sync_time']) >= parse(start_time), (
f'After polling finished in-progress sync task(s), for capsule {self.hostname},'
' last_sync_time was not the same as or after start_time.'
)
assert len(sync_status['active_sync_tasks']) == 0, (
f'Expected no active sync task(s) remaining for capsule {self.hostname},'
' after polling finished task(s).'
)
assert (
len(sync_status['last_failed_sync_tasks']) == 0
), f'One or more sync tasks have failed for capsule {self.hostname}'

def get_published_repo_url(self, org, prod, repo, lce=None, cv=None):
"""Forms url of a repo or CV published on a Satellite or Capsule.
Expand Down

0 comments on commit 9949945

Please sign in to comment.