image-info: add test
Add two kinds of tests, with one case each: 1. Run image-info against an osbuild pipeline. Uses osbuild from a submodule to make an image from the pipeline. 2. Run image-info against an existing image, fetched from the internet.
This commit is contained in:
parent
2854b2938e
commit
329964f2ab
8 changed files with 4020 additions and 7 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
|||
__pycache__
|
||||
|
||||
/osbuild-composer
|
||||
/osbuild-worker
|
||||
|
|
|
|||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "osbuild"]
|
||||
path = osbuild
|
||||
url = https://github.com/osbuild/osbuild.git
|
||||
29
.travis.yml
29
.travis.yml
|
|
@ -1,7 +1,22 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.12.x
|
||||
env:
|
||||
- GO111MODULE=on # needed even for Go 1.12
|
||||
script:
|
||||
- go test -v ./...
|
||||
dist: bionic
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- systemd-container
|
||||
- qemu-utils
|
||||
- yum
|
||||
- gnupg2
|
||||
matrix:
|
||||
include:
|
||||
- language: go
|
||||
go: 1.12.x
|
||||
env: GO111MODULE=on # needed even for Go 1.12
|
||||
script: go test -v ./...
|
||||
|
||||
- language: python
|
||||
python: 3.7
|
||||
env: PYTHONUNBUFFERED=1
|
||||
script:
|
||||
# ubuntu's rpm package sets dbpath to ~/.rpmdb, which makes rpm fail...
|
||||
- sudo sh -c 'mkdir /etc/rpm; echo "%_dbpath /var/lib/rpm" > /etc/rpm/macros'
|
||||
- sudo env "PATH=$PATH" "OSBUILD_TEST_BUILD_PIPELINE=tools/test_image_info/build-from-yum.json" python3 -m unittest tools.test_image_info
|
||||
|
|
|
|||
1
osbuild
Submodule
1
osbuild
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit cd49e2407c83f7fcdf30566af5f7ab470d801e19
|
||||
81
tools/test_image_info/__init__.py
Normal file
81
tools/test_image_info/__init__.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
import urllib.request
|
||||
|
||||
|
||||
TEST_DIR = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def json_files(path):
|
||||
"""Reads .json files in path and yields (name, blob) for each of them."""
|
||||
for entry in os.scandir(path):
|
||||
name, ext = os.path.splitext(entry.name)
|
||||
if ext == ".json":
|
||||
with open(entry.path) as f:
|
||||
data = json.load(f)
|
||||
yield name, data
|
||||
|
||||
|
||||
class TestImageInfo(unittest.TestCase):
|
||||
"""Tests for image-info
|
||||
|
||||
All tests share the same osbuild store to make running them more efficient.
|
||||
That's ok, because we're not testing osbuild itself.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.store = tempfile.mkdtemp(dir="/var/tmp", prefix="osbuild-composer-test-")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
shutil.rmtree(cls.store)
|
||||
|
||||
def run_osbuild(self, pipeline, input=None):
|
||||
osbuild_cmd = ["python3", "-m", "osbuild", "--json", "--libdir", ".", "--store", self.store, pipeline]
|
||||
|
||||
build_pipeline = os.getenv("OSBUILD_TEST_BUILD_PIPELINE", None)
|
||||
if build_pipeline:
|
||||
osbuild_cmd.append("--build-pipeline")
|
||||
osbuild_cmd.append(os.path.abspath(build_pipeline))
|
||||
|
||||
result = json.loads(subprocess.check_output(osbuild_cmd, cwd="./osbuild", encoding="utf-8", input=input))
|
||||
return result["tree_id"], result["output_id"]
|
||||
|
||||
def run_image_info(self, image):
|
||||
return json.loads(subprocess.check_output(["tools/image-info", image]))
|
||||
|
||||
def test_pipelines(self):
|
||||
"""Run image-info against an image generated by an osbuild pipepline
|
||||
|
||||
The test case should have these keys:
|
||||
"pipeline": the pipeline to run, which should have an assembler
|
||||
with a "filename" option
|
||||
"expected": the expected output from image-info
|
||||
"""
|
||||
for name, case in json_files(f"{TEST_DIR}/pipelines"):
|
||||
with self.subTest(name):
|
||||
_, output_id = self.run_osbuild("-", input=json.dumps(case["pipeline"]))
|
||||
filename = os.path.join(self.store, "refs", output_id, case["pipeline"]["assembler"]["options"]["filename"])
|
||||
info = self.run_image_info(filename)
|
||||
self.assertEqual(info, case["expected"])
|
||||
|
||||
def test_images(self):
|
||||
"""Run image-info against an image from the web
|
||||
|
||||
The test case should have these keys:
|
||||
"url": the url at which to find the image
|
||||
"expected": the expected output from image-info
|
||||
"""
|
||||
for name, case in json_files(f"{TEST_DIR}/images"):
|
||||
with self.subTest(name):
|
||||
try:
|
||||
filename, _ = urllib.request.urlretrieve(case["url"])
|
||||
info = self.run_image_info(filename)
|
||||
self.assertEqual(info, case["expected"])
|
||||
finally:
|
||||
urllib.request.urlcleanup()
|
||||
23
tools/test_image_info/build-from-yum.json
Normal file
23
tools/test_image_info/build-from-yum.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"stages": [
|
||||
{
|
||||
"name": "org.osbuild.yum",
|
||||
"options": {
|
||||
"releasever": "27",
|
||||
"basearch": "x86_64",
|
||||
"repos": [
|
||||
{
|
||||
"baseurl": "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/$releasever/Everything/$basearch/os/",
|
||||
"gpgkey": "860E 19B0 AFA8 00A1 7518 81A6 F55E 7430 F528 2EE4"
|
||||
}
|
||||
],
|
||||
"packages": [
|
||||
"dnf",
|
||||
"systemd",
|
||||
"tar",
|
||||
"gnupg"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
3830
tools/test_image_info/images/fedora-30-cloud-base.json
Normal file
3830
tools/test_image_info/images/fedora-30-cloud-base.json
Normal file
File diff suppressed because it is too large
Load diff
58
tools/test_image_info/pipelines/empty-qcow2.json
Normal file
58
tools/test_image_info/pipelines/empty-qcow2.json
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
"pipeline": {
|
||||
"build": {
|
||||
"stages": [
|
||||
{
|
||||
"name": "org.osbuild.dnf",
|
||||
"options": {
|
||||
"releasever": "30",
|
||||
"basearch": "x86_64",
|
||||
"install_weak_deps": false,
|
||||
"repos": [
|
||||
{
|
||||
"metalink": "https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch",
|
||||
"gpgkey": "F1D8 EC98 F241 AAF2 0DF6 9420 EF3C 111F CFC6 59B9",
|
||||
"checksum": "sha256:9f596e18f585bee30ac41c11fb11a83ed6b11d5b341c1cb56ca4015d7717cb97"
|
||||
}
|
||||
],
|
||||
"packages": [
|
||||
"dnf",
|
||||
"e2fsprogs",
|
||||
"grub2-pc",
|
||||
"policycoreutils",
|
||||
"qemu-img",
|
||||
"systemd"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"assembler": {
|
||||
"name": "org.osbuild.qemu",
|
||||
"options": {
|
||||
"filename": "empty.qcow2",
|
||||
"format": "qcow2",
|
||||
"root_fs_uuid": "ef157bb8-5c6f-4f10-a275-24f92e8c6370",
|
||||
"ptuuid": "4ca14fe5-cccf-4780-9fc6-a2b387d3b703",
|
||||
"size": 10485760
|
||||
}
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"bootloader": "grub",
|
||||
"image-format": "qcow2",
|
||||
"partition-table": "dos",
|
||||
"partition-table-id": "0x4ca14fe5",
|
||||
"partitions": [
|
||||
{
|
||||
"bootable": true,
|
||||
"fstype": "ext4",
|
||||
"label": null,
|
||||
"size": 9437184,
|
||||
"start": 1048576,
|
||||
"type": "83",
|
||||
"uuid": "ef157bb8-5c6f-4f10-a275-24f92e8c6370"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue