Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/try/basic/data/action.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ foreach arg $argv {
send -- "$arg\r"
}

# Make sure we wait for some output and timeout quickly
set timeout 1
# Wait for the next prompt after the action completes
expect "What do we do next?"
send -- "q\r"
set timeout 3
expect eof
63 changes: 50 additions & 13 deletions tmt/steps/provision/testcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
ProvisionError,
ShellScript,
configure_constant,
retry,
retry_session,
)
from tmt.utils.wait import Deadline, Waiting
Expand Down Expand Up @@ -218,6 +219,10 @@ def import_testcloud(logger: tmt.log.Logger) -> None:
IMAGE_URL_FETCH_RETRY_ATTEMPTS = 5
IMAGE_URL_FETCH_RETRY_INTERVAL = 5

#: Image prepare retry attempts and interval
IMAGE_PREPARE_RETRY_ATTEMPTS = 3
IMAGE_PREPARE_RETRY_INTERVAL = 5


def normalize_memory_size(
key_address: str,
Expand Down Expand Up @@ -1113,22 +1118,54 @@ def start(self) -> None:
# Adjust selinux tags for the actual image
testcloud.image.Image._adjust_image_selinux(image_path)

# Initialize and prepare testcloud image
self._image = testcloud.image.Image(self.image_url)
self.verbose('qcow', self._image.name, 'green')
if not Path(self._image.local_path).exists():
self.info('progress', 'downloading...', 'cyan')
# Initialize and prepare testcloud image with validation and retry.
# Testcloud does not check the qemu-img return code when creating
# an overlay, so a corrupt base image causes a confusing libvirt
# error later. Validate the image after download and retry if needed.
def prepare_image() -> None:
self._image = testcloud.image.Image(self.image_url)
self.verbose('qcow', self._image.name, 'green')
if not Path(self._image.local_path).exists():
self.info('progress', 'downloading...', 'cyan')
try:
self._image.prepare()
except FileNotFoundError as error:
raise ProvisionError(f"Image '{self._image.local_path}' not found.") from error
except (testcloud.exceptions.TestcloudPermissionsError, PermissionError) as error:
raise ProvisionError(
f"Failed to prepare the image. Check the "
f"'{self.testcloud_image_dirpath}' directory permissions."
) from error
except KeyError as error:
raise ProvisionError(f"Failed to prepare image '{self.image_url}'.") from error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any of these exceptions occur, the function will get retried by rety(). Do they have a chance of succeeding if retried? If not, only 15 seconds are wasted, so it doesn't seem like a huge deal. Just wondering if it was intended that these would also cause retries.


# Validate the base image is a proper qcow2 file
image_path = Path(self._image.local_path)
try:
Command("qemu-img", "info", str(image_path)).run(
cwd=Path.cwd(),
logger=self._logger,
)
except tmt.utils.RunError as error:
if image_path.exists():
self.debug(f"Removing corrupt image '{image_path}'.")
image_path.unlink()
raise ProvisionError(
f"Image '{image_path}' is not a valid qcow2 image."
) from error

try:
self._image.prepare()
except FileNotFoundError as error:
raise ProvisionError(f"Image '{self._image.local_path}' not found.") from error
except (testcloud.exceptions.TestcloudPermissionsError, PermissionError) as error:
retry(
func=prepare_image,
attempts=IMAGE_PREPARE_RETRY_ATTEMPTS,
interval=IMAGE_PREPARE_RETRY_INTERVAL,
label=f"Prepare image '{self.image_url}'",
logger=self._logger,
)
except tmt.utils.RetryError as error:
raise ProvisionError(
f"Failed to prepare the image. Check the '{self.testcloud_image_dirpath}' "
f"directory permissions."
f"Failed to prepare a valid image after {IMAGE_PREPARE_RETRY_ATTEMPTS} attempts."
) from error
except KeyError as error:
raise ProvisionError(f"Failed to prepare image '{self.image_url}'.") from error

# Prepare hostname (get rid of possible unwanted characters)
hostname = re.sub(r"[^a-zA-Z0-9\-]+", "-", self.name.lower()).strip("-")
Expand Down
Loading