-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support running Standard Test Interface tests via 'tmt'. Example of the workflow $ fedpkg clone python3 $ cd python3 $ tmt run -a provision -h virtual.testcloud execute -h sti Signed-off-by: Miroslav Vadkerti <mvadkert@redhat.com>
- Loading branch information
Showing
5 changed files
with
164 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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,108 @@ | ||
import os | ||
import click | ||
import tmt | ||
|
||
from tmt.utils import GeneralError | ||
|
||
# The default playbook used to run the tests | ||
DEFAULT_PLAYBOOK = 'tests/tests.yml' | ||
|
||
# Ansible inventory file required to run the tests | ||
ANSIBLE_INVENTORY = """ | ||
[localhost] | ||
sut ansible_host={hostname} ansible_user=root ansible_remote_tmp={remote_tmp} | ||
""" | ||
|
||
|
||
class ExecutorSTI(tmt.steps.execute.ExecutePlugin): | ||
""" Run tests using ansible according to Standard Test Interface spec """ | ||
_doc = """ | ||
Execute STI tests | ||
An inventory file is prepared according to the STI specification | ||
and ansible-playbook is used to run the given playbook. | ||
""" | ||
|
||
# Supported methods | ||
_methods = [ | ||
tmt.steps.Method( | ||
name='sti', doc=_doc, order=50), | ||
] | ||
|
||
@classmethod | ||
def options(cls, how=None): | ||
""" Prepare command line options for given method """ | ||
options = [] | ||
if how == 'sti': | ||
options.append(click.option( | ||
'-p', '--playbook', metavar='PLAYBOOK', | ||
help=f""" | ||
Ansible playbook to be run as a test. | ||
By default '{DEFAULT_PLAYBOOK}' | ||
""")) | ||
return options + super().options(how) | ||
|
||
def show(self): | ||
""" Show discover details """ | ||
super().show(['playbook']) | ||
|
||
def _playbook(self): | ||
if 'playbook' in self.data and self.data['playbook']: | ||
playbook = self.data['playbook'] | ||
else: | ||
playbook = DEFAULT_PLAYBOOK | ||
|
||
if not os.path.exists(playbook): | ||
raise GeneralError(f"Playbook '{playbook}' not found.") | ||
|
||
return playbook | ||
|
||
def _inventory(self, guest): | ||
""" Provides Ansible inventory compared to STI """ | ||
hostname = guest.guest or guest.container | ||
|
||
inventory_file = os.path.join( | ||
self.step.workdir, f'inventory-{hostname}') | ||
# Note that we have to force remote_tmp because in rootless container | ||
# it would default to '/root/.ansible/tmp' which is | ||
# not accessible by ordinary users | ||
inventory_content = ANSIBLE_INVENTORY.format( | ||
hostname=hostname, | ||
remote_tmp=os.path.expanduser('~/.ansible/tmp') | ||
) | ||
|
||
with open(inventory_file, 'w') as inventory: | ||
inventory.write(inventory_content) | ||
|
||
return inventory_file | ||
|
||
def wake(self): | ||
""" Wake up the plugin (override data with command line) """ | ||
|
||
value = self.opt('playbook') | ||
if value: | ||
self.data['playbook'] = value | ||
|
||
def go(self): | ||
""" Execute available tests """ | ||
super().go() | ||
|
||
# Nothing to do in dry mode | ||
if self.opt('dry'): | ||
self._results = [] | ||
return | ||
|
||
for guest in self.step.plan.provision.guests(): | ||
guest.ansible( | ||
self._playbook(), | ||
inventory=self._inventory(guest), | ||
options=f'-e artifacts={self.step.workdir}' | ||
) | ||
|
||
def results(self): | ||
""" Returns results from executed tests """ | ||
return [] | ||
|
||
def requires(self): | ||
""" No packages are required """ | ||
return [] |
This file contains 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 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