Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ Common
(#2185)
[Ashish - @Ashishjob]

- [Utils] Fix ``parse_date`` returning a timestamp one microsecond short for
some fractional seconds (e.g. ``.000249`` was parsed as 248 microseconds),
because the fraction went through a float.
(#2243)
[@aad1tyaaaaa]

- [Utils] Fix ``get_pubkey_openssh_fingerprint`` returning a wrong fingerprint
for Ed25519 keys and raising ``binascii.Error`` for ECDSA keys. The function
assumed a 7 character ``ssh-rsa`` key type prefix. This also affects the
Expand Down
2 changes: 1 addition & 1 deletion libcloud/test/compute/test_scaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_list_nodes_success(self):

def test_list_nodes_fills_created_datetime(self):
nodes = self.driver.list_nodes()
self.assertEqual(nodes[0].created_at, datetime(2014, 5, 22, 12, 57, 22, 514298, tzinfo=UTC))
self.assertEqual(nodes[0].created_at, datetime(2014, 5, 22, 12, 57, 22, 514299, tzinfo=UTC))

def test_create_node_success(self):
image = self.driver.list_images()[0]
Expand Down
18 changes: 18 additions & 0 deletions libcloud/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from libcloud.utils.misc import get_driver, set_driver, get_secure_random_string
from libcloud.common.types import LibcloudError
from libcloud.compute.types import Provider
from libcloud.utils.iso8601 import parse_date
from libcloud.utils.publickey import (
get_pubkey_comment,
get_pubkey_ssh2_fingerprint,
Expand Down Expand Up @@ -487,6 +488,23 @@ def test_increment_ipv4_segments(self):
self.assertEqual(result, incremented_ip)


@pytest.mark.parametrize(
"fraction, microsecond",
[
("5", 500000),
("123456", 123456),
("1234567", 123456),
# These used to come out one microsecond short through float rounding
("000249", 249),
("000251", 251),
("000493", 493),
],
)
def test_parse_date_fraction(fraction, microsecond):
parsed = parse_date("2020-01-01T00:00:00.%sZ" % fraction)
assert parsed.microsecond == microsecond


class TestPublicKeyUtils(unittest.TestCase):
PUBKEY = (
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOfbWSXOlqvYjZmRO84/lIoV4gvuX+"
Expand Down
4 changes: 3 additions & 1 deletion libcloud/utils/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ def parse_date(datestring, default_timezone=UTC, allow_empty=False):
if groups["fraction"] is None:
groups["fraction"] = 0
else:
groups["fraction"] = int(float("0.%s" % groups["fraction"]) * 1e6)
# Take the microseconds from the digits: going through a float, e.g.
# int(0.000249 * 1e6), can come out one microsecond short
groups["fraction"] = int(groups["fraction"][:6].ljust(6, "0"))
return datetime(
int(groups["year"]),
int(groups["month"]),
Expand Down