Skip to content

Commit

Permalink
Fixes #36, we now have a POLL directive
Browse files Browse the repository at this point in the history
  • Loading branch information
kushaldas committed Mar 3, 2017
1 parent 3000c08 commit ca2c9f4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
15 changes: 15 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ Example::
SLEEP 40
ls /etc

POLL directive
---------------

.. versionadded:: 0.17

We also have a *POLL* directive, which can be used to keep polling the vm for a
successful ssh connection. It polls after every 10 seconds, and timeout is
currently set for 300 seconds. One should this one instead of *SLEEP* directive
after a reboot.



For Multi-VM configurations
###########################

Expand All @@ -171,6 +183,9 @@ executed on vm2.
Using Ansible
--------------

.. note:: If you want to run Ansible playbooks in your test, please have a look at the `gotun <https://gotun.rtfd.io>`_, it has
better support for running Ansible, or any other tool in the host as the part of the test.

.. versionadded:: 0.14

Along with Multi-VM configuration, we got a new feature of using
Expand Down
29 changes: 25 additions & 4 deletions tunir.8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "TUNIR" "8" "June 16, 2016" "0.16" "Tunir"
.TH "TUNIR" "8" "Mar 03, 2017" "0.16" "Tunir"
.SH NAME
tunir \- Tunir, the simple CI with a big heart.
.
Expand Down Expand Up @@ -35,7 +35,7 @@ Tunir is a simple testing tool. The goal is to have a system which is
simple to setup, and easy to maintain.
.sp
Contents:
.SH WHY ANOTHER CI?
.SH WHY ANOTHER TESTING TOOL?
.sp
I have used Jenkins before. I was maintaining one instance in one of my VPS
instance. The amount of RAM required by Jenkins was too much for my small VM.
Expand All @@ -50,7 +50,9 @@ This is the point where I came up with Tunir. Tunir is a simple testing tool
that will help me run automated tests for the cloud images. I kept the system
generic enough to execute any kind of tests people want.
.sp
The configuration is very minimal with Tunir.
The configuration is very minimal with Tunir. There is also a golang verion
called \fI\%gotun\fP which has better option to run the tests
inside OpenStack or AWS.
.SH INSTALLATION
.sp
Tunir is written in Python. Currently it works with Python2.7+
Expand Down Expand Up @@ -91,6 +93,8 @@ typing
python\-systemd (python2\-systemd package in Fedora)
.IP \(bu 2
Ansible (optional)
.IP \(bu 2
libcloud
.UNINDENT
.sp
You can install them in Fedora by the following command:
Expand All @@ -99,7 +103,7 @@ You can install them in Fedora by the following command:
.sp
.nf
.ft C
$ sudo dnf install libguestfs\-tools python\-paramiko docker\-io vagrant\-libvirt ansible net\-tools python\-crypto python2\-typing python2\-systemd
$ sudo dnf install libguestfs\-tools python\-paramiko docker\-io vagrant\-libvirt ansible net\-tools python\-crypto python2\-typing python2\-systemd python\-libcloud
.ft P
.fi
.UNINDENT
Expand Down Expand Up @@ -286,6 +290,15 @@ ls /etc
.fi
.UNINDENT
.UNINDENT
.SS POLL directive
.sp
New in version 0.17.

.sp
We also have a \fIPOLL\fP directive, which can be used to keep polling the vm for a
successful ssh connection. It polls after every 10 seconds, and timeout is
currently set for 300 seconds. One should this one instead of \fISLEEP\fP directive
after a reboot.
.SS For Multi\-VM configurations
.sp
New in version 0.14.
Expand Down Expand Up @@ -314,6 +327,14 @@ In the above example the line 1, and 3 will be executed on the vm1, and line 2 w
executed on vm2.
.SS Using Ansible
.sp
\fBNOTE:\fP
.INDENT 0.0
.INDENT 3.5
If you want to run Ansible playbooks in your test, please have a look at the \fI\%gotun\fP, it has
better support for running Ansible, or any other tool in the host as the part of the test.
.UNINDENT
.UNINDENT
.sp
New in version 0.14.

.sp
Expand Down
25 changes: 25 additions & 0 deletions tunirlib/tunirutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ def create_ansible_inventory(vms, filepath):
if extra:
fobj.write(extra)


def poll(config):
"Keeps polling for a SSH connection"
for i in range(30):
try:
print "Polling for SSH connection"
result = run(config['host_string'], config.get('port', '22'), config['user'],
config.get('password', None), 'true', key_filename=config.get('key', None),
timeout=config.get('timeout', 60), pkey=config.get('pkey', None))
return True
except: # Keeping trying
time.sleep(10)
return False


def run(host='127.0.0.1', port=22, user='root',
password=None, command='/bin/true', bufsize=-1, key_filename='',
timeout=120, pkey=None, debug=False):
Expand Down Expand Up @@ -289,6 +304,16 @@ def run_job(jobpath, job_name='', extra_config={}, container=None,
print "Sleeping for %s." % word
time.sleep(int(word))
continue
if command.startswith("POLL"): # We will have to POLL vm1
#For now we will keep polling for 300 seconds.
# TODO: fix for multivm situation
pres = poll(vms['vm1'])
if not pres:
print "Final poll failed"
status = False
break
else:
continue # We don't want to execute a POLL command in the remote system
elif command.startswith('PLAYBOOK'):
playbook_name = command.split(' ')[1]
playbook = os.path.join(ansible_path, playbook_name)
Expand Down

0 comments on commit ca2c9f4

Please sign in to comment.