Eutesteruserguide

%define=code bgcolor=#BEE554 padding=3px indent lframe% %define=output bgcolor=#FFCCCC padding=3px indent lframe% %define=text bgcolor=#F0F8FF padding=3px indent lframe%

[++Eutester User Guide++]


 * 1)  Introduction to Eutester
 * 2)  Installation Using Virtualenv
 * 3) Writing a Test
 * 4)  Running a Test Case
 * 5)  Information on Boto and Paramiko
 * 6)  Further Reading and Various Resources
 * 7)  References

[+Introduction to Eutester+]

Eutester is a project designed to allow a user to validate a Cloud setup. The goal of the project is to have a way to confirm that a specific Cloud/Image is functioning properly, or, in the case of a private Cloud; that it was properly installed.

Eutester is installed and run on a local machine, and is dependent on the user having the proper credentials to access the Cloud ([| Euca2ools User Guide - Initial Setup]). It is also assumed that the Cloud being tested is properly configured, allows SSH and has at least one registered EMI (Eucalyptus Machine Image).

Eutester is written entirely in Python and it is recommended the user first familiarize her/himself with this language.

[+Installation Using Virtualenv+]

Virtualenv is a virtual Python Environment builder. What this means is that a user can create an isolated Python environment, wherein any changes or updates to dependencies will not affect the main system.

First, ensure that Python 2.6 or greater is installed (note: Python3.x is not yet supported):

>>code<< @@python --version@@<< >><<<<

Next, install python-setuptools and python-virtualenv:

>>code<< @@apt-get install python-setuptools git@@<< @@easy_install virtualenv@@<< >><<<<

Set up a virtual environment (note: this will create a new folder in the current directory), naming is user dependent and should replace 'anyname' in subsequent code:

>>code<< @@virtualenv anyname@@<< >><<<<

Then enter the environment:

>>code<< @@source anyname/bin/activate@@<< @@cd anyname@@<< >><<<<

For each environment created you will need to install the dependencies necessary to run Eutester as well as the tester itself:

>>code<< @@easy_install boto paramiko@@<< @@git clone git://github.com/eucalyptus/eutester.git@@<< @@cd eutester@@<< @@python setup.py install@@<< >><<<<

If desired python can be configured for tab completion as well as a file tracking the history of commands entered. First create a file entitled ".pythonrc" in your home directory. Add the following code to the file:

>>text<< @@import atexit@@<< @@import os@@<< @@import readline@@<< @@import rlcompleter@@<<

@@history = os.path.expanduser('~/.python_history')@@<< @@readline.read_history_file(history)@@<< @@readline.parse_and_bind('tab: complete')@@<< @@atexit.register(readline.write_history_file, history)@@<< >><<<<

Next add PYTHONSTARTUP to the .bashrc (or equivalent) file and source the .bashrc file:

>>code<< @@echo export PYTHONSTARTUP=~/.pythonrc>>~/.bashrc@@<< @@source ~/.bashrc@@<< >><<<<

Create the log file:

>>code<< @@touch ~/.python_history@@<< >><<<<

The virtual environment is ready to use and can be accessed with a direct call to the binary:

>>code<< @@~/anyname/bin/python@@<< >><<<<

[+ Writing a Test +]

Writing a test is made easy by utilizing the Python unittest library found in Python 2.6 and later versions. Python unittest allows you to create, catalog, and execute test cases in an efficient manner. Below is an example of a test case written with code inherited from the [| TestCase] class.

>>code<< import unittest

from eucaops import Eucaops

class MyFirstTest(unittest.TestCase):

def setUp(self): self.tester = Eucaops(credpath="/home/ubuntu/.euca") self.keypair = self.tester.add_keypair self.group = self.tester.add_group self.tester.authorize_group(self.group) self.tester.authorize_group(self.group, port=-1, protocol="icmp") self.reservation = None

def testInstance(self): image = self.tester.get_emi(root_device_type="instance-store") ### 1) Run an instance       try:            self.reservation = self.tester.run_instance(image, self.keypair.name, self.group.name)        except Exception, e:            self.fail("Caught an exception when running the instance: " + str(e))        for instance in self.reservation.instances:            ### 2) Ping the instance ping_result = self.tester.ping(instance.public_dns_name) self.assertTrue(ping_result, "Ping to instance failed") ### 3) Run command on instance           uname_result = instance.sys("uname -r")            self.assertNotEqual(len(uname_result), 0, "uname failed")        pass

def tearDown(self): if self.reservation is not None: self.tester.terminate_instances(self.reservation) self.tester.delete_keypair(self.keypair) self.tester.local("rm " + self.keypair.name + ".pem") self.tester.delete_group(self.group)<<

if __name__ == '__main__': unittest.main >><<<<

As shown above there are a couple of major portions of this code. First we have the setup which gives us the necessary artifacts to execute, our case also requires a keypair and a security group authorized for both SSH and Ping. Then we have the tear down which will remove these artifacts regardless of whether or not the test passes/fails. This is similar to memory management in C where you need to free memory after you use it. You do not want artifacts hanging out in your system after you've run tests as this will clog the system.

Additionally we have a testInstance method in order to actually run some tests. This testInstace method tests for three things:
 * 1) Running an instance
 * 2) Network connectivity between the instance an the test machine
 * 3) Execution of commands on the remote host

[+ Running a Test Case +]

Given the code above we can simply invoke the script from the command line thanks to the following two lines:

>>code<<

if __name__ == '__main__': unittest.main<< >><<<<

[+ Information on Boto and Paramiko +]

Paramiko is basically just a Python module that uses an ssh protocol that allows secure connections to remote machines. Here is a link to read up and/or download it: %newwin% http://www.lag.net/paramiko/ %% Also, here is the link to the Boto github page. Boto is a Python interface for Amazon E2C. It is pretty much just an API for Python development on the Amazon cloud. %newwin% https://github.com/boto/boto %%

[+ Further Reading and Various Resources +]

[+ References +]
 * 1) %newwin% http://testingclouds.wordpress.com/author/viglesiasce/ %%
 * 2) %newwin% http://testingclouds.wordpress.com/2012/04/02/eutester-basics-part-iii-creating-your-first-testcase/ %%