Add docker-compose event
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
f38c29f37b
commit
d1d3969661
8 changed files with 195 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
import signal
|
||||
|
|
@ -855,6 +856,16 @@ class CLITestCase(DockerClientTestCase):
|
|||
self.assertEqual(get_port(3000, index=2), containers[1].get_local_port(3000))
|
||||
self.assertEqual(get_port(3002), "")
|
||||
|
||||
def test_events_json(self):
|
||||
events_proc = start_process(self.base_dir, ['events', '--json'])
|
||||
self.dispatch(['up', '-d'])
|
||||
wait_on_condition(ContainerCountCondition(self.project, 2))
|
||||
|
||||
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']
|
||||
|
||||
def test_env_file_relative_to_compose_file(self):
|
||||
config_path = os.path.abspath('tests/fixtures/env-file/docker-compose.yml')
|
||||
self.dispatch(['-f', config_path, 'up', '-d'], None)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
|
||||
import docker
|
||||
|
||||
from .. import mock
|
||||
|
|
@ -197,6 +199,83 @@ class ProjectTest(unittest.TestCase):
|
|||
project.get_service('test')._get_volumes_from(),
|
||||
[container_ids[0] + ':rw'])
|
||||
|
||||
def test_events(self):
|
||||
services = [Service(name='web'), Service(name='db')]
|
||||
project = Project('test', services, self.mock_client)
|
||||
self.mock_client.events.return_value = iter([
|
||||
{
|
||||
'status': 'create',
|
||||
'from': 'example/image',
|
||||
'id': 'abcde',
|
||||
'time': 1420092061,
|
||||
'timeNano': 14200920610000002000,
|
||||
},
|
||||
{
|
||||
'status': 'attach',
|
||||
'from': 'example/image',
|
||||
'id': 'abcde',
|
||||
'time': 1420092061,
|
||||
'timeNano': 14200920610000003000,
|
||||
},
|
||||
{
|
||||
'status': 'create',
|
||||
'from': 'example/other',
|
||||
'id': 'bdbdbd',
|
||||
'time': 1420092061,
|
||||
'timeNano': 14200920610000005000,
|
||||
},
|
||||
{
|
||||
'status': 'create',
|
||||
'from': 'example/db',
|
||||
'id': 'ababa',
|
||||
'time': 1420092061,
|
||||
'timeNano': 14200920610000004000,
|
||||
},
|
||||
])
|
||||
|
||||
def dt_with_microseconds(dt, us):
|
||||
return datetime.datetime.fromtimestamp(dt).replace(microsecond=us)
|
||||
|
||||
def get_container(cid):
|
||||
if cid == 'abcde':
|
||||
labels = {LABEL_SERVICE: 'web'}
|
||||
elif cid == 'ababa':
|
||||
labels = {LABEL_SERVICE: 'db'}
|
||||
else:
|
||||
labels = {}
|
||||
return {'Id': cid, 'Config': {'Labels': labels}}
|
||||
|
||||
self.mock_client.inspect_container.side_effect = get_container
|
||||
|
||||
events = project.events()
|
||||
|
||||
events_list = list(events)
|
||||
# Assert the return value is a generator
|
||||
assert not list(events)
|
||||
assert events_list == [
|
||||
{
|
||||
'service': 'web',
|
||||
'event': 'create',
|
||||
'container': 'abcde',
|
||||
'image': 'example/image',
|
||||
'time': dt_with_microseconds(1420092061, 2),
|
||||
},
|
||||
{
|
||||
'service': 'web',
|
||||
'event': 'attach',
|
||||
'container': 'abcde',
|
||||
'image': 'example/image',
|
||||
'time': dt_with_microseconds(1420092061, 3),
|
||||
},
|
||||
{
|
||||
'service': 'db',
|
||||
'event': 'create',
|
||||
'container': 'ababa',
|
||||
'image': 'example/db',
|
||||
'time': dt_with_microseconds(1420092061, 4),
|
||||
},
|
||||
]
|
||||
|
||||
def test_net_unset(self):
|
||||
project = Project.from_config('test', Config(None, [
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue