chaos tests disrupt the cluster in different ways in order to build confidence in the robustness of OpenShift Virtualization.
To run the chaos tests:
uv run pytest <pytest_args> -m chaosuv run pytestTo see optional CLI arguments run:
uv run pytest --helpCLI arguments can be passed to pytest by setting them in pytest.ini.
You can either use the default pytest.ini file and pass CLI arguments or create a custom one.
For example, add the below under the addopts section:
--skip-artifactory-check
Then pass the path to the custom pytest.ini file to pytest:
uv run pytest -c custom-pytest.ini
To run a particular set of tests, you can use name pattern matching.
For example, to run all tests that contain test_clone_windows_vm or test_migrate_vm in their names:
uv run pytest <pytest_args> -k "test_clone_windows_vm or test_migrate_vm"To run all network component tests:
uv run pytest <pytest_args> -m networkYou can use marker matching to select tests based on their IP version type. The available markers are: ipv4 and ipv6. These markers are useful when running tests in an IPv4 or IPv6 single-stack cluster.
For example, to run only the IPV4 network tests:
uv run pytest -m "network and ipv4"You can also run all IPV4 network tests in addition to all the other general tests that are not specifically marked with IP version type marker:
uv run pytest -m "network and not ipv6"By default, cluster sanity checks are run to make cluster ready for tests.
To skip cluster sanity checks, pass --cluster-sanity-skip-check to skip all tests.
To skip specific node checks, pass --cluster-sanity-skip-nodes-check.
To skip specific storage checks, pass --cluster-sanity-skip-storage-check.
To skip virt specific checks, pass --skip-virt-sanity-check.
To skip tests which require access to internal images, pass --skip-artifactory-check.
To override the matrix value, you can create your own global_config file and pass the necessary parameters.
Example for AWS cluster:
--tc-file=tests/global_config_aws.py --storage-class-matrix=px-csi-db-shared
Example for SNO cluster:
--tc-file=tests/global_config_sno.py --storage-class-matrix=lvms-vg1
See Multi-Architecture Clusters.
To run tests with an admin client only, pass --tc=no_unprivileged_client:True to pytest.
Matrix fixtures can be added in global_config.py. You can run a test using a subset of a simple matrix (i.e flat list).
To run a test using a subset of a complex matrix (e.g list of dicts), you'll also need to add
the following to openshift-virtualization-tests/conftest.py
- Add
parser.addoptionunderpytest_addoption(the name must end with_matrix)
Multiple keys can be selected by passing them with ,
Available storage classes can be found in global_config.py under storage_class_matrix dictionary.
Example:
--storage-class-matrix=ocs-storagecluster-ceph-rbd-virtualization,hostpath-csi-basicUsing matrix fixtures requires providing a scope. Format:
<type>_matrix__<scope>__
Example:
storage_class_matrix__module__
storage_class_matrix__class__
You can customize existing matrix with function logic. For example, when tests need to run on storage matrix but only on storage with snapshot capabilities.
Add a desired function logic to pytest_matrix_utils.py
def foo_matrix(matrix):
<customize matrix code>
return matrix
Example:
storage_class_matrix_foo_matrix__module__
storage_class_matrix_foo_matrix__class__
Pytest_jira plugin allows you to link tests to existing tickets. To use the plugin during a test run, use '--jira.' Issues are considered as resolved if their status appears in resolved_statuses (verified, release pending, closed), that are set as an environment variable in openshift-virtualization-tests GitHub repository, and saved to the temporary file jira.cfg. You can mark a test to be skipped if a Jira issue is not resolved. Example:
@pytest.mark.jira("CNV-1234", run=False)
You can mark a test to be marked as xfail if a Jira issue is not resolved. Example:
@pytest.mark.jira("CNV-1234")
To use jira plugin, you need to set the following environment variables:
export PYTEST_JIRA_URL=<url>
export PYTEST_JIRA_TOKEN=<your_token>
export PYTEST_JIRA_USERNAME=<email> # email associated with the Jira accountThere are other parameters that can be passed to the test suite if needed.
--tc-file=tests/global_config.py
--tc-format=python
--cpu-arch=amd64
--junitxml /tmp/xunit_results.xml
--jiraLog file 'pytest-tests.log' is generated with the full pytest output in openshift-virtualization-tests root directory. For each test failure cluster log is collected and stored under 'tests-collected-info'.
To run a test with a log level that is different from the default, use the --log-cli-level command line switch. The full list of possible log level strings can be found here: https://docs.python.org/3/library/logging.html#logging-levels
When the switch is not used, we set the default level to INFO.
Example:
--log-cli-level=DEBUGTo see verbose logging of a test run, add the following parameter:
uv run pytest <test_to_run> -o log_cli=trueWhen you pass the --data-collector flag, openshift-virtualization-tests will gather must-gather archives, pexpect logs, and alert data for failure analysis. By default, collected logs land in:
tests-collected-info/for local runs/data/tests-collected-info/for containerized runs (i.e., when you’ve exported theCNV_TESTS_CONTAINERenvironment variable)
uv run pytest <test_to_run> --data-collectorIf you need to override the default output directory, use --data-collector-output-dir:
uv run pytest <test_to_run> \
--data-collector \
--data-collector-output-dir=<path/to/your/dir>To skip must-gather collection on a given module or test, skip_must_gather_collection can be used:
pytest.mark.skip_must_gather_collectionCheck containers/utility/README.md
ExecCommandOnPod is used to run command on nodes
workers_utility_pods and control_plane_utility_pods are fixtures that hold the pods.
pod_exec = ExecCommandOnPod(utility_pods=workers_utility_pods, node=node)
out = pod_exec.exec(command=cmd, ignore_rc=True)To run tests on a standard cluster configuration (more than 1 node is required), use the following command:
uv run pytest -m "conformance" --conformance-storage-class=<storage class name> --skip-artifactory-checkTo run on single-node cluster, use the following command:
uv run pytest -m "conformance and sno" --conformance-storage-class <storage class name> --skip-artifactory-checkSupported storage classes are mapped in StorageClassConfig.
An unsupported storage class can be used as well, and its configuration can be controlled via --conformance-storage-class-config.
If an attribute's value is not provided, the default value is used.
Supported storage class configuration:
`access_mode` - allowed values: RWX, RWO, ROX. Default: RWO
`volume_mode` - allowed values: Block, Filesystem. Default: Filesystem
`online_resize` - allowed values: False, True. Default: False
'snapshot' - allowed values: False, True. Default: False
`wffc` - allowed values: False, True. Default: False
uv run pytest -m "conformance" --conformance-storage-class=<unsupported storage class name> --conformance-storage-class-config='volume_mode=Block,access_mode=RWO,snapshot=True,online_resize=True,wffc=False' --skip-artifactory-check