Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[RFR] Reintroduce the reverted Add periodic call and use it to prolong the appliances from Sprout #9890

Merged
merged 2 commits into from
Jan 30, 2020
Merged
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
8 changes: 6 additions & 2 deletions cfme/fixtures/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from cfme.test_framework.sprout.client import SproutClient
from cfme.utils import conf
from cfme.utils import periodic_call
from cfme.utils.log import logger


Expand All @@ -38,7 +39,7 @@ def sprout_appliances(
config: pytestconfig object to lookup sprout_user_key
count: Number of appliances
preconfigured: True if the appliance should be already configured, False otherwise
lease_time: Lease time in minutes (3 hours by default)
lease_time: Lease time in minutes (2 hours by default)
stream: defaults to appliance stream
provider_type: no default, sprout chooses, string type otherwise
version: defaults to appliance version, string type otherwise
Expand Down Expand Up @@ -71,7 +72,10 @@ def sprout_appliances(
logger.info("Appliance update finished on temp appliance...")

try:
yield apps
# Renew in half the lease time interval which is number of minutes.
with periodic_call(lease_time * 60 / 2.,
sprout_client.prolong_pool, (request_id, lease_time)):
yield apps
finally:
sprout_client.destroy_pool(request_id)

Expand Down
3 changes: 3 additions & 0 deletions cfme/test_framework/sprout/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@ def provision_appliances(

def destroy_pool(self, pool_id):
self.call_method('destroy_pool', id=pool_id)

def prolong_pool(self, pool_id, minutes):
self.call_method('prolong_appliance_pool_lease', id=pool_id, minutes=minutes)
24 changes: 24 additions & 0 deletions cfme/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import re
import subprocess
import threading
from contextlib import contextmanager
from functools import partial

import diaper
Expand Down Expand Up @@ -387,3 +389,25 @@ def __get__(self, instance, owner):
return getattr(instance, self.instance_attr)
else:
return getattr(owner, self.class_attr)


@contextmanager
def periodic_call(period_seconds, call, args=None, kwargs=None):
timer = None
args = args or []
kwargs = kwargs or {}

def timer_event():
call(*args, **kwargs)
reschedule()

def reschedule():
nonlocal timer
timer = threading.Timer(period_seconds, timer_event)
timer.start()

reschedule()
try:
yield
finally:
timer.cancel()