From c24bfbed3939da1736e0defe27ad29763cc47852 Mon Sep 17 00:00:00 2001 From: Mike McGrath Date: Wed, 30 Sep 2009 13:43:09 -0500 Subject: [PATCH] added mirrormanager base test --- scripts/site-tests/mirrormanager.py | 173 ++++++++++++++++++++++++++++ scripts/site-tests/tests.py | 44 +++++++ 2 files changed, 217 insertions(+) create mode 100644 scripts/site-tests/mirrormanager.py create mode 100644 scripts/site-tests/tests.py diff --git a/scripts/site-tests/mirrormanager.py b/scripts/site-tests/mirrormanager.py new file mode 100644 index 0000000..45aaa80 --- /dev/null +++ b/scripts/site-tests/mirrormanager.py @@ -0,0 +1,173 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import getpass +import mechanize +import sys + +from optparse import OptionParser +from mechanize import Browser, LinkNotFoundError +from urllib import urlencode +from urllib2 import HTTPError +from tests import * + +parser = OptionParser() + +parser.add_option('-u', '--username', + dest = 'username', + default = getpass.getuser(), + metavar = 'username', + help = 'Username to connect with (default: %default)') +parser.add_option('-p', '--password', + dest = 'password', + default = None, + metavar = 'password', + help = 'Password to connect with (Will prompt if not specified') +parser.add_option('-b', '--baseurl', + dest = 'baseurl', + default = 'https://admin.fedoraproject.org/mirrormanager/', + metavar = 'baseurl', + help = 'Url to mirrormanager (default: %default)') +parser.add_option('-d', '--debug', + dest = 'debug', + default = False, + action = 'store_true', + help = 'Url (default: False)') +(opts, args) = parser.parse_args() + +username = opts.username +headers = Headers(debug=opts.debug) + +if not opts.password: + password = getpass.getpass('FAS password for %s: ' % username) +else: + password = opts.password +del getpass + +print +print +print "Starting tests on MirrorManager" +print " Note: Results shown in terms of test success. Anything not OK should be looked at" +print + +b = Browser() +b.set_handle_robots(False) +data = urlencode({'user_name': username, + 'password': password, + 'login': 'Login'}) +data_bad = urlencode({'user_name': username, + 'password': 'badpass', + 'login': 'Login'}) + + +print 'Logging in bad password:', +try: + r = b.open(opts.baseurl, data=data_bad) +except HTTPError, e: + print OK +else: + print FAILED + +print 'Logging in good password:', +try: + r = b.open(opts.baseurl, data=data) +except HTTPError, e: + print '%s - %s' % (FAILED, e) +else: + print OK +headers.check(r._headers, 3000000) + +print 'Getting Link Count:', +hosts = sites = 0 +l = b.links() +try: + while 1: + link = l.next() + if link.url.startswith('/mirrormanager/site/'): + sites += 1 + if link.url.startswith('/mirrormanager/host/'): + hosts += 1 +except StopIteration: + pass +print OK +print '\tHosts %s - %s' % is_normal(hosts, 580) +print '\tSites %s - %s' % is_normal(sites, 555) + + +print 'Creating Site:', +r = b.follow_link(text_regex=r'Add Site') +b.select_form(name='form') +b['name'] = 'Fedora Admin Test Site - %s' % username +b['password'] = 'Test' +b['orgUrl'] = 'http://fedoraproject.org/' +b['downstreamComments'] = 'This is a test site, it should not exist. Please let admin@fedoraproject.org know it is here' +r = b.submit() +print OK + +headers.check(r._headers, 3000000) + +print 'Verifying Site:', +b.follow_link(text_regex=r'Main') +b.follow_link(text_regex=r'Fedora Admin Test Site - %s' % username) +b.select_form(name='form') +if b['name'] == 'Fedora Admin Test Site - %s' % username: + print '%s - %s' % (OK, b['name']) +else: + print '%s - %s' % (FAILED, b['name']) + sys.exit(1) + +print 'Deleting Site:', +r = b.follow_link(text_regex=r'Delete Site') +print OK +headers.check(r._headers, 3000000) + +print 'Verifying Deletion:', +r = b.follow_link(text_regex=r'Main') +try: + b.follow_link(text_regex=r'Fedora Admin Test Site - %s' % username) +except LinkNotFoundError: + print OK +else: + print '%s - Site still exists! Please examine' % FAILED +headers.check(r._headers, 3000000) + + +print 'Verifying Public List:' +r = b.open('http://mirrors.fedoraproject.org/publiclist/') +for version in [10, 11, 'rawhide']: + print 'Looking for %s' % version, + print '%s - %s' % (OK, b.find_link(text_regex=r'^%s$' % version).url) +headers.check(r._headers, 3000) + + +print 'Verifying mirrorlist:' +print '\tgeneric test:', +r = b.open('http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=i386') +generic_count = len(r.readlines()) - 1 +print '\t %s - %s' % is_normal(generic_count, 50) +headers.check(r._headers, 300000) + +print '\tglobal test:', +r = b.open('http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=i386&country=global') +generic_count = len(r.readlines()) - 1 +print '\t %s - %s' % is_normal(generic_count, 170) +headers.check(r._headers, 300000) + +print '\tgeoipv4 test:', +r = b.open('http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=i386&ip=64.34.163.94') +if r.readlines()[0].count('country = US'): + print OK +headers.check(r._headers, 300000) + +print '\tgeoipv6 test:', +r = b.open('http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=i386&ip=2610:28:200:1:216:3eff:fe62:9fdd') +if r.readlines()[0].count('country = US'): + print OK +headers.check(r._headers, 300000) + +print '\tASN test:', +r = b.open('http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=i386&ip=64.34.163.94') + +if r.readline().count('Using ASN 30099') and r.readline().count('serverbeach1'): + print OK +headers.check(r._headers, 300000) diff --git a/scripts/site-tests/tests.py b/scripts/site-tests/tests.py new file mode 100644 index 0000000..bc39eb7 --- /dev/null +++ b/scripts/site-tests/tests.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +color = { 'red' : '\x1b[0;31m', + 'green' : '\x1b[0;32m', + 'yellow' : '\x1b[1;33m', + 'white' : '\x1b[1;37m', + 'bold' : '\x1b[1m', + 'nobold' : '\x1b[22m', + 'default' : '\x1b[39m', + 'reset' : '\x1b[0m' } +OK = "%sOK%s" % (color['green'], color['reset']) +FAILED = "%sFAILED%s" % (color['red'], color['reset']) +WARNING = "%sWARNING%s" % (color['yellow'], color['reset']) + +def is_normal(count, baseline, percent='10'): + ''' Pass count and baseline and compare. Throws warning if not in acceptable range''' + baseline = float(baseline) + diff = ((count / baseline) * 100) - 100 + if diff < 0: + diff = diff * -1 + if diff > 10: + return (WARNING, '%s is greater then %%%.4s of baseline. (Maybe baseline needs an update?)', (count, diff)) + else: + return (OK, '%s is within %%%.4s of baseline' % (count, diff)) + + +class Headers(): + debug=None + def __init__(self, debug=None): + self.debug=debug + return + + def check(self, headers, baseline): + ''' Check the headers of a page for slowness or other errors ''' + if self.debug: + print "\tProxy time: %s" % headers['proxytime'].split('=')[1] + print "\tProxy server: %s" % headers['proxyserver'] + print "\tApp time: %s" % headers['apptime'].split('=')[1] + print "\tApp server: %s" % headers['appserver'] + + if headers['proxytime'].split('=')[1] > baseline: + print "\t%s Proxy Time slower than baseline %s > %s" % (WARNING, headers['proxytime'].split('=')[1], baseline) + return (WARNING, headers['proxytime'].split('=')[1]) \ No newline at end of file