No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/test
.gitignore
README.adoc
pom.xml

README.adoc

OpenShift Deployment Testing

The project aims at executing deployment tests using Arquillian Kube together with Fabric8 OpenShift Client for a WordPress and MySQL Application to ensure that the application will work correcty when deployed on an OpenShift cluster.

What Do You Test ?

The project aims at demonstrating a black box approach to testing your deployment that neither mutates the containers (by deploying, reconfiguring etc) nor the Kubernetes/OpenShift resources.

The focus of the project is on immutable infrastructure and integration testing, wherein the test cases are meant to, consume and test the provided services and assert that the environment is in the expected state, providing you with the confidence that your application will work correctly when deployed on an OpenShift cluster.

How Do You Test The Deployment ?

The following sections explain how to leverage the Arquillian Kube Extension and Fabric8 OpenShift Client to test your OpenShift deployments.

Preparing the Environment

Setup OpenShift Cluster Locally

One of the pre-requisites to use Arquillian Kube Extension, is to have the OpenShift cluster running on your host machine.

An easier way to setup and start the OpenShift cluter on your local host is to use MiniShift.

Setup Maven Project Dependencies

For OpenShift deployment testing using Arquillian Kube extension, include the following dependencies in pom.xml:

Arquillian Cube BOM - Unified Dependencies
<properties>
    <version.arquillian_cube>${latest_released_version}</version.arquillian_cube>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.arquillian.cube</groupId>
            <artifactId>arquillian-cube-bom</artifactId>
            <version>${version.arquillian_cube}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>
Arquillian Cube Requirement
<dependency>
    <groupId>org.arquillian.cube</groupId>
    <artifactId>arquillian-cube-requirement</artifactId>
    <scope>test</scope>
</dependency>
Arquillian Cube OpenShift
<dependency>
    <groupId>org.arquillian.cube</groupId>
    <artifactId>arquillian-cube-openshift</artifactId>
    <scope>test</scope>
</dependency>
Arquillian Junit
<dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-standalone</artifactId>
    <version>${latest_released_version}</version>
    <scope>test</scope>
</dependency>

For Fabric8 OpenShift Client, include the following dependency in the pom.xml

Fabric8 OpenShift Client
dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>openshift-client</artifactId>
    <version>${latest_released_version}</version>
</dependency>

For fabric8 kubernetes assertions, include the following dependency in the pom.xml

Fabric8 Kubernetes Assertions
<dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>kubernetes-assertions</artifactId>
    <version>${latest_released_version}</version>
    <scope>test</scope>
</dependency>

Writing Deployment Tests

Arquillian Kube extension provides out of the box functionality to create and manage a temporary namespace per test suite for your tests and then applies all the required kubernetes/openshift resources as defined in the OpenShift manifest/template file provided by you to create your environment.

The extension by default looks for the manifest file named kubernetes.json or kubernetes.yaml in the classpath.

The name of the manifest/template file can be changed by setting the property env.config.resource.name either as an environment variable or as system property or by defining it in the arquillian.xml as shown below with latter having the maximum priority.

arquillian.xml
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://jboss.org/schema/arquillian"
    xsi:schemaLocation="http://jboss.org/schema/arquillianhttp://jboss.org/schema/arquillian/arquillian_1_0.xsd">

    <extension qualifier="kubernetes">
        <property name="env.config.resource.name">sample-template.yaml</property>
    </extension>

</arquillian>

Kubernetes/OpenShift resources can then be made accessible within the Test Cases by injecting them using Arquillian’s @ArquillianResources annotation (see example test below).

ExampleTest.java
@RunWith(Arquillian.class)
public class ExampleTest {

    @ArquillianResource       (1)
    OpenShiftClient client;

    @Named("dummy")           (2)
    @PortForward
    @ArquillianResource
    Service dummyService;

    @Test
    public void service_instance_should_not_be_null() throws Exception {
        assertThat(service).isNotNull();                                                              (3)
    }

    @Test
    public void test_at_least_one_pod() throws Exception {
       assertThat(client).pods().runningStatus().filterNamespace(session.getNamespace()).hasSize(1);  (4)
    }
}

The resource providers available, can be used to inject to your test cases the following resources:

  • A kubernetes client as an instance of KubernetesClient.

  • Session object that contains information (e.g. the namespace) or the uuid of the test session.

  • Services (by id or as a list of all services created during the session, optionally filtered by label)

  • Deployments (by id or as a list of all deployments created during the session, optionally filtered by label)

  • Pods (by id or as a list of all pods created during the session, optionally filtered by label)

  • Replication Controllers (by id or as a list of all replication controllers created during the session, optionally filtered by label)

  • Replica Sets (by id or as a list of all replica sets created during the session, optionally filtered by label)

The OpenShift extension also provides:

  • An openshift client as an instance of OpenShiftClient.

  • Deployment Configs (by id or as a list of all deployment configs created during the session)

Further, using Fabric8 Kubernetes Assertions, a nice library based on assert4j, aids in performing meaningful and expressive assertions on top of the Kubernetes/OpenShift model.

Once everything is ready, Arquillian Kube runs your tests, enriched with resources required to access service and finally cleaning up everything after the testing is over.

For more details and available configuration options check arquillian kube documentation.

Running Sample Tests

To run the sample deployment tests in this project follow the steps below:

  • git clone git@github.com:hemanik/openshift-deployment-testing.git

  • minishift start (tested with OpenShift Origin 3.6.0)

  • oc login

  • mvn clean verify