You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
import subprocess |
|
from utils import * |
|
from docker import docker, check_state, print_errors |
|
|
|
|
|
class Compose: |
|
ALL_CONTAINERS = [ |
|
'u_agent_1', |
|
'u_agent_2', |
|
'u_server', |
|
'u_db', |
|
'tests_runner', |
|
] |
|
|
|
def __init__(self): |
|
self.cmd_container = 'tests_runner' |
|
|
|
def _call(self, *args): |
|
subprocess.check_call([ |
|
'docker-compose', |
|
'--no-ansi', |
|
] + list(args) |
|
) |
|
|
|
def up(self): |
|
log('Instanciating cluster') |
|
self._call('up') |
|
log('Ok') |
|
|
|
def down(self): |
|
log('Shutting down cluster') |
|
self._call('down') |
|
log('Ok') |
|
|
|
def stop(self): |
|
log('Stopping cluster') |
|
self._call('stop') |
|
log('Ok') |
|
|
|
def run(self, cmd): |
|
container = self.cmd_container |
|
log(f'Running command "{cmd}" in container {container}') |
|
docker([ |
|
'exec', |
|
'-i', |
|
f"'{container}'", |
|
f"'{cmd}'" |
|
]) |
|
log('Ok') |
|
|
|
def is_alive(self): |
|
log('Check if all containers are alive') |
|
|
|
errors = check_state(self.ALL_CONTAINERS) |
|
log('Check done') |
|
|
|
if errors: |
|
print_errors(errors) |
|
raise TestsError('Error during `is_alive` check') |
|
else: |
|
log('All containers are alive')
|
|
|