summaryrefslogtreecommitdiff
path: root/contrib/python/podman
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2018-10-10 09:24:17 -0700
committerJhon Honce <jhonce@redhat.com>2018-10-12 09:34:23 -0700
commit40cb7568017a36b411801608a32cdd8502287924 (patch)
tree1f5bbccd42e843d223eaa5cfa08133253d5d1673 /contrib/python/podman
parentb0b6dc40bd916698f87bc68f7b4b603582e93ef2 (diff)
downloadpodman-40cb7568017a36b411801608a32cdd8502287924.tar.gz
podman-40cb7568017a36b411801608a32cdd8502287924.tar.bz2
podman-40cb7568017a36b411801608a32cdd8502287924.zip
Add support for pod commands
* Add support for pod -- create, inspect, kill, pause, ps, rm, restart, start, stop, top, unpause * Update pylintrc to better reflect pep8 code standards * Fix various pylint reported errors * Refactor code that determines screen width to no longer require initializing curses. Improved start up time and pushing data blob down ssh tunnel. * Correct pod-create man page, cgroupparent not boolean * Abort integration tests if podman service fails to start Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'contrib/python/podman')
-rw-r--r--contrib/python/podman/podman/libs/images.py31
-rw-r--r--contrib/python/podman/podman/libs/pods.py7
-rw-r--r--contrib/python/podman/test/test_images.py2
-rwxr-xr-xcontrib/python/podman/test/test_runner.sh8
4 files changed, 20 insertions, 28 deletions
diff --git a/contrib/python/podman/podman/libs/images.py b/contrib/python/podman/podman/libs/images.py
index 325ee46f4..982546cd2 100644
--- a/contrib/python/podman/podman/libs/images.py
+++ b/contrib/python/podman/podman/libs/images.py
@@ -1,11 +1,10 @@
"""Models for manipulating images in/to/from storage."""
import collections
import copy
-import functools
import json
import logging
-from . import ConfigDict
+from . import ConfigDict, fold_keys
from .containers import Container
@@ -14,7 +13,7 @@ class Image(collections.UserDict):
def __init__(self, client, id, data):
"""Construct Image Model."""
- super(Image, self).__init__(data)
+ super().__init__(data)
for k, v in data.items():
setattr(self, k, v)
@@ -26,12 +25,12 @@ class Image(collections.UserDict):
self._id, data['id']
)
- def __getitem__(self, key):
- """Get items from parent dict."""
- return super().__getitem__(key)
-
- def _split_token(self, values=None, sep='='):
- return dict([v.split(sep, 1) for v in values if values])
+ @staticmethod
+ def _split_token(values=None, sep='='):
+ return {
+ k: v1
+ for k, v1 in (v0.split(sep, 1) for v0 in values if values)
+ }
def create(self, *args, **kwargs):
"""Create container from image.
@@ -41,8 +40,8 @@ class Image(collections.UserDict):
details = self.inspect()
config = ConfigDict(image_id=self._id, **kwargs)
- config['command'] = details.containerconfig['cmd']
- config['env'] = self._split_token(details.containerconfig['env'])
+ config['command'] = details.containerconfig.get('cmd')
+ config['env'] = self._split_token(details.containerconfig.get('env'))
config['image'] = copy.deepcopy(details.repotags[0])
config['labels'] = copy.deepcopy(details.labels)
config['net_mode'] = 'bridge'
@@ -68,19 +67,11 @@ class Image(collections.UserDict):
for r in podman.HistoryImage(self._id)['history']:
yield collections.namedtuple('HistoryDetail', r.keys())(**r)
- # Convert all keys to lowercase.
- def _lower_hook(self):
- @functools.wraps(self._lower_hook)
- def wrapped(input_):
- return {k.lower(): v for (k, v) in input_.items()}
-
- return wrapped
-
def inspect(self):
"""Retrieve details about image."""
with self._client() as podman:
results = podman.InspectImage(self._id)
- obj = json.loads(results['image'], object_hook=self._lower_hook())
+ obj = json.loads(results['image'], object_hook=fold_keys())
return collections.namedtuple('ImageInspect', obj.keys())(**obj)
def push(self, target, tlsverify=False):
diff --git a/contrib/python/podman/podman/libs/pods.py b/contrib/python/podman/podman/libs/pods.py
index b14a13dd2..2a85f2624 100644
--- a/contrib/python/podman/podman/libs/pods.py
+++ b/contrib/python/podman/podman/libs/pods.py
@@ -42,16 +42,15 @@ class Pod(collections.UserDict):
default signal is signal.SIGTERM.
wait n of seconds, 0 waits forever.
"""
- running = FoldedString(self.status)
-
with self._client() as podman:
podman.KillPod(self._ident, signal_)
timeout = time.time() + wait
while True:
# pylint: disable=maybe-no-member
self._refresh(podman)
+ running = FoldedString(self.status)
if running != 'running':
- return self
+ break
if wait and timeout < time.time():
raise TimeoutError()
@@ -131,7 +130,7 @@ class Pods():
self._client = client
def create(self,
- ident,
+ ident=None,
cgroupparent=None,
labels=None,
share=None,
diff --git a/contrib/python/podman/test/test_images.py b/contrib/python/podman/test/test_images.py
index 854f57dd7..f6b95f98a 100644
--- a/contrib/python/podman/test/test_images.py
+++ b/contrib/python/podman/test/test_images.py
@@ -64,7 +64,7 @@ class TestImages(PodmanTestCase):
self.assertEqual(actual.status, 'configured')
ctnr = actual.start()
- self.assertIn(ctnr.status, ['running', 'exited'])
+ self.assertIn(ctnr.status, ['running', 'stopped', 'exited'])
ctnr_details = ctnr.inspect()
for e in img_details.containerconfig['env']:
diff --git a/contrib/python/podman/test/test_runner.sh b/contrib/python/podman/test/test_runner.sh
index ce518e7ed..1b7e0a85e 100755
--- a/contrib/python/podman/test/test_runner.sh
+++ b/contrib/python/podman/test/test_runner.sh
@@ -119,15 +119,18 @@ if [[ -n $VERBOSE ]]; then
fi
PODMAN="podman $PODMAN_ARGS"
-cat >/tmp/test_podman.output <<-EOT
+cat <<-EOT |tee /tmp/test_podman.output
$($PODMAN --version)
$PODMAN varlink --timeout=0 ${PODMAN_HOST}
==========================================
EOT
# Run podman in background without systemd for test purposes
-set -x
$PODMAN varlink --timeout=0 ${PODMAN_HOST} >>/tmp/test_podman.output 2>&1 &
+if [[ $? != 0 ]]; then
+ echo 1>&2 Failed to start podman
+ showlog /tmp/test_podman.output
+fi
if [[ -z $1 ]]; then
export PYTHONPATH=.
@@ -139,7 +142,6 @@ else
RETURNCODE=$?
fi
-set +x
pkill -9 podman
pkill -9 conmon