Files
test/automated-pytest-suite/testfixtures/config_host.py
Yang Liu 33756ac899 Initial submission for starlingx pytest framework.
Include:
- util modules. such as table_parser, ssh/localhost clients, cli module,
exception, logger, etc. Util modules are mostly used by keywords.
- keywords modules. These are helper functions that are used directly by
test functions.
- platform (with platform or platform_sanity marker) and stx-openstack
(with sanity, sx_sanity, cpe_sanity, or storage_sanity marker) sanity
testcases
- pytest config conftest, and test fixture modules
- test config file template/example

Required packages:
- python3.4 or python3.5
- pytest >=3.10,<4.0
- pexpect
- requests
- pyyaml
- selenium (firefox, ffmpeg, pyvirtualdisplay, Xvfb or Xephyr or Xvnc)

Limitations:
- Anything that requires copying from Test File Server will not work until
a public share is configured to shared test files. Tests skipped for now.

Co-Authored-By: Maria Yousaf <maria.yousaf@windriver.com>
Co-Authored-By: Marvin Huang <marvin.huang@windriver.com>
Co-Authored-By: Yosief Gebremariam <yosief.gebremariam@windriver.com>
Co-Authored-By: Paul Warner <paul.warner@windriver.com>
Co-Authored-By: Xueguang Ma <Xueguang.Ma@windriver.com>
Co-Authored-By: Charles Chen <charles.chen@windriver.com>
Co-Authored-By: Daniel Graziano <Daniel.Graziano@windriver.com>
Co-Authored-By: Jordan Li <jordan.li@windriver.com>
Co-Authored-By: Nimalini Rasa <nimalini.rasa@windriver.com>
Co-Authored-By: Senthil Mukundakumar <senthil.mukundakumar@windriver.com>
Co-Authored-By: Anuejyan Manokeran <anujeyan.manokeran@windriver.com>
Co-Authored-By: Peng Peng <peng.peng@windriver.com>
Co-Authored-By: Chris Winnicki <chris.winnicki@windriver.com>
Co-Authored-By: Joe Vimar <Joe.Vimar@windriver.com>
Co-Authored-By: Alex Kozyrev <alex.kozyrev@windriver.com>
Co-Authored-By: Jack Ding <jack.ding@windriver.com>
Co-Authored-By: Ming Lei <ming.lei@windriver.com>
Co-Authored-By: Ankit Jain <ankit.jain@windriver.com>
Co-Authored-By: Eric Barrett <eric.barrett@windriver.com>
Co-Authored-By: William Jia <william.jia@windriver.com>
Co-Authored-By: Joseph Richard <Joseph.Richard@windriver.com>
Co-Authored-By: Aldo Mcfarlane <aldo.mcfarlane@windriver.com>

Story: 2005892
Task: 33750
Signed-off-by: Yang Liu <yang.liu@windriver.com>

Change-Id: I7a88a47e09733d39f024144530f5abb9aee8cad2
2019-07-15 15:30:00 -04:00

102 lines
2.9 KiB
Python

from pytest import fixture, mark
from utils.tis_log import LOG
from keywords import host_helper
from testfixtures.recover_hosts import HostsToRecover
@mark.tryfirst
@fixture(scope='module')
def config_host_module(request):
"""
Module level fixture to configure a host.
Setup:
- Lock a host
- Configure host
- Unlock host
Teardown (if revert_func is given):
- Lock host
- Run revert_func
- Unlock host
Args:
request: pytest param. caller of this func.
Returns (function): config_host_func.
Test or another fixture can execute it to pass the hostname,
modify_func, and revert_func
Examples:
see 'add_shared_cpu' fixture in nova/test_shared_cpu.py for usage.
"""
return __config_host_base(scope='module', request=request)
@mark.tryfirst
@fixture(scope='class')
def config_host_class(request):
"""
Class level fixture to configure a host.
Setup:
- Lock a host
- Configure host
- Unlock host
Teardown (if revert_func is given):
- Lock host
- Run revert_func
- Unlock host
Args:
request: pytest param. caller of this func.
Returns (function): config_host_func.
Test or another fixture can execute it to pass the hostname,
modify_func, and revert_func
Examples:
see 'add_shared_cpu' fixture in nova/test_shared_cpu.py for usage.
"""
return __config_host_base(scope='class', request=request)
def __config_host_base(scope, request):
def config_host_func(host, modify_func, revert_func=None, *args, **kwargs):
HostsToRecover.add(host, scope=scope)
LOG.fixture_step("({}) Lock host: {}".format(scope, host))
host_helper.lock_host(host=host, swact=True)
# add teardown before running modify (as long as host is locked
# successfully) in case modify or unlock fails.
if revert_func is not None:
def revert_host():
LOG.fixture_step("({}) Lock host: {}".format(scope, host))
host_helper.lock_host(host=host, swact=True)
try:
LOG.fixture_step("({}) Execute revert function: {}".format(
scope, revert_func))
revert_func(host)
finally:
LOG.fixture_step("({}) Unlock host: {}".format(scope, host))
# Put it in finally block in case revert_func fails -
# host will still be unlocked for other tests.
host_helper.unlock_host(host=host)
request.addfinalizer(revert_host)
LOG.fixture_step("({}) Execute modify function: {}".format(
scope, modify_func))
modify_func(host, *args, **kwargs)
LOG.fixture_step("({}) Unlock host: {}".format(scope, host))
host_helper.unlock_host(host=host)
return config_host_func