parse_timestamp_from_date requires GNU coreutils' date

Bug #1853470 reported by Mina Galić
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Undecided
Unassigned

Bug Description

running tests on FreeBSD, here's the output from "test_parse_unexpected_timestamp_format_with_date_command"

======================================================================
ERROR: test_dump.TestParseTimestamp.test_parse_unexpected_timestamp_format_with_date_command
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/home/freebsd/src/cloud-init/cloudinit/analyze/tests/test_dump.py", line 57, in test_parse_unexpected_timestamp_format_with_date_command
    float(dt.strftime('%s.%f')), parse_timestamp(new_stamp))
  File "/usr/home/freebsd/src/cloud-init/cloudinit/analyze/dump.py", line 48, in parse_timestamp
    timestamp = parse_timestamp_from_date(timestampstr)
  File "/usr/home/freebsd/src/cloud-init/cloudinit/analyze/dump.py", line 54, in parse_timestamp_from_date
    out, _ = util.subp(['date', '+%s.%3N', '-d', timestampstr])
  File "/usr/home/freebsd/src/cloud-init/cloudinit/tests/helpers.py", line 182, in _fake_subp
    return _real_subp(*args, **kwargs)
  File "/usr/home/freebsd/src/cloud-init/cloudinit/util.py", line 2079, in subp
    cmd=args)
cloudinit.util.ProcessExecutionError: Unexpected error while running command.
Command: ['date', '+%s.%3N', '-d', '17:15 08/08']
Exit code: 1
Reason: -
Stdout:
Stderr: date: illegal time format
        usage: date [-jnRu] [-d dst] [-r seconds|file] [-t west] [-v[+|-]val[ymwdHMS]]
                    [-I[date | hours | minutes | seconds]]
                    [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
-------------------- >> begin captured logging << --------------------
cloudinit.util: DEBUG: Running command ['date', '+%s.%3N', '-d', '17:15 08/08'] with allowed return codes [0] (shell=False, capture=True)
--------------------- >> end captured logging << ---------------------

BSD date cannot parse arbitrary input, it will only parse input based on an input format.
Additionally, the `-d` flag *sets* the date on BSD.

Tags: freebsd
Revision history for this message
Scott Moser (smoser) wrote :

I think the right fix on this is to drop the 'date' usage entirely.
Just support a reasonable set of formats and blow up with a good error that says what it tried to parse.

Revision history for this message
Mina Galić (minagalic) wrote :

extremely 👍

Revision history for this message
Paride Legovini (paride) wrote :

I think Scott's suggestion is sensible. The dateparser python module is able to parse free format human readable date strings, mostly like GNU `date -d <date>`, but we probably don't need it.

Changed in cloud-init:
status: New → Triaged
Revision history for this message
Mina Galić (minagalic) wrote :

I think this code has moved, or been removed in the unit test refactoring

Revision history for this message
James Falcon (falcojr) wrote :
Changed in cloud-init:
status: Triaged → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.