mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-11-02 18:17:11 +09:00
The API now answers 503 when docker ps fails instead of an empty list, so the Containers page no longer says "No containers" on a host running many. The Containers and Images tabs show that error, and a late answer from the previously selected server can no longer replace the current server's list. Also fixes the local branch of the remote Docker listing, which passed all= to a parameter named all_containers and always failed.
41 lines
1.8 KiB
Python
41 lines
1.8 KiB
Python
"""Docker being down is an error, not an empty host.
|
|
|
|
list_containers returned [] when `docker ps` failed, so the Containers
|
|
page said "no containers" on a box running dozens. The local branch of
|
|
RemoteDockerService also passed `all=` to a function whose parameter is
|
|
`all_containers`, so it always failed with a TypeError.
|
|
"""
|
|
import pytest
|
|
|
|
from app.exceptions import DependencyUnavailableError
|
|
from app.services.docker_service import DockerService
|
|
from app.services.remote_docker_service import RemoteDockerService
|
|
from factories import headers_for, make_user
|
|
|
|
PS_ROW = ('{"ID": "abc", "Names": "web", "Image": "nginx", "Status": "Up", '
|
|
'"State": "running", "Ports": "", "CreatedAt": "now", "Size": "0B"}')
|
|
|
|
|
|
def test_daemon_down_raises_instead_of_listing_nothing(fake_subprocess):
|
|
fake_subprocess.script(['docker', 'ps'], returncode=1,
|
|
stderr='Cannot connect to the Docker daemon')
|
|
with pytest.raises(DependencyUnavailableError, match='Cannot connect'):
|
|
DockerService.list_containers()
|
|
|
|
|
|
def test_containers_route_answers_503_when_docker_is_down(app, client, fake_subprocess):
|
|
from app import db
|
|
headers = headers_for(make_user(db, 'dk_admin', 'admin'))
|
|
fake_subprocess.script(['docker', 'ps'], returncode=1,
|
|
stderr='Cannot connect to the Docker daemon')
|
|
resp = client.get('/api/v1/docker/containers', headers=headers)
|
|
assert resp.status_code == 503
|
|
assert 'Docker is not reachable' in resp.get_json()['error']
|
|
|
|
|
|
def test_local_remote_docker_listing_works(fake_subprocess):
|
|
fake_subprocess.script(['docker', 'ps'], stdout=PS_ROW)
|
|
result = RemoteDockerService.list_containers('local', all=True)
|
|
assert result['success'], result
|
|
assert [c['name'] for c in result['data']] == ['web']
|