diff options
author | Jhon Honce <jhonce@redhat.com> | 2018-05-21 16:31:36 -0700 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-05-23 17:54:09 +0000 |
commit | 5f0d4b10e9b5ea18e91090e82ddfb22f63b06635 (patch) | |
tree | 0a308dd23c0f1c2149f8d597224ba73440bf793d | |
parent | c1efde20e01f255b1186d6958371da4f5401310a (diff) | |
download | podman-5f0d4b10e9b5ea18e91090e82ddfb22f63b06635.tar.gz podman-5f0d4b10e9b5ea18e91090e82ddfb22f63b06635.tar.bz2 podman-5f0d4b10e9b5ea18e91090e82ddfb22f63b06635.zip |
Add support for Zulu timestamp parsing
- Improve error message when podman varlink service is not running
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Closes: #800
Approved by: rhatdan
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | Dockerfile | 3 | ||||
-rw-r--r-- | Dockerfile.CentOS | 1 | ||||
-rw-r--r-- | Dockerfile.Fedora | 1 | ||||
-rw-r--r-- | contrib/python/podman/client.py | 11 | ||||
-rw-r--r-- | contrib/python/podman/libs/__init__.py | 43 | ||||
-rw-r--r-- | contrib/python/requirements.txt | 3 | ||||
-rw-r--r-- | contrib/python/test/test_libs.py | 19 | ||||
-rw-r--r-- | contrib/spec/podman.spec.in | 5 |
9 files changed, 38 insertions, 50 deletions
diff --git a/.travis.yml b/.travis.yml index 795c758ab..c604b7800 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ services: before_install: - sudo apt-get -qq update - sudo apt-get -qq install btrfs-tools libdevmapper-dev libgpgme11-dev libapparmor-dev - - sudo apt-get -qq install autoconf automake bison e2fslibs-dev libfuse-dev libtool liblzma-dev gettext python3-setuptools + - sudo apt-get -qq install autoconf automake bison e2fslibs-dev libfuse-dev libtool liblzma-dev gettext python3-setuptools python3-dateutil - sudo make install.libseccomp.sudo install: diff --git a/Dockerfile b/Dockerfile index d09ab31e1..bb8adbfe2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,6 +36,7 @@ RUN apt-get update && apt-get install -y \ netcat \ socat \ python3-pip \ + python3-dateutil \ --no-install-recommends \ && apt-get clean @@ -115,7 +116,7 @@ COPY cni/87-podman-bridge.conflist /etc/cni/net.d/87-podman-bridge.conflist # Make sure we have some policy for pulling images RUN mkdir -p /etc/containers && curl https://raw.githubusercontent.com/projectatomic/registries/master/registries.fedora -o /etc/containers/registries.conf -# Install python3 pip module +# Install python3 varlink module from pypi RUN pip3 install varlink COPY test/policy.json /etc/containers/policy.json diff --git a/Dockerfile.CentOS b/Dockerfile.CentOS index cecb354ba..db7cb839e 100644 --- a/Dockerfile.CentOS +++ b/Dockerfile.CentOS @@ -19,6 +19,7 @@ RUN yum -y install btrfs-progs-devel \ make \ ostree-devel \ python \ + python3-dateutil \ which\ golang-github-cpuguy83-go-md2man \ iptables && yum clean all diff --git a/Dockerfile.Fedora b/Dockerfile.Fedora index 782dd6d29..f75074213 100644 --- a/Dockerfile.Fedora +++ b/Dockerfile.Fedora @@ -20,6 +20,7 @@ RUN dnf -y install btrfs-progs-devel \ make \ ostree-devel \ python \ + python3-dateutil \ which\ golang-github-cpuguy83-go-md2man \ procps-ng \ diff --git a/contrib/python/podman/client.py b/contrib/python/podman/client.py index 8a1acdd9b..c6112aae8 100644 --- a/contrib/python/podman/client.py +++ b/contrib/python/podman/client.py @@ -53,9 +53,14 @@ class Client(object): self._client = functools.partial(_podman, uri, interface) # Quick validation of connection data provided - if not System(self._client).ping(): - raise ValueError('Failed varlink connection "{}/{}"'.format( - uri, interface)) + try: + if not System(self._client).ping(): + raise ValueError('Failed varlink connection "{}/{}"'.format( + uri, interface)) + except FileNotFoundError: + raise ValueError('Failed varlink connection "{}/{}".' + ' Is podman service running?'.format( + uri, interface)) def __enter__(self): """Return `self` upon entering the runtime context.""" diff --git a/contrib/python/podman/libs/__init__.py b/contrib/python/podman/libs/__init__.py index ab8fb94a8..7285921d7 100644 --- a/contrib/python/podman/libs/__init__.py +++ b/contrib/python/podman/libs/__init__.py @@ -1,7 +1,8 @@ """Support files for podman API implementation.""" import datetime -import re import threading +from dateutil.parser import parse as dateutil_parse + __all__ = [ 'cached_property', @@ -44,45 +45,11 @@ class cached_property(object): def datetime_parse(string): - """Convert timestamp to datetime. - - Because date/time parsing in python is still pedantically stupid, - we rip the input string apart throwing out the stop characters etc; - then rebuild a string strptime() can parse. Igit! - - - Python >3.7 will address colons in the UTC offset. - - There is no ETA on microseconds > 6 digits. - - And giving an offset and timezone name... - - # match: 2018-05-08T14:12:53.797795191-07:00 - # match: 2018-05-08T18:24:52.753227-07:00 - # match: 2018-05-08 14:12:53.797795191 -0700 MST - # match: 2018-05-09T10:45:57.576002 (python isoformat()) + """Convert timestamps to datetime. - Some people, when confronted with a problem, think “I know, - I'll use regular expressions.” Now they have two problems. - -- Jamie Zawinski + tzinfo aware, if provided. """ - ts = re.compile(r'^(\d+)-(\d+)-(\d+)' - r'[ T]?(\d+):(\d+):(\d+).(\d+)' - r' *([-+][\d:]{4,5})? *') - - x = ts.match(string) - if x is None: - raise ValueError('Unable to parse {}'.format(string)) - - # converting everything to int() not worth the readablity hit - igit_proof = '{}T{}.{}{}'.format( - '-'.join(x.group(1, 2, 3)), - ':'.join(x.group(4, 5, 6)), - x.group(7)[0:6], - x.group(8).replace(':', '') if x.group(8) else '', - ) - - format = '%Y-%m-%dT%H:%M:%S.%f' - if x.group(8): - format += '%z' - return datetime.datetime.strptime(igit_proof, format) + return dateutil_parse(string.upper(), fuzzy=True) def datetime_format(dt): diff --git a/contrib/python/requirements.txt b/contrib/python/requirements.txt index f5d264ddb..368a095b2 100644 --- a/contrib/python/requirements.txt +++ b/contrib/python/requirements.txt @@ -1,2 +1,3 @@ -varlink==25 +varlink>=25 setuptools +dateutil diff --git a/contrib/python/test/test_libs.py b/contrib/python/test/test_libs.py index e2160fc30..202bed1d8 100644 --- a/contrib/python/test/test_libs.py +++ b/contrib/python/test/test_libs.py @@ -18,19 +18,26 @@ class TestLibs(unittest.TestCase): '2018-05-08T14:12:53.797795191-07:00', '2018-05-08T14:12:53.797795-07:00', '2018-05-08T14:12:53.797795-0700', - '2018-05-08 14:12:53.797795191 -0700 MST' + '2018-05-08 14:12:53.797795191 -0700 MST', ]: actual = podman.datetime_parse(v) self.assertEqual(actual, expected) - podman.datetime_parse(datetime.datetime.now().isoformat()) + expected = datetime.datetime.strptime( + '2018-05-08T14:12:53.797795-0000', '%Y-%m-%dT%H:%M:%S.%f%z') + for v in [ + '2018-05-08T14:12:53.797795191Z', + '2018-05-08T14:12:53.797795191z', + ]: + actual = podman.datetime_parse(v) + self.assertEqual(actual, expected) + + actual = podman.datetime_parse(datetime.datetime.now().isoformat()) + self.assertIsNotNone(actual) def test_parse_fail(self): - # chronologist humor: '1752-09-05T12:00:00.000000-0000' also not - # handled correctly by python for my locale. for v in [ - '1752-9-5', - '1752-09-05', + 'There is no time here.', ]: with self.assertRaises(ValueError): podman.datetime_parse(v) diff --git a/contrib/spec/podman.spec.in b/contrib/spec/podman.spec.in index 2c2b098c6..51926870c 100644 --- a/contrib/spec/podman.spec.in +++ b/contrib/spec/podman.spec.in @@ -200,6 +200,11 @@ BuildArch: noarch BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-varlink + +Requires: python3-setuptools +Requires: python3-varlink +Requires: python3-dateutil + Provides: python3-%{name} = %{version}-%{release} Summary: Python 3 bindings for %{name} |