Skip to content

Commit

Permalink
Merge pull request #1635 from jwhonce/wip/pods
Browse files Browse the repository at this point in the history
Add support for pod commands
  • Loading branch information
openshift-merge-robot authored Oct 13, 2018
2 parents b0b6dc4 + 40cb756 commit 2c4f3d6
Show file tree
Hide file tree
Showing 25 changed files with 1,273 additions and 45 deletions.
31 changes: 11 additions & 20 deletions contrib/python/podman/podman/libs/images.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)

Expand All @@ -26,12 +25,12 @@ def __init__(self, client, id, data):
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.
Expand All @@ -41,8 +40,8 @@ def create(self, *args, **kwargs):
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'
Expand All @@ -68,19 +67,11 @@ def history(self):
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):
Expand Down
7 changes: 3 additions & 4 deletions contrib/python/podman/podman/libs/pods.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ def kill(self, signal_=signal.SIGTERM, wait=25):
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()
Expand Down Expand Up @@ -131,7 +130,7 @@ def __init__(self, client):
self._client = client

def create(self,
ident,
ident=None,
cgroupparent=None,
labels=None,
share=None,
Expand Down
2 changes: 1 addition & 1 deletion contrib/python/podman/test/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_create(self):
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']:
Expand Down
8 changes: 5 additions & 3 deletions contrib/python/podman/test/test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=.
Expand All @@ -139,7 +142,6 @@ else
RETURNCODE=$?
fi

set +x
pkill -9 podman
pkill -9 conmon

Expand Down
Loading

0 comments on commit 2c4f3d6

Please sign in to comment.