Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling when lease is None #981

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions modules/test/conn/python/src/connection_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,8 @@ def _run_subnet_test(self, config):
else:
LOGGER.info('New lease not found. Waiting to check again')

except Exception as e: # pylint: disable=W0718
LOGGER.error('Failed to restore DHCP server configuration: ' + str(e))
LOGGER.error(traceback.format_exc())
except Exception: # pylint: disable=W0718
LOGGER.error('Failed to restore DHCP server configuration')

return final_result, final_result_details

Expand Down
41 changes: 23 additions & 18 deletions modules/test/conn/python/src/dhcp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,29 @@ def setup_single_dhcp_server(self):

def wait_for_lease_expire(self, lease, max_wait_time=30):

expiration_utc = datetime.strptime(lease['expires'], '%Y-%m-%d %H:%M:%S')

# Lease information stored in UTC so we need to convert to local time
expiration = self.utc_to_local(expiration_utc)
time_to_expire = expiration - datetime.now(tz=tz.tzlocal())

# Wait until the expiration time and padd 5 seconds
# If wait time is longer than max_wait_time, only wait
# for the max wait time
wait_time = min(max_wait_time,
time_to_expire.total_seconds() +
5) if time_to_expire.total_seconds() > 0 else 0

LOGGER.info('Time until lease expiration: ' + str(wait_time))
LOGGER.info('Waiting for current lease to expire: ' + str(expiration))
if wait_time > 0:
time.sleep(wait_time)
LOGGER.info('Current lease expired.')
try:
expiration_utc = datetime.strptime(lease['expires'], '%Y-%m-%d %H:%M:%S')

# Lease information stored in UTC so we need to convert to local time
expiration = self.utc_to_local(expiration_utc)
time_to_expire = expiration - datetime.now(tz=tz.tzlocal())

# Wait until the expiration time and padd 5 seconds
# If wait time is longer than max_wait_time, only wait
# for the max wait time
wait_time = min(max_wait_time,
time_to_expire.total_seconds() +
5) if time_to_expire.total_seconds() > 0 else 0

LOGGER.info('Time until lease expiration: ' + str(wait_time))
LOGGER.info('Waiting for current lease to expire: ' + str(expiration))

if wait_time > 0:
time.sleep(wait_time)
LOGGER.info('Current lease expired')

except TypeError:
LOGGER.error('Device does not have an active lease')

# Convert from a UTC datetime to the local time zone
def utc_to_local(self, utc_datetime):
Expand Down