mirror of
https://github.com/docker/compose.git
synced 2025-07-22 21:24:38 +02:00
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
|
--json Output events as a stream of json objects
|
||||||
"""
|
"""
|
||||||
def format_event(event):
|
def format_event(event):
|
||||||
return ("{time}: service={service} event={event} "
|
attributes = ["%s=%s" % item for item in event['attributes'].items()]
|
||||||
"container={container} image={image}").format(**event)
|
return ("{time} {type} {action} {id} ({attrs})").format(
|
||||||
|
attrs=", ".join(sorted(attributes)),
|
||||||
|
**event)
|
||||||
|
|
||||||
def json_format_event(event):
|
def json_format_event(event):
|
||||||
event['time'] = event['time'].isoformat()
|
event['time'] = event['time'].isoformat()
|
||||||
@ -266,6 +268,7 @@ class TopLevelCommand(DocoptCommand):
|
|||||||
for event in project.events():
|
for event in project.events():
|
||||||
formatter = json_format_event if options['--json'] else format_event
|
formatter = json_format_event if options['--json'] else format_event
|
||||||
print(formatter(event))
|
print(formatter(event))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
def help(self, project, options):
|
def help(self, project, options):
|
||||||
"""
|
"""
|
||||||
|
@ -282,11 +282,15 @@ class Project(object):
|
|||||||
time = time.replace(
|
time = time.replace(
|
||||||
microsecond=microseconds_from_time_nano(event['timeNano']))
|
microsecond=microseconds_from_time_nano(event['timeNano']))
|
||||||
return {
|
return {
|
||||||
'service': container.service,
|
|
||||||
'event': event['status'],
|
|
||||||
'container': container.id,
|
|
||||||
'image': event['from'],
|
|
||||||
'time': time,
|
'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)
|
service_names = set(self.service_names)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
@ -864,7 +865,26 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
os.kill(events_proc.pid, signal.SIGINT)
|
os.kill(events_proc.pid, signal.SIGINT)
|
||||||
result = wait_on_process(events_proc, returncode=1)
|
result = wait_on_process(events_proc, returncode=1)
|
||||||
lines = [json.loads(line) for line in result.stdout.rstrip().split('\n')]
|
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):
|
def test_env_file_relative_to_compose_file(self):
|
||||||
config_path = os.path.abspath('tests/fixtures/env-file/docker-compose.yml')
|
config_path = os.path.abspath('tests/fixtures/env-file/docker-compose.yml')
|
||||||
|
@ -238,12 +238,19 @@ class ProjectTest(unittest.TestCase):
|
|||||||
|
|
||||||
def get_container(cid):
|
def get_container(cid):
|
||||||
if cid == 'abcde':
|
if cid == 'abcde':
|
||||||
labels = {LABEL_SERVICE: 'web'}
|
name = 'web'
|
||||||
|
labels = {LABEL_SERVICE: name}
|
||||||
elif cid == 'ababa':
|
elif cid == 'ababa':
|
||||||
labels = {LABEL_SERVICE: 'db'}
|
name = 'db'
|
||||||
|
labels = {LABEL_SERVICE: name}
|
||||||
else:
|
else:
|
||||||
labels = {}
|
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
|
self.mock_client.inspect_container.side_effect = get_container
|
||||||
|
|
||||||
@ -254,24 +261,36 @@ class ProjectTest(unittest.TestCase):
|
|||||||
assert not list(events)
|
assert not list(events)
|
||||||
assert events_list == [
|
assert events_list == [
|
||||||
{
|
{
|
||||||
|
'type': 'container',
|
||||||
'service': 'web',
|
'service': 'web',
|
||||||
'event': 'create',
|
'action': 'create',
|
||||||
'container': 'abcde',
|
'id': 'abcde',
|
||||||
|
'attributes': {
|
||||||
|
'name': 'project_web_1',
|
||||||
'image': 'example/image',
|
'image': 'example/image',
|
||||||
|
},
|
||||||
'time': dt_with_microseconds(1420092061, 2),
|
'time': dt_with_microseconds(1420092061, 2),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
'type': 'container',
|
||||||
'service': 'web',
|
'service': 'web',
|
||||||
'event': 'attach',
|
'action': 'attach',
|
||||||
'container': 'abcde',
|
'id': 'abcde',
|
||||||
|
'attributes': {
|
||||||
|
'name': 'project_web_1',
|
||||||
'image': 'example/image',
|
'image': 'example/image',
|
||||||
|
},
|
||||||
'time': dt_with_microseconds(1420092061, 3),
|
'time': dt_with_microseconds(1420092061, 3),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
'type': 'container',
|
||||||
'service': 'db',
|
'service': 'db',
|
||||||
'event': 'create',
|
'action': 'create',
|
||||||
'container': 'ababa',
|
'id': 'ababa',
|
||||||
|
'attributes': {
|
||||||
|
'name': 'project_db_1',
|
||||||
'image': 'example/db',
|
'image': 'example/db',
|
||||||
|
},
|
||||||
'time': dt_with_microseconds(1420092061, 4),
|
'time': dt_with_microseconds(1420092061, 4),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user