Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 40c4567f authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

import the test suite from the legacy runners

parent ea7b9223
No related branches found
No related tags found
No related merge requests found
......@@ -185,16 +185,32 @@ test-docker:
extends: [.test]
tags: [$RUNNER_NAME]
image:
name: ubuntu,cpu:1,ram:2
entrypoint: ["/bin/bash", "-c"]
name: python:3-alpine,cpu:1,ram:2
entrypoint: ["/bin/sh", "-c"]
cache:
paths:
- cache
script:
- cat /etc/lsb-release
- cat /etc/os-release
- pwd
- cat /etc/lsb-release > target
- cat /etc/os-release > target
- mkdir -p cache/apk
- ln -s "$PWD/cache/apk" /etc/apk/cache
- apk add docker-cli
- python3 -m unittest -v tests/test_ci_docker.py
artifacts:
paths:
- target
test-docker-legacy-runners:
extends: [.test]
tags: [ci.inria.fr, small]
image:
name: python:3-alpine
script:
- apk add docker-cli
- python3 -m unittest -v tests/test_ci_docker.py
test-squash:
extends: [.test]
tags: [$RUNNER_NAME]
......
# make pytest ignore this test (this is an integration test to be run inside a job)
collect_ignore = ["test_ci_docker.py"]
#!/usr/bin/python3
import subprocess
import time
import unittest
import urllib.request
from contextlib import contextmanager
from typing import Iterator, List
# basic plain HTTP url opener (that does not process redirect responses)
http_opener = urllib.request.OpenerDirector()
http_opener.add_handler(urllib.request.HTTPHandler())
SERVICE_URL = "http://nginx-svc/"
@contextmanager
def run_container(docker_args: List[str]) -> Iterator[str]:
container_id = subprocess.check_output(
["docker", "run", "-d", *docker_args], encoding="utf-8"
).strip()
try:
yield container_id
finally:
subprocess.call(
["docker", "rm", "-f", "--", container_id],
# stdout=subprocess.STDERR
)
class DockerAPITest(unittest.TestCase):
def test_publish_port(self):
"""ensure that user-published port are reachable at 172.17.0.1"""
with run_container(["-p", "280:80", "nginx"]):
time.sleep(1)
status = http_opener.open("http://172.17.0.1:280").status
self.assertEqual(status, 200)
def test_shared_network_stack(self):
"""ensure that we can run multiple containers on the same network stack"""
with run_container(["busybox", "sleep", "30"]) as c1, run_container(
[f"--net=container:{c1}", "busybox", "hostname"]
) as c2:
# c2 must have the same hostname as c1
self.assertEqual(
subprocess.check_output(
["docker", "logs", "--follow", "--", c2]
).strip(),
c1[:12].encode(),
)
@unittest.expectedFailure
def test_volumes(self):
"""ensure that the /builds and /tmp volumes are mountable"""
with run_container(
[
"-v",
"/builds:/mnt/builds",
"-v",
"/tmp:/mnt/tmp",
"busybox",
"sleep",
"30",
]
) as container_id:
for name in "builds", "tmp":
with self.subTest(name=name):
content = b"this is /{name}"
with open(f"/{name}/foo", "wb") as fp:
fp.write(content)
self.assertEqual(
content,
subprocess.check_output(
["docker", "exec", container_id, "cat", f"/mnt/{name}/foo"]
),
)
@unittest.expectedFailure
def test_experimental(self):
"""ensure that experimental features are enabled in the docker daemon"""
self.assertIn(
b"Experimental: true", subprocess.check_output(["docker", "info"])
)
class ServicesTest(unittest.TestCase):
@unittest.expectedFailure
def test_nginx_service(self):
"""ensure that gitlab-ci services are reachable"""
# access the service
rep = http_opener.open(SERVICE_URL)
self.assertEqual(rep.status, 200)
self.assertIn(b"Welcome to nginx!", rep.read())
class MiscTest(unittest.TestCase):
def test_faccessat2(self):
"""ensure that faccessat2 is usable"""
# faccessat2 was added in linux 5.8
#
# Running with an old kernel or an old seccomp profile breaks some workflows because
# faccessat2() would fail with EPERM. The workaround consists of patching the seccomp
# profile to fail with ENOSYS instead and let the caller fall back to faccessat().
#
# see: https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.14.0#faccessat2
# this command must not fail with: "make: true: Operation not permitted"
proc = subprocess.run(
["docker", "build", "-"],
capture_output=True,
input=rb"""
FROM alpine:3.14
RUN apk add make &&\
echo -e 'nop:\n\ttrue' > Makefile &&\
make
""",
)
self.assertNotIn(b"Operation not permitted", proc.stdout + proc.stderr)
if proc.returncode != 0:
raise RuntimeError("build failed", proc)
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