Skip to content

Commit

Permalink
fix unittest: test_pytest.py
Browse files Browse the repository at this point in the history
Signed-off-by: vavuthu <vavuthu@redhat.com>
  • Loading branch information
vavuthu authored and fbalak committed Jun 14, 2024
1 parent 350f51c commit 48d7a6f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
13 changes: 13 additions & 0 deletions ocs_ci/framework/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ def process_ocsci_conf(arguments):

args, unknown = parser.parse_known_args(args=arguments)
load_config(args.ocsci_conf)
if unknown:
for each_arg in unknown:
if each_arg.startswith("--cluster-path"):
if "=" in each_arg:
framework.config.ENV_DATA["cluster_path"] = each_arg.split("=", 1)[
1
]
else:
cluster_path_position = unknown.index("--cluster-path")
framework.config.ENV_DATA["cluster_path"] = unknown[
cluster_path_position + 1
]
break
ocs_version = args.ocs_version or framework.config.ENV_DATA.get("ocs_version")
ocp_version = args.ocp_version or framework.config.ENV_DATA.get("ocp_version")
ocs_registry_image = framework.config.DEPLOYMENT.get("ocs_registry_image")
Expand Down
3 changes: 3 additions & 0 deletions ocs_ci/framework/pytest_customization/ocscilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ def process_cluster_cli_params(config):
ocsci_config.RUN["resource_checker"] = resource_checker
custom_kubeconfig_location = get_cli_param(config, "kubeconfig")
ocsci_config.RUN["custom_kubeconfig_location"] = custom_kubeconfig_location
if custom_kubeconfig_location:
os.environ["KUBECONFIG"] = custom_kubeconfig_location
ocsci_config.RUN["kubeconfig"] = custom_kubeconfig_location


def pytest_collection_modifyitems(session, config, items):
Expand Down
58 changes: 29 additions & 29 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,20 @@ def environment_checker(request):
log.debug("Skipping environment checker")
return

node = request.node
# List of marks for which we will ignore the leftover checker
marks_to_ignore = [m.mark for m in [deployment, ignore_leftovers]]
# app labels of resources to be excluded for leftover check
exclude_labels = [
constants.must_gather_pod_label,
constants.S3CLI_APP_LABEL,
constants.MUST_GATHER_HELPER_LABEL,
]
for mark in node.iter_markers():
if mark in marks_to_ignore:
return
if mark.name == ignore_leftover_label.name:
exclude_labels.extend(list(mark.args))
if ocsci_config.ENV_DATA["platform"] in {
constants.FUSIONAAS_PLATFORM,
constants.HCI_BAREMETAL,
Expand All @@ -1819,7 +1833,6 @@ def environment_checker(request):
"This needs to be updated"
)
else:
exclude_labels = get_exclude_labels(request)
request.addfinalizer(
partial(get_status_after_execution, exclude_labels=exclude_labels)
)
Expand All @@ -1833,32 +1846,6 @@ def resource_checker(request):
return

create_resource_dct()
if ocsci_config.ENV_DATA["platform"] in {
constants.FUSIONAAS_PLATFORM,
constants.HCI_BAREMETAL,
constants.HCI_VSPHERE,
}:
log.error(
"Environment checker is NOT IMPLEMENTED for Fusion service and provider/client hci setup."
"This needs to be updated"
)
else:
exclude_labels = get_exclude_labels(request)
request.addfinalizer(
lambda: get_environment_status_after_execution(
exclude_labels=exclude_labels
)
)


def get_exclude_labels(request):
"""
Gets the labels which should be excluded for left over checks
Returns:
list: List of exclude labels
"""
node = request.node
# List of marks for which we will ignore the leftover checker
marks_to_ignore = [m.mark for m in [deployment, ignore_leftovers]]
Expand All @@ -1873,8 +1860,21 @@ def get_exclude_labels(request):
return
if mark.name == ignore_leftover_label.name:
exclude_labels.extend(list(mark.args))

return exclude_labels
if ocsci_config.ENV_DATA["platform"] in {
constants.FUSIONAAS_PLATFORM,
constants.HCI_BAREMETAL,
constants.HCI_VSPHERE,
}:
log.error(
"Resource checker is NOT IMPLEMENTED for Fusion service and provider/client hci setup."
"This needs to be updated"
)
else:
request.addfinalizer(
lambda: get_environment_status_after_execution(
exclude_labels=exclude_labels
)
)


@pytest.fixture(scope="session")
Expand Down

0 comments on commit 48d7a6f

Please sign in to comment.