test: Split up the test class to allow booting other images
This splits out the lorax-composer specific execution so that the built image can be downloaded from the build vm and booted by the host instead of using nested virt to try and boot it inside the build vm. Also adds copying the ssh key from the build vm so that it can log into the image and run the test_boot_* scripts.
This commit is contained in:
parent
b8bf258a3c
commit
df7a018ee2
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import tempfile
|
||||
import unittest
|
||||
import composertest
|
||||
|
||||
@ -28,14 +29,47 @@ class TestImages(composertest.ComposerTestCase):
|
||||
|
||||
|
||||
class TestQcow2(composertest.ComposerTestCase):
|
||||
def tearDown(self):
|
||||
super().tearDownTestMachine()
|
||||
|
||||
def test_qcow2(self):
|
||||
self.runCliTest("/tests/cli/test_compose_qcow2.sh")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="/var/tmp/lorax-test.") as tmpdir:
|
||||
# Copy the resulting qcow2 image and shut down the VM
|
||||
self.tearDownVirt(virt_dir="/var/tmp/test-results/*", local_dir=tmpdir)
|
||||
|
||||
# Boot the image
|
||||
self.setUpTestMachine(tmpdir + "/disk.qcow2", tmpdir + "/id_rsa")
|
||||
|
||||
# Upload the contents of the ./tests/ directory to the machine
|
||||
self.machine.upload(["../tests"], "/")
|
||||
|
||||
# Run the test, on the booted image
|
||||
self.runImageTest("/tests/cli/test_boot_qcow2.sh")
|
||||
|
||||
|
||||
class TestLiveIso(composertest.ComposerTestCase):
|
||||
def tearDown(self):
|
||||
super().tearDownTestMachine()
|
||||
|
||||
def test_live_iso(self):
|
||||
self.runCliTest("/tests/cli/test_compose_live-iso.sh")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="/var/tmp/lorax-test.") as tmpdir:
|
||||
# Copy the resulting iso and shut down the VM
|
||||
self.tearDownVirt(virt_dir="/var/tmp/test-results/*", local_dir=tmpdir)
|
||||
|
||||
# Boot the image
|
||||
self.setUpTestMachine(tmpdir + "/live.iso")
|
||||
|
||||
# Upload the contents of the ./tests/ directory to the machine
|
||||
self.machine.upload(["../tests"], "/")
|
||||
|
||||
# Run the test, on the booted image
|
||||
self.runImageTest("/tests/cli/test_boot_live-iso.sh")
|
||||
|
||||
|
||||
class TestRepos(composertest.ComposerTestCase):
|
||||
def test_repos_sanity(self):
|
||||
self.runCliTest("/tests/cli/test_repos_sanity.sh")
|
||||
|
@ -23,15 +23,20 @@ def print_exception(etype, value, tb):
|
||||
traceback.print_exception(etype, value, tb, limit=limit)
|
||||
|
||||
|
||||
class ComposerTestCase(unittest.TestCase):
|
||||
image = testvm.DEFAULT_IMAGE
|
||||
class VirtMachineTestCase(unittest.TestCase):
|
||||
sit = False
|
||||
network = None
|
||||
machine = None
|
||||
ssh_command = None
|
||||
|
||||
def setUp(self):
|
||||
def setUpTestMachine(self, image, identity_file=None):
|
||||
self.network = testvm.VirtNetwork(0)
|
||||
self.machine = testvm.VirtMachine(self.image, networking=self.network.host(), memory_mb=2048)
|
||||
if identity_file:
|
||||
self.machine = testvm.VirtMachine(image, networking=self.network.host(), cpus=2, memory_mb=2048, identity_file=identity_file)
|
||||
else:
|
||||
self.machine = testvm.VirtMachine(image, networking=self.network.host(), cpus=2, memory_mb=2048)
|
||||
|
||||
print("Starting virtual machine '{}'".format(self.image))
|
||||
print("Starting virtual machine '{}'".format(image))
|
||||
self.machine.start()
|
||||
self.machine.wait_boot()
|
||||
|
||||
@ -46,15 +51,7 @@ class ComposerTestCase(unittest.TestCase):
|
||||
print(" ".join(self.ssh_command))
|
||||
print()
|
||||
|
||||
print("Waiting for lorax-composer to become ready...")
|
||||
curl_command = ["curl", "--max-time", "360",
|
||||
"--silent",
|
||||
"--unix-socket", "/run/weldr/api.socket",
|
||||
"http://localhost/api/status"]
|
||||
r = subprocess.run(self.ssh_command + curl_command, stdout=subprocess.DEVNULL)
|
||||
self.assertEqual(r.returncode, 0)
|
||||
|
||||
def tearDown(self):
|
||||
def tearDownTestMachine(self):
|
||||
if os.environ.get('TEST_ATTACHMENTS'):
|
||||
self.machine.download_dir('/var/log/tests', os.environ.get('TEST_ATTACHMENTS'))
|
||||
|
||||
@ -79,6 +76,35 @@ class ComposerTestCase(unittest.TestCase):
|
||||
"""
|
||||
return subprocess.run(self.ssh_command + command, **args)
|
||||
|
||||
|
||||
class ComposerTestCase(VirtMachineTestCase):
|
||||
def setUp(self):
|
||||
self.setUpTestMachine(testvm.DEFAULT_IMAGE)
|
||||
|
||||
# Upload the contents of the ./tests/ directory to the machine (it must have beakerlib already installed)
|
||||
self.machine.upload(["../tests"], "/")
|
||||
|
||||
print("Waiting for lorax-composer to become ready...")
|
||||
curl_command = ["curl", "--max-time", "360",
|
||||
"--silent",
|
||||
"--unix-socket", "/run/weldr/api.socket",
|
||||
"http://localhost/api/status"]
|
||||
r = subprocess.run(self.ssh_command + curl_command, stdout=subprocess.DEVNULL)
|
||||
self.assertEqual(r.returncode, 0)
|
||||
|
||||
def tearDown(self):
|
||||
self.tearDownVirt()
|
||||
|
||||
def tearDownVirt(self, virt_dir=None, local_dir=None):
|
||||
if os.environ.get('TEST_ATTACHMENTS'):
|
||||
self.machine.download_dir('/var/log/tests', os.environ.get('TEST_ATTACHMENTS'))
|
||||
|
||||
if virt_dir and local_dir:
|
||||
self.machine.download_dir(virt_dir, local_dir)
|
||||
|
||||
self.tearDownTestMachine()
|
||||
return local_dir
|
||||
|
||||
def runCliTest(self, script):
|
||||
extra_env = []
|
||||
if self.sit:
|
||||
@ -91,6 +117,16 @@ class ComposerTestCase(unittest.TestCase):
|
||||
"/tests/test_cli.sh", script])
|
||||
self.assertEqual(r.returncode, 0)
|
||||
|
||||
def runImageTest(self, script):
|
||||
extra_env = []
|
||||
if self.sit:
|
||||
extra_env.append("COMPOSER_TEST_FAIL_FAST=1")
|
||||
|
||||
r = self.execute(["TEST=" + self.id(),
|
||||
*extra_env,
|
||||
"/tests/test_image.sh", script])
|
||||
self.assertEqual(r.returncode, 0)
|
||||
|
||||
|
||||
class ComposerTestResult(unittest.TestResult):
|
||||
def name(self, test):
|
||||
|
Loading…
Reference in New Issue
Block a user