-FROM debian:latest
+FROM docker.io/debian:latest
ENV LC_ALL=C.UTF-8
import sys
import requests
import hashlib
+import click
+import json
from _hashlib import HASH as Hash
from pathlib import Path, PurePath
def _api_build_container(self, image_name: str, data: BinaryIO):
response = requests.post(
- self._create_url("libpod/build"), params=[("t", image_name)], data=data
+ self._create_url("libpod/build"), params=[("t", image_name)], data=data, stream=True
)
response.raise_for_status()
+ for line in response.iter_lines():
+ print(f"\t\t{json.loads(str(line, 'utf8'))['stream'].rstrip()}")
+
def _read_and_remove_hashfile(self, context_dir: Path) -> Optional[str]:
hashfile: Path = context_dir / PodmanServiceManager._HASHFILE_NAME
if hashfile.exists():
def _api_start_exec(self, exec_id):
response = requests.post(
- self._create_url(f"libpod/exec/{exec_id}/start"), json={}
+ self._create_url(f"libpod/exec/{exec_id}/start"), json={}, stream=True
)
response.raise_for_status()
+ for line in response.iter_lines():
+ print(f"\t\t{str(line, 'utf8').rstrip()}")
+
def _api_get_exec_exit_code(self, exec_id) -> int:
response = requests.get(self._create_url(f"libpod/exec/{exec_id}/json"))
response.raise_for_status()
response.raise_for_status()
def start_temporary_and_wait(
- self, image: str, command: List[str], bind_mount_ro: Dict[PurePath, PurePath] = {}
+ self, image: str, command: List[str], bind_mount_ro: Dict[PurePath, PurePath] = {}, wait_interactively: bool = False
) -> int:
# start the container
container_id = self._api_create_container(image, bind_mount_ro)
self._api_start_exec(exec_id)
test_exit_code = self._api_get_exec_exit_code(exec_id)
+ if wait_interactively:
+ print(f"\tExit code is {test_exit_code}")
+ print("\tPress [ENTER] to continue...")
+ input()
+
# issue shutdown command to the container
exec_id = self._api_create_exec(container_id, ["systemctl", "poweroff"])
self._api_start_exec(exec_id)
def _get_git_root() -> PurePath:
- result = subprocess.run("git rev-parse --show-toplevel", shell=True, capture_output=True)
+ result = subprocess.run("git rev-parse --show-toplevel", shell=True, stdout=subprocess.PIPE)
return PurePath(str(result.stdout, encoding='utf8').strip())
class TestRunner:
]
@staticmethod
- def run():
+ @click.command()
+ @click.argument('tests', nargs=-1)
+ @click.option("-w", "--wait", help="Do not stop the test container immediately, wait for confirmation.", default=False, is_flag=True)
+ def run(tests: List[str] = [], wait: bool = False):
with PodmanService() as manager:
for test_path in TestRunner._list_tests():
test_name = test_path.absolute().name
+
+ if len(tests) != 0 and test_name not in tests:
+ print(f"Skipping test {Colors.YELLOW}{test_name}{Colors.RESET}")
+ continue
+
print(f"Running test {Colors.YELLOW}{test_name}{Colors.RESET}")
image = "knot_test_" + test_name
print("\tBuilding...")
bind_mount_ro={
_get_git_root(): PurePath('/repo'),
test_path.absolute(): '/test'
- }
+ },
+ wait_interactively=wait
)
if exit_code == 0:
print(f"\t{Colors.GREEN}Test succeeded{Colors.RESET}")
-FROM debian:latest
+FROM docker.io/debian:latest
ENV LC_ALL=C.UTF-8
# install test dependencies
RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -y curl
+RUN pip3 install requests requests-unixsocket
CMD ["/bin/systemd"]
cd /test
echo "Starting manager..."
-cp knot-manager.service /etc/systemd/system
+cp knot-resolver.service /etc/systemd/system
systemctl daemon-reload
-systemctl start knot-manager.service
+systemctl start knot-resolver.service
+# give it time to start
+sleep 1
-echo -e "lua_config: \"\"\nnum_workers: 4" | curl -X POST --unix-socket /tmp/manager.sock localhost/config -f --data-binary @-
+python3 send_request.py
# assert that any kresd process is running
systemctl status | grep kresd
--- /dev/null
+
+
+
+import requests
+import requests_unixsocket
+
+# patch requests library so that it supports unix socket
+requests_unixsocket.monkeypatch()
+
+# prepare the payload
+LUA_CONFIG = """
+-- SPDX-License-Identifier: CC0-1.0
+-- vim:syntax=lua:set ts=4 sw=4:
+-- Refer to manual: https://knot-resolver.readthedocs.org/en/stable/
+
+-- Network interface configuration
+net.listen('127.0.0.1', 53, { kind = 'dns' })
+net.listen('127.0.0.1', 853, { kind = 'tls' })
+--net.listen('127.0.0.1', 443, { kind = 'doh2' })
+net.listen('::1', 53, { kind = 'dns', freebind = true })
+net.listen('::1', 853, { kind = 'tls', freebind = true })
+--net.listen('::1', 443, { kind = 'doh2' })
+
+-- Load useful modules
+modules = {
+ 'hints > iterate', -- Load /etc/hosts and allow custom root hints
+ 'stats', -- Track internal statistics
+ 'predict', -- Prefetch expiring/frequent records
+}
+
+-- Cache size
+cache.size = 100 * MB
+"""
+PREPROCESSED_CONFIG = "\n ".join(LUA_CONFIG.splitlines(keepends=False))
+PAYLOAD = f"""
+num_workers: 4
+lua_config: |
+{ PREPROCESSED_CONFIG }
+"""
+
+# send the config
+r = requests.post('http+unix://%2Ftmp%2Fmanager.sock/config', data=PAYLOAD)
+r.raise_for_status()
\ No newline at end of file
-FROM debian:buster
+FROM docker.io/debian:buster
RUN apt-get update && apt-get install -y systemd sudo
await self._spawn_new_child()
async def _write_config(self, config: YAML):
- raise NotImplementedError()
+ # FIXME: this code is blocking!!!
+ with open("/etc/knot-resolver/kresd.conf", 'w') as f:
+ f.write(config['lua_config'].text)
async def apply_config(self, config: YAML):
async with self._children_lock:
security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"]
socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]
+[[package]]
+name = "requests-unixsocket"
+version = "0.2.0"
+description = "Use requests to talk HTTP via a UNIX domain socket"
+category = "dev"
+optional = false
+python-versions = "*"
+
+[package.dependencies]
+requests = ">=1.1"
+urllib3 = ">=1.8"
+
[[package]]
name = "requirements-detector"
version = "0.7"
[metadata]
lock-version = "1.1"
python-versions = "^3.6.12"
-content-hash = "3c88907317606698cea3e6abbf6e5d84a68a32f942f90e3115f8a02f88539051"
+content-hash = "19afffd5ea930c525a9a723ede432e8fcffcfef19801c15e721d83d6f79cdeae"
[metadata.files]
aiohttp = [
{file = "PyYAML-5.4.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185"},
{file = "PyYAML-5.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253"},
{file = "PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc"},
+ {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347"},
+ {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_s390x.whl", hash = "sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541"},
{file = "PyYAML-5.4.1-cp36-cp36m-win32.whl", hash = "sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5"},
{file = "PyYAML-5.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df"},
{file = "PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018"},
{file = "PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63"},
+ {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa"},
+ {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_s390x.whl", hash = "sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"},
{file = "PyYAML-5.4.1-cp37-cp37m-win32.whl", hash = "sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b"},
{file = "PyYAML-5.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf"},
{file = "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46"},
{file = "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb"},
+ {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247"},
+ {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_s390x.whl", hash = "sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc"},
{file = "PyYAML-5.4.1-cp38-cp38-win32.whl", hash = "sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc"},
{file = "PyYAML-5.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696"},
{file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77"},
{file = "PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183"},
+ {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122"},
+ {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_s390x.whl", hash = "sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6"},
{file = "PyYAML-5.4.1-cp39-cp39-win32.whl", hash = "sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10"},
{file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"},
{file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"},
{file = "requests-2.25.1-py2.py3-none-any.whl", hash = "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e"},
{file = "requests-2.25.1.tar.gz", hash = "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"},
]
+requests-unixsocket = [
+ {file = "requests-unixsocket-0.2.0.tar.gz", hash = "sha256:9e5c1a20afc3cf786197ae59c79bcdb0e7565f218f27df5f891307ee8817c1ea"},
+ {file = "requests_unixsocket-0.2.0-py2.py3-none-any.whl", hash = "sha256:014d07bfb66dc805a011a8b4b306cf4ec96d2eddb589f6b2b5765e626f0dc0cc"},
+]
requirements-detector = [
{file = "requirements-detector-0.7.tar.gz", hash = "sha256:0d1e13e61ed243f9c3c86e6cbb19980bcb3a0e0619cde2ec1f3af70fdbee6f7b"},
]
poethepoet = "^0.9.0"
prospector = {extras = ["with_mypy", "with_bandit"], version = "^1.3.1"}
requests = "^2.25.1"
+requests-unixsocket = "^0.2.0"
+click = "^7.1.2"
[tool.poe.tasks]
run = { cmd = "python -m knot_resolver_manager", help = "Run the manager" }