-
Notifications
You must be signed in to change notification settings - Fork 164
Fix flaky test, add retry to testcloud #4717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bajertom
wants to merge
2
commits into
main
Choose a base branch
from
tbajer-fix-flaky-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| ProvisionError, | ||
| ShellScript, | ||
| configure_constant, | ||
| retry, | ||
| retry_session, | ||
| ) | ||
| from tmt.utils.wait import Deadline, Waiting | ||
|
|
@@ -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, | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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("-") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.