mirror of
https://github.com/VinylDNS/vinyldns
synced 2025-08-22 02:02:14 +00:00
Major overhaul of func tests to allow them to run in parallel. Major changes include: 1. Consolidate all separate test fixtures into a single test fixture in the `shared_zone_test_context` 1. Add `xdist` to allow running tests in parallel 1. Add hooks in main `conftest.py` to setup the test fixture before workers run, and tear it down when workers are finished 1. After fixture is setup, save state in a local `tmp.out` so the workers will use that state instead of trying to recreate the fixture. 1. Add a `utils.generate_record_name` which generates a unique record name in order to avoid conflicts when running tests in parallel 1. Add a `pytest.mark.serial` for func tests that just cannot be run in serial 1. Tests are now run in two phases, first we run in parallel, and if that is successful, we run the serial tests 1. Add a `--teardown` flag, this allows us to reuse the test fixture between the two phases parallel and serial
104 lines
4.4 KiB
Python
104 lines
4.4 KiB
Python
import os
|
|
|
|
from vinyldns_context import VinylDNSTestContext
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
"""
|
|
Adds additional options that we can parse when we run the tests, stores them in the parser / py.test context
|
|
"""
|
|
parser.addoption("--url", dest="url", action="store", default="http://localhost:9000",
|
|
help="URL for application to root")
|
|
parser.addoption("--dns-ip", dest="dns_ip", action="store", default="127.0.0.1:19001",
|
|
help="The ip address for the dns server to use for the tests")
|
|
parser.addoption("--dns-zone", dest="dns_zone", action="store", default="vinyldns.",
|
|
help="The zone name that will be used for testing")
|
|
parser.addoption("--dns-key-name", dest="dns_key_name", action="store", default="vinyldns.",
|
|
help="The name of the key used to sign updates for the zone")
|
|
parser.addoption("--dns-key", dest="dns_key", action="store", default="nzisn+4G2ldMn0q1CV3vsg==",
|
|
help="The tsig key")
|
|
|
|
# optional
|
|
parser.addoption("--basic-auth", dest="basic_auth_creds",
|
|
help="Basic auth credentials in 'user:pass' format")
|
|
parser.addoption("--basic-auth-realm", dest="basic_auth_realm",
|
|
help="Basic auth realm to use with credentials supplied by \"-b\"")
|
|
parser.addoption("--iauth-creds", dest="iauth_creds",
|
|
help="Intermediary auth (codebig style) in 'key:secret' format")
|
|
parser.addoption("--oauth-creds", dest="oauth_creds",
|
|
help="OAuth credentials in consumer:secret format")
|
|
parser.addoption("--environment", dest="cim_env", action="store", default="test",
|
|
help="CIM_ENV that we are testing against.")
|
|
parser.addoption("--teardown", dest="teardown", action="store", default="True",
|
|
help="True | False - Whether to teardown the test fixture, or leave it for another run")
|
|
|
|
|
|
def pytest_configure(config):
|
|
"""
|
|
Loads the test context since we are no longer using run.py
|
|
"""
|
|
|
|
# Monkey patch ssl so we do not verify ssl certs
|
|
import ssl
|
|
try:
|
|
_create_unverified_https_context = ssl._create_unverified_context
|
|
except AttributeError:
|
|
# Legacy Python that doesn't verify HTTPS certificates by default
|
|
pass
|
|
else:
|
|
# Handle target environment that doesn't support HTTPS verification
|
|
ssl._create_default_https_context = _create_unverified_https_context
|
|
|
|
url = config.getoption("url", default="http://localhost:9000/")
|
|
if not url.endswith('/'):
|
|
url += '/'
|
|
|
|
import sys
|
|
sys.dont_write_bytecode = True
|
|
|
|
VinylDNSTestContext.configure(config.getoption("dns_ip"),
|
|
config.getoption("dns_zone"),
|
|
config.getoption("dns_key_name"),
|
|
config.getoption("dns_key"),
|
|
config.getoption("url"),
|
|
config.getoption("teardown"))
|
|
|
|
from shared_zone_test_context import SharedZoneTestContext
|
|
if not hasattr(config, 'workerinput'):
|
|
print 'Master, standing up the test fixture...'
|
|
# use the fixture file if it exists
|
|
if os.path.isfile('tmp.out'):
|
|
print 'Fixture file found, assuming the fixture file'
|
|
SharedZoneTestContext('tmp.out')
|
|
else:
|
|
print 'No fixture file found, loading a new test fixture'
|
|
ctx = SharedZoneTestContext()
|
|
ctx.out_fixture_file("tmp.out")
|
|
else:
|
|
print 'This is a worker'
|
|
|
|
|
|
def pytest_unconfigure(config):
|
|
# this attribute is only set on workers
|
|
print 'Master exiting...'
|
|
if not hasattr(config, 'workerinput') and VinylDNSTestContext.teardown:
|
|
print 'Master cleaning up...'
|
|
from shared_zone_test_context import SharedZoneTestContext
|
|
ctx = SharedZoneTestContext('tmp.out')
|
|
ctx.tear_down()
|
|
os.remove('tmp.out')
|
|
else:
|
|
print 'Worker exiting...'
|
|
|
|
|
|
def pytest_report_header(config):
|
|
"""
|
|
Overrides the test result header like we do in pyfunc test
|
|
"""
|
|
header = "Testing against CIM_ENV " + config.getoption("cim_env")
|
|
header += "\r\nURL: " + config.getoption("url")
|
|
header += "\r\nRunning from directory " + os.getcwd()
|
|
header += '\r\nTest shim directory ' + os.path.dirname(__file__)
|
|
header += "\r\nDNS IP: " + config.getoption("dns_ip")
|
|
return header
|