Skip to content
Snippets Groups Projects
Commit 07faf4a5 authored by Sjoerd Simons's avatar Sjoerd Simons
Browse files

test: Don't hardcode the port to listen on


Hardcoding the port to let the test server listen on is can be
problematic in case the build hosts happens to have something on that
port (e.g. another daemon or build running at the same time). Instead
let the kernel pick a free port for us.

Apart from that, this changes all configuration files to be
templated, with HOST expected to be updated with the actual address/port
picked. For explicit configuration files there is a new context manager
which will provide a temporary config file with the right information
while the sysroot http server will setup a temporary directory to
serve files from (with all files updates with correct url information
as well).

Signed-off-by: default avatarSjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: default avatarGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Differential Revision: https://phabricator.apertis.org/D5243
parent 3b3dc41e
No related branches found
No related tags found
No related merge requests found
[general] [general]
url=http://127.0.0.1:1234/versions/@SYSROOT@ url=http://HOST/versions/@SYSROOT@
version=16.09 20161101.0 version=16.09 20161101.0
url=http://127.0.0.1:1234/archives/eraroj-16.09-armhf_invalidarchive.tar.gz url=http://HOST/archives/eraroj-16.09-armhf_invalidarchive.tar.gz
version=16.09 20161101.0 version=16.09 20161101.0
url=http://127.0.0.1:1234/archives/eraroj-16.09-armhf_invalidversion.tar.gz url=http://HOST/archives/eraroj-16.09-armhf_invalidversion.tar.gz
version=20161101.0 version=20161101.0
url=http://127.0.0.1:1234/data/sysroot-apertis-16.09-arm64_20161101.0.tar.gz url=http://HOST/data/sysroot-apertis-16.09-arm64_20161101.0.tar.gz
[general] [general]
url=http://127.0.0.1:1234/versions/%(distro)-%(release)-%(arch)_latest url=http://HOST/versions/%(distro)-%(release)-%(arch)_latest
url=http://127.0.0.1:1234/data/sysroot-apertis-16.09-arm64_20161101.0.tar.gz url=http://HOST/data/sysroot-apertis-16.09-arm64_20161101.0.tar.gz
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
url=http://example.com/sysroot url=http://example.com/sysroot
[apertis] [apertis]
url=http://127.0.0.1:1234/versions/apertis-%(release)-%(arch)_latest url=http://HOST/versions/apertis-%(release)-%(arch)_latest
[babiladis] [babiladis]
url=http://127.0.0.1:1234/versions/babiladis-%(release)-%(arch)_latest url=http://HOST/versions/babiladis-%(release)-%(arch)_latest
[fermis] [fermis]
url=http://127.0.0.1:1234/versions/fermis-%(release)-%(arch)_latest url=http://HOST/versions/fermis-%(release)-%(arch)_latest
version=@RELEASE@ @BUILD@ version=@RELEASE@ @BUILD@
url=http://127.0.0.1:1234/archives/@DISTRO@-@RELEASE@-@ARCH@_@BUILD@.tar.gz url=http://HOST/archives/@DISTRO@-@RELEASE@-@ARCH@_@BUILD@.tar.gz
version=16.09 20161101.0 version=16.09 20161101.0
url=http://127.0.0.1:1234/archives/apertis-16.09-armhf_20161101.0.tar.gz url=http://HOST/archives/apertis-16.09-armhf_20161101.0.tar.gz
version=16.09 20161101.0 version=16.09 20161101.0
url=http://127.0.0.1:1234/archives/eraroj-16.12-armhf_20161101.0.tar.gz url=http://HOST/archives/eraroj-16.12-armhf_20161101.0.tar.gz
...@@ -13,8 +13,9 @@ import os ...@@ -13,8 +13,9 @@ import os
import tempfile import tempfile
from test_util import SysrootServer from test_util import SysrootServer
from test_util import templatedconfig
from test_util import should_succeed, should_fail from test_util import should_succeed, should_fail
from test_util import BASE_URL, BASE_ARCHIVE, BASE_CONFIG, \ from test_util import BASE_ARCHIVE, BASE_CONFIG, \
SYSROOTS, LATEST_SYSROOTS, \ SYSROOTS, LATEST_SYSROOTS, \
CONFIG_FILES, BAD_URLS CONFIG_FILES, BAD_URLS
...@@ -33,7 +34,7 @@ server.start() ...@@ -33,7 +34,7 @@ server.start()
# Test "ade sysroot download --url" usage # Test "ade sysroot download --url" usage
for sysroot in SYSROOTS: for sysroot in SYSROOTS:
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
params = ['--url', BASE_URL.format(*sysroot), '--distro', sysroot[0], params = ['--url', server.base_url().format(*sysroot), '--distro', sysroot[0],
'--release', sysroot[1], '--arch', sysroot[2]] '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('download', *params, path=tmpdir, should_succeed('download', *params, path=tmpdir,
check=lambda x: check_archive(x, sysroot)) check=lambda x: check_archive(x, sysroot))
...@@ -41,22 +42,24 @@ for sysroot in SYSROOTS: ...@@ -41,22 +42,24 @@ for sysroot in SYSROOTS:
# Test "ade sysroot download --distro --release --arch" usage # Test "ade sysroot download --distro --release --arch" usage
for sysroot in SYSROOTS: for sysroot in SYSROOTS:
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]] with templatedconfig(server, BASE_CONFIG.format(*sysroot)) as config:
should_succeed('download', *params, config=BASE_CONFIG.format(*sysroot), path=tmpdir, params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]]
check=lambda x: check_archive(x, sysroot)) should_succeed('download', *params, config=config, path=tmpdir,
check=lambda x: check_archive(x, sysroot))
# Test "ade sysroot download --distro --release --arch" usage with different config files # Test "ade sysroot download --distro --release --arch" usage with different config files
for config_file in CONFIG_FILES: for config_file in CONFIG_FILES:
config = os.path.join(os.getcwd(), "configs", config_file) with templatedconfig(server, config_file) as config:
for sysroot in LATEST_SYSROOTS: for sysroot in LATEST_SYSROOTS:
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]] params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('download', *params, config=config, path=tmpdir, should_succeed('download', *params, config=config, path=tmpdir,
check=lambda x: check_archive(x, sysroot)) check=lambda x: check_archive(x, sysroot))
# Test error cases # Test error cases
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
for url in BAD_URLS: for url in BAD_URLS:
url.replace("HOST", server.host())
params = ['--url', url, '--distro', 'eraroj', '--release', '16.09', '--arch', 'armhf'] params = ['--url', url, '--distro', 'eraroj', '--release', '16.09', '--arch', 'armhf']
should_fail('download', *params, path=tmpdir) should_fail('download', *params, path=tmpdir)
......
...@@ -13,8 +13,9 @@ import os ...@@ -13,8 +13,9 @@ import os
import tempfile import tempfile
from test_util import SysrootServer from test_util import SysrootServer
from test_util import templatedconfig
from test_util import should_succeed, should_fail from test_util import should_succeed, should_fail
from test_util import BASE_TAG, BASE_URL, BASE_ARCHIVE, BASE_CONFIG, \ from test_util import BASE_TAG, BASE_ARCHIVE, BASE_CONFIG, \
SYSROOTS, LATEST_SYSROOTS, SYSROOT1, SYSROOT2, \ SYSROOTS, LATEST_SYSROOTS, SYSROOT1, SYSROOT2, \
CONFIG_FILES, BAD_URLS CONFIG_FILES, BAD_URLS
...@@ -39,7 +40,7 @@ server.start() ...@@ -39,7 +40,7 @@ server.start()
# Test "ade sysroot install --url" usage # Test "ade sysroot install --url" usage
for sysroot in SYSROOTS: for sysroot in SYSROOTS:
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
params = ['--url', BASE_URL.format(*sysroot), '--distro', sysroot[0], params = ['--url', server.base_url().format(*sysroot), '--distro', sysroot[0],
'--release', sysroot[1], '--arch', sysroot[2]] '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('install', *params, path=tmpdir, should_succeed('install', *params, path=tmpdir,
check=lambda x: check_sysroot(x, tmpdir, sysroot)) check=lambda x: check_sysroot(x, tmpdir, sysroot))
...@@ -53,19 +54,20 @@ for sysroot in SYSROOTS: ...@@ -53,19 +54,20 @@ for sysroot in SYSROOTS:
# Test "ade sysroot install --distro --release --arch" usage # Test "ade sysroot install --distro --release --arch" usage
for sysroot in SYSROOTS: for sysroot in SYSROOTS:
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]] with templatedconfig(server, BASE_CONFIG.format(*sysroot)) as config:
should_succeed('install', *params, config=BASE_CONFIG.format(*sysroot), path=tmpdir,
check=lambda x: check_sysroot(x, tmpdir, sysroot))
# Test "ade sysroot install --distro --release --arch" usage with different config files
for config_file in CONFIG_FILES:
config = os.path.join(os.getcwd(), "configs", config_file)
for sysroot in LATEST_SYSROOTS:
with tempfile.TemporaryDirectory() as tmpdir:
params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]] params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('install', *params, config=config, path=tmpdir, should_succeed('install', *params, config=config, path=tmpdir,
check=lambda x: check_sysroot(x, tmpdir, sysroot)) check=lambda x: check_sysroot(x, tmpdir, sysroot))
# Test "ade sysroot install --distro --release --arch" usage with different config files
for config_file in CONFIG_FILES:
with templatedconfig(server, config_file) as config:
for sysroot in LATEST_SYSROOTS:
with tempfile.TemporaryDirectory() as tmpdir:
params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('install', *params, config=config, path=tmpdir,
check=lambda x: check_sysroot(x, tmpdir, sysroot))
# Test "ade sysroot install --force" usage # Test "ade sysroot install --force" usage
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
should_succeed('install', '--file', BASE_ARCHIVE.format(*SYSROOT1), path=tmpdir, should_succeed('install', '--file', BASE_ARCHIVE.format(*SYSROOT1), path=tmpdir,
......
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
import os import os
from test_util import SysrootServer from test_util import SysrootServer
from test_util import templatedconfig
from test_util import should_succeed, should_fail from test_util import should_succeed, should_fail
from test_util import BASE_TAG, BASE_URL, BASE_ARCHIVE, BASE_CONFIG, \ from test_util import BASE_TAG, BASE_ARCHIVE, BASE_CONFIG, \
SYSROOTS, LATEST_SYSROOTS, \ SYSROOTS, LATEST_SYSROOTS, \
CONFIG_FILES, BAD_VERSION_URLS CONFIG_FILES, BAD_VERSION_URLS
...@@ -28,25 +29,26 @@ server.start() ...@@ -28,25 +29,26 @@ server.start()
# Test "ade sysroot latest --url" usage # Test "ade sysroot latest --url" usage
for sysroot in SYSROOTS: for sysroot in SYSROOTS:
params = ['--url', BASE_URL.format(*sysroot), '--distro', sysroot[0], params = ['--url', server.base_url().format(*sysroot), '--distro', sysroot[0],
'--release', sysroot[1], '--arch', sysroot[2]] '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('latest', *params, should_succeed('latest', *params,
check=lambda x: check_version(x, sysroot)) check=lambda x: check_version(x, sysroot))
# Test "ade sysroot latest --distro --release --arch" usage # Test "ade sysroot latest --distro --release --arch" usage
for sysroot in SYSROOTS: for sysroot in SYSROOTS:
params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]] with templatedconfig(server, BASE_CONFIG.format(*sysroot)) as config:
should_succeed('latest', *params, config=BASE_CONFIG.format(*sysroot),
check=lambda x: check_version(x, sysroot))
# Test "ade sysroot latest --distro --release --arch" usage with different config files
for config_file in CONFIG_FILES:
config = os.path.join(os.getcwd(), "configs", config_file)
for sysroot in LATEST_SYSROOTS:
params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]] params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('latest', *params, config=config, should_succeed('latest', *params, config=config,
check=lambda x: check_version(x, sysroot)) check=lambda x: check_version(x, sysroot))
# Test "ade sysroot latest --distro --release --arch" usage with different config files
for config_file in CONFIG_FILES:
with templatedconfig(server, config_file) as config:
for sysroot in LATEST_SYSROOTS:
params = ['--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('latest', *params, config=config,
check=lambda x: check_version(x, sysroot))
# Test error cases # Test error cases
for url in BAD_VERSION_URLS: for url in BAD_VERSION_URLS:
params = ['--url', url, '--distro', 'eraroj', '--release', '16.09', '--arch', 'armhf'] params = ['--url', url, '--distro', 'eraroj', '--release', '16.09', '--arch', 'armhf']
......
...@@ -13,8 +13,9 @@ import os ...@@ -13,8 +13,9 @@ import os
import tempfile import tempfile
from test_util import SysrootServer from test_util import SysrootServer
from test_util import templatedconfig
from test_util import should_succeed, should_fail from test_util import should_succeed, should_fail
from test_util import BASE_TAG, BASE_URL, BASE_ARCHIVE, BASE_CONFIG, \ from test_util import BASE_TAG, BASE_ARCHIVE, BASE_CONFIG, \
SYSROOTS, LATEST_SYSROOTS, SYSROOT1, SYSROOT2, \ SYSROOTS, LATEST_SYSROOTS, SYSROOT1, SYSROOT2, \
SYSROOT_VERSIONS, CONFIG_FILES, BAD_URLS SYSROOT_VERSIONS, CONFIG_FILES, BAD_URLS
...@@ -33,7 +34,7 @@ def check_sysroot(result, path, sysroot): ...@@ -33,7 +34,7 @@ def check_sysroot(result, path, sysroot):
return check_result(result, sysroot) and check_install(path, sysroot) return check_result(result, sysroot) and check_install(path, sysroot)
def install_initial_release(path): def install_initial_release(path):
params = ['--url', BASE_URL.format(*SYSROOT1), '--distro', SYSROOT1[0], params = ['--url', server.base_url().format(*SYSROOT1), '--distro', SYSROOT1[0],
'--release', SYSROOT1[1], '--arch', SYSROOT1[2]] '--release', SYSROOT1[1], '--arch', SYSROOT1[2]]
should_succeed('install', *params, path=path) should_succeed('install', *params, path=path)
...@@ -45,30 +46,31 @@ server.start() ...@@ -45,30 +46,31 @@ server.start()
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
install_initial_release(tmpdir) install_initial_release(tmpdir)
for sysroot in SYSROOT_VERSIONS: for sysroot in SYSROOT_VERSIONS:
params = ['--url', BASE_URL.format(*sysroot), params = ['--url', server.base_url().format(*sysroot),
'--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]] '--distro', sysroot[0], '--release', sysroot[1], '--arch', sysroot[2]]
should_succeed('update', *params, path=tmpdir, should_succeed('update', *params, path=tmpdir,
check=lambda x: check_sysroot(x, tmpdir, sysroot)) check=lambda x: check_sysroot(x, tmpdir, sysroot))
# Test "ade sysroot update --distro --release --arch" usage # Test "ade sysroot update --distro --release --arch" usage
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
install_initial_release(tmpdir) with templatedconfig(server, BASE_CONFIG.format(*SYSROOT2)) as config:
params = ['--distro', SYSROOT2[0], '--release', SYSROOT2[1], '--arch', SYSROOT2[2]] install_initial_release(tmpdir)
should_succeed('update', *params, config=BASE_CONFIG.format(*SYSROOT2), path=tmpdir, params = ['--distro', SYSROOT2[0], '--release', SYSROOT2[1], '--arch', SYSROOT2[2]]
check=lambda x: check_sysroot(x, tmpdir, SYSROOT2)) should_succeed('update', *params, config=config, path=tmpdir,
check=lambda x: check_sysroot(x, tmpdir, SYSROOT2))
# Test "ade sysroot update --distro --release --arch" usage with different config files # Test "ade sysroot update --distro --release --arch" usage with different config files
for config_file in CONFIG_FILES: for config_file in CONFIG_FILES:
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
install_initial_release(tmpdir) install_initial_release(tmpdir)
config = os.path.join(os.getcwd(), "configs", config_file) with templatedconfig(server, config_file) as config:
params = ['--distro', SYSROOT2[0], '--release', SYSROOT2[1], '--arch', SYSROOT2[2]] params = ['--distro', SYSROOT2[0], '--release', SYSROOT2[1], '--arch', SYSROOT2[2]]
should_succeed('update', *params, config=config, path=tmpdir, should_succeed('update', *params, config=config, path=tmpdir,
check=lambda x: check_sysroot(x, tmpdir, SYSROOT2)) check=lambda x: check_sysroot(x, tmpdir, SYSROOT2))
# Test "ade sysroot update --force" usage # Test "ade sysroot update --force" usage
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
params = ['--url', BASE_URL.format(*SYSROOT2), '--distro', SYSROOT2[0], params = ['--url', server.base_url().format(*SYSROOT2), '--distro', SYSROOT2[0],
'--release', SYSROOT2[1], '--arch', SYSROOT2[2]] '--release', SYSROOT2[1], '--arch', SYSROOT2[2]]
# Trying to update non-installed sysroot # Trying to update non-installed sysroot
...@@ -91,7 +93,7 @@ with tempfile.TemporaryDirectory() as tmpdir: ...@@ -91,7 +93,7 @@ with tempfile.TemporaryDirectory() as tmpdir:
if not os.path.exists(stamp.name): if not os.path.exists(stamp.name):
exit(1) exit(1)
params = ['--url', BASE_URL.format(*SYSROOT1), '--distro', SYSROOT1[0], params = ['--url', server.base_url().format(*SYSROOT1), '--distro', SYSROOT1[0],
'--release', SYSROOT1[1], '--arch', SYSROOT1[2]] '--release', SYSROOT1[1], '--arch', SYSROOT1[2]]
# Try to downgrade to older version # Try to downgrade to older version
......
...@@ -13,9 +13,13 @@ import os ...@@ -13,9 +13,13 @@ import os
import socket import socket
import subprocess import subprocess
import threading import threading
import tempfile
import shutil
import atexit
from pathlib import Path
from contextlib import contextmanager
BASE_TAG = "{0}-{1}-{2}_{3}" BASE_TAG = "{0}-{1}-{2}_{3}"
BASE_URL = "http://127.0.0.1:1234/versions/{0}".format(BASE_TAG)
BASE_ARCHIVE = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'archives', "{0}.tar.gz".format(BASE_TAG)) BASE_ARCHIVE = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'archives', "{0}.tar.gz".format(BASE_TAG))
BASE_CONFIG = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'configs', "{0}.conf".format(BASE_TAG)) BASE_CONFIG = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'configs', "{0}.conf".format(BASE_TAG))
BASE_INSTALL = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'install') BASE_INSTALL = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'install')
...@@ -68,18 +72,18 @@ CONFIG_FILES = [ ...@@ -68,18 +72,18 @@ CONFIG_FILES = [
BAD_VERSION_URLS = [ BAD_VERSION_URLS = [
'invalidformat', 'invalidformat',
'http://127.0.0.1:1234/not_found', 'http://HOST/not_found',
'http://127.0.0.1:1234/versions/empty', 'http://HOST/versions/empty',
'http://127.0.0.1:1234/versions/missing_version', 'http://HOST/versions/missing_version',
'http://127.0.0.1:1234/versions/missing_url', 'http://HOST/versions/missing_url',
'http://127.0.0.1:1234/versions/invalid_version' 'http://HOST/versions/invalid_version'
] ]
BAD_SYSROOT_URLS = [ BAD_SYSROOT_URLS = [
'http://127.0.0.1:1234/versions/wrong_distro', 'http://HOST/versions/wrong_distro',
'http://127.0.0.1:1234/versions/wrong_release', 'http://HOST/versions/wrong_release',
'http://127.0.0.1:1234/versions/invalid_archive', 'http://HOST/versions/invalid_archive',
'http://127.0.0.1:1234/versions/invalid_sysroot' 'http://HOST/versions/invalid_sysroot'
] ]
BAD_URLS = BAD_VERSION_URLS + BAD_SYSROOT_URLS BAD_URLS = BAD_VERSION_URLS + BAD_SYSROOT_URLS
...@@ -130,14 +134,39 @@ class SysrootHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): ...@@ -130,14 +134,39 @@ class SysrootHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def log_message(self, *args): def log_message(self, *args):
pass pass
def template_config_file(server, src, dst):
with open(src) as fsrc:
host = "{}:{}".format(*server.server_address)
output = []
for line in fsrc.readlines():
output.append((line.replace("HOST", host)))
with open(dst, 'w') as fdst:
fdst.writelines(output)
class SysrootServer(http.server.HTTPServer): class SysrootServer(http.server.HTTPServer):
def __init__(self): def __init__(self):
os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files')) contentdir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
super().__init__(("", 1234), SysrootHTTPRequestHandler) 'files')
tmpdir = tempfile.TemporaryDirectory()
atexit.register (tmpdir.cleanup)
self.tmpcontentdir = os.path.join(tmpdir.name, 'files')
shutil.copytree(contentdir, self.tmpcontentdir)
os.chdir(self.tmpcontentdir)
# This binds so we can determine the port that's used
super().__init__(("127.0.0.1", 0), SysrootHTTPRequestHandler)
for f in Path(self.tmpcontentdir).rglob("versions/*"):
template_config_file (self, f.as_posix(), f.as_posix())
for f in Path(self.tmpcontentdir).rglob("configs/*"):
template_config_file (self, f.as_posix(), f.as_posix())
def server_bind(self): def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address) super().server_bind()
def start(self): def start(self):
self.thread = threading.Thread(target=self.serve_forever) self.thread = threading.Thread(target=self.serve_forever)
...@@ -147,3 +176,19 @@ class SysrootServer(http.server.HTTPServer): ...@@ -147,3 +176,19 @@ class SysrootServer(http.server.HTTPServer):
def stop(self): def stop(self):
self.shutdown() self.shutdown()
self.thread.join() self.thread.join()
def host(self):
return "{}:{}".format(*self.server_address)
def base_url(self):
url = "http://{}/versions/{}"
return url.format(self.host(), BASE_TAG)
@contextmanager
def templatedconfig(server, config_file):
config = os.path.join(os.getcwd(), "configs", config_file)
with tempfile.TemporaryDirectory() as t:
tmpconfig = os.path.join(t, os.path.basename(config_file))
template_config_file(server, config, tmpconfig)
yield tmpconfig
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment