Refactor fixtures that check required files and settings
Refactor those fixtures in a more general way, so they can be used in any test, not only netchecker one. Just set class variables required_files and required_settings to use them In that way all required files and settings will be in the test class, and not in the fixture itself. Change-Id: I27eb98e46978205f4a4e9769e368d4720e2f8b55
This commit is contained in:
parent
b1fb1706d2
commit
493dc8b27a
|
@ -85,28 +85,21 @@ def k8scluster(revert_snapshot, request, config,
|
|||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def check_netchecker_files(request):
|
||||
files_missing = []
|
||||
for arg in request.cls.netchecker_files:
|
||||
if not os.path.isfile(arg):
|
||||
files_missing.append(arg)
|
||||
def check_files_missing(request):
|
||||
LOG.info("Required files: {}".format(request.cls.required_files))
|
||||
files_missing = [f for f in request.cls.required_files
|
||||
if not os.path.isfile(f)]
|
||||
assert len(files_missing) == 0, \
|
||||
("The following netchecker files not found: "
|
||||
"{0}!".format(', '.join(files_missing)))
|
||||
"Following files are not found {0}".format(files_missing)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def check_netchecker_images_settings():
|
||||
settings_missing = []
|
||||
for setting in ('MCP_NETCHECKER_AGENT_IMAGE_REPO',
|
||||
'MCP_NETCHECKER_AGENT_VERSION',
|
||||
'MCP_NETCHECKER_SERVER_IMAGE_REPO',
|
||||
'MCP_NETCHECKER_SERVER_VERSION'):
|
||||
if not getattr(settings, setting, None):
|
||||
settings_missing.append(setting)
|
||||
def check_settings_missing(request):
|
||||
LOG.info("Required settings: {}".format(request.cls.required_settings))
|
||||
settings_missing = [s for s in request.cls.required_settings
|
||||
if not getattr(settings, s, None)]
|
||||
assert len(settings_missing) == 0, \
|
||||
("The following environment variables are not set: "
|
||||
"{0}!".format(', '.join(settings_missing)))
|
||||
"Following env variables are not set {}". format(settings_missing)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
|
|
|
@ -27,6 +27,11 @@ LOG = logger.logger
|
|||
|
||||
class TestFuelCCPNetCheckerMixin:
|
||||
|
||||
required_settings = ('MCP_NETCHECKER_AGENT_IMAGE_REPO',
|
||||
'MCP_NETCHECKER_AGENT_VERSION',
|
||||
'MCP_NETCHECKER_SERVER_IMAGE_REPO',
|
||||
'MCP_NETCHECKER_SERVER_VERSION')
|
||||
|
||||
kube_settings = settings.DEFAULT_CUSTOM_YAML
|
||||
kube_settings['deploy_netchecker'] = False
|
||||
|
||||
|
@ -38,7 +43,7 @@ class TestFuelCCPNetCheckerMixin:
|
|||
'k8s_resources/netchecker-server_svc.yaml')
|
||||
ds_yaml_file = os.path.join(
|
||||
settings.NETCHECKER_AGENT_DIR, 'netchecker-agent.yaml')
|
||||
netchecker_files = (pod_yaml_file, svc_yaml_file, ds_yaml_file)
|
||||
required_files = (pod_yaml_file, svc_yaml_file, ds_yaml_file)
|
||||
|
||||
@property
|
||||
def pod_spec(self):
|
||||
|
@ -62,8 +67,7 @@ class TestFuelCCPNetCheckerMixin:
|
|||
return [i for i in yaml.load_all(ds_conf)]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("check_netchecker_files")
|
||||
@pytest.mark.usefixtures("check_netchecker_images_settings")
|
||||
@pytest.mark.usefixtures("check_files_missing", "check_settings_missing")
|
||||
class TestFuelCCPNetChecker(base_test.SystemBaseTest,
|
||||
TestFuelCCPNetCheckerMixin):
|
||||
"""Test class for network connectivity verification in k8s"""
|
||||
|
|
Loading…
Reference in New Issue