Several repositories offer ready-made container images for Red Hat Enterprise Linux and other systems running Linux. The InterOp team at Red Hat tests these application images in Red Hat OpenShift. To simplify the integration of tests into the continuous integration/continuous delivery (CI/CD) process, we are adding Ansible playbooks to the repositories that host the container images. The Red Hat Software Collections GitHub repository currently has the first of these Ansible playbooks, but we will add playbooks to other repositories over time.
This article shows how to submit a test to a repository, and how to download the tests if you want to run them in your own container environment.
Parameters for testing a container
In order to test a container under a Red Hat OpenShift 4 environment, the developer has to provide information about where to download, deploy, and test the container. The necessary information is illustrated in the following playbook for a PostgreSQL container image:
registry_redhat_io: "rhscl/postgresql-10-rhel7" tag_name: "postgresql:10-el7" deployment: "oc new-app postgresql:10-el7~https://github.com/sclorg/postgresql-container.git \ --name new-postgresql \ --context-dir examples/extending-image/ \ -e POSTGRESQL_USER=user \ -e POSTGRESQL_DATABASE=db \ -e POSTGRESQL_PASSWORD=password" pod_name: "new-postgresql" add_route: true test_exec_command: "./files/check_postgresql_container.sh" expected_exec_result: "FINE" check_curl_output: “SOMETHING from curl output” scl_url: "postgresql-container" is_name: "postgresql"
The meanings of the fields follow:
registry_redhat_io: The image in the registry.redhat.io catalog, including the namespace, which is
rhsclin this case.
tag_name: The tag name of the image.
deployment: The command that deploys the image into the OpenShift environment.
pod_name: name of the pod in the OpenShift namespace.
add_route: Whether the route should be exposed, where the default is not to expose it.
test_exec_command: The file that performs the test.
expected_exec_result: A string expected from executing the
check_curl_output: A substring from the expected output of a
scl_url: The repository name, for the Software Collections repositories only.
is_name: The imagestream of the container.
To submit a test for public use, file a pull request at the site hosting the tests. There is currently one site at the Software Collections GitHub repository.
Storing a test locally
If you want to keep the test in your private environment instead of sharing the test, you can download our test suite and add your test to it as follows.
Clone the test repository:
$ git clone https://github.com/sclorg/ansible-tests
Go to the cloned repository:
$ cd ansible-tests
Add your container test suite to the main Ansible playbook.
Running a test
This section assumes that you are running an OpenShift 4 cluster.
Downloading the OpenShift 4 client
The latest version of the OpenShift 4 client, 4.6.18, can be obtained for your system at this mirror site. Download the ZIP file and unpack it through:
$ tar -xzvf <FILE>
The kubeconfig file
Tests refer to the Kubernetes kubeconfig file, so you need to point the
KUBECONFIG environment variable to the file. Ask your OpenShift 4 cluster administrator for the location of the file, then insert the path into the following command:
$ export KUBECONFIG=<path_to_kubeconfig>/kubeconfig
Running your test
Switch to the cloned repository:
$ cd ansible-tests
Execute the test as follows:
$ make ocp4-tests EXT_TEST=<your_test_name>
More details are available in a README file in the repository.
This article showed a new method that makes it easy to add a test for your container to a test suite and run the test in an OpenShift 4 cluster that has been set up by an administrator. You can keep the test in your own environment, but we recommend that you heed the Red Hat phrase, "It’s better to share."
By providing your test to the InterOp team, you can get the container tested during each feature freeze or code freeze done by the OpenShift 4 development team. Feel free to contact the InterOp team at Red Hat.Last updated: March 10, 2023