Skip to content

Commit

Permalink
testlib: force use of prepared images
Browse files Browse the repository at this point in the history
For images not explicitly specified by a provision, and in case
--machine wasn't given, assume that we want to use an image created by
test/image-prepare.

Throw an early exception with a useful message, for ourselves, if it
doesn't exist.

Note that passing a pathname as the image name is explicitly supported,
and the basename (without extension) will be used for setting the
Machine.image variable.
  • Loading branch information
allisonkarlitskaya committed Jun 15, 2021
1 parent 737881c commit 8a9787d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,15 +853,17 @@ def label(self):

def new_machine(self, image=None, forward={}, restrict=True, cleanup=True, **kwargs):
machine_class = self.machine_class
if image is None:
image = self.image
if opts.address:
if machine_class or forward:
raise unittest.SkipTest("Cannot run this test when specific machine address is specified")
machine = testvm.Machine(address=opts.address, image=image, verbose=opts.trace, browser=opts.browser)
machine = testvm.Machine(address=opts.address, image=image or self.image, verbose=opts.trace, browser=opts.browser)
if cleanup:
self.addCleanup(machine.disconnect)
else:
if image is None:
image = os.path.join(TEST_DIR, "images", self.image)
if not os.path.exists(image):
raise FileNotFoundError("Can't run tests without a prepared image; use test/image-prepare")
if not machine_class:
machine_class = testvm.VirtMachine
if not self.network:
Expand Down

0 comments on commit 8a9787d

Please sign in to comment.