Set start date to 'now' rather than current time

When the Blazar CLI client is run without specifying a start date, it
uses the current time on the client machine. If the lease creation
request is sent to the Blazar service just before the end of a minute,
e.g. at 12:34:59, the Blazar manager might only process it during the
next minute (i.e. after 12:35:00). In this case, the manager will reject
the request with:

    Start date must be later than current date

This can also be an issue if the clocks on the client and server are not
synchronized closely.

This patch uses the special start date value 'now' which is resolved to
the current time on the server rather than on the client. Note that this
can result in leases that are one minute shorter than what the user
might expect, as the end date is still specified by the client.

It also clarifies help messages for start and end dates.

Change-Id: Ib761d8f4f15e44e28452497f282447472f0cf918
Closes-Bug: #1783296
This commit is contained in:
Pierre Riteau 2018-07-24 11:56:15 +01:00
parent 98b2414eec
commit f017a924d3
2 changed files with 21 additions and 4 deletions

View File

@ -76,8 +76,8 @@ class CreateLease(command.CreateCommand):
resource = 'lease'
json_indent = 4
log = logging.getLogger(__name__ + '.CreateLease')
default_start = datetime.datetime.utcnow()
default_end = default_start + datetime.timedelta(days=1)
default_start = 'now'
default_end = datetime.datetime.utcnow() + datetime.timedelta(days=1)
def get_parser(self, prog_name):
parser = super(CreateLease, self).get_parser(prog_name)
@ -89,14 +89,14 @@ class CreateLease(command.CreateCommand):
'--start-date',
dest='start',
help='Time (YYYY-MM-DD HH:MM) UTC TZ for starting the lease '
'(default: now)',
'(default: current time on the server)',
default=self.default_start
)
parser.add_argument(
'--end-date',
dest='end',
help='Time (YYYY-MM-DD HH:MM) UTC TZ for ending the lease '
'(default: 24h later)',
'(default: 24h from now)',
default=self.default_end
)
parser.add_argument(

View File

@ -0,0 +1,17 @@
---
upgrade:
- |
When creating a lease using the CLI client, the default value for start
date was changed to use the string 'now', which is resolved to the current
time on the server rather than on the client. Note that if the request is
sent at the end of a minute and interpreted by the service at the beginning of
the next minute, this can result in leases that are one minute shorter than
what the user might expect, as the end date is still specified by the
client. Users who care about the exact timing of their leases should
explicitly specify both start and end dates.
fixes:
- |
Creating a lease using the CLI client without specifying a start date no
longer fails if the request is sent to the Blazar service just before the
end of a minute. For more details, see `bug 1783296
<https://launchpad.net/bugs/1783296>`_.