Tuesday, July 13, 2010

Hello All,

while continuing working on the PyPI Testing Infrastructure (PyTI)[0], this week i will work on adding an EC2 interface to pony-build which will enable us to run package test in the EC2 Virtual Machine from the pony-build server.

The idea of using the EC2 machine was in the first place because we wanted to run test in a clean environment to do so Tarek Ziade has proposed to run test in an EC2 machine[1] after we reset the machine like that we have always a clean environment where we run tests .

About how to implement and after the suggestion of my mentor Jesse Noller to use server provisioning here is my ideas until now :

The problem :

- EC2 machines are in the first place down and i have to init them
- i have to follow the pony-build architecture which is client - server (so no master slave, so commanding client from server).
- the EC2 instance are fractured by the hour so when i finish testing i have to put it down again.

Idea:

The questions that give me the answer was :
is it an obligation that the test client (script) must be run in the test platform (EC2 VM) ?

The answer was : no, what should be run in the test platform is the test commands .

So the idea is to run the test client in a machine (in my case and to simplify it's will be the same where i run the server ) , it's will be like a Hub and from their i init the VM and run all commands and then i can put the VM down again.

To do so , i will create first a "Context" in pony-build like the "virtualenvContext" in which i will init and finish my EC2 VM and for running commands i will have to change the _run_commands function to enable it to run commands from a remote machine .
i think it's the easy way to do it the first time, if any one have another idea please let me know .

[0] http://bitbucket.org/mouad/pypi-testing-infrastructure-pyti/
[1] http://tarekziade.wordpress.com/2010/03/21/another-gsoc-idea-a-pypi-testing-infrastructure/

Thursday, July 1, 2010

Creating a new web interface for pony-build

Hello ,

In this tutorial i will try to explain the procedure that i follow to create a web interface for pony-build [0] which is a continuous integration system that i'm using in the GSoC project "pypi testing infrastructure"[1].

So first pony-build come with a default web interface created with Quixote and if you want to create a new web interface let say using Django in this tutorial i will show you how i interface the my web interface with pony-build .

1- First you have to run pony-build using the web interface in my project i created a script that i have called run.py where i have put this code:

from django.core.handlers.wsgi import WSGIHandler
from django.core.servers.basehttp import AdminMediaHandler

from adapter import CoordinatorAdapter
from pony_build import server, coordinator, dbsqlite


if __name__ == '__main__':
""" run pony-build server in local host

"""
_host = 'localhost'
_port = 8800

# create the sqlite database
_db_file = dbsqlite.open_shelf("pyti")
_db_file = coordinator.IntDictWrapper(_db_file)

# pass the database to the coordinator
my_coordinator = CoordinatorAdapter(db=_db_file)

# create the server using server module
pony_server = server.create(_host, _port, my_coordinator, AdminMediaHandler(WSGIHandler()))

print 'pony-build server started on host %s, port %d' % (_host, _port)

# run the server
pony_server.serve_forever()

2- Next i created a new implementation of the coordianator in my case i need it because i have two database the first one sqlite is used by the pony-build server to save packages build info and the other is used by Django , all this complexity is because i want to change the database layer to support not only sqlite and like that i will have only one database but not for now .

here my code :


import datetime
from django.contrib.auth.models import User

from pony_build.coordinator import PonyBuildCoordinator
from packages.models import Packages, History, Report

# inherit from the PonyBuildCoordinator
class CoordinatorAdapter(PonyBuildCoordinator):
""" Adapter design pattern

"""

# override add_result method so i can save the build info in the web interface DB
def add_results(self, client_ip, client_info, results):
""" copy build result to Django database.

"""

super(CoordinatorAdapter, self).add_results(client_ip, client_info, results)

#update existing package info or creating a new entry
new = Packages.objects.get_or_create(package_name=client_info['package'])[0]

new.package_description=client_info['package']
new.last_state = client_info['success']
new.last_build = datetime.datetime.now()
new.save()

package_history = History()

package_history.time = new.last_state
package_history.state = new.last_build
package_history.package_build = new

new_report = Report()
new_report.platform = client_info['arch']
new_report.report = 'TO ADD'
new_report.save()

package_history.report = new_report
package_history.save()

print "package saved"


if you want to see all the example go to [2]

[0] http://github.com/ctb/pony-build
[1] http://bitbucket.org/mouad/pypi-testing-infrastructure-pyti/
[2] http://bitbucket.org/mouad/pypi-testing-infrastructure-pyti/src/tip/GUI/