Integrating OpenShift with Sauce OnDemand

May 2nd, 2012 by Ross Rowe

OpenShift is Red Hat’s Cloud Computing Platform as a Service (PaaS) offering. It provides the infrastructure to let you run your applications (Node.js, Ruby, Python, PHP, Perl, and Java). Integrating OpenShift applications with Sauce OnDemand is really easy, so you can run your applications and your tests in the cloud within minutes.

The instructions below cover Java applications built with Maven deployed under JBoss.

Firstly, follow the instructions on the OpenShift Getting Started page to create an OpenShift account, create a SSH key and install the client tools.

Once this is done, you can create a namespace for your application by running the following:

rhc domain create -n YOUR_NAMESPACE -l YOUR_OPENSHIFT_LOGIN

Then create a JBoss application with Jenkins enabled:

rhc app create -a YOUR_APP -t jbossas-7 --enable-jenkins

This will create a Git repository, and both a JBoss and a Jenkins instance for your application.

We’ve created a fork of the JBoss OpenShift Kitchen Sink example to demonstrate how you can write a Selenium test to run against an OpenShift instance.

The fork includes some key additions to the Maven pom.xml file, namely the inclusion of the following dependencies:

	<!-- Selenium dependency -->
	<dependency>
		<groupId>org.seleniumhq.selenium</groupId>
		<artifactId>selenium-java</artifactId>
		<version>2.13.0</version>
		<scope>test</scope>
	</dependency>
	<!-- selenium-client-factory dependencies -->
	<dependency>
		<groupId>com.saucelabs.selenium</groupId>
		<artifactId>sauce-ondemand-driver</artifactId>
		<version>2.4</version>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>com.saucelabs.selenium</groupId>
		<artifactId>selenium-client-factory</artifactId>
		<version>2.4</version>
		<scope>test</scope>
	</dependency>

The pom.xml file also includes a new ‘arq-jbossas-openshift’ profile, which can be used to run the Kitchen Sink unit tests against the OpenShift instance.

<profile>
	<id>arq-jbossas-openshift</id>
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<systemPropertyVariables>
						<arquillian.launch>openshift</arquillian.launch>
					</systemPropertyVariables>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>org.jboss.arquillian.container</groupId>
			<artifactId>arquillian-openshift-express</artifactId>
			<version>1.0.0.Beta1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</profile>

The org.seleniumhq.selenium dependency will add the Selenium classes to the classpath, and the com.saucelabs.selenium dependencies will add the selenium-client-factory library, which provides some helper classes to construct the Selenium/WebDriver instances so that they can connect to Sauce OnDemand.

The org.jboss.as.quickstarts.kitchensink.test.MemberRegistrationIntegrationTest class demonstrates how to write a Selenium test to run against an OpenShift instance. It is basically the same as any other Selenium test, but it uses the selenium-client-factory library. The class relies on some environment variables to be populated, which provide details of the Selenium host, port and starting URL. This is done so that the class can easily be integrated with the Sauce OnDemand plugins for your choice of continuous integration build (eg. Jenkins, Hudson or Bamboo).

In addition, the org.jboss.as.quickstarts.kitchensink.test.MemberRegistrationArquillianTest class demonstrates how to write an Arquillian-enabled Selenium test to run against an OpenShift instance.

In order to use Arquillian for your tests, you will also need to modify the src/test/resources/arquillian.xml file to reflect your OpenShift instance.  The relevant section of the arquillian.xml file to modify is:

<container qualifier="openshift">
<configuration>
<property name="namespace">YOUR_OPENSHIFT_NAMESPACE</property>
<property name="application">YOUR_OPENSHIFT_APPLICATION</property>
<property name="sshUserName">YOUR_OPENSHIFT_UUID</property>
<!-- Passphrase can be specified by defining the environment variable SSH_PASSPHRASE -->
<property name="login">YOUR_OPENSHIFT_LOGIN</property>
</configuration>
</container>

To update your OpenShift project to use the forked Kitchen Sink example source code, run the following from your project’s directory:

git remote add upstream -m master git://github.com/saucelabs/kitchensink-example.git
git pull -s recursive -X theirs upstream master

To deploy the updated code, simply run the following

git push

That’s it, the Kitchen Sink example should now be available from http://YOUR_APP-YOUR_NAMESPACE.rhcloud.com.

Now you can run the integration tests! You can run them in your local environment by executing:

mvn -Dsauce.user=YOUR_SAUCE_USER -Daccess.key=YOUR_SAUCE_KEY \
-DSELENIUM_STARTING_URL=http://YOUR_APP-YOUR_NAMESPACE.rhcloud.com \-Parq-jbossas-openshift test

You can also configure a Job in your OpenShift Jenkins instance to run the integration tests. To do this, first install, configure and enable the Sauce OnDemand plugin for Jenkins, then you can create a new Job in Jenkins to run the Maven build.

As a bonus, for any OpenShift users who open a free Sauce account and run at least one KitchenSink test as outlined above, we’ll fill their account with the equivalent of three months of our “small team” plan. That’s 3000 minutes, which is 50 hours of free testing!

So to qualify for three months free Sauce “Small Team” balance:

  • create an account on OpenShift,
  • create a matching account on Sauce Labs
  • enter the ‘RedSauce’ promo code at the time of account creation and
  • run at least one test following the template
  • email the link to the job video from your test to sales [at] saucelabs [dot] com and we’ll set you up!

Leave a Comment