mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Merge branch 'dihmuzikien-5525-ps-show-health'
This commit is contained in:
commit
db5af97326
@ -129,7 +129,7 @@ class Container(object):
|
|||||||
if self.is_restarting:
|
if self.is_restarting:
|
||||||
return 'Restarting'
|
return 'Restarting'
|
||||||
if self.is_running:
|
if self.is_running:
|
||||||
return 'Ghost' if self.get('State.Ghost') else 'Up'
|
return 'Ghost' if self.get('State.Ghost') else self.human_readable_health_status
|
||||||
else:
|
else:
|
||||||
return 'Exit %s' % self.get('State.ExitCode')
|
return 'Exit %s' % self.get('State.ExitCode')
|
||||||
|
|
||||||
@ -172,6 +172,18 @@ class Container(object):
|
|||||||
log_type = self.log_driver
|
log_type = self.log_driver
|
||||||
return not log_type or log_type in ('json-file', 'journald')
|
return not log_type or log_type in ('json-file', 'journald')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def human_readable_health_status(self):
|
||||||
|
""" Generate UP status string with up time and health
|
||||||
|
"""
|
||||||
|
status_string = 'Up'
|
||||||
|
container_status = self.get('State.Health.Status')
|
||||||
|
if container_status == 'starting':
|
||||||
|
status_string += ' (health: starting)'
|
||||||
|
elif container_status is not None:
|
||||||
|
status_string += ' (%s)' % container_status
|
||||||
|
return status_string
|
||||||
|
|
||||||
def attach_log_stream(self):
|
def attach_log_stream(self):
|
||||||
"""A log stream can only be attached if the container uses a json-file
|
"""A log stream can only be attached if the container uses a json-file
|
||||||
log driver.
|
log driver.
|
||||||
|
@ -129,6 +129,73 @@ class ContainerTest(unittest.TestCase):
|
|||||||
|
|
||||||
assert container.get_local_port(45454, protocol='tcp') == '0.0.0.0:49197'
|
assert container.get_local_port(45454, protocol='tcp') == '0.0.0.0:49197'
|
||||||
|
|
||||||
|
def test_human_readable_states_no_health(self):
|
||||||
|
container = Container(None, {
|
||||||
|
"State": {
|
||||||
|
"Status": "running",
|
||||||
|
"Running": True,
|
||||||
|
"Paused": False,
|
||||||
|
"Restarting": False,
|
||||||
|
"OOMKilled": False,
|
||||||
|
"Dead": False,
|
||||||
|
"Pid": 7623,
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Error": "",
|
||||||
|
"StartedAt": "2018-01-29T00:34:25.2052414Z",
|
||||||
|
"FinishedAt": "0001-01-01T00:00:00Z"
|
||||||
|
},
|
||||||
|
}, has_been_inspected=True)
|
||||||
|
expected = "Up"
|
||||||
|
assert container.human_readable_state == expected
|
||||||
|
|
||||||
|
def test_human_readable_states_starting(self):
|
||||||
|
container = Container(None, {
|
||||||
|
"State": {
|
||||||
|
"Status": "running",
|
||||||
|
"Running": True,
|
||||||
|
"Paused": False,
|
||||||
|
"Restarting": False,
|
||||||
|
"OOMKilled": False,
|
||||||
|
"Dead": False,
|
||||||
|
"Pid": 11744,
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Error": "",
|
||||||
|
"StartedAt": "2018-02-03T07:56:20.3591233Z",
|
||||||
|
"FinishedAt": "2018-01-31T08:56:11.0505228Z",
|
||||||
|
"Health": {
|
||||||
|
"Status": "starting",
|
||||||
|
"FailingStreak": 0,
|
||||||
|
"Log": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, has_been_inspected=True)
|
||||||
|
expected = "Up (health: starting)"
|
||||||
|
assert container.human_readable_state == expected
|
||||||
|
|
||||||
|
def test_human_readable_states_healthy(self):
|
||||||
|
container = Container(None, {
|
||||||
|
"State": {
|
||||||
|
"Status": "running",
|
||||||
|
"Running": True,
|
||||||
|
"Paused": False,
|
||||||
|
"Restarting": False,
|
||||||
|
"OOMKilled": False,
|
||||||
|
"Dead": False,
|
||||||
|
"Pid": 5674,
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Error": "",
|
||||||
|
"StartedAt": "2018-02-03T08:32:05.3281831Z",
|
||||||
|
"FinishedAt": "2018-02-03T08:11:35.7872706Z",
|
||||||
|
"Health": {
|
||||||
|
"Status": "healthy",
|
||||||
|
"FailingStreak": 0,
|
||||||
|
"Log": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, has_been_inspected=True)
|
||||||
|
expected = "Up (healthy)"
|
||||||
|
assert container.human_readable_state == expected
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
container = Container(None, {
|
container = Container(None, {
|
||||||
"Status": "Up 8 seconds",
|
"Status": "Up 8 seconds",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user