Tuesday, November 9, 2010

BuildAPI: Errors

Problems Getting BuildAPI to Work on Seneca's Iraq Host
From my previous post, it is apparent that I had BuildAPI running on a virtual machine on my laptop. However, I tried running and installing it on one of our Seneca host systems, iraq.proximity.on.ca,  but it only gave me errors and I could not figure out why (see errors below).

I followed the same steps as I did on my virtual machine, and checked online for similar issues/errors but was left with little. I even tried working with it in a python virtual environment and also set SELinux to permissive to test but it was the same issue. I ended up doing most of the work on my VM but I would still like to get it working on the Iraq machine.

Running in a Virtual Environment
The following error was encountered when running paster serve --reload --daemon config.ini in a virtual environment:

--From the paster.log file--
File "/usr/lib/python2.6/site-packages/paste/config.py", line 76, in _current_obj
    "No configuration has been registered for this process "
AttributeError: No configuration has been registered for this process or thread
Removing PID file paster.pid

I checked the /var/log/messages file and it showed:

Nov  9 22:39:00 iraq python: abrt: detected unhandled Python exception in /home/asingh114/newbuild/venv/bin/paster
Nov  9 22:39:00 iraq abrtd: dumpsocket: New client connected
Nov  9 22:39:00 iraq abrtd: dumpsocket: Saved Python crash dump of pid 10494 to /var/spool/abrt/pyhook-1289360340-10494
Nov  9 22:39:00 iraq abrtd: dumpsocket: Socket client disconnected
Nov  9 22:39:00 iraq abrtd: Directory 'pyhook-1289360340-10494' creation detected
Nov  9 22:39:00 iraq abrtd: Executable '/home/asingh114/newbuild/venv/bin/paster' doesn't belong to any package
Nov  9 22:39:00 iraq abrtd: Corrupted or bad crash /var/spool/abrt/pyhook-1289360340-10494 (res:4), deleting
Nov  9 22:39:17 iraq python: abrt: detected unhandled Python exception in ../venv/bin/paster

If I run yum info python, it shows python 2.6.4 installed, but if I do python -V, it shows python 2.6.6 installed. In addition, python-setuptools are installed.


Running Outside Virtual Environment
I also tried running paster serve --reload --daemon config.ini outside of the virtual environment (after all dependencies and packages were installed) and I also get an error:
Traceback (most recent call last):
  File "/usr/bin/paster", line 5, in <module>
    from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

And in the /var/log/messages file:
Nov  9 22:39:00 iraq abrtd: Executable '/home/asingh114/newbuild/venv/bin/paster' doesn't belong to any package
Nov  9 22:39:00 iraq abrtd: Corrupted or bad crash /var/spool/abrt/pyhook-1289360340-10494 (res:4), deleting
Nov  9 22:39:17 iraq python: abrt: detected unhandled Python exception in ../venv/bin/paster


I will check into it further, and in the meantime I will continue to work on BuildAPI on my virtual machine and get my scripts going.

I would remove and reinstall the packages but don't want to screw up anyone's work on the Iraq system.

Additionally, I don't want to spend all my time trying to get it to work on Iraq when I have it working on my virtual machine anyway but if anyone has any ideas or input, please let me know!

Friday, November 5, 2010

BuildAPI: 0.1

Getting StartedTo run BuildAPI locally, there were a few things that needed to be done, as outlined in the ReleaseEngineering/BuildAPI wiki (< Many thanks for that!!).

These were the steps:
  1. Install MySQL and import database snapshots
  2. Install Python and Python SetupTools (Easy_install)
  3. Install Pylons (or use a virtual environment)
  4. Install Google Python Visualizations Library
  5. Install MySQL-Python (MySQLdb for Python)
  6. Configure BuildAPI
 1. Installing MySQLInstalling MySQL is easy:

$ yum install mysql-server



Then create a new user and password for MySQL (optional), create the two databases (schedulerdb and statusdb) in MySQL and import the two snapshots into the appropriate databases. As noted in my previous post, I did run into problems getting the snapshots into MySQL, see here. However, that was resolved.


2.  Python and Python SetupTools
There were a few version of Python that I could have installed, however I chose to install version 2.6.6 as I had noted that the newest version 3.x was (maybe) not compatible with some of the components such as python mysqldb. I had used yum install to install it but it installed version 2.4 through yum so I downloaded the source and compiled it.
The python-setuptools package is necessary as it contains easy_install, which definitely lives up to its name and makes our lives soooo much easier (it resolves dependencies for python packages, just like yum)!

3. Install Pylons
What do you know, yum install pylons could work as well but instead I did easy_install pylons.


4. Install Google Python Visualizations Library
The visualizations library is used for, you guessed it, creating  graphical output such as graphs and charts for BuildAPI reports. After downloading the source code, I used python setup.py install to install it.

5. Install MySQL-Python (MySQLdb for Python)
This one took me a while to get installed and working. There were several dependencies that I needed to have installed before it could build, such as python-devel.
Smooth-sailing after that though.


6. BuildAPI
Once the BuildAPI source has been downloaded (buildapi source), I had to extract it to a directory called buildapi/ (by default it did not do this). Then run easy_install buildapi - it seems that easy_install goes into the folder and runs the python setup.py.

Once that is done, a default config.ini file was created (using paster make-config buildapi config.ini while in the buildapi directory) which would serve as the runtime configuration file. Changes needed to be made in here to allow BuildAPI to be accessible on the localhost and to be able to access the MySQL databases (SQLAlchemy is used with MySQL).

Thus, the following changes were made to the default config.ini file that was created using paster:
 
[server:main]
use = egg:Paste#http
host = 127.0.0.1
port = 5000

# SQLAlchemy database URL
sqlalchemy.scheduler_db.url = mysql://root:root@localhost/schedulerdb
sqlalchemy.status_db.url = mysql://root:root@localhost/statusdb
sqlalchemy.pool_recycle = 3600

That's it, that sets up BuildAPI to be accessible on http://127.0.0.1:5000/. Accessing it on the browser produces the following:



Each of the links work, as the database is set up as well. Here are a few example outputs:






MVC: Model–View–Controller
This is the concept that I need to understand in order to create the necessary code for the project. I noticed it is very similar to Perl's Templating Toolkit, where it allows you to separate the logic and view. 
From what I understand so far, the controller contains the logic, the model has the data and the view is basically the template that the end user will read the data from, as on a webpage for example.

Controller
When I am creating the scripts, I understand that the controller will call on the models or the views and return data to the model (please correct if this is wrong). It was also possible to use just a controller to show data on a webpage, however, it was not formatted. Using the command paster controller name created a default template controller that I could play around with.

Model
The model is where I can put the database connection and queries and store it into values that the template would then also use. I did read that for passing arguments from the model to the template, BuildAPI can use a function called "tmpl_context as c". Variables are called using the ${c.name} and this allows us to use the objects assigned as attributes of c anywhere else in the application - therefore, like global variables.


View
The model passes the data to the view/template which will display that information on a webpage with graphs and charts. These templates use a library set called Mako, which again, is similar to Perl's Templating Toolkit. It has many functions, expressions and tags that can be used. The template files are saved as name.mako

Here is a diagram of it (from wikipedia):



Well, this is how I understand the code will be created using MVC and its quite a lot to learn!


Testing 

One of the difficulties is knowing how all the components fit together, but after playing around with BuildAPI and taking a look at the structure of the pre-existing controllers, mako templates and model files, I have a fairly better understanding to progress into milestone 0.2.

I managed to create a few controllers myself, along with models and views using documentation on the internet (such as on PylonsHQ)

However, they were pretty simple and I need to learn more about the syntax and formats.
Example:


As an example, I was able to pull data (only used one column and a simple select query) and print it out on the screen using just a controller. I ran the command paster controller datatest, which created the template controller file and I modified that.
Note: To print to console, I had to edit the config.ini file and set
sqlalchemy.echo = True.


Simple Controller: datatest.py

from sqlalchemy import *

engine = create_engine('mysql://root:root@localhost/schedulerdb
charset=utf8&use_unicode=0')
connection = engine.connect()

result = engine.execute("select name from schedulers")
for row in result:
        print "name:", row['name']
result.close()


This printed out all the names from the schedulers table from the schedulerdb database:



I believe I can get this to display on a webpage, but I need a little help. I can use a controller file, datatest.py, such as this:

import logging

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from buildapi.lib.base import BaseController, render
from buildapi.model.getmydata import functionnname

log = logging.getLogger(__name__)

class DatatestController(BaseController):

    def index(self):
        # Return a rendered template
        c.message = GetMessage()
        return render('/displaydata.mako')


The return render will call on the displaydata.mako View/Template.
In the line
"from buildapi.model.getmydata import functionnname"

It will call the model getmydata.py (indicated by buildapi.model.getmydata - i.e. directory/directory/file) and in this file is where I could define the functionname.
For example, if the function name is GetMessage, then it would be defined as:


def GetMessage():
    return "Gimme my data fool!"

In the template, I simply use ${c.message}to get the data. If it is defined as above, then in the webpage (view) that is displayed, it will replace ${c.message} with "Gimme my data fool!".
Note: as shown in the controller file, datatest.py, c.message was defined as:
c.message = GetMessage()


Expectations
  • I would like to be able to print the data out to a webpage but will need to understand MVC and pylons syntax more. I will use the resources as listed on the BuildAPI wiki to help me with this
  • Once that is done, then I will try to put that data into a graph or chart
  • Next would be to pull the correct data and generate graphs based on the project objectives
  • And finally, get it all documented!



Quick Note about Python Virtual Environment
A python virtual environment was highly recommended by  Release Engineering, and therefore I also set up one for testing BuildAPI code before I brought it over to my actual installation on Fedora. It was extremely easy to set up, and literally took a few minutes to get it running.
Using easy_install, you can simply use easy_install virtualenv and it will install the virtualenv script to your path. Then you just need to create a directory, run the script wit the directory as your argument and it will set up a sandbox environment. Inside the sandbox/bin folder is an activate script, which as the name implies, activates the virtual environment.

Here are the commands if you are interested:
$ easy_install virtualenv

$ mkdir ~/venv
$ virtualenv ~/venv/sandbox
$ source ~/venv/sandbox/bin/activate
(sandbox)$ easy_install [packagename]
Once you're in the sandbox, you can install whatever else you need to install 


I kept detailed instructions on how to do each step, and I will leave that for the final documentation. 

BuildAPI: Pre 0.1 - free disk space problem

MySQL Database in my space!

For BuildAPI, I needed to install MySQL and import snapshots of two databases that I would be using. So it was installed on my Fedora virtual machine (with a 25GB raw disk (yes, it should have been LVM))... and that eventually ran out of space. The database snapshots 'statusdb' and 'schedulerdb' were almost 10GB of space combined - something I did not expect, and did not account for.

I was close to cloning my virtual machine into another with a larger disk but after consulting with Chris Tyler, there were much simpler options - such as simply adding another raw disk, and this is what I did.

Moreover, I edited my MySQL configuration file (/etc/my.cnf) and pointed the data directory to be on the new virtual raw disk and worked on it from there. Although my VM was terribly slow at importing the (very large) sql dumpfile, and even failed once, it worked out worked out fine in the end.

Lesson: use LVM, or better yet, do this all on an actual host and not a virtual machine

BuildAPI: Milestone 0.1 Release (To be blogged)

Three cups of coffee later...
Instead of posting everything for my BuildAPI 0.1 release now, I am going to get some sleep and post it later on today. However, the BuildAPI Project Page has been updated with what has been done for 0.1 so far and what needs to be done between now and milestone 0.2.


Here's a quick summary of 0.1:
  • Completed a local installation of Python, Pylons, MySQL (with databases snapshots loaded) and google virtualization
  • Set up BuildAPI and ran the Paste server to use the pre-existing BuildAPI controllers 
  • Created several test controllers, models and templates for testing and gaining a practical understanding how Pylons work
  • Created my own script using SQLAlchemy and MySQL engine to pull information from the SchedulerDB and StatusDB database. 
  • However, it displays only text (one line - refreshing page shows next line etc) and I need it to loop the values on the page to display all (should not be hard at all)
  • Before milestone 0.2, I would like to be able to generate a simple graph from the data I pulled so far.

--and would you believe it, I actually had fun working with BuildAPI all night...until the caffeine was gone and dawn broke.

Oh, and save the procrastination lecture for later. I have just been extremely busy (if you want to know - drop me a comment and I'll tell ya) and did not find enough time to work on the project. However, this is what all-nighters are for, because I'm a crazy workhorse!!


zzzzzzzzzzz......

Tuesday, October 26, 2010

BuildAPI: A First Look

The Beginning
Previously we had a conference call with Armen Zambrano from Mozilla regarding Mozharness, BuildAPI and Simple Release Bugs (Thanks Armen!). He had introduced us to these topics and got us rolling on projects that we could tackle. Consequently, I took an interest in BuildAPI which is a Pylons project used by RelEng (Release Engineering) to surface information collected from two databases updated through Buildbot (http://buildbot.net/trac) masters as they run jobs.

The BuildAPI project wiki page can be found here.


A Little About BuildAPI
This project involves generating analytic reports by querying databases, which can be used for a multitude of purposes such as performance or usage reports or discovering rogue Buildbot slave machines. Furthermore, it uses Pylons which combines the very best ideas from the worlds of Ruby, Python and Perl, providing a structured but extremely flexible Python web framework.


Getting Started
However, there is a great deal of information that needs to be learned and it would definitely require me to take a strong iniative. The first step is figuring out where exactly to start and how to progress.
Fortunately, Armen had posted more information about BuildAPI on his blog (http://armenzg.blogspot.com/search/label/mozharness), which provided an objective:

What I need students to do is one of the two:
1) generate graphs, charts, CSVs and CPU totals for infrastructure load blog posts like this 
    a) this is very useful and could move us forward towards having this information being published publicly for consumption
    b)  I highly encourage this one as understanding the mental model behind it is easier
2) write a tool that analyzes our statusDB and figure out slaves that have been continually been burning jobs (sometimes it takes us several days to spot them)

He also provided us with snapshots from the database and extremely helpful links such as How to get started with BuildAPI and Google Chart API  (more on that later).


Challenges (I love 'em, bring 'em on!):
  • Need to wrap my head around BuildAPI's concepts
  • Absolutely no experience with Python (although it is similar to BASH, which I am fine with) and just barely touched Ruby
  • Need to learn how to integrate Google Chart API / how it works
  • Figure out the database structure and which information needs to be pulled to generate the required reports
  • How to integrate it all and create a tool that can accomplish the latter


What I have done so far:
- I have looked at the links Armen had posted, especially the ReleaseEngineering/BuildAPI  as it provides instructions on how to get started with BuildAPI.
- Went over the database and its structure, which can be seen here and here or below:


 and


- Started reading on Pylons framework from the following sources:
http://pylonshq.com/docs/en/0.9.7/gettingstarted/
http://pylonshq.com/docs/en/0.9.7/tutorials/
- Also, briefly went over Google Chart API (It's awesome!)


A Note about Google Chart API:
The Google Chart API allows you to dynamically generate charts using a URL string.
It is the perfect tool as the charts can be embedded on web pages which the advantage is there are no files to save or serve. Although, the API does provide the option to download the image for local or offline use.

Here is an example:
http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Work|Play

Isn't that awesome?

Monday, October 25, 2010

Signing RPM Packages and Creating Your Own Repository

So much for "break" week. With so much to do, I'll be spending most of it just doing work.
Anyway, aside from that, let's look at another lab which consists of two phases:
- signing RPM packages, and then
- creating our own yum repository from where we will serve our signed packages.


First Phase - Signing Packages
The first phase involved signing rpm packages and I had chosen to sign two rpms that I created using spec files: nled and snort.
This was an easy task which is accomplished by:
- generating a GPG key (using gpg --gen-key),
- editing the .rpmmacros file and adding my email address (adding %_gpg_name "asingh114@learn.senecac.on.ca"), and finally,
- signing the desired rpm packages using rpm --addsign packagefilename

Instructions can be found on our SBR600 Weekly Schedule wiki under "Week 5 (October 4) - Repositories/Distributing)"



Second Phase - Creating a Yum Repository
Again, instructions can be found on our SBR600 Weekly Schedule wiki.

Since I am running my host system (Fedora 12) in a virtual machine, I decided to create a local or internal yum repository and test it using another fedora virtual machine that I already had installed. The test virtual machine is running Fedora 13 64-bit edition. Furthermore, I will be using HTTP as the protocol to serve my repository directories and of course, Apache Web Server was already installed and running on the system.

The repository directories were created in the public HTTP directory, and will be served out of /var/www/html/fedora/12/. However, in order to organize content I created two additional directories:
- i386, for 32 bit Fedora editions, and
- x86_64 for 64 bit.

The following command was used:
mkdir -p /var/www/html/fedora/{i386,x86_64}

Then, I copied my signed repositories from Phase 1 over to their respective directory (either i386 or x86_64). Next is creating the repository metadata for both of the directories, which can be accomplished through the command:

createrepo /var/www/html/fedora/i386
and then do the same for x86_64 directory.

Or through a script such as this:


#!/bin/bash
destdir="/var/www/html/repo/fedora"

for repo in i386 x86_64
    do
    pushd ${destdir}/${repo}
    createrepo .
done

Modified from http://blogs.techrepublic.com.com/opensource/?p=609

Either way, this will create a repodata directory containing the repository metadata in both of those directories.



Testing the Repository
We will be using a GPG key for our repository, so I also had to create a GPG key file. This is simply done by using the command:
gpg --export --armour asingh114@learn.senecac.on.ca > RPM-GPG-KEY-asingh114
This created the gpg key output which is saved into the RPM-GPG-KEY-asingh114 file. This file is placed into the /etc/pki/rpm-gpg/ directory and will be used by the repository.

As mentioned before, this repository will be tested by serving to internal clients. Therefore, I created a new repository file in the /etc/yum.repos.d directory called asingh114.repo, which contained the following:

[asingh114 repo]
name=Asingh114 Repository
failovermethod=priority
baseurl=http://localhost/repo/fedora/$basearch
enabled=1
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-asingh114

Notes:
- The gpgkey is pointing to the file I generated earlier.
- Notice the baseurl is pointing to my localhost. The yum built-in $basearch variable denotes the architecture such as i386 or x86_64, etc, hence using $basearch at the end allows it to be able to find the proper repository directories for the host depending on the host's architecure.
- Additionally, I could have used another yum variable, $releasever, which is the release version of the system (e.g. Fedora 12, 13 etc) to further organize content, but this is just a simple repository test and I figured it is not needed.

When I tested this on my host machine, it worked fine.


Moreover, these two files were packaged into the RPM below that was created using a SPEC file:
http://asdesigned.ca/asingh114-repo-1-1.fc12.i686.rpm

I wanted to try this on the test virtual machine (Fedora 13 64 bit) so I temporarily moved all other repository files from the test machines' /etc/yum.repos.d directory and installed the rpm I created. This placed my repository file and my GPG key file into the proper locations.
Then I ran yum to test it, which I was then prompted to import the keys - after which, it was able to pull from my own repository. Cool stuff!

By the way, we can also use rpm --import GRPM-GPG-KEY-asingh114 to import the GPG key files manually.

To summarize, the setup was as follows:
Host machine: Fedora 12 (32 bit)
- Repository Serving Protocol: HTTP, Web Server
- Repository Directories: /var/www/html/fedora/i386 and /var/www/html/fedora/x86_64

Test Virtual machine: Fedora 13 64 bit
- Moved all other repository files out of the /etc/yum.repos.d directory temporarily
- Repository configuration file installed: /etc/yum.repos.d/asingh114.repo via my RPM package
- GPG Key file installed: /etc/pki/rpm-gpg/RPM-GPG-KEY-asingh114 via my RPM package
- Ran yum

Monday, October 11, 2010

Mock and Koji testing with NLED (simple)

Mock:
After recreating my own NLED spec file, I test it with Mock using:
mock -r fedora-12-i386 --rebuild nled-252-6.fc12.src.rpm

The results were successful. I checked the log files in /var/lib/mock/fedora-12-i386/results/, mainly the root.log file and went through it. There were no errors and I did see the ncurses-devel dependency that I had originally placed into my spec file was tested. NLED was really simple so I didn't expect any errors anyway.
I expect to run into issues when I try my own SNORT and Irrsi spec file (when I get around to finishing them).

Koji:
Next, I installed Koji - the instructions are on http://fedoraproject.org/wiki/PackageMaintainers/UsingKoji
The basic steps are running yum install fedora-packager and then running the fedora-packager-setup, at which point you will be prompted to enter your FAS username and password.

In LAB 1 (Communication Lab), we created our FAS accounts, so I used those credentials successfully. It then creates the necessary certificates (see the fedoraproject.org link above for more information) and allows you to access the Koji Fedora Build system where you can see your builds and tests.

Here is a link to mine: Koji Fedora Builds
If you click on my "Tasks", you will see that I have tested NLED on Fedora 12 platforms and all were successful.

Below is the command and ouput for Koji on my Fedora system:
# koji build dist-f12 --scratch nled-2.52-6.fc12.src.rpm
2528731 build (dist-f12, nled-2.52-6.fc12.src.rpm) completed successfully

I have to say that Koji is excellent and was very easy to set up! It's good to have such a resource available.

Well, I am going to test SNORT and Irssi source RPMs here later and will post results.

P.S. Happy Thanksgiving! Mmm Turkey....and if you don't get any work done, blame it on the Tryptophan!!!