2023-08-10 06:58:50 +00:00
|
|
|
import logging
|
2024-06-26 07:21:20 +00:00
|
|
|
import time
|
2023-08-04 18:27:03 +00:00
|
|
|
import typing
|
|
|
|
|
|
|
|
import configs.testpath
|
|
|
|
from scripts.utils import local_system
|
2023-11-30 15:25:59 +00:00
|
|
|
from scripts.utils.wait_for_port import wait_for_port
|
2023-08-04 18:27:03 +00:00
|
|
|
|
|
|
|
_PROCESS_NAME = '_squishserver'
|
|
|
|
|
2023-11-30 13:07:26 +00:00
|
|
|
LOG = logging.getLogger(__name__)
|
2023-08-10 06:58:50 +00:00
|
|
|
|
2023-08-04 18:27:03 +00:00
|
|
|
|
|
|
|
class SquishServer:
|
2023-10-23 11:53:11 +00:00
|
|
|
__instance = None
|
|
|
|
path = configs.testpath.SQUISH_DIR / 'bin' / 'squishserver'
|
2023-11-30 14:57:39 +00:00
|
|
|
config = configs.testpath.ROOT / 'squish.ini'
|
2023-10-23 11:53:11 +00:00
|
|
|
host = '127.0.0.1'
|
|
|
|
port = None
|
|
|
|
pid = None
|
|
|
|
|
|
|
|
def __new__(cls):
|
|
|
|
if not SquishServer.__instance:
|
|
|
|
SquishServer.__instance = super(SquishServer, cls).__new__(cls)
|
|
|
|
return SquishServer.__instance
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def start(cls):
|
|
|
|
cls.port = local_system.find_free_port(configs.squish.SERVER_PORT, 100)
|
2023-11-30 13:07:26 +00:00
|
|
|
LOG.info('Starting Squish Server on port: %d', cls.port)
|
2023-08-04 18:27:03 +00:00
|
|
|
cmd = [
|
2023-11-30 11:50:06 +00:00
|
|
|
str(cls.path),
|
|
|
|
'--verbose',
|
|
|
|
f'--configfile={cls.config}',
|
2023-10-23 11:53:11 +00:00
|
|
|
f'--host={cls.host}',
|
|
|
|
f'--port={cls.port}',
|
2023-08-04 18:27:03 +00:00
|
|
|
]
|
2023-12-01 08:11:52 +00:00
|
|
|
with open(configs.SQUISH_LOG_FILE, "ab") as log:
|
|
|
|
cls.pid = local_system.execute(cmd, stderr=log, stdout=log)
|
2023-08-04 18:27:03 +00:00
|
|
|
|
2023-10-23 11:53:11 +00:00
|
|
|
@classmethod
|
|
|
|
def stop(cls):
|
2023-11-30 10:51:00 +00:00
|
|
|
if cls.pid is None:
|
|
|
|
return
|
2023-11-30 13:07:26 +00:00
|
|
|
LOG.info('Stopping Squish Server with PID: %d', cls.pid)
|
2024-06-11 14:04:06 +00:00
|
|
|
local_system.kill_process(cls.pid)
|
2024-06-26 07:21:20 +00:00
|
|
|
time.sleep(1)
|
2023-11-30 10:51:00 +00:00
|
|
|
cls.pid = None
|
2023-10-23 11:53:11 +00:00
|
|
|
cls.port = None
|
2023-08-04 18:27:03 +00:00
|
|
|
|
2023-11-30 15:25:59 +00:00
|
|
|
@classmethod
|
|
|
|
def wait(cls, timeout: int = 1, retries: int = 10):
|
|
|
|
LOG.info('Waiting for Squish server port %s:%d...', cls.host, cls.port)
|
|
|
|
wait_for_port(cls.host, cls.port, timeout, retries)
|
|
|
|
LOG.info('Squish server port available!')
|
|
|
|
|
2023-08-04 18:27:03 +00:00
|
|
|
# https://doc-snapshots.qt.io/squish/cli-squishserver.html
|
2023-10-23 11:53:11 +00:00
|
|
|
@classmethod
|
|
|
|
def configuring(cls, action: str, options: typing.Union[int, str, list]):
|
2023-12-01 08:11:52 +00:00
|
|
|
LOG.info('Configuring Squish server config: %s', cls.config)
|
|
|
|
cmd = [
|
|
|
|
str(cls.path),
|
|
|
|
f'--configfile={cls.config}',
|
|
|
|
f'--config={action}',
|
|
|
|
] + options
|
|
|
|
with open(configs.SQUISH_LOG_FILE, "ab") as log:
|
|
|
|
rval = local_system.run(cmd, stdout=log, stderr=log)
|
2023-08-04 18:27:03 +00:00
|
|
|
|
2023-10-23 11:53:11 +00:00
|
|
|
@classmethod
|
|
|
|
def add_attachable_aut(cls, aut_id: str, port: int):
|
|
|
|
cls.configuring('addAttachableAUT', [aut_id, f'localhost:{port}'])
|