From f017a924d301bed939f8811923c83b9a41740560 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Tue, 24 Jul 2018 11:56:15 +0100 Subject: [PATCH] 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 --- blazarclient/v1/shell_commands/leases.py | 8 ++++---- ...-set-start-date-to-now-e329a6923c11432f.yaml | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/bug-1783296-set-start-date-to-now-e329a6923c11432f.yaml diff --git a/blazarclient/v1/shell_commands/leases.py b/blazarclient/v1/shell_commands/leases.py index aad5f9d..8124927 100644 --- a/blazarclient/v1/shell_commands/leases.py +++ b/blazarclient/v1/shell_commands/leases.py @@ -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( diff --git a/releasenotes/notes/bug-1783296-set-start-date-to-now-e329a6923c11432f.yaml b/releasenotes/notes/bug-1783296-set-start-date-to-now-e329a6923c11432f.yaml new file mode 100644 index 0000000..f0513fb --- /dev/null +++ b/releasenotes/notes/bug-1783296-set-start-date-to-now-e329a6923c11432f.yaml @@ -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 + `_.