Test images
This commit is contained in:
parent
12281d8dee
commit
1955b951d1
@ -15,6 +15,8 @@ import sys
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from cloud_build.test_images import test_image
|
||||||
|
|
||||||
PROG = 'cloud-build'
|
PROG = 'cloud-build'
|
||||||
|
|
||||||
|
|
||||||
@ -299,6 +301,9 @@ Dir::Etc::preferencesparts "/var/empty";
|
|||||||
def prerequisites_by_image(self, image: str) -> List[str]:
|
def prerequisites_by_image(self, image: str) -> List[str]:
|
||||||
return self._images[image].get('prerequisites', [])
|
return self._images[image].get('prerequisites', [])
|
||||||
|
|
||||||
|
def tests_by_image(self, image: str) -> List[Dict]:
|
||||||
|
return self._images[image].get('tests', [])
|
||||||
|
|
||||||
def scripts_by_image(self, image: str) -> Dict[str, str]:
|
def scripts_by_image(self, image: str) -> Dict[str, str]:
|
||||||
scripts = {}
|
scripts = {}
|
||||||
for name, value in self._scripts.items():
|
for name, value in self._scripts.items():
|
||||||
@ -473,6 +478,14 @@ Dir::Etc::preferencesparts "/var/empty";
|
|||||||
)
|
)
|
||||||
image_path = self.image_path(image, branch, arch, kind)
|
image_path = self.image_path(image, branch, arch, kind)
|
||||||
self.copy_image(tarball, image_path)
|
self.copy_image(tarball, image_path)
|
||||||
|
for test in self.tests_by_image(image):
|
||||||
|
if not test_image(
|
||||||
|
image=image_path,
|
||||||
|
branch=branch,
|
||||||
|
arch=arch,
|
||||||
|
**test,
|
||||||
|
):
|
||||||
|
self.error(f'Test for {image} failed')
|
||||||
images_in_branch.append(image_path)
|
images_in_branch.append(image_path)
|
||||||
self.checksum_sign(images_in_branch)
|
self.checksum_sign(images_in_branch)
|
||||||
|
|
||||||
|
0
cloud_build/__init__.py
Normal file
0
cloud_build/__init__.py
Normal file
42
cloud_build/test_images/__init__.py
Normal file
42
cloud_build/test_images/__init__.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import contextlib
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from .lxd import test_lxd
|
||||||
|
from .docker import test_docker
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def pushtmpd():
|
||||||
|
previous_dir = os.getcwd()
|
||||||
|
tmpdir = tempfile.mkdtemp()
|
||||||
|
try:
|
||||||
|
os.chdir(tmpdir)
|
||||||
|
yield tmpdir
|
||||||
|
finally:
|
||||||
|
os.chdir(previous_dir)
|
||||||
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
|
def test_image(method, image, branch, arch):
|
||||||
|
if arch not in ['x86_64', 'i586']:
|
||||||
|
return True
|
||||||
|
|
||||||
|
with pushtmpd() as tmpdir:
|
||||||
|
image = shutil.copy(image, tmpdir)
|
||||||
|
image = os.path.basename(image)
|
||||||
|
if method == 'lxd':
|
||||||
|
commands = test_lxd(image)
|
||||||
|
elif method == 'docker':
|
||||||
|
commands = test_docker(image)
|
||||||
|
else:
|
||||||
|
raise Exception(f'Undefined test method {method}')
|
||||||
|
|
||||||
|
for command in commands:
|
||||||
|
rc = subprocess.call(command, shell=True)
|
||||||
|
if rc:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
27
cloud_build/test_images/docker.py
Normal file
27
cloud_build/test_images/docker.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
def test_docker(image: str) -> List[str]:
|
||||||
|
dockerfile = rf"""FROM scratch
|
||||||
|
ADD {image} /
|
||||||
|
|
||||||
|
RUN true > /etc/security/limits.d/50-defaults.conf
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y vim-console; \
|
||||||
|
rm -f /var/cache/apt/archives/*.rpm \
|
||||||
|
/var/cache/apt/*.bin \
|
||||||
|
/var/lib/apt/lists/*.*
|
||||||
|
|
||||||
|
CMD ["/bin/bash"]"""
|
||||||
|
|
||||||
|
with open('Dockerfile', 'w') as f:
|
||||||
|
f.write(dockerfile)
|
||||||
|
|
||||||
|
name = 'cloud_build_test_docker_image'
|
||||||
|
commands = [
|
||||||
|
f'docker build --rm --tag={name} .',
|
||||||
|
f'docker run --rm {name}',
|
||||||
|
f'docker image rm {name}',
|
||||||
|
]
|
||||||
|
|
||||||
|
return commands
|
5
cloud_build/test_images/lxd.py
Normal file
5
cloud_build/test_images/lxd.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
def test_lxd(image: str) -> List[str]:
|
||||||
|
return []
|
@ -28,12 +28,16 @@ images:
|
|||||||
target: ve/docker
|
target: ve/docker
|
||||||
kinds:
|
kinds:
|
||||||
- tar.xz
|
- tar.xz
|
||||||
|
tests:
|
||||||
|
- method: docker
|
||||||
no_scripts:
|
no_scripts:
|
||||||
- var
|
- var
|
||||||
rootfs-systemd:
|
rootfs-systemd:
|
||||||
target: ve/systemd-base
|
target: ve/systemd-base
|
||||||
kinds:
|
kinds:
|
||||||
- tar.xz
|
- tar.xz
|
||||||
|
tests:
|
||||||
|
- method: lxd
|
||||||
scripts:
|
scripts:
|
||||||
- securetty
|
- securetty
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user