Handle both SIGINT and SIGTERM for docker-compose run.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
be5b7b6f0e
commit
83760d0e9e
2 changed files with 102 additions and 44 deletions
|
|
@ -8,6 +8,8 @@ import time
|
|||
from collections import namedtuple
|
||||
from operator import attrgetter
|
||||
|
||||
from docker import errors
|
||||
|
||||
from .. import mock
|
||||
from compose.cli.command import get_project
|
||||
from compose.cli.docker_client import docker_client
|
||||
|
|
@ -61,6 +63,25 @@ class ContainerCountCondition(object):
|
|||
return "waiting for counter count == %s" % self.expected
|
||||
|
||||
|
||||
class ContainerStateCondition(object):
|
||||
|
||||
def __init__(self, client, name, running):
|
||||
self.client = client
|
||||
self.name = name
|
||||
self.running = running
|
||||
|
||||
# State.Running == true
|
||||
def __call__(self):
|
||||
try:
|
||||
container = self.client.inspect_container(self.name)
|
||||
return container['State']['Running'] == self.running
|
||||
except errors.APIError:
|
||||
return False
|
||||
|
||||
def __str__(self):
|
||||
return "waiting for container to have state %s" % self.expected
|
||||
|
||||
|
||||
class CLITestCase(DockerClientTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -554,6 +575,32 @@ class CLITestCase(DockerClientTestCase):
|
|||
self.assertEqual(len(networks), 1)
|
||||
self.assertEqual(container.human_readable_command, u'true')
|
||||
|
||||
def test_run_handles_sigint(self):
|
||||
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
running=True))
|
||||
|
||||
os.kill(proc.pid, signal.SIGINT)
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
running=False))
|
||||
|
||||
def test_run_handles_sigterm(self):
|
||||
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
running=True))
|
||||
|
||||
os.kill(proc.pid, signal.SIGTERM)
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
running=False))
|
||||
|
||||
def test_rm(self):
|
||||
service = self.project.get_service('simple')
|
||||
service.create_container()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue