mirror of https://github.com/docker/compose.git
Update event field names to match the new API fields.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
d1d3969661
commit
d3cd038b84
|
@ -256,8 +256,10 @@ class TopLevelCommand(DocoptCommand):
|
|||
--json Output events as a stream of json objects
|
||||
"""
|
||||
def format_event(event):
|
||||
return ("{time}: service={service} event={event} "
|
||||
"container={container} image={image}").format(**event)
|
||||
attributes = ["%s=%s" % item for item in event['attributes'].items()]
|
||||
return ("{time} {type} {action} {id} ({attrs})").format(
|
||||
attrs=", ".join(sorted(attributes)),
|
||||
**event)
|
||||
|
||||
def json_format_event(event):
|
||||
event['time'] = event['time'].isoformat()
|
||||
|
@ -266,6 +268,7 @@ class TopLevelCommand(DocoptCommand):
|
|||
for event in project.events():
|
||||
formatter = json_format_event if options['--json'] else format_event
|
||||
print(formatter(event))
|
||||
sys.stdout.flush()
|
||||
|
||||
def help(self, project, options):
|
||||
"""
|
||||
|
|
|
@ -282,11 +282,15 @@ class Project(object):
|
|||
time = time.replace(
|
||||
microsecond=microseconds_from_time_nano(event['timeNano']))
|
||||
return {
|
||||
'service': container.service,
|
||||
'event': event['status'],
|
||||
'container': container.id,
|
||||
'image': event['from'],
|
||||
'time': time,
|
||||
'type': 'container',
|
||||
'action': event['status'],
|
||||
'id': container.id,
|
||||
'service': container.service,
|
||||
'attributes': {
|
||||
'name': container.name,
|
||||
'image': event['from'],
|
||||
}
|
||||
}
|
||||
|
||||
service_names = set(self.service_names)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
|
@ -864,7 +865,26 @@ class CLITestCase(DockerClientTestCase):
|
|||
os.kill(events_proc.pid, signal.SIGINT)
|
||||
result = wait_on_process(events_proc, returncode=1)
|
||||
lines = [json.loads(line) for line in result.stdout.rstrip().split('\n')]
|
||||
assert [e['event'] for e in lines] == ['create', 'start', 'create', 'start']
|
||||
assert [e['action'] for e in lines] == ['create', 'start', 'create', 'start']
|
||||
|
||||
def test_events_human_readable(self):
|
||||
events_proc = start_process(self.base_dir, ['events'])
|
||||
self.dispatch(['up', '-d', 'simple'])
|
||||
wait_on_condition(ContainerCountCondition(self.project, 1))
|
||||
|
||||
os.kill(events_proc.pid, signal.SIGINT)
|
||||
result = wait_on_process(events_proc, returncode=1)
|
||||
lines = result.stdout.rstrip().split('\n')
|
||||
assert len(lines) == 2
|
||||
|
||||
container, = self.project.containers()
|
||||
expected_template = (
|
||||
' container {} {} (image=busybox:latest, '
|
||||
'name=simplecomposefile_simple_1)')
|
||||
|
||||
assert expected_template.format('create', container.id) in lines[0]
|
||||
assert expected_template.format('start', container.id) in lines[1]
|
||||
assert lines[0].startswith(datetime.date.today().isoformat())
|
||||
|
||||
def test_env_file_relative_to_compose_file(self):
|
||||
config_path = os.path.abspath('tests/fixtures/env-file/docker-compose.yml')
|
||||
|
|
|
@ -238,12 +238,19 @@ class ProjectTest(unittest.TestCase):
|
|||
|
||||
def get_container(cid):
|
||||
if cid == 'abcde':
|
||||
labels = {LABEL_SERVICE: 'web'}
|
||||
name = 'web'
|
||||
labels = {LABEL_SERVICE: name}
|
||||
elif cid == 'ababa':
|
||||
labels = {LABEL_SERVICE: 'db'}
|
||||
name = 'db'
|
||||
labels = {LABEL_SERVICE: name}
|
||||
else:
|
||||
labels = {}
|
||||
return {'Id': cid, 'Config': {'Labels': labels}}
|
||||
name = ''
|
||||
return {
|
||||
'Id': cid,
|
||||
'Config': {'Labels': labels},
|
||||
'Name': '/project_%s_1' % name,
|
||||
}
|
||||
|
||||
self.mock_client.inspect_container.side_effect = get_container
|
||||
|
||||
|
@ -254,24 +261,36 @@ class ProjectTest(unittest.TestCase):
|
|||
assert not list(events)
|
||||
assert events_list == [
|
||||
{
|
||||
'type': 'container',
|
||||
'service': 'web',
|
||||
'event': 'create',
|
||||
'container': 'abcde',
|
||||
'image': 'example/image',
|
||||
'action': 'create',
|
||||
'id': 'abcde',
|
||||
'attributes': {
|
||||
'name': 'project_web_1',
|
||||
'image': 'example/image',
|
||||
},
|
||||
'time': dt_with_microseconds(1420092061, 2),
|
||||
},
|
||||
{
|
||||
'type': 'container',
|
||||
'service': 'web',
|
||||
'event': 'attach',
|
||||
'container': 'abcde',
|
||||
'image': 'example/image',
|
||||
'action': 'attach',
|
||||
'id': 'abcde',
|
||||
'attributes': {
|
||||
'name': 'project_web_1',
|
||||
'image': 'example/image',
|
||||
},
|
||||
'time': dt_with_microseconds(1420092061, 3),
|
||||
},
|
||||
{
|
||||
'type': 'container',
|
||||
'service': 'db',
|
||||
'event': 'create',
|
||||
'container': 'ababa',
|
||||
'image': 'example/db',
|
||||
'action': 'create',
|
||||
'id': 'ababa',
|
||||
'attributes': {
|
||||
'name': 'project_db_1',
|
||||
'image': 'example/db',
|
||||
},
|
||||
'time': dt_with_microseconds(1420092061, 4),
|
||||
},
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue