-
Notifications
You must be signed in to change notification settings - Fork 6
Implement fistpoint for smapi in tests #340
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
Nambrok
wants to merge
6
commits into
master
Choose a base branch
from
dtt-fp
base: master
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.
+196
−0
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2d62d64
feat(fistpoint): Add fistpoint interface in lib
Nambrok 4b14411
Add function lvs to Host
Nambrok 3410d57
Add size and resize on vdi
Nambrok 38026d3
Temporary fist tests for resize
Nambrok 2359991
Add a docstring for fistpoint
Nambrok b48046e
Address some comments
Nambrok 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import logging | ||
|
||
from lib.host import Host | ||
|
||
from typing import Final | ||
|
||
FISTPOINT_DIR: Final = "/tmp" | ||
LVHDRT_EXIT_FIST: Final = "fist_LVHDRT_exit" | ||
|
||
|
||
class FistPoint: | ||
""" | ||
A fistpoint is an action that you can enable in the smapi for tests. | ||
|
||
It allows for example, add a sleep at some point or raise an exception. | ||
For example: | ||
``` | ||
with FistPoint(vm.host, "blktap_activate_inject_failure"): | ||
with pytest.raises(SSHCommandFailed): | ||
vm.start() | ||
vm.shutdown(force=True) | ||
``` | ||
Activating the fistpoint `blktap_activate_inject_failure` mean that the VDI | ||
activation will fail. This fistpoint always raise an exception but most | ||
fistpoint just add a sleep at a point in the code. | ||
Using the fixture `exit_on_fistpoint` make all fistpoints raise an | ||
exception instead by enabling a special fistpoint called `fist_LVHDRT_exit` | ||
""" | ||
|
||
fistpointName: str | ||
|
||
def __init__(self, host: Host, name: str): | ||
self.fistpointName = self._get_name(name) | ||
self.host = host | ||
|
||
@staticmethod | ||
def enable_exit_on_fistpoint(host: Host): | ||
host.create_file(FistPoint._get_path(LVHDRT_EXIT_FIST), "") | ||
|
||
@staticmethod | ||
def disable_exit_on_fistpoint(host: Host): | ||
host.ssh(["rm", FistPoint._get_path(LVHDRT_EXIT_FIST)]) | ||
|
||
@staticmethod | ||
def _get_name(name: str) -> str: | ||
if name.startswith("fist_"): | ||
return name | ||
else: | ||
return f"fist_{name}" | ||
|
||
@staticmethod | ||
def _get_path(name) -> str: | ||
return f"{FISTPOINT_DIR}/{name}" | ||
|
||
def enable(self): | ||
logging.info(f"Enable fistpoint {self.fistpointName}") | ||
self.host.create_file(self._get_path(self.fistpointName), "") | ||
|
||
def disable(self): | ||
logging.info(f"Disabling fistpoint {self.fistpointName}") | ||
self.host.ssh(["rm", self._get_path(self.fistpointName)]) | ||
|
||
def __enter__(self): | ||
self.enable() | ||
return self | ||
|
||
def __exit__(self, *_): | ||
self.disable() |
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
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
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.