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.
Cherry-picked from df7a018ee2
Related: rhbz#1770193
This commit is contained in:
parent
8b8f5355bf
commit
c1609d7ffe
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import composertest
|
import composertest
|
||||||
@ -30,15 +31,47 @@ class TestImages(composertest.ComposerTestCase):
|
|||||||
|
|
||||||
@unittest.skip('Disabled due to issues with nested KVM')
|
@unittest.skip('Disabled due to issues with nested KVM')
|
||||||
class TestQcow2(composertest.ComposerTestCase):
|
class TestQcow2(composertest.ComposerTestCase):
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDownTestMachine()
|
||||||
|
|
||||||
def test_qcow2(self):
|
def test_qcow2(self):
|
||||||
self.runCliTest("/tests/cli/test_compose_qcow2.sh")
|
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")
|
||||||
|
|
||||||
|
|
||||||
@unittest.skip('Disabled due to issues with nested KVM')
|
@unittest.skip('Disabled due to issues with nested KVM')
|
||||||
class TestLiveIso(composertest.ComposerTestCase):
|
class TestLiveIso(composertest.ComposerTestCase):
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDownTestMachine()
|
||||||
|
|
||||||
def test_live_iso(self):
|
def test_live_iso(self):
|
||||||
self.runCliTest("/tests/cli/test_compose_live-iso.sh")
|
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 TestTar(composertest.ComposerTestCase):
|
class TestTar(composertest.ComposerTestCase):
|
||||||
def test_tar(self):
|
def test_tar(self):
|
||||||
|
@ -22,15 +22,20 @@ def print_exception(etype, value, tb):
|
|||||||
traceback.print_exception(etype, value, tb, limit=limit)
|
traceback.print_exception(etype, value, tb, limit=limit)
|
||||||
|
|
||||||
|
|
||||||
class ComposerTestCase(unittest.TestCase):
|
class VirtMachineTestCase(unittest.TestCase):
|
||||||
image = testvm.DEFAULT_IMAGE
|
|
||||||
sit = False
|
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.network = testvm.VirtNetwork(0)
|
||||||
self.machine = testvm.VirtMachine(self.image, networking=self.network.host(), memory_mb=3072)
|
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.start()
|
||||||
self.machine.wait_boot()
|
self.machine.wait_boot()
|
||||||
|
|
||||||
@ -45,15 +50,7 @@ class ComposerTestCase(unittest.TestCase):
|
|||||||
print(" ".join(self.ssh_command))
|
print(" ".join(self.ssh_command))
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print("Waiting for lorax-composer to become ready...")
|
def tearDownTestMachine(self):
|
||||||
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):
|
|
||||||
if os.environ.get('TEST_ATTACHMENTS'):
|
if os.environ.get('TEST_ATTACHMENTS'):
|
||||||
self.machine.download_dir('/var/log/tests', os.environ.get('TEST_ATTACHMENTS'))
|
self.machine.download_dir('/var/log/tests', os.environ.get('TEST_ATTACHMENTS'))
|
||||||
|
|
||||||
@ -78,6 +75,35 @@ class ComposerTestCase(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
return subprocess.run(self.ssh_command + command, **args)
|
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):
|
def runCliTest(self, script):
|
||||||
extra_env = []
|
extra_env = []
|
||||||
if self.sit:
|
if self.sit:
|
||||||
@ -90,6 +116,16 @@ class ComposerTestCase(unittest.TestCase):
|
|||||||
"/tests/test_cli.sh", script])
|
"/tests/test_cli.sh", script])
|
||||||
self.assertEqual(r.returncode, 0)
|
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):
|
class ComposerTestResult(unittest.TestResult):
|
||||||
def name(self, test):
|
def name(self, test):
|
||||||
|
Loading…
Reference in New Issue
Block a user