diff --git a/CHANGES b/CHANGES index 53beb38f..d2e72bd0 100644 --- a/CHANGES +++ b/CHANGES @@ -94,6 +94,8 @@ gcf 2.9: at once on Windows. (#824) * Define default initial sliver expirations for other Utah/PG AMs (Apt, Cloudlab, stitch). (#826) * Allow defining new such AMs in the omni config `omni_defaults` -> `utah_am_urns` (CSV). + * When calculating `expires` time to request, don't exceed the slice expiration, + and don't request less than some # of hours - 6 for APIv2, 3 for v3+. (#827) * Scripts * Initial commit of `examples/renewSliceAndSlivers.py`. (#798) diff --git a/src/gcf/omnilib/stitch/objects.py b/src/gcf/omnilib/stitch/objects.py index e760c45e..03fd48e0 100644 --- a/src/gcf/omnilib/stitch/objects.py +++ b/src/gcf/omnilib/stitch/objects.py @@ -957,9 +957,10 @@ def __init__(self, logger, opts): self.slicecred = _load_cred(MyHandler(self.logger, opts), opts.slicecredfile) sliceexp = get_cred_exp(self.logger, self.slicecred) sliceExpFromNow = naiveUTC(sliceexp) - now - minDays = sliceExpFromNow.days + minDays = max(sliceExpFromNow.days, 1) # Start out going for 1 day from now at least newExpires = naiveUTC(sliceexp) self.logger.debug("Starting newExpires at slice expiration %s, so init minDays to %d", sliceexp, minDays) + #self.logger.debug("now=%s", now) # Singleton for getting the default sliver expirations by AM type, that knows about values # from the omni_config @@ -1043,6 +1044,17 @@ def __init__(self, logger, opts): # End loop over AMs on path # End loop over paths + minHours = 6 + if self.api_version > 2: + minHours = allocHours + if naiveUTC(newExpires) - naiveUTC(now) < datetime.timedelta(hours=minHours): + self.logger.debug("Calculated new expiration within %d hour(s): reset to %d hour(s) from now", minHours, minHours) + newExpires = naiveUTC(now) + datetime.timedelta(hours=minHours) + + if naiveUTC(sliceexp) < naiveUTC(newExpires): + self.logger.debug("Calculated new expiration after slice expiration: reset to slice expiration") + newExpires = sliceexp + # In APIv3+, this should be a temporary hold. So only request the resources for a few hours. if self.api_version > 2: shortExpires = now + datetime.timedelta(hours=allocHours)