Friday, November 26, 2010

SBR600 project 0.2 (man page checker)e

The test I'm trying to implement extracts the man pages from the package uploaded in the koji-build system and see the SEE ALSO section of the man pages to check if any invalid links are contained.
The following script is to get a list of man-pages from RPMs uploaded in the koji-build system

#!/bin/bash
# parameter - directory with rpm
# ouptput - list of its man-pages
rpm_path=$1

for rpm in `ls $rpm_path`; do
if [[ $rpm == *.rpm ]]
then
rpm -qlp $rpm_path/$rpm 2>/dev/null| grep "^/usr/share/man/man.*"
fi
done


After getting a list of man pages, the following script test the man pages extracted

#!/bin/bash
# first parametr - srpm
# second parametr - man-pages list
# output - false SEE ALSO links

rpm=$1
list=$2
#set -x

mkdir ./tmp
cd ./tmp
rpm2cpio ../$1 >tmp.cpio
cpio -i -d --force-local /dev/null

if [ -d ./usr/share/man/ ]; then

for i in `ls ./usr/share/man/man[0-9]*/*`; do
# find the start of SEE ALSO section
if [ `zcat $i | grep -n "SEE ALSO" | grep ".SH" | wc -l` -ne 0 ]; then
# begin of this section
min=`zcat $i | grep -n "SEE ALSO" | grep ".SH" | sed "s|:.*||" | head -n1`
max=`zcat $i | wc -l`

let "suf=$max-$min"
if [ $suf -ne 0 ]; then
# end of SEE ALSO section
end=`zcat $i >/dev/null| tail -n$suf | grep -n ".SH" | head -n1 | sed "s|:.*||"`
if [ "x" = "x$d" ]; then
# there is next section after SEE ALSO
# SEE ALSO is the last section
end=`zcat $i |wc -l`
else
# SEE ALSO is the last section
let end="$end-1"
fi

fil1=`zcat $i | tail -n$suf | head -n$end | grep "^.BR" | sed "s|.BR \([^ ]*\) (\([1-9][^ ]*\)).*|/usr/share/man/man\2/\1.\2.|g" | grep -v BR`
for jj in `echo $fil1`; do
j=`echo $jj | sed 's|\\\-|-|g'`
grep "$j" ../$2 >/dev/null;
if [ $? -ne 0 ]; then
j2=`echo $j | sed "s|/usr/share/man/man\(.*\)/\([^.]*\).*|/usr/share/man/man.*/\2.[0-9]|"`
pom=`grep "$j2" ../$2`
if [ `echo $pom | wc -l` -ne 0 ]; then
printf " BUG - package: %20s, man-page: %30s, link %20s\n" $1 $i $j
fi
else
printf " OK - package: %20s, man-page: %30s, link %20s\n" $1 $i $j
fi
done
fi
fi
done
fi



1. Install and configure AutoQA # Some useful imports
import autoqa.util
from autoqa.test import AutoQATest
from autoqa.decorators import ExceptionCatcher
from autotest_lib.client.bin import utils

# Your class name must match file name (without .py) and also run_test line in
# its control file.
class (AutoQATest): # <-- UPDATE Classname version = 1 # increment this if setup() changes # During the execution fill these variables: # self.result: test result keyword # self.summary: one line test result summary # self.outputs: full test output (string or list of strings) # self.highlights: important lines to notice (string or list of strings) @ExceptionCatcher("self.run_once_failed") def run_once(self, some_params, **kwargs): #**kwargs needs to stay cmd = 'test_binary --param %s' % some_params self.outputs = utils.system_output(cmd, retain_output=True) self.result = "PASSED" #FAILED, INFO, ABORTED, ... self.summary = "This test was awesome!" self.highlights = "Note these important lines, if you miss them,\n" self.highlights += "you'll regret it forever.
  • Get the source code using GIT : git clone git://git.fedorahosted.org/autoqa.git autoqa : #This command downloads the source code us
  • For Fedora, execute the command: wget -P /etc/yum.repos.d http://repos.fedorapeople.org/repos/fedora-qa/autoqa/fedora-autoqa.repo
  • Yum repository for AutoQA server has been set up. Use yum to download it : yum install autoqa
  • Now on the server, event watchers, which triggers corresponding autoqa tests when events occur, are needed to run periodically. :
    cp /usr/share/autoqa/autoqa.cron /etc/cron.d/
2. Setting for the new test.

There's four parts to a test: the test code, the test object, the Autotest control file, and the AutoQA control file. all live in a single directory, located in the tests directory of the autoqa source directory. From the autoqa/doc directory, copy template files, autoqa.template, autoqa.control.template, and test_class.py to the directory /tests/man_page_checker/ and rename them autoqa, autoqa.control, and man_page_checker.py respectively. After that, put the man_page_checker source code in it.

* control file for man_page_checker
AUTHOR = "Jaewoo Park "
TIME="SHORT"
NAME = 'man_page_checker' #name of the test
DOC = """
This test checks validity in man pages
"""
TEST_TYPE = 'CLIENT'
TEST_CLASS = 'General'
TEST_CATEGORY = 'Functional'
job.run_test('man_page_checker', config=autoqa_conf, **autoqa_args)
# should use the name of test for the first value


* control.autoqa file

# this test can be run just once and on any architecture
archs = ['noarch']

# we want to run this test just for post-koji-build hook
if hook not in ['post-koji-build']:
execute = False


* man_page_checker.py file

# Some useful imports
import autoqa.util
from autoqa.test import AutoQATest
from autoqa.decorators import ExceptionCatcher
from autotest_lib.client.bin import utils

# Your class name must match file name (without .py) and also run_test line in
# its control file.
class (AutoQATest): # <-- UPDATE Classname
version = 1 # increment this if setup() changes

# During the execution fill these variables:
# self.result: test result keyword
# self.summary: one line test result summary
# self.outputs: full test output (string or list of strings)
# self.highlights: important lines to notice (string or list of strings)
@ExceptionCatcher("self.run_once_failed")
def run_once(self, some_params, **kwargs): #**kwargs needs to stay
cmd = 'test_binary --param %s' % some_params
self.outputs = utils.system_output(cmd, retain_output=True)
self.result = "PASSED" #FAILED, INFO, ABORTED, ...
self.summary = "This test was awesome!"
self.highlights = "Note these important lines, if you miss them,\n"
self.highlights += "you'll regret it forever.
"


Thursday, November 11, 2010

SBR600 - AutoQA Project plan 0.1

Project plan 0.1 : Autotest server setting.

AutoQA is an automated test system for Fedora. Its design is simple: when certain events occur, AutoQA launches automated tests.
Autotest is currently b used as the test harness for AutoQA. It handles the dirty work of getting code onto test machines, running it, and holding all the results. Autotest is currently packaged for Fedora 13, but due to unpackaged dependencies, is not yet available for Fedora. Hence in order to install autotest, AutoQA package repository is needed to be configured first.
#wget -P /etc/yum.repos.d http://repos.fedorapeople.org/repos/fedora-qa/autoqa/fedora-autoqa.repo : This command adds the autoQA repository to the fedora repository directory.

Finally, with yum repositories configured, use the yum command to install autotest and it's dependencies.
# yum install autotest-server : This step installs autotest-server and its dependencies

The autotest server requires the Apache HTTP Server. No additional configuration is required,
autotest provides a /etc/httpd/conf.d/autotest.conf configuration file. All the conf files in
the conf.d directory will be included when httpd starts.

1. Start httpd:
# service httpd restart

2. Configure httpd to start on system boot:
# chkconfig httpd on

Autotest requires access to a mysql server. Also need set up a password for the mysql root . If it's not done, errors occur
#mysqladmin -u root password sbr600
After this, create the autotest_web and autotest_tko databases and user permissions needed by autotest.

create database autotest_web; grant all privileges on autotest_web.* TO 'autotest'@'localhost' identified by 'NEWPASSWORD'; grant SELECT on autotest_web.* TO 'nobody'@'%'; grant SELECT on autotest_web.* TO 'nobody'@'localhost'; flush privileges;

create database autotest_tko; grant all privileges on autotest_tko.* TO 'autotest'@'localhost' identified by 'NEWPASSWORD'; grant SELECT on autotest_tko.* TO 'nobody'@'%'; grant SELECT on autotest_tko.* TO 'nobody'@'localhost'; flush privileges;

With the mysql database configured, it's time to tell autotest how to connect, and to pre-populate the database with initial data.

1. The /usr/share/autotest/global_config.ini file is needed to be modified to do this.

In sections [TKO] and [AUTOTEST_WEB], enter the correct values for password
In section [TKO], change the value of database to autotest_tko
In section [SERVER], set the value of hostname

2. Setup the database schemas and populate initial data

# python /usr/share/autotest/database/migrate.py --database=AUTOTEST_WEB sync
# python /usr/share/autotest/database/migrate.py --database=TKO sync

3. Run the Django syncdb operation

# python /usr/share/autotest/frontend/manage.py syncdb --noinput

4. Restart httpd

# service httpd restart

5. Start the autotest scheduler

# service autotestd start

If all the steps are properly done, you can access web-based autotest server page.