This repository contains tests.
The infra for the tests can be found in https://github.com/RedHatQE/openshift-python-wrapper and https://github.com/RedHatQE/openshift-python-utilities flake8 plugins defined in .flake8 can be found in https://github.com/RedHatQE/flake8-plugins
Use poetry to manage virtualenv.
pip install poetry
After installation, run:
poetry install
To get current env info
poetry env info
To get poetry virtualenv names
poetry env list
To remove current env
poetry env remove <env name>
To clear poetry cache (needed before update if there is an existing update but the package is not updated)
poetry cache list # get poetry available cache list
poetry cache clear --all <cache name> # delete all cache (except _default_cache)
To update one package
poetry update openshift-python-wrapper
This project runs tests against an OCP cluster running on OSD / ROSA. To get the cluster's kubeconfig run:
ocm get clusters -p search="name like '"$CLUSTER_NAME"%'" | jq -r '.items | .[] | .id' \
| xargs -I {} ocm get /api/clusters_mgmt/v1/clusters/{}/credentials | jq -r .kubeconfig
Save the output to a file and export it as KUBECONFIG
export KUBECONFIG=<path to kubeconfig file>
Log file 'pytest-tests.log' is generated with the full pytest output in the tests root directory. For each test failure cluster logs are collected and stored under 'tests-collected-info'.
To see verbose logging of a test run, add the following parameter:
make tests PYTEST_ARGS="-o log_cli=true"
To enable data-collector pass data-collector.yaml YAML format:
data_collector_base_directory: "<base directory for data collection>"
collect_data_function: "<import path for data collection method>"
YAML Example:
data_collector_base_directory: "tests-collected-info"
collect_data_function: "ocp_wrapper_data_collector.data_collector.collect_data"
collect_pod_logs: true
poetry run pytest .... --data-collector=data-collector.yaml
Logs will be available under tests-collected-info/ folder.
In order 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
When the switch is not used, we set the default level to INFO.
Example:
--log-cli-level=DEBUG
To run the cluster upgrade test, you will need to provide the cluster name and the OCP target version.
Example:
poetry run pytest -m upgrade --ocp-target-version 4.10.35 --cluster-name {cluster name} \
--data-collector={path to data collector yaml}
If running against a production cluster, add: --tc=api_server:production
To run hypershift installation tests make sure the following environment variables are set: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY OCM_TOKEN
poetry run pytest ... --ocp-target-version {OCP version} -m hypershift_install
Container can be generated and pushed using make targets.
make -f Makefile
We use checks tools that are defined in .pre-commit-config.yaml file To install pre-commit:
pip install pre-commit --user
pre-commit install
pre-commit install --hook-type commit-msg
pre-commit will try to fix the error. If some error where fixed git add & git commit is needed again. commit-msg use gitlint (https://jorisroovers.com/gitlint/)
To check for PEP 8 issues locally run:
tox
Export OCM_TOKEN
env variable locally or in test container
export OCM_TOKEN="production or stage OCM token"
You can overwrite the api server defined in global_config.py by passing the following in command line: For example:
poetry run pytest ... --tc=api_server:stage