diff --git a/README b/README index 8ab250f..0fe974b 100644 --- a/README +++ b/README @@ -1,6 +1,7 @@ -This script will run through some basic sanity tests for a Red Hat Enterprise Linux image -A valid Red Hat bugzilla username and password will be required at the end of the script -http://bugzilla.redhat.com/ - - -USAGE image_validation --help +MOVED TO https://github.com/RedHatQE/valid +MOVED TO https://github.com/RedHatQE/valid +MOVED TO https://github.com/RedHatQE/valid +MOVED TO https://github.com/RedHatQE/valid +MOVED TO https://github.com/RedHatQE/valid +MOVED TO https://github.com/RedHatQE/valid +MOVED TO https://github.com/RedHatQE/valid \ No newline at end of file diff --git a/src/bugzilla/__init__.pyc b/src/bugzilla/__init__.pyc index 89e466a..767b816 100644 Binary files a/src/bugzilla/__init__.pyc and b/src/bugzilla/__init__.pyc differ diff --git a/src/bugzilla/base.pyc b/src/bugzilla/base.pyc index d37bad4..9285362 100644 Binary files a/src/bugzilla/base.pyc and b/src/bugzilla/base.pyc differ diff --git a/src/bugzilla/bugzilla3.pyc b/src/bugzilla/bugzilla3.pyc index 3e3948e..cb8fd7c 100644 Binary files a/src/bugzilla/bugzilla3.pyc and b/src/bugzilla/bugzilla3.pyc differ diff --git a/src/bugzilla/nvlbugzilla.pyc b/src/bugzilla/nvlbugzilla.pyc index cc4342c..dec26fa 100644 Binary files a/src/bugzilla/nvlbugzilla.pyc and b/src/bugzilla/nvlbugzilla.pyc differ diff --git a/src/bugzilla/rhbugzilla.pyc b/src/bugzilla/rhbugzilla.pyc index 7c6a952..37ceb42 100644 Binary files a/src/bugzilla/rhbugzilla.pyc and b/src/bugzilla/rhbugzilla.pyc differ diff --git a/src/bugzilla/util.py b/src/bugzilla/util.py index 1580d9c..14a4f34 100644 --- a/src/bugzilla/util.py +++ b/src/bugzilla/util.py @@ -28,7 +28,7 @@ def open_without_clobber(name, *args): while fd is None: try: fd = os.open(name, os.O_CREAT|os.O_EXCL, 0666) - except OSError as e: + except OSError, e: if e.errno == os.errno.EEXIST: name = "%s.%i" % (orig_name, count) count += 1 diff --git a/src/bugzilla/util.pyc b/src/bugzilla/util.pyc index 6101ec9..e86c09f 100644 Binary files a/src/bugzilla/util.pyc and b/src/bugzilla/util.pyc differ diff --git a/src/getAmiDetails.py b/src/getAmiDetails.py index 70c587b..e161bda 100755 --- a/src/getAmiDetails.py +++ b/src/getAmiDetails.py @@ -31,7 +31,8 @@ parser.add_option('-z','--bugzilla_password', type='string',dest='BZPASS',help='bugzilla password') parser.add_option('-m','--arch', dest='ARCH', default='x86_64', help='arch = i386, or x86_64') parser.add_option('-x','--ignore', dest='IGNORE', default='IGNORE', help='If set.. ignore the generated bug') #c1.medium -parser.add_option('-g','--noGit',dest='NOGIT', default=False, help='If set.. do not pull valid src from git, scp to each instance' ) +parser.add_option('-g','--noGit',dest="NOGIT", default=True, help='If set.. do not pull valid src from git, scp to each instance' ) +#parser.add_option('-g','--noGit',action="store_true", default=True, help='If set.. do not pull valid src from git, scp to each instance' ) parser.add_option('-d','--baseDir',dest='BASEDIR',type='string',help='the dir of the src checkout ie.. ~/workspace/valid/src') @@ -66,7 +67,8 @@ print "**** No bugzilla # was passed, will open one here ****" bugzilla=Bugzilla36(url='https://bugzilla.redhat.com/xmlrpc.cgi',user=BZUSER,password=BZPASS) mySummary=AMI+" "+RHEL+" "+ARCH+" "+REGION - BZ_Object=bugzilla.createbug(product="Cloud Image Validation",component="images",version="RHEL6.1",rep_platform="x86_64",summary=mySummary) + RHV="RHEL"+RHEL + BZ_Object=bugzilla.createbug(product="Cloud Image Validation",component="images",version=RHV,rep_platform=ARCH,summary=mySummary) BZ = str(BZ_Object.bug_id) print "Buzilla # = https://bugzilla.redhat.com/show_bug.cgi?id="+ BZ else: diff --git a/src/getAmiDetails_withCSV.py b/src/getAmiDetails_withCSV.py new file mode 100755 index 0000000..82b8f65 --- /dev/null +++ b/src/getAmiDetails_withCSV.py @@ -0,0 +1,341 @@ +#!/usr/bin/python -tt + +from pprint import pprint +from boto import ec2 +import boto, thread +import sys, time, argparse, os +import csv +#from boto.ec2.blockdevicemapping import BlockDeviceMapping +from boto.ec2.blockdevicemapping import EBSBlockDeviceType, BlockDeviceMapping +from bugzilla.bugzilla3 import Bugzilla36 +import rhui_lib +import ConfigParser + +config = ConfigParser.ConfigParser() +config.read('/etc/validation.cfg') + +argparser = argparse.ArgumentParser(description=\ + 'Remotely execute validation testcases') +argparser.add_argument('--skip-tests', metavar='',nargs="*", + help="space-separated expressions describing tests to skip") +argparser.add_argument('--list-tests', action='store_const', const=True, + default=False, help='display available test names and exit') +args = argparser.parse_args() + +if args.skip_tests: + SKIPLIST=",".join(args.skip_tests) +else: + SKIPLIST="" + +if args.list_tests: + os.system("./image_validation.sh --list-tests") + sys.exit() + +#us-west-2 has been used as SSHKEY_US_O and SSHKEY_NAME_US_O, O stands for +#Oregon + +SSHKEY_NAME_AP_S = config.get('SSH-Info', 'ssh-key-name_apsouth') +SSHKEY_AP_S = config.get('SSH-Info', 'ssh-key-path_apsouth') +SSHKEY_NAME_AP_N = config.get('SSH-Info', 'ssh-key-name_apnorth') +SSHKEY_AP_N = config.get('SSH-Info', 'ssh-key-path_apnorth') +SSHKEY_NAME_EU_W = config.get('SSH-Info', 'ssh-key-name_euwest') +SSHKEY_EU_W = config.get('SSH-Info', 'ssh-key-path_euwest') +SSHKEY_NAME_US_W = config.get('SSH-Info', 'ssh-key-name_uswest') +SSHKEY_US_W = config.get('SSH-Info', 'ssh-key-path_uswest') +SSHKEY_NAME_US_E = config.get('SSH-Info', 'ssh-key-name_useast') +SSHKEY_US_E = config.get('SSH-Info', 'ssh-key-path_useast') +SSHKEY_NAME_US_O = config.get('SSH-Info', 'ssh-key-name_uswest-oregon') +SSHKEY_US_O = config.get('SSH-Info', 'ssh-key-path_uswest-oregon') + +BZUSER = config.get('Bugzilla-Info', 'bugzilla_usr') +BZPASS = config.get('Bugzilla-Info', 'bugzilla_pwd') + +AWS_ACCESS_KEY_ID = config.get('EC2-Keys', 'ec2-key') +AWS_SECRET_ACCESS_KEY = config.get('EC2-Keys', 'ec2-secret-key') + +CSV = config.get('Misc-Info', 'csv') +NOGIT = config.get('Misc-Info', 'git') +BASEDIR = config.get('Misc-Info', 'basedir') + +BZ = None + +val1 = { + 'SSHKEY_US_E': SSHKEY_US_E, + 'SSHKEY_NAME_US_E': SSHKEY_NAME_US_E, + 'SSHKEY_US_O': SSHKEY_US_O, + 'SSHKEY_NAME_US_O': SSHKEY_NAME_US_O, + 'SSHKEY_US_W': SSHKEY_US_W, + 'SSHKEY_NAME_US_W': SSHKEY_NAME_US_W, + 'SSHKEY_EU_W': SSHKEY_EU_W, + 'SSHKEY_NAME_EU_W': SSHKEY_NAME_EU_W, + 'SSHKEY_AP_N': SSHKEY_AP_N, + 'SSHKEY_NAME_AP_N': SSHKEY_NAME_AP_N, + 'SSHKEY_AP_S': SSHKEY_AP_S, + 'SSHKEY_NAME_AP_S': SSHKEY_NAME_AP_S, + 'BZUSER': BZUSER, + 'BZPASS': BZPASS, + 'AWS_ACCESS_KEY_ID': AWS_ACCESS_KEY_ID, + 'AWS_SECRET_ACCESS_KEY': AWS_SECRET_ACCESS_KEY, + 'CSV': CSV, + 'NOGIT': NOGIT, + 'BASEDIR': BASEDIR, +} + +for v in val1: + if not val1[v]: + print "The value ", v, "is missing in .cfg file." + sys.exit() + +CSVFILE = "test1.csv" + +def addBugzilla(BZ, AMI, RHEL, ARCH, REGION): + if BZ is None: + print "**** No bugzilla # was passed, will open one here ****" + bugzilla=Bugzilla36(url='https://bugzilla.redhat.com/xmlrpc.cgi',user=BZUSER,password=BZPASS) + mySummary=AMI+" "+RHEL+" "+ARCH+" "+REGION + RHV = "RHEL"+RHEL + BZ_Object=bugzilla.createbug(product="Cloud Image Validation",component="images",version=RHV,rep_platform=ARCH,summary=mySummary) + BZ = str(BZ_Object.bug_id) + print "Buzilla # = https://bugzilla.redhat.com/show_bug.cgi?id="+ BZ + return BZ + else: + mySummary=AMI+" "+RHEL+" "+ARCH+" "+REGION + print "Already opened Buzilla # = https://bugzilla.redhat.com/show_bug.cgi?id="+ BZ + return BZ + + file = open('/tmp/bugzilla',"a") + file.write("\n") + file.write(BZ) + file.write("\t") + file.write(mySummary) + file.close() + os.system("cp "+BASEDIR+"/nohup.out "+BASEDIR+"/nohup_"+AMI+".out ; cat /dev/null > "+BASEDIR+"/nohup.out") + +if CSV == 'false': + BID = addBugzilla(BZ, AMI, RHEL, ARCH, REGION) + + +def getConnection(key, secret, region): + """establish a connection with ec2""" + reg = boto.ec2.get_region(region, aws_access_key_id=key, aws_secret_access_key=secret) + return reg.connect(aws_access_key_id=key, aws_secret_access_key=secret) + +#east# reservation = ec2conn.run_instances('ami-8c8a7de5', instance_type='t1.micro', key_name='cloude-key') +#block_device_map +#'/dev/sda=:20' + +def startInstance(ec2connection, hardwareProfile, ARCH, RHEL, AMI, SSHKEYNAME): + conn_region = ec2connection + map = BlockDeviceMapping() + t = EBSBlockDeviceType() + t.size = '15' + #map = {'DeviceName':'/dev/sda','VolumeSize':'15'} + map['/dev/sda1'] = t + + #blockDeviceMap = [] + #blockDeviceMap.append( {'DeviceName':'/dev/sda', 'Ebs':{'VolumeSize' : '100'} }) + + if ARCH == 'i386' and RHEL == '6.1': + reservation = conn_region.run_instances(AMI, instance_type=hardwareProfile, key_name=SSHKEYNAME, block_device_map=map ) + elif ARCH == 'x86_64' and RHEL == '6.1': + reservation = conn_region.run_instances(AMI, instance_type=hardwareProfile, key_name=SSHKEYNAME, block_device_map=map ) + elif ARCH == 'i386': + reservation = conn_region.run_instances(AMI, instance_type=hardwareProfile, key_name=SSHKEYNAME, block_device_map=map ) + elif ARCH == 'x86_64': + reservation = conn_region.run_instances(AMI, instance_type=hardwareProfile, key_name=SSHKEYNAME, block_device_map=map) + else: + print "arch type is neither i386 or x86_64.. will exit" + exit(1) + + myinstance = reservation.instances[0] + + time.sleep(5) + while(not myinstance.update() == 'running'): + time.sleep(5) + print myinstance.update() + + instanceDetails = myinstance.__dict__ + pprint(instanceDetails) + #region = instanceDetails['placement'] + #print 'region =' + region + publicDNS = instanceDetails['public_dns_name'] + print 'public hostname = ' + publicDNS + # check for console output here to make sure ssh is up + return publicDNS + +def executeValidScript(SSHKEY, publicDNS, hwp, BZ, ARCH, AMI, REGION, RHEL, SKIPLIST=""): + filepath = BASEDIR + serverpath = "/root/valid" + commandPath = "/root/valid/src" + + if NOGIT == 'false': + if hwp["name"] == 't1.micro': + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" mkdir -p /root/valid") + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" touch /root/noswap") + else: + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" mkdir -p /root/valid") + print "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath+"\n" + os.system("scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath) + elif NOGIT == 'true': + if hwp["name"] == 't1.micro': + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" touch /root/noswap") + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" yum -y install git") + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" git clone git://github.com/dparalen/valid.git") + + + # COPY KERNEL if there + serverpath = "/root/kernel" + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" mkdir -p /root/kernel") + if ARCH == 'i386': + filepath = BASEDIR+"/kernel/i386/*" + print "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath+"\n" + os.system("scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath) + if ARCH == 'x86_64': + filepath = BASEDIR+"/kernel/x86_64/*" + print "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath+"\n" + os.system("scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath) + + + +# command = commandPath+"/image_validation.sh --imageID="+IGNORE+AMI+"_"+REGION+"_"+hwp["name"]+" --RHEL="+RHEL+" --full-yum-suite=yes --skip-questions=yes --bugzilla-username="+BZUSER+" --bugzilla-password="+BZPASS+" --bugzilla-num="+BZ+ " --memory="+hwp["memory"] + command = commandPath+"/image_validation.sh --skip-list='"+SKIPLIST+"' --imageID="+AMI+"_"+REGION+"_"+hwp["name"]+" --RHEL="+RHEL+" --full-yum-suite=yes --skip-questions=yes --bugzilla-username="+BZUSER+" --bugzilla-password='"+BZPASS+"' --bugzilla-num="+BZ+ " --memory="+hwp["memory"]+" --public-dns="+publicDNS+" --ami-id="+AMI+" --arch-id="+ARCH + + print "nohup ssh -n -f -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" "+command + print "" + os.system("nohup ssh -n -f -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" "+command) + + +def printValues(hwp): + print "+++++++" + print AMI + print REGION + print SSHKEY + print RHEL + print hwp + print "+++++++\n" + +def myfunction(string, sleeptime,lock,SSHKEY,publicDNS): + #entering critical section + lock.acquire() + print string," Now Sleeping after Lock acquired for ",sleeptime + time.sleep(sleeptime) + + print string," Now releasing lock and then sleeping again" + lock.release() + + #exiting critical section + time.sleep(sleeptime) # why? + +# Define hwp +m1Small = {"name":"m1.small","memory":"1700000","cpu":"1","arch":"i386"} +m1Large = {"name":"m1.large","memory":"7500000","cpu":"2","arch":"x86_64"} +m1Xlarge = {"name":"m1.xlarge","memory":"15000000","cpu":"4","arch":"x86_64"} +t1Micro = {"name":"t1.micro","memory":"600000","cpu":"1","arch":"both"} +m2Xlarge = {"name":"m2.xlarge","memory":"17100000","cpu":"2","arch":"x86_64"} +m22Xlarge = {"name":"m2.2xlarge","memory":"34200000","cpu":"4","arch":"x86_64"} +m24Xlarge = {"name":"m2.4xlarge","memory":"68400000","cpu":"8","arch":"x86_64"} +c1Medium = {"name":"c1.medium","memory":"1700000","cpu":"2","arch":"i386"} +c1Xlarge = {"name":"c1.xlarge","memory":"7000000","cpu":"8","arch":"x86_64"} + + +#Use all hwp types for ec2 memory tests, other hwp tests +hwp_i386 = [c1Medium, t1Micro , m1Small ] +#hwp_i386 = [c1Medium] +hwp_x86_64 = [m1Xlarge, t1Micro , m1Large , m2Xlarge, m22Xlarge, m24Xlarge , c1Xlarge] +#hwp_x86_64 = [m24Xlarge] + +#Use just one hwp for os tests +#hwp_i386 = [c1Medium] +#hwp_x86_64 = [m1Xlarge,m22Xlarge] +if CSV == 'true': + reader = csv.reader(open(CSVFILE,"rb")) + fields = reader.next() + ami = [(row[0], row[1], row[2], row[3], row[4], row[5]) for row in reader] + for x in range(len(ami)): + myRow = ami[x] + print myRow + ARCH = myRow[0] + REGION = myRow[1] + RHEL = myRow[4] +# BZ = myRow[3] + AMI = myRow[5] + + BID = addBugzilla(BZ, AMI, RHEL, ARCH, REGION) + + if REGION == "us-east-1": + SSHKEY = SSHKEY_US_E + SSHKEYNAME = SSHKEY_NAME_US_E + elif REGION == "us-west-2": + SSHKEY = SSHKEY_US_O + SSHKEYNAME = SSHKEY_NAME_US_O + elif REGION == "us-west-1": + SSHKEY = SSHKEY_US_W + SSHKEYNAME = SSHKEY_NAME_US_W + elif REGION == "eu-west-1": + SSHKEY = SSHKEY_EU_W + SSHKEYNAME = SSHKEY_NAME_EU_W + elif REGION == "ap-southeast-1": + SSHKEY = SSHKEY_AP_S + SSHKEYNAME = SSHKEY_NAME_AP_S + elif REGION == "ap-northeast-1": + SSHKEY = SSHKEY_AP_N + SSHKEYNAME = SSHKEY_NAME_AP_N + + + publicDNS = [] + if ARCH == 'i386': + for hwp in hwp_i386: + printValues(hwp) + myConn = getConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, REGION) + this_hostname = startInstance(myConn, hwp["name"], ARCH, RHEL, AMI, SSHKEYNAME) + map = {"hostname":this_hostname,"hwp":hwp} + publicDNS.append(map) + elif ARCH == 'x86_64': + for hwp in hwp_x86_64: + printValues(hwp) + myConn = getConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, REGION) + this_hostname = startInstance(myConn, hwp["name"], ARCH, RHEL, AMI, SSHKEYNAME) + map = {"hostname":this_hostname,"hwp":hwp} + publicDNS.append(map) + + lock = thread.allocate_lock() +# print "sleep for 130 seconds" +# time.sleep(130) + print "Trying to fetch a file to make sure the SSH works, before proceeding ahead." + f_path = "/tmp/network" + l_path = "/etc/init.d/network" + for host in publicDNS: + keystat = rhui_lib.putfile(host["hostname"], SSHKEY, l_path, f_path) + if not keystat: + executeValidScript(SSHKEY, host["hostname"], host["hwp"], BID, ARCH, AMI, REGION, RHEL, SKIPLIST) + else: + print "The Amazon node : "+host["hostname"]+" is not accessible, waited for 210 sec. Skipping and proceeding with the next Profile" +else: + publicDNS = [] + if ARCH == 'i386': + for hwp in hwp_i386: + printValues(hwp) + myConn = getConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, REGION) + this_hostname = startInstance(myConn, hwp["name"], ARCH, RHEL, AMI, SSHKEYNAME) + map = {"hostname":this_hostname,"hwp":hwp} + publicDNS.append(map) + elif ARCH == 'x86_64': + for hwp in hwp_x86_64: + printValues(hwp) + myConn = getConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, REGION) + this_hostname = startInstance(myConn, hwp["name"], ARCH, RHEL, AMI, SSHKEYNAME) + map = {"hostname":this_hostname,"hwp":hwp} + publicDNS.append(map) + + lock = thread.allocate_lock() +# print "sleep for 130 seconds" +# time.sleep(130) + print "Trying to fetch a file and make sure the SSH works, before proceeding ahead." + f_path = "/tmp/network" + l_path = "/etc/init.d/network" + for host in publicDNS: + keystat = rhui_lib.putfile(host["hostname"], SSHKEY, l_path, f_path) + if not keystat: + executeValidScript(SSHKEY, host["hostname"],host["hwp"], BID, ARCH, AMI, REGION, RHEL, SKIPLIST) + else: + print "The Amazon node : "+host["hostname"]+" is not accessible, waited for 210 sec. Skipping and proceeding with the next Profile" diff --git a/src/image_validation.sh b/src/image_validation.sh index b742922..aa95382 100755 --- a/src/image_validation.sh +++ b/src/image_validation.sh @@ -14,10 +14,41 @@ # # written by whayutin@redhat.com # modified by kbidarka@redhat.com for RHEL 6 +# mkovacik@redhat.com FAILURES=0 MEM_HWP=0 +# try to pushd to a `valid' source tree +[ -z $BASEDIR ] && BASEDIR=/root/valid/src +[ -d $BASEDIR ] || BASEDIR=$PWD +pushd $BASEDIR > /dev/null +source testlib.sh + +function list_tests(){ + # return the list of defined tests + declare -F | cut -d\ -f3,3 | grep "^test_.*" +} + +function filter_tests(){ + # produces the list of tests to execute + # args: + # list of skip expressions to use with egrep + # return: + # list of passing function names + + # @ is an identity element; hopefully, it won't ever match ;) + local skip="@,${@}" + skip="${skip%,}" # cut off trailing spaces; takes care of empty $@, too + # convert the coma or space separated list to an expression of elements + # separated by `|' + shopt -s extglob + skip="${skip//*([[:space:]])[,[:space:]]*([[:space:]])/|}" + shopt -u extglob + # figure out all test functions passing the skip list + list_tests | egrep -v "${skip}" +} + function usage() { echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " @@ -38,9 +69,14 @@ function usage() echo "--bugzilla-num :: If a bug has already been opened you can specify the number here " echo "--memory :: Minium total memory the system *should* have available" echo "--public-dns :: The Public-DNS Host name of the machine" + echo "--ami-id :: The AMI ID" + echo "--arch-id :: The Architecture i386 or x86_64 for the launched instance" + echo "--skip-list :: A list of coma-separated expressions specifying test names + to skip. A skip-list might contain: + test_repos,test_yum_full_test,test_IPv6" + echo "--list-tests :: list available tests" } - #cli for i in $* do @@ -78,14 +114,29 @@ for i in $* --public-dns=*) PUB_DNS="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" ;; + --ami-id=*) + AMI_ID="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" + ;; + --arch-id=*) + ARCH_ID="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" + ;; + --skip-list=*) + SKIP_LIST="${i#*=}" + ;; + --list-tests) + list_tests + exit 0 + ;; + *) - # unknown option + # unknown option usage exit 1 ;; esac done - +# initialize testlib +_testlib_init if [[ -z $IMAGEID ]] || [[ -z $RHELV ]] || [[ -z $yum_test ]] || [[ -z $BUG_USERNAME ]] || [[ -z $BUG_PASSWORD ]] || [[ -z $MEM_HWP ]]; then usage @@ -94,8 +145,6 @@ fi -pushd /root/valid/src -source $PWD/testlib.sh ### DONT REMOVE OR COMMENT OUT ### echo "opening a bugzilla for logging purposes" @@ -122,47 +171,18 @@ if [ $QUESTIONS == "no" ];then fi echo "##### START TESTS #####" echo "" -test_uname -test_disk_format -test_disk_size -test_swap_file -test_selinux -test_package_set -test_verify_rpms -test_gpg_keys -#test_repos #remarking this out for now.. until additional repo's land. the yum tests should be sufficient -test_yum_plugin -if [ $yum_test == "yes" ];then - test_yum_full_test -else - test_yum_general_test -fi -test_bash_history -test_system_id -test_cloud-firstboot -test_nameserver -test_group -test_passwd -test_inittab -test_shells -#test_IPv6 no longer needed -test_networking -test_iptables -test_sshd -test_chkconfig -test_syslog -test_auditd -test_sshSettings -test_libc6-xen.conf -test_grub -#installTestKernel -test_resize2fs -test_fetch_host_details +# skip-list might contain +# installTestKernel,test_repos,test_yum_full_test,test_IPv6, + +for f in $( filter_tests $SKIP_LIST ) ; do + $f +done ### DONT REMOVE OR COMMENT OUT ### show_failures open_bugzilla bugzilla_comments +sed -i 's/default=1/default=0/' /boot/grub/grub.conf setup_rc.local #sos_report echo "REBOOTING" @@ -173,9 +193,3 @@ echo "REBOOTING" reboot #im_exit ################################## - - - - - - diff --git a/src/image_validation.sh~ b/src/image_validation.sh~ deleted file mode 100755 index 10b26b0..0000000 --- a/src/image_validation.sh~ +++ /dev/null @@ -1,171 +0,0 @@ -#!/bin/bash -# Copyright (c) 2010 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# -# written by whayutin@redhat.com -# modified by kbidarka@redhat.com for RHEL 6 - -FAILURES=0 -MEM_HWP=0 - -function usage() -{ - echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " - echo "Please use all options" - echo "" - echo " This script will run through some basic sanity tests for a Red Hat Enterprise Linux image " - echo " A valid Red Hat bugzilla username and password will be required at the end of the script " - echo " http://bugzilla.redhat.com/ " - echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " - echo "" - echo "Available options are:" - echo "--imageID= :: Please provide a unique id for the image" - echo "--RHEL= :: Please specify the correct FULL rhel version eg: --RHEL=5.7 or --RHEL=6.1" - echo "--full-yum-suite= :: Please input the value "yes" OR "no"" - echo "--skip-questions= :: Please input the value "yes" or "no"" - echo "--bugzilla-username :: Please specify your bugzilla username@email.com" - echo "--bugzilla-password :: Please specify your bugzilla password" - echo "--bugzilla-num :: If a bug has already been opened you can specify the number here " - echo "--memory :: Minium total memory the system *should* have available" -} - - -#cli -for i in $* - do - case $i in - --imageID=*) - IMAGEID="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --RHEL=*) - RHELV="`echo $i | sed 's/[-A-Z]*=//'`" - ;; - --full-yum-suite=*) - yum_test="`echo $i | sed 's/[-a-zA-Z]*=//'`" - if [ "$yum_test" == "yes" ] || [ "$yum_test" == "no" ]; then - : - else - usage - exit 1 - fi - ;; - --skip-questions=*) - QUESTIONS="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --bugzilla-username=*) - BUG_USERNAME="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --bugzilla-password=*) - BUG_PASSWORD="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --bugzilla-num=*) - BUG_NUM="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --memory=*) - MEM_HWP="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - *) - # unknown option - usage - exit 1 - ;; - esac -done - - -if [[ -z $IMAGEID ]] || [[ -z $RHELV ]] || [[ -z $yum_test ]] || [[ -z $BUG_USERNAME ]] || [[ -z $BUG_PASSWORD ]] || [[ -z $MEM_HWP ]]; then - usage - exit 1 -fi - - - -pushd /root/valid/src -source $PWD/testlib.sh - -echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " -echo " This script will run through some basic sanity tests for a Red Hat Enterprise Linux image " -echo " A valid Red Hat bugzilla username and password will be required at the end of the script " -echo " http://bugzilla.redhat.com/ " -echo "" -echo "***************** DETAILED RESULTS LOGGED TO validate.log ********************************" -echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " -echo "" -echo "" -test_rhel_version -echo "" -if [ $QUESTIONS == "no" ];then - userInput_CloudProvider - userInput_Filesystem - userInput_Errata_Notification - userInput_Availability -fi -echo "##### START TESTS #####" -echo "" -test_uname -test_disk_format -test_disk_size -test_swap_file -test_selinux -test_package_set -test_verify_rpms -test_gpg_keys -#test_repos #remarking this out for now.. until additional repo's land. the yum tests should be sufficient -test_yum_plugin -if [ $yum_test == "yes" ];then - test_yum_full_test -else - test_yum_general_test -fi -test_bash_history -test_system_id -test_cloud-firstboot -test_nameserver -test_group -test_passwd -test_inittab -test_shells -#test_IPv6 no longer needed -test_networking -test_iptables -test_sshd -test_chkconfig -test_syslog -test_auditd -test_sshSettings -test_libc6-xen.conf -test_grub -#installTestKernel -resize2fs - - -### DONT REMOVE OR COMMENT OUT ### -show_failures -open_bugzilla -bugzilla_comments -setup_rc.local -#sos_report -echo "REBOOTING" -sleep 1 -echo "REBOOTING" -sleep 1 -echo "REBOOTING" -reboot -#im_exit -################################## - - - - - - diff --git a/src/image_validation_postreboot.sh b/src/image_validation_postreboot.sh index 0bfb837..3fa3f02 100755 --- a/src/image_validation_postreboot.sh +++ b/src/image_validation_postreboot.sh @@ -111,14 +111,15 @@ echo "" test_yum_plugin test_uname test_memory -test_fetch_host_details print_rhel_version #installTestKernel ### DONT REMOVE OR COMMENT OUT ### show_failures -bugzilla_comments() +sleep 360 +open_bugzilla +bugzilla_comments verify_bugzilla #sos_report im_exit diff --git a/src/image_validation_postreboot.sh~ b/src/image_validation_postreboot.sh~ deleted file mode 100755 index 0e2e5e6..0000000 --- a/src/image_validation_postreboot.sh~ +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash -# Copyright (c) 2010 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# -# written by whayutin@redhat.com -# modified by kbidarka@redhat.com for RHEL 6 - -FAILURES=0 - -function usage() -{ - echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " - echo "Please use all options" - echo "" - echo " This script will run through some basic sanity tests for a Red Hat Enterprise Linux image " - echo " A valid Red Hat bugzilla username and password will be required at the end of the script " - echo " http://bugzilla.redhat.com/ " - echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " - echo "" - echo "Available options are:" - echo "--imageID= :: Please provide a unique id for the image" - echo "--RHEL= :: Please specify the correct FULL rhel version eg: --RHEL=5.7 or --RHEL=6.1" - echo "--full-yum-suite= :: Please input the value "yes" OR "no"" - echo "--skip-questions= :: Please input the value "yes" or "no"" - echo "--bugzilla-username :: Please specify your bugzilla username@email.com" - echo "--bugzilla-password :: Please specify your bugzilla password" - echo "--bugzilla-num :: If a bug has already been opened you can specify the number here " - echo "--memory :: Minium total kb of memory the system *should* have available " -} - - -#cli -for i in $* - do - case $i in - --imageID=*) - IMAGEID="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --RHEL=*) - RHELV="`echo $i | sed 's/[-A-Z]*=//'`" - ;; - --full-yum-suite=*) - yum_test="`echo $i | sed 's/[-a-zA-Z]*=//'`" - if [ "$yum_test" == "yes" ] || [ "$yum_test" == "no" ]; then - : - else - usage - exit 1 - fi - ;; - --skip-questions=*) - QUESTIONS="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --bugzilla-username=*) - BUG_USERNAME="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --bugzilla-password=*) - BUG_PASSWORD="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --bugzilla-num=*) - BUG_NUM="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --failures=*) - FAILURES="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - --memory=*) - MEM_HWP="`echo $i | sed 's/[-a-zA-Z0-9]*=//'`" - ;; - *) - # unknown option - usage - exit 1 - ;; - esac -done - - -if [[ -z $IMAGEID ]] || [[ -z $RHELV ]] || [[ -z $yum_test ]] || [[ -z $BUG_USERNAME ]] || [[ -z $BUG_PASSWORD ]] ; then - usage - exit 1 -fi - - - - -source $PWD/testlib.sh - -echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " -echo " This script will run through some basic sanity tests for a Red Hat Enterprise Linux image " -echo " A valid Red Hat bugzilla username and password will be required at the end of the script " -echo " http://bugzilla.redhat.com/ " -echo "" -echo "***************** DETAILED RESULTS LOGGED TO validate.log ********************************" -echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " -echo "" -echo "" -postReboot -echo "" -echo "##### START TESTS #####" -echo "" -test_yum_plugin -test_uname -test_memory -print_rhel_version -#installTestKernel - - -### DONT REMOVE OR COMMENT OUT ### -show_failures -open_bugzilla -bugzilla_comments() -verify_bugzilla -#sos_report -im_exit -################################## - - - - - - diff --git a/src/installRHUI.sh b/src/installRHUI.sh new file mode 100644 index 0000000..9bb25a8 --- /dev/null +++ b/src/installRHUI.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +## ASSUMES RHUI DVD in /root ### +## Run on the rhua and each cds ## +## +## example ./script.sh rhua xvdk +## example ./script.sh cds xvdf (xvdf for 6.0 rhel or so I've seen) + +## CHANGE ME #### +export rhua=host.internal +export cds1=host.internal +export cds2=host.internal +## CHANGE ME #### + + + +export server="$1" +export device="$2" + +if [ "$server" == "rhua" ]; then + echo "RHUI Selected" + mkdir /var/lib/pulp + ls /var/lib/pulp +fi +if [ "$server" == "cds" ]; then + echo "CDS Selected" + mkdir /var/lib/pulp-cds + ls /var/lib/pulp-cds +fi + +iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT +iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5674 -j ACCEPT + +/etc/init.d/iptables save +/etc/init.d/iptables restart + +fdisk /dev/$device << EOF +n +p +1 +1 +54823 +p +w +EOF + +export partition=1 +mkfs.ext4 /dev/$device$partition + +if [ "$server" == "rhua" ]; then + echo "/dev/$device$partition /var/lib/pulp ext4 defaults 1 1" >> /etc/fstab + mount -a + mount +fi +if [ "$server" == "cds" ]; then + echo "/dev/$device$partition /var/lib/pulp-cds ext4 defaults 1 1" >> /etc/fstab + mount -a + mount +fi + +if [ "$server" == "rhua" ]; then + mkdir -p pem && pushd pem + openssl req -new -x509 -extensions v3_ca -keyout ca.key -subj '/C=US/ST=NC/L=Raleigh/CN=localhost' -out ca.crt -days 365 + echo 10 > ca.srl + openssl genrsa -out server.key 2048 + + for node in $rhua $cds1 $cds2 ; do + echo -ne "\n\n\n## set CN for $server\n==" + openssl req -new -key server.key -subj '/C=US/ST=NC/L=Raleigh/CN='$node'' -out $node.csr + openssl x509 -req -days 365 -CA ca.crt -CAkey ca.key -in $node.csr -out $node.crt + done +fi + +mkdir /tmp/mnt +mount -o loop /root/RH* /tmp/mnt/ +pushd /tmp/mnt/ +if [ "$server" == "rhua" ]; then + ./install_RHUA.sh ;./install_tools.sh +fi +if [ "$server" == "cds" ]; then + ./install_CDS.sh +fi + +popd + +nss-db-gen + +#/etc/pulp/pulp.conf +#/etc/pulp/consumer/consumer.conf +#/etc/pulp/client.conf +#host = localhost.localdomain + +if [ "$server" == "rhua" ]; then + perl -npe 's/server_name: localhost/server_name: $rhui/g' -i /etc/pulp/pulp.conf; + perl -npe 's/host = localhost.localdomain/host = $rhui/g' -i /etc/pulp/client.conf; + perl -npe 's/host = localhost.localdomain/host = $rhui/g' -i /etc/pulp/consumer/consumer.conf; +fi + +if [ "$server" == "cds" ]; then + perl -npe 's/host = localhost.localdomain/host = $rhui/g' -i /etc/pulp/cds.conf; +fi + +export cert=.crt + +cat > /root/answers.txt < 1: + try: + key = paramiko.RSAKey.from_private_key_file(pkey_file) + tr = paramiko.Transport((hostname, 22)) + tr.connect(username=username, pkey=key) + sftp = paramiko.SFTPClient.from_transport(tr) + break + except: + print "\n\nError, re-trying in 30 secs" + print "The Hostname is :", hostname + print "The key is :", pkey_file + print "The Local and REmote path is :", localpath, " ", filepath + num = num - 1 + print "Number of attempts left", num + time.sleep(30) + continue + if num == 1: + return 1 + print "\n\nPlease wait, Trying to upload the file ", localpath, " to hostname : ", hostname + sftp.put(localpath,filepath) + print "Uploading the file : ", localpath, " to ", hostname, " completed" + sftp.close() + tr.close() + + +#def getfile(hostname, pkey_file, localpath, filepath): +# username = 'root' +# key = paramiko.RSAKey.from_private_key_file(pkey_file) +# tr = paramiko.Transport((hostname, 22)) +# tr.connect(username=username, pkey=key) +# sftp = paramiko.SFTPClient.from_transport(tr) +# print "\n\nPlease wait, Trying to download the file ", filepath, " from hostname : ", hostname +# sftp.get(filepath,localpath) +# print "Downloading the file : ", filepath, " from ", hostname, " completed" +# sftp.close() +# tr.close() + + +def getfile(hostname, pkey_file, localpath, filepath): + username = 'root' + num = 7 + while num > 1: + try: + key = paramiko.RSAKey.from_private_key_file(pkey_file) + tr = paramiko.Transport((hostname, 22)) + tr.connect(username=username, pkey=key) + sftp = paramiko.SFTPClient.from_transport(tr) + break + except: + print "\nError, re-trying in 30 secs" + print "\nThe Hostname is :", hostname + print "\nThe key is :", pkey_file + print "\nThe Local and Remote path is :", localpath, " ", filepath + num = num - 1 + print "Number of attempts left", num + time.sleep(30) + continue + if num == 1: + return 1 + print "\n\nPlease wait, Trying to download the file ", filepath, " from hostname : ", hostname + sftp.get(filepath,localpath) + print "Downloading the file : ", filepath, " from ", hostname, " completed" + sftp.close() + tr.close() + +def remote_exe(hostname, pkey_file, cmd): + user = 'root' + key = paramiko.RSAKey.from_private_key_file(pkey_file) + s = paramiko.SSHClient() + s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + s.connect(hostname, username=user, pkey=key) + stdin, stdout, stderr = s.exec_command(cmd) + print stdout.read() + s.close() + +def answers_replace(stext, dtext, input_file): + print "\nReplacing", stext, " with ", dtext, "in file : ", input_file + data = open(input_file).read() + o = open(input_file,"w") + o.write( re.sub(stext, dtext ,data) ) + o.close() + +def chek_files(fil_list, lis_sz): + print "\n\nChecking for the pre-requisites : \n" + home_dir = os.path.expanduser("~") + file_not = [] + for kde in range(lis_sz): + file = home_dir + "/" + fil_list[kde] + stat = os.path.exists(file) + if stat == False: + file_not.append(file) + elif stat == True: + print file + " : Present" + + if file_not: + print "\n\nFollowing files are not present in your home-directory : \n" + for disp in file_not: + print disp + print "\nPlease include the above files." + sys.exit() diff --git a/src/testRegion.py b/src/testRegion.py new file mode 100755 index 0000000..541a41b --- /dev/null +++ b/src/testRegion.py @@ -0,0 +1,243 @@ +#!/usr/bin/python -tt + +from pprint import pprint +from boto import ec2 +import boto, thread +import sys, time, optparse, os +#from boto.ec2.blockdevicemapping import BlockDeviceMapping +from boto.ec2.blockdevicemapping import EBSBlockDeviceType, BlockDeviceMapping +from bugzilla.bugzilla3 import Bugzilla36 + +#def main(argv): +# try: +# opts, args = getopt.getopt(argv, "hr:vb:a:", ["help","region", "version","bugzilla","ami-number"]) +# except getopt.GetoptError: +# usage() +# sys.exit(2) + +parser = optparse.OptionParser() + +desc="ami test script" + +parser.add_option('-r','--region', type='string', dest='REGION', help='specify ec2 region') +parser.add_option('-v','--RHEL_Version', type='string', dest='RHEL', help='RHEL version') +parser.add_option('-b', '--bugzilla_number', type='string', dest='BZ', help='optional bugzilla number') +parser.add_option('-a','--ami_number', type='string', dest='AMI', help='ami id number') +parser.add_option('-s','--ssh-key-path', type='string',dest='SSHKEY',help='full path to ssh key for the ec2 region') +parser.add_option('-k','--ssh-key-name', type='string',dest='SSHKEYNAME',help='name of the key pair') +parser.add_option('-i','--ec2-key', type='string',dest='AWS_ACCESS_KEY_ID',help='EC2 Access Key ID') +parser.add_option('-p','--ec2-secret-key', type='string',dest='AWS_SECRET_ACCESS_KEY',help='EC2 Secret Access Key ID') +parser.add_option('-y','--bugzilla_username', type='string',dest='BZUSER',help='bugzilla username') +parser.add_option('-z','--bugzilla_password', type='string',dest='BZPASS',help='bugzilla password') +parser.add_option('-m','--arch', dest='ARCH', default='x86_64', help='arch = i386, or x86_64') +parser.add_option('-x','--ignore', dest='IGNORE', default='IGNORE', help='If set.. ignore the generated bug') #c1.medium +parser.add_option('-g','--noGit',dest="NOGIT", default=True, help='If set.. do not pull valid src from git, scp to each instance' ) +#parser.add_option('-g','--noGit',action="store_true", default=True, help='If set.. do not pull valid src from git, scp to each instance' ) +parser.add_option('-d','--baseDir',dest='BASEDIR',type='string',help='the dir of the src checkout ie.. ~/workspace/valid/src') + + + +(opts, args) = parser.parse_args() +AMI = opts.AMI +REGION = opts.REGION +RHEL = opts.RHEL +BZ = opts.BZ +SSHKEY = opts.SSHKEY +SSHKEYNAME = opts.SSHKEYNAME +AWS_ACCESS_KEY_ID = opts.AWS_ACCESS_KEY_ID +AWS_SECRET_ACCESS_KEY = opts.AWS_SECRET_ACCESS_KEY +BZUSER = opts.BZUSER +BZPASS = opts.BZPASS +ARCH = opts.ARCH +IGNORE = opts.IGNORE +NOGIT = opts.NOGIT +BASEDIR = opts.BASEDIR + + + + +mandatories = ['BASEDIR','AMI','REGION','SSHKEY','RHEL','AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'ARCH'] +for m in mandatories: + if not opts.__dict__[m]: + print "mandatory option is missing\n" + parser.print_help() + exit(-1) + +if BZ is None: + print "**** No bugzilla # was passed, will open one here ****" + bugzilla=Bugzilla36(url='https://bugzilla.redhat.com/xmlrpc.cgi',user=BZUSER,password=BZPASS) + mySummary=AMI+" "+RHEL+" "+ARCH+" "+REGION + RHV="RHEL"+RHEL + BZ_Object=bugzilla.createbug(product="Cloud Image Validation",component="images",version=RHV,rep_platform=ARCH,summary=mySummary) + BZ = str(BZ_Object.bug_id) + print "Buzilla # = https://bugzilla.redhat.com/show_bug.cgi?id="+ BZ +else: + print "Already opened Buzilla # = https://bugzilla.redhat.com/show_bug.cgi?id="+ BZ + +file = open('/tmp/bugzilla',"w") +file.write(BZ) +file.close() + +os.system("cat /dev/null > "+BASEDIR+"/nohup.out") + + +def getConnection(key, secret, region): + """establish a connection with ec2""" + reg = boto.ec2.get_region(region, aws_access_key_id=key, + aws_secret_access_key=secret) + return reg.connect( + aws_access_key_id=key, aws_secret_access_key=secret) + +#east# reservation = ec2conn.run_instances('ami-8c8a7de5', instance_type='t1.micro', key_name='cloude-key') +#block_device_map +#'/dev/sda=:20' + +def startInstance(ec2connection, hardwareProfile): + conn_region = ec2connection + map = BlockDeviceMapping() + t = EBSBlockDeviceType() + t.size = '15' + #map = {'DeviceName':'/dev/sda','VolumeSize':'15'} + map['/dev/sda1'] = t + + #blockDeviceMap = [] + #blockDeviceMap.append( {'DeviceName':'/dev/sda', 'Ebs':{'VolumeSize' : '100'} }) + + if ARCH == 'i386' and RHEL == '6.1': + reservation = conn_region.run_instances(AMI, instance_type=hardwareProfile, key_name=SSHKEYNAME, block_device_map=map ) + elif ARCH == 'x86_64' and RHEL == '6.1': + reservation = conn_region.run_instances(AMI, instance_type=hardwareProfile, key_name=SSHKEYNAME, block_device_map=map ) + elif ARCH == 'i386': + reservation = conn_region.run_instances(AMI, instance_type=hardwareProfile, key_name=SSHKEYNAME, block_device_map=map ) + elif ARCH == 'x86_64': + reservation = conn_region.run_instances(AMI, instance_type=hardwareProfile, key_name=SSHKEYNAME, block_device_map=map) + else: + print "arch type is neither i386 or x86_64.. will exit" + exit(1) + + myinstance = reservation.instances[0] + + time.sleep(5) + while(not myinstance.update() == 'running'): + time.sleep(5) + print myinstance.update() + + instanceDetails = myinstance.__dict__ + pprint(instanceDetails) + #region = instanceDetails['placement'] + #print 'region =' + region + publicDNS = instanceDetails['public_dns_name'] + print 'public hostname = ' + publicDNS + + + # check for console output here to make sure ssh is up + return publicDNS + +def executeValidScript(SSHKEY, publicDNS,hwp,BZ): + filepath = BASEDIR+"/*" + serverpath = "/root/valid/src" + commandPath = "/root/valid/src" + + + if NOGIT: + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" mkdir -p /root/valid/src") + print "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath+"/n" + os.system("scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath) + else: + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" yum -y install git") + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" git clone git://github.com/weshayutin/valid.git") + + + + # COPY KERNEL if there + serverpath = "/root/kernel" + os.system("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" mkdir -p /root/kernel") + if ARCH == 'i386': + filepath = BASEDIR+"/kernel/i386/*" + print "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath+"/n" + os.system("scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath) + if ARCH == 'x86_64': + filepath = BASEDIR+"/kernel/x86_64/*" + print "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath+"/n" + os.system("scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " -r " + filepath + " root@"+publicDNS+":"+serverpath) + + + +# command = commandPath+"/image_validation.sh --imageID="+IGNORE+AMI+"_"+REGION+"_"+hwp["name"]+" --RHEL="+RHEL+" --full-yum-suite=yes --skip-questions=yes --bugzilla-username="+BZUSER+" --bugzilla-password="+BZPASS+" --bugzilla-num="+BZ+ " --memory="+hwp["memory"] + command = commandPath+"/image_validation.sh --imageID="+IGNORE+AMI+"_"+REGION+"_"+hwp["name"]+" --RHEL="+RHEL+" --full-yum-suite=yes --skip-questions=yes --bugzilla-username="+BZUSER+" --bugzilla-password="+BZPASS+" --bugzilla-num="+BZ+ " --memory="+hwp["memory"]+" --public-dns="+publicDNS + + print "nohup ssh -n -f -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" "+command + print "" + os.system("nohup ssh -n -f -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "+SSHKEY+ " root@"+publicDNS+" "+command) + + + +def printValues(hwp): + print "+++++++" + print AMI + print REGION + print SSHKEY + print RHEL + print hwp + print "+++++++\n" + +def myfunction(string, sleeptime,lock,SSHKEY,publicDNS): + #entering critical section + lock.acquire() + print string," Now Sleeping after Lock acquired for ",sleeptime + time.sleep(sleeptime) + + print string," Now releasing lock and then sleeping again" + lock.release() + + #exiting critical section + time.sleep(sleeptime) # why? + +# Define hwp +m1Small = {"name":"m1.small","memory":"1700000","cpu":"1","arch":"i386"} +m1Large = {"name":"m1.large","memory":"7500000","cpu":"2","arch":"x86_64"} +m1Xlarge = {"name":"m1.xlarge","memory":"15000000","cpu":"4","arch":"x86_64"} +t1Micro = {"name":"t1.micro","memory":"600000","cpu":"1","arch":"both"} +m2Xlarge = {"name":"m2.2xlarge","memory":"17100000","cpu":"2","arch":"x86_64"} +m22Xlarge = {"name":"m2.2xlarge","memory":"34200000","cpu":"4","arch":"x86_64"} +m24Xlarge = {"name":"m2.4xlarge","memory":"68400000","cpu":"8","arch":"x86_64"} +c1Medium = {"name":"c1.medium","memory":"1700000","cpu":"2","arch":"i386"} +c1Xlarge = {"name":"c1.xlarge","memory":"7000000","cpu":"8","arch":"x86_64"} + + +#Use all hwp types for ec2 memory tests, other hwp tests +#hwp_i386 = [c1Medium, t1Micro , m1Small ] +#hwp_x86_64 = [m1Xlarge, t1Micro , m1Large , m2Xlarge , m22Xlarge , m24Xlarge , c1Xlarge] +hwp_x86_64 = [m1Xlarge] + +#Use just one hwp for os tests +hwp_i386 = [c1Medium] +#hwp_x86_64 = [m1Xlarge,m22Xlarge] + + + +publicDNS = [] + +if ARCH == 'i386': + for hwp in hwp_i386: + printValues(hwp) + myConn = getConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, REGION) + this_hostname = startInstance(myConn, hwp["name"]) + map = {"hostname":this_hostname,"hwp":hwp} + publicDNS.append(map) + + +elif ARCH == 'x86_64': + for hwp in hwp_x86_64: + printValues(hwp) + myConn = getConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, REGION) + this_hostname = startInstance(myConn, hwp["name"]) + map = {"hostname":this_hostname,"hwp":hwp} + publicDNS.append(map) + +lock = thread.allocate_lock() +print "sleep for 130 seconds" +time.sleep(130) +for host in publicDNS: + + executeValidScript(SSHKEY, host["hostname"],host["hwp"],BZ) diff --git a/src/testlib.sh b/src/testlib.sh index 790b64d..a7cc4c5 100755 --- a/src/testlib.sh +++ b/src/testlib.sh @@ -14,44 +14,50 @@ # # written by whayutin@redhat.com # modified by kbidarka@redhat.com - -LOGFILE=$PWD/validate.log -DLOG=" tee -a ${LOGFILE} " #Display and log output -cat /dev/null > $LOGFILE -RSLT="" -LOGRESULT="echo ${RSLT} 1>>$LOGFILE 2>>$LOGFILE" -DIFFDIR=$PWD -SYSDATE=$( /bin/date '+%Y-%m-%d %H:%M' ) -UNAMEI=$( /bin/uname -i ) -BETA=0 - - -echo "" -echo "" - -txtred=$(tput setaf 1) # Red -txtgrn=$(tput setaf 2) # Green -txtrst=$(tput sgr0) # Text reset - -### Begin: Create a list of partitions -rm -Rf disk_partitions -rm -Rf swap_partitions -mount | grep ^/dev | awk '{print $1}' >> disk_partitions -parted -l | grep -B 5 swap | grep ^Disk | awk '{print $2}' | sed '$s/.$//' >> swap_partitions - -rm -Rf tmp1_partitions tmp2_partitions -### End: Create a list of partitions - -RHEL=`cat /etc/redhat-release | awk '{print $7}' | awk -F. '{print $1}'` -RHELU=`cat /etc/redhat-release | awk '{print $7}' | awk -F. '{print $2}'` -RHEL_FOUND=$RHEL.$RHELU -KERNEL="" -KERNEL_UPDATED="" -TEST_CURRENT="" -TEST_FAILED="" -echo "IMAGE ID= ${IMAGEID}" >> $LOGFILE - - +# mkovacik@redhat.com + +[ -n "$__TESTLIB__" ] && return 0 +__TESTLIB__=loaded + +function _testlib_init(){ + [ -n "$__TESTLIB_INIT__" ] && return 0 + LOGFILE=$PWD/validate.log + DLOG=" tee -a ${LOGFILE} " #Display and log output + cat /dev/null > $LOGFILE + RSLT="" + LOGRESULT="echo ${RSLT} 1>>$LOGFILE 2>>$LOGFILE" + DIFFDIR=$PWD + SYSDATE=$( /bin/date '+%Y-%m-%d %H:%M' ) + UNAMEI=$( /bin/uname -i ) + BETA=0 + + + echo "" + echo "" + + txtred=$(tput setaf 1) # Red + txtgrn=$(tput setaf 2) # Green + txtrst=$(tput sgr0) # Text reset + + ### Begin: Create a list of partitions + rm -Rf disk_partitions + rm -Rf swap_partitions + mount | grep ^/dev | awk '{print $1}' >> disk_partitions + parted -l | grep -B 5 swap | grep ^Disk | awk '{print $2}' | sed '$s/.$//' >> swap_partitions + + rm -Rf tmp1_partitions tmp2_partitions + ### End: Create a list of partitions + + RHEL=`cat /etc/redhat-release | awk '{print $7}' | awk -F. '{print $1}'` + RHELU=`cat /etc/redhat-release | awk '{print $7}' | awk -F. '{print $2}'` + RHEL_FOUND=$RHEL.$RHELU + KERNEL="" + KERNEL_UPDATED="" + TEST_CURRENT="" + TEST_FAILED="" + echo "IMAGE ID= ${IMAGEID}" >> $LOGFILE + __TESTLIB_INIT__=initialized +} function new_test() { @@ -162,20 +168,31 @@ function print_rhel_version() function test_fetch_host_details() { + yum install -y wget > /dev/null BP_ID=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i billingProducts | gawk -F":" '{print $NF}' | gawk -F"\"" '{print $2}'` + INS_ID=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i instanceId | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` + IMG_ID=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i imageId | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` + INS_TYP=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i instanceType | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` + ARCH=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i architecture | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` + REG=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i zone | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` + SIGN1=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/signature` + new_test "Fetching the identity doc Details" + echo "Verifying that signature exists" >> $LOGFILE + [ ! -z SIGN1 ] && SIGNAT=1 || SIGNAT=0 + assert "echo $SIGNAT" "1" + echo "Verifying the IMAGE ID" >> $LOGFILE + [ $AMI_ID == $IMG_ID ] && IMGID=1 || IMGID=0 + assert "echo $IMGID" "1" + echo "Verifying the Architecture" >> $LOGFILE + [ $ARCH_ID == $ARCH ] && ARCHID=1 || ARCHID=0 + assert "echo $ARCHID" "1" + echo "This Host => $PUB_DNS with Image Id : $IMG_ID, is launched with Instance Id : $INS_ID , Instance Type : $INS_TYP and Arch : $ARCH in the Region : $REG" >> $LOGFILE + echo "The Validate Signature is : $SIGN1" >> $LOGFILE + if [ $BP_ID == "bp-6fa54006" ]; then - HOSTNAME=`hostname` - INS_ID=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i instanceId | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` - IMG_ID=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i imageId | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` - INS_TYP=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i instanceType | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` - ARCH=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i architecture | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` - REG=`wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep -i zone | gawk '{print $NF}'| gawk -F"\"" '{print $2}'` - new_test "Fetching Host Details " - echo "This Host => $PUB_DNS with Image Id : $IMG_ID, is launched with Instance Id : $INS_ID , Instance Type : $INS_TYP and Arch : $ARCH in the Region : $REG" >> $LOGFILE echo "This is a Hourly image" >> $LOGFILE - else - new_test "Fetching Host Details " - echo "This is not a Hourly image" >> $LOGFILE + elif [ $BP_ID == "bp-63a5400a" ]; then + echo "This is a Cloud Access image" >> $LOGFILE fi } @@ -298,7 +315,7 @@ function test_package_set() new_test "## Verify no missing packages ... " file=/tmp/rpmqa rc "/bin/rpm -qa --queryformat='%{NAME}\n' > ${file}.tmp" - #/bin/rpm -qa --queryformat="%{NAME}.%{ARCH}\n" > ${file}.tmp + #/bin/rpm -qa --queryformat="%{NAME}.%{ARCH}\n" > ${file}.tmp cat ${file}.tmp | sort -f > ${file} if [ $RHEL == 5 ] ; then rc "comm -23 packages_5 ${file}" @@ -306,9 +323,12 @@ function test_package_set() elif [ $RHEL_FOUND == "6.0" ]; then rc "comm -23 packages_6 ${file}" comm -23 packages_6 ${file} > /tmp/package_diff - elif [ $RHEL_FOUND == "6.1" ]; then - rc "comm -23 packages_61 ${file}" + elif [ $RHEL_FOUND == "6.1" ]; then + rc "comm -23 packages_61 ${file}" comm -23 packages_61 ${file} > /tmp/package_diff + elif [ $RHEL_FOUND == "6.2" ]; then + rc "comm -23 packages_62 ${file}" + comm -23 packages_62 ${file} > /tmp/package_diff else echo "VERSION NOT FOUND" fi @@ -344,7 +364,7 @@ function test_verify_rpms() assert "cat ${file} | wc -l" "2" new_test "## Verify Version 2 ... " assert "/bin/rpm -q --queryformat '%{RELEASE}\n' redhat-release | cut -d. -f1,2" $RHELV # to-do, pass this in - else + else file=/tmp/rpmqaV.txt new_test "## Verify RPMs ... " /bin/rpm -Va --nomtime --nosize --nomd5 2>> $LOGFILE | sort -fu > ${file} @@ -428,13 +448,22 @@ function test_bash_history() function test_swap_file() { + if [ -f /root/noswap ] ; then + echo "/root/noswap present -- this machine doesn't require swap" >> $LOGFILE + return 0 + fi new_test "## Verify turning on/off swap file ... " if [ $UNAMEI == "i386" ]; then swap=`cat swap_partitions` + fst=`cat /etc/fstab | grep swap | awk '{print $1}'` + [ $swap != $fst ] && [ -b /dev/xvde3 ] && sed -i 's/\/dev\/xvda3/\/dev\/xvde3/' /etc/fstab + [ $swap != $fst ] && [ -b /dev/xvda3 ] && sed -i 's/\/dev\/xvde3/\/dev\/xvda3/' /etc/fstab + swapon `cat swap_partitions` 2> /dev/null assert "/sbin/swapoff $swap && /sbin/swapon $swap" fi -# The below logic needs to be reversed, after checking the actual images. Actual images have swap partitions only for i386 and not for x86_64. +# The below logic was reversed, after checking the images. +# The images have swap partitions only for i386(not for t1.micro) and not for x86_64. new_test "## Verify swap size ... " if [ $UNAMEI == "i386" ]; then size=`free | grep Swap | awk '{print $2}'` @@ -468,7 +497,7 @@ function test_cloud-firstboot() if [ $RHELV == 6.0 ]; then echo "WAIVED TESTS FOR BUGZILLA 704821" else - new_test "## Verify rh-cloud-firstboot is on ... " + new_test "## Verify rh-cloud-firstboot is OFF ... " assert "chkconfig --list | grep rh-cloud | grep 3:off | wc -l" "1" if [ -f /etc/sysconfig/rh-cloud-firstboot ]; then echo "/etc/sysconfig/rh-cloud-firstboot FOUND" >> $LOGFILE @@ -553,7 +582,7 @@ function test_gpg_keys() new_test "## Verify GPG Keys ... " if [ $BETA == 1 ]; then - assert "rpm -qa gpg-pubkey* | wc -l " 3 + assert "rpm -qa gpg-pubkey* | wc -l " 2 elif [ $RHEL_FOUND == "6.1" ]; then assert "rpm -qa gpg-pubkey* | wc -l " 2 else @@ -683,10 +712,17 @@ function test_auditd() assert "md5sum /etc/audit/audit.rules | cut -f 1 -d \" \"" "f9869e1191838c461f5b9051c78a638d" new_test "## Verify auditd.conf ... " - assert "md5sum /etc/audit/auditd.conf | cut -f 1 -d \" \"" "612ddf28c3916530d47ef56a1b1ed1ed" - + if [ $RHEL_FOUND == 6.2 ] ; then + assert "md5sum /etc/audit/auditd.conf | cut -f 1 -d \" \"" "e1886162554c18906df2ecd258aa4794" + else + assert "md5sum /etc/audit/auditd.conf | cut -f 1 -d \" \"" "612ddf28c3916530d47ef56a1b1ed1ed" + fi new_test "## Verify auditd sysconfig ... " - assert "md5sum /etc/sysconfig/auditd | cut -f 1 -d \" \"" "123beb3a97a32d96eba4f11509e39da2" + if [ $RHEL_FOUND == 6.2 ] ; then + assert "md5sum /etc/sysconfig/auditd | cut -f 1 -d \" \"" "d4d43637708e30418c30003e212f76fc" + else + assert "md5sum /etc/sysconfig/auditd | cut -f 1 -d \" \"" "123beb3a97a32d96eba4f11509e39da2" + fi } function test_uname() @@ -744,13 +780,13 @@ function test_resize2fs() { new_test "## Verify resize2fs ... " if [ $RHEL == 6 ] ; then - rc "resize2fs -p /dev/xvde1 15000M" + [ -b /dev/xvde1 ] && rc "resize2fs -p /dev/xvde1 15000M" + [ -b /dev/xvda1 ] && rc "resize2fs -p /dev/xvda1 15000M" fi if [ $RHEL == 5 ] ; then rc "resize2fs -p /dev/sda1 15000M" fi - sleep 10 - assert "df -h | grep 13G | wc -l " 1 + assert "df -h | grep 15G | wc -l " 1 } function installTestKernel() @@ -824,7 +860,7 @@ function open_bugzilla() function bugzilla_comments() { echo "Adding log file contents to bugzilla" - split ${LOGFILE} -l 200 splitValid.log + split ${LOGFILE} -l 500 splitValid.log for part in $(ls splitValid.log*);do BUG_COMMENTS=`cat $part` @@ -870,7 +906,7 @@ function setup_rc.local() { echo "####################### cat of /etc/rc.local ##################" >> $LOGFILE echo "cd /root/valid/src" >> /etc/rc.local - echo "./image_validation_postreboot.sh --imageID=asdf --RHEL=$RHELV --full-yum-suite=no --skip-questions=yes --bugzilla-username=$BUG_USERNAME --bugzilla-password=$BUG_PASSWORD --bugzilla-num=$BUGZILLA --failures=$FAILURES --memory=$MEM_HWP >> /var/log/messages" >> /etc/rc.local + echo "./image_validation_postreboot.sh --imageID=${IMAGEID} --RHEL=$RHELV --full-yum-suite=no --skip-questions=yes --bugzilla-username=$BUG_USERNAME --bugzilla-password=$BUG_PASSWORD --bugzilla-num=$BUGZILLA --failures=$FAILURES --memory=$MEM_HWP >> /var/log/messages" >> /etc/rc.local cat /etc/rc.local >> $LOGFILE echo "####################### cat of /etc/rc.local ##################" >> $LOGFILE diff --git a/src/testlib.sh~ b/src/testlib.sh~ deleted file mode 100755 index 98caf1a..0000000 --- a/src/testlib.sh~ +++ /dev/null @@ -1,882 +0,0 @@ -#!/bin/bash -# Copyright (c) 2010 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# -# written by whayutin@redhat.com -# modified by kbidarka@redhat.com - -LOGFILE=$PWD/validate.log -DLOG=" tee -a ${LOGFILE} " #Display and log output -cat /dev/null > $LOGFILE -RSLT="" -LOGRESULT="echo ${RSLT} 1>>$LOGFILE 2>>$LOGFILE" -DIFFDIR=$PWD -SYSDATE=$( /bin/date '+%Y-%m-%d %H:%M' ) -UNAMEI=$( /bin/uname -i ) -BETA=0 - - -echo "" -echo "" - -txtred=$(tput setaf 1) # Red -txtgrn=$(tput setaf 2) # Green -txtrst=$(tput sgr0) # Text reset - -### Begin: Create a list of partitions -rm -Rf disk_partitions -rm -Rf swap_partitions -mount | grep ^/dev | awk '{print $1}' >> disk_partitions -parted -l | grep -B 5 swap | grep ^Disk | awk '{print $2}' | sed '$s/.$//' >> swap_partitions - -rm -Rf tmp1_partitions tmp2_partitions -### End: Create a list of partitions - -RHEL=`cat /etc/redhat-release | awk '{print $7}' | awk -F. '{print $1}'` -RHELU=`cat /etc/redhat-release | awk '{print $7}' | awk -F. '{print $2}'` -RHEL_FOUND=$RHEL.$RHELU -KERNEL="" -KERNEL_UPDATED="" -TEST_CURRENT="" -TEST_FAILED="" -echo "IMAGE ID= ${IMAGEID}" >> $LOGFILE - - - -function new_test() -{ - echo -n $1 - echo "######################################################################################" >> $LOGFILE - echo "# NEW TEST: $1" >> $LOGFILE - TEST_CURRENT=$1 - echo "######################################################################################" >> $LOGFILE -} - -#rus a basic command -function rc() -{ - echo "COMMAND: $1" >>$LOGFILE - RSLT=`eval $1 2>>${LOGFILE}` - rc=$? - echo "RETURN CODE: $rc" >>$LOGFILE -} - -function rq() -{ - echo "QUESTION: $1" -} - -#runs a basic command and redirects stdout to file $2 -function rc_outFile() -{ - echo "COMMAND: $1 $2" >>$LOGFILE - `eval $1 1>>${LOGFILE}` - rc=$? - echo "RETURN CODE: $rc" >>$LOGFILE -} - -#runs a basic command and asserts its return code -function assert() -{ - args=("$@") - cmd=${args[0]} - option=${args[1]} - option2=${args[2]} - echo "COMMAND: $1" >>$LOGFILE - RSLT=`eval $cmd 2>>$LOGFILE` - rc=$? - echo "RESULT: $RSLT " >>$LOGFILE - if [ -z $option2 ];then - echo "EXPECTED RESULT: $option" >>$LOGFILE - option2="zzz###zzz" - else - echo "EXPECTED RESULT: $option OR $option2 " >>$LOGFILE - fi - echo "RETURN CODE: $rc" >>$LOGFILE - - if [[ "$RSLT" == "$option" ]] || [[ "$RSLT" == $option2 ]] && [[ "$option" != "" ]];then - #echo "IN FIRST TEST" >>$LOGFILE - echo "${txtgrn}PASS${txtrst}" - echo "PASS" >> $LOGFILE - elif [ -z "$option" ] && [ "$rc" == 0 ];then - #echo "IN SECOND TEST" >>$LOGFILE - echo "${txtgrn}PASS${txtrst}" - echo "PASS" >> $LOGFILE - elif [[ "$rc" == "$option" ]];then - echo "${txtgrn}PASS${txtrst}" - echo "PASS" >> $LOGFILE - elif [[ "$RSLT" != "$option" ]] && [[ "$RSLT" != "$option2" ]] && [[ "$rc" != 0 ]] ;then - #echo "IN THIRD TEST" >>$LOGFILE - echo "${txtred}FAIL${txtrst}" - echo "FAIL" >> $LOGFILE - echo ${RSLT} >>${LOGFILE} - TEST_FAILED="$TEST_FAILED $TEST_CURRENT" - let FAILURES++ - else - echo "${txtred}FAIL${txtrst}" - echo "FAIL" >> $LOGFILE - echo ${RSLT} >>${LOGFILE} - TEST_FAILED="$TEST_FAILED $TEST_CURRENT" - let FAILURES++ - fi -} - -function test_rhel_version() -{ - pwd >> $LOGFILE - hostname >> $LOGFILE - echo `cat /etc/redhat-release` >> $LOGFILE - if [ $RHELV == $RHEL_FOUND ]; then - new_test "The selected image has the version RHEL $RHELV" - else - echo "Version Mismatched !!!!, The input version RHEL$RHELV should be similar to the selected Ami's version RHEL$RHEL_FOUND" - exit - fi - BETA=`cat /etc/redhat-release | grep -i beta | wc -l` - if [ $BETA == 1 ]; then - echo "ami is a BETA" >> $LOGFILE - fi -} - -function print_rhel_version() -{ - echo hostname >> $LOGFILE - echo `cat /etc/redhat-release` - if [ $RHELV == $RHEL_FOUND ]; then - new_test "The selected image has the version RHEL $RHELV" - else - echo "Version Mismatched !!!!, The input version RHEL$RHELV should be similar to the selected Ami's version RHEL$RHEL_FOUND" - echo "Version Mismatched !!!!, Check the logs to see if yum update changed the RHEL version" - fi -} - - -function userInput_CloudProvider() -{ - echo "" - echo "******** Please answer the following questions *********" - new_test "Cloud Provider Basic Information.." - echo "" - rq "What is the cloud providers company name?" - read answer - echo $answer >>$LOGFILE - rq "What is your full name?" - read answer - echo $answer >>$LOGFILE - rq "What is your email address?" - read email - echo $email >>$LOGFILE -} - -function userInput_Filesystem() -{ - echo "" - echo "******** Please answer the following questions *********" - new_test "Non-Standard Image Layout or Filesystem Types.." - echo "" - rq "If this image contains a non standard partition or filesystem, please describe it" - read answer - echo $answer >>$LOGFILE -} - -function userInput_Errata_Notification() -{ - echo "" - echo "******** Please answer the following questions *********" - new_test "Description of Errata Notification Procedure/Process to be Used to Notify Cloud Users" - echo "" - rq "Please describe the process to be used in order to notify Cloud Users of errata and critical updates." - read answer - echo $answer >>$LOGFILE -} - -function userInput_Availability() -{ - echo "" - echo "******** Please answer the following questions *********" - new_test "Description of Policy for Availability of Updated Starter Images" - echo "" - rq "Please clearly define the policy for making starter images available." - read answer - echo $answer >>$LOGFILE - new_test "Description of Policy for retiring starter images" - echo "" - rq "Please clearly define the policy for retiring " - read answer - echo $answer >>$LOGFILE -} - -function test_disk_size() -{ - new_test "## Partition Size ..." - for part in $(cat disk_partitions);do - echo "size=`df -k $part | awk '{ print $2 }' | tail -n 1`" >> $LOGFILE - size=`df -k $part | awk '{ print $2 }' | tail -n 1` - if [ "$size" -gt "3937219" ] - then - echo "$part is 4gb or greater" - assert "echo true" true - else - echo "$part is NOT 4gb or greater" - assert "echo false" true - fi - done -} - -function test_disk_format() -{ - new_test "## Partition Format ..." - for part in $(cat disk_partitions);do - echo "mount | grep $part | awk '{ print $5 }'" >> $LOGFILE - result=`mount | grep $part | awk '{ print $5 }'` - - if [ $RHEL == 5 ] ; then - assert "echo $result" ext3 - else - ext=`mount | grep $part | awk '{print $3}'` - if [ "$ext" == "/" ] ; then - assert "echo $result" "ext4" - else - assert "echo $result" "ext3" - fi - fi - done -} - - -function test_selinux() -{ - echo "## SELINUX TESTS" - new_test "## /sbin/getenforce ... " - assert "/usr/sbin/getenforce" "Enforcing" - - new_test "## Verify SELINUX enforcing ... " - assert "grep ^SELINUX= /etc/sysconfig/selinux | cut -d\= -f2" enforcing - - new_test "## Verify SELINUXTYPE targeted ... " - assert "grep ^SELINUXTYPE= /etc/sysconfig/selinux | cut -d\= -f2" targeted - - new_test "## Flip Selinux Permissive ... " - assert "/usr/sbin/setenforce Permissive && /usr/sbin/getenforce" Permissive - - new_test "## Flip Selinux Enforcing ... " - assert "/usr/sbin/setenforce Enforcing && /usr/sbin/getenforce" Enforcing - -} - - -function test_package_set() -{ - new_test "## Verify no missing packages ... " - file=/tmp/rpmqa - rc "/bin/rpm -qa --queryformat='%{NAME}\n' > ${file}.tmp" - #/bin/rpm -qa --queryformat="%{NAME}.%{ARCH}\n" > ${file}.tmp - cat ${file}.tmp | sort -f > ${file} - if [ $RHEL == 5 ] ; then - rc "comm -23 packages_5 ${file}" - comm -23 packages_5 ${file} > /tmp/package_diff - elif [ $RHEL_FOUND == "6.0" ]; then - rc "comm -23 packages_6 ${file}" - comm -23 packages_6 ${file} > /tmp/package_diff - elif [ $RHEL_FOUND == "6.1" ]; then - rc "comm -23 packages_61 ${file}" - comm -23 packages_61 ${file} > /tmp/package_diff - else - echo "VERSION NOT FOUND" - fi - - cat /tmp/package_diff >>$LOGFILE - COUNT=`cat /tmp/package_diff | wc -l` - echo "COUNT = `cat /tmp/package_diff | wc -l`" >> $LOGFILE - if [ $BETA == 1 ]; then - if [ $COUNT == 1 ]; then - assert "cat /tmp/package_diff | wc -l" 1 - else - assert "echo test failed" 1 - fi - else - if [ $COUNT -gt 0 ]; then - assert "echo test failed" 1 - else - assert "echo test passed" 0 - fi - fi -} - -function test_verify_rpms() -{ - THIS_RHEL=`echo $RHELV | cut -d . -f 1` - if [ $THIS_RHEL == 5 ] ; then - file=/tmp/rpmqaV.txt - new_test "## Verify RPMs ... " - /bin/rpm -Va --nomtime --nosize --nomd5 2>> $LOGFILE | sort -fu > ${file} - echo "/bin/rpm -Va --nomtime --nosize --nomd5" >> $LOGFILE - cat $file >> $LOGFILE - cat rpmVerifyTable >> $LOGFILE - assert "cat ${file} | wc -l" "2" - new_test "## Verify Version 2 ... " - assert "/bin/rpm -q --queryformat '%{RELEASE}\n' redhat-release | cut -d. -f1,2" $RHELV # to-do, pass this in - else - file=/tmp/rpmqaV.txt - new_test "## Verify RPMs ... " - /bin/rpm -Va --nomtime --nosize --nomd5 2>> $LOGFILE | sort -fu > ${file} - cat $file >> $LOGFILE - cat rpmVerifyTable >> $LOGFILE - if [[ $RHEL_FOUND == "6.1" ]] && [[ $UNAMEI == "x86_64" ]] ; then - assert "cat ${file} | wc -l" "5" - else - assert "cat ${file} | wc -l" "4" - fi - new_test "## Verify Version 2 ... " - assert "/bin/rpm -q --queryformat '%{RELEASE}\n' redhat-release-server | cut -d. -f1,2" $RHELV # to-do, pass this in - fi - - new_test "## Verify packager ... " - file=/tmp/Packager - `cat /dev/null > $file` - #echo "for x in $file ;do echo -n $x >> $file; rpm -qi $x | grep Packager >> $file;done" >>$LOGFILE - for x in $(cat /tmp/rpmqa);do - echo -n $x >>$file - rpm -qi $x | grep Packager >>$file - done - assert "cat $file | grep -v 'Red Hat, Inc.' | grep -v crash-trace-commandPackager| wc -l" 0 - cat $file | grep -v 'Red Hat, Inc.' >>$LOGFILE -} - -function test_yum_full_test() -{ - #echo "Invoking more rigorous yum tests" - new_test "## List the configured repositories..." - assert "/usr/bin/yum repolist" - - new_test "## Search zsh..." - assert "/usr/bin/yum search zsh" - - new_test "## install zsh ... " - rc "/usr/bin/yum -y install zsh" - assert "/bin/rpm -q --queryformat '%{NAME}\n' zsh" zsh - - new_test "## List available groups.." - assert "/usr/bin/yum grouplist" - - new_test "## Install Development tools group..." - assert "/usr/bin/yum -y groupinstall 'Development tools'" - - new_test "## Verify yum update ... " - assert "/usr/bin/yum -y update" - - new_test "## Verify no fa1lures in rpm package ... " - assert "cat $LOGFILE | grep 'failure in rpm package' | wc -l" "1" - - new_test "## Verify no rpm scriplet fa1lures ... " - assert "cat $LOGFILE | grep 'scriptlet failed, exit status 1' | wc -l" "1" - - new_test "## Verify package removal... " - rc "/bin/rpm -e zsh" - assert "/bin/rpm -q zsh" "package zsh is not installed" - -} - -function test_yum_general_test() -{ - new_test "## install zsh ... " - rc "/usr/bin/yum -y install zsh" - assert "/bin/rpm -q --queryformat '%{NAME}\n' zsh" zsh - - new_test "## Verify package removal ... " - rc "/bin/rpm -e zsh" - assert "/bin/rpm -q zsh" "package zsh is not installed" - - new_test "## Verify yum update ... " - assert "/usr/bin/yum -y update" -} - -function test_bash_history() -{ - new_test "## Verify bash_history ... " - assert "cat ~/.bash_history | wc -l " 0 -} - - -function test_swap_file() -{ - new_test "## Verify turning on/off swap file ... " - if [ $UNAMEI == "x86_64" ]; then - swap=`cat swap_partitions` - assert "/sbin/swapoff $swap && /sbin/swapon $swap" - fi - - new_test "## Verify swap size ... " - if [ $UNAMEI == "x86_64" ]; then - size=`free | grep Swap | awk '{print $2}'` - echo "free | grep Swap | awk '{print $2}'" >> $LOGFILE - echo "swap size = $size" >> LOGFILE - if [ $size -gt 0 ]; then - assert "echo true" - else - assert "echo false" "1" - fi - fi - - if [ $UNAMEI == "i386" ]; then - echo "no swap for i386 is expected" >> $LOGFILE - fi - -} - -function test_system_id() -{ - new_test "## Verify no systemid file ... " - if [ ! -f /etc/sysconfig/rhn/systemid ]; then - assert "echo true" - else - assert "/bin/asdf" - fi -} - -function test_cloud-firstboot() -{ - if [ $RHELV == 6.0 ]; then - echo "WAIVED TESTS FOR BUGZILLA 704821" - else - new_test "## Verify rh-cloud-firstboot is on ... " - assert "chkconfig --list | grep rh-cloud | grep 3:off | wc -l" "1" - if [ -f /etc/sysconfig/rh-cloud-firstboot ]; then - echo "/etc/sysconfig/rh-cloud-firstboot FOUND" >> $LOGFILE - assert "echo true" - else - echo "/etc/sysconfig/rh-cloud-firstboot NOT FOUND" >> $LOGFILE - assert "/bin/asdf" - fi - assert "cat /etc/sysconfig/rh-cloud-firstboot" "RUN_FIRSTBOOT=NO" - fi -} - -function test_nameserver() -{ - new_test "## Verify nameserver ... " - assert "/usr/bin/dig clock.redhat.com 2>> $LOGFILE | grep 66.187.233.4 | wc -l" -} - -function test_group() -{ - new_test "## Verify group file ... " - assert "cat /etc/group | grep root:x:0" "root:x:0:root" - assert "cat /etc/group | grep bin:x:1" "bin:x:1:root,bin,daemon" - assert "cat /etc/group | grep daemon:x:2" "daemon:x:2:root,bin,daemon" - assert "cat /etc/group | grep nobody:x:99" "nobody:x:99:" -} - -function test_passwd() -{ - new_test "## Verify new passwd file ... " - assert "cat /etc/passwd | grep root:x:0" "root:x:0:0:root:/root:/bin/bash" - assert "cat /etc/passwd | grep nobody:x:99" "nobody:x:99:99:Nobody:/:/sbin/nologin" - assert "cat /etc/passwd | grep sshd" "sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin" -} - -function test_inittab() -{ - if [ $RHEL == 5 ] ;then - new_test "## Verify runlevel ... " - assert "cat /etc/inittab | grep id:" "id:3:initdefault:" - assert "cat /etc/inittab | grep si:" "si::sysinit:/etc/rc.d/rc.sysinit" - else - new_test "## Verify runlevel ... " - assert "cat /etc/inittab | grep id:" "id:3:initdefault:" - fi -} - - -function test_shells() -{ - new_test "## Verify new shells file ... " - assert "cat /etc/shells | grep bash" "/bin/bash" - assert "cat /etc/shells | grep nologin" "/sbin/nologin" -} - -function test_repos() -{ - - if [ $RHEL == 5 ]; then - new_test "## test repo files ... " - assert "ls /etc/yum.repos.d/ | wc -l " 6 - assert "ls /etc/yum.repos.d/redhat* | wc -l" 4 - assert "ls /etc/yum.repos.d/rhel* | wc -l" 2 - else - new_test "## test repo files ... " - assert "ls /etc/yum.repos.d/ | wc -l " 4 - assert "ls /etc/yum.repos.d/redhat* | wc -l" 4 - assert "ls /etc/yum.repos.d/rhel* | wc -l" 0 - fi -} - -function test_yum_plugin() -{ - new_test "## Verify disabled yum plugin ... " - assert "grep ^enabled /etc/yum/pluginconf.d/rhnplugin.conf | grep -v '^#' | cut -d\= -f2 | awk '{print $1}' | sort -f | uniq" -} - -function test_gpg_keys() -{ - new_test "## Verify GPG checking ... " - assert "grep '^gpgcheck=1' /etc/yum.repos.d/redhat-*.repo | cut -d\= -f2 | sort -f | uniq" 1 - - new_test "## Verify GPG Keys ... " - if [ $BETA == 1 ]; then - assert "rpm -qa gpg-pubkey* | wc -l " 3 - elif [ $RHEL_FOUND == "6.1" ]; then - assert "rpm -qa gpg-pubkey* | wc -l " 2 - else - assert "rpm -qa gpg-pubkey* | wc -l " 2 - fi - - - if [ $BETA == 1 ]; then - echo "SKIPPING TEST, BETA DETECTED" >> $LOGFILE - elif [[ $RHEL == 5 ]] && [[ $BETA == 0 ]]; then - new_test "## Verify GPG RPMS ... " - assert "rpm -qa gpg-pubkey* | sort -f | tail -n 1" "gpg-pubkey-37017186-45761324" - assert "rpm -qa gpg-pubkey* | grep 2fa6" "gpg-pubkey-2fa658e0-45700c69" - elif [[ $RHEL_FOUND == "6.1" ]] && [[ $BETA == 0 ]]; then - assert "rpm -qa gpg-pubkey* | sort -f | tail -n 1" "gpg-pubkey-fd431d51-4ae0493b" - assert "rpm -qa gpg-pubkey* | sort -f | head -n 1" "gpg-pubkey-2fa658e0-45700c69" - else - new_test "## Verify GPG RPMS ... " - assert "rpm -qa gpg-pubkey* | sort -f | tail -n 1" "gpg-pubkey-fd431d51-4ae0493b" - assert "rpm -qa gpg-pubkey* | grep 2fa6" "gpg-pubkey-2fa658e0-45700c69" - fi -} - -function test_IPv6() -{ - new_test "## Verify IPv6 disabled ... " - assert "grep ^NETWORKING_IPV6= /etc/sysconfig/network" "NETWORKING_IPV6=no" -} - -function test_networking() -{ - new_test "## Verify networking ... " - assert "grep ^NETWORKING= /etc/sysconfig/network | cut -d\= -f2" yes - - new_test "## Verify device ... " - assert "grep ^DEVICE= /etc/sysconfig/network-scripts/ifcfg-eth0 | cut -d\= -f2" eth0 -} - -function test_sshd() -{ - new_test "## Verify sshd ..." - assert "chkconfig --list | grep sshd" "sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off" - assert "/etc/init.d/sshd status | grep running | wc -l" 1 -} - - -function test_iptables() -{ - if [ $RHEL == 5 ]; then - new_test "## Verify iptables ... " - rc_outFile "/etc/init.d/iptables status | grep REJECT" - assert "/etc/init.d/iptables status | grep :22 | grep ACCEPT | wc -l " "1" - assert "/etc/init.d/iptables status | grep "dpt:631" | grep ACCEPT | wc -l " "2" -# assert "/etc/init.d/iptables status | grep "icmp type" | grep ACCEPT | wc -l" "1" - assert "/etc/init.d/iptables status | grep "dpt:5353" | grep ACCEPT | wc -l" "1" - assert "/etc/init.d/iptables status | grep "RELATED,ESTABLISHED" | grep ACCEPT | wc -l" "1" - assert "/etc/init.d/iptables status | grep -e esp -e ah | grep ACCEPT | wc -l" "2" -# assert "/etc/init.d/iptables status | grep :80 | grep ACCEPT | wc -l " "1" -# assert "/etc/init.d/iptables status | grep :443 | grep ACCEPT | wc -l " "1" - assert "/etc/init.d/iptables status | grep REJECT | grep all | grep 0.0.0.0/0 | grep icmp-host-prohibited | wc -l" "1" - else - new_test "## Verify iptables ... " - rc_outFile "/etc/init.d/iptables status | grep REJECT" - assert "/etc/init.d/iptables status | grep :22 | grep ACCEPT | wc -l " "1" -# assert "/etc/init.d/iptables status | grep "dpt:631" | grep ACCEPT | wc -l " "2" -# assert "/etc/init.d/iptables status | grep "icmp type" | grep ACCEPT | wc -l" "1" -# assert "/etc/init.d/iptables status | grep "dpt:5353" | grep ACCEPT | wc -l" "1" -# assert "/etc/init.d/iptables status | grep "ESTABLISHED,RELATED" | grep ACCEPT | wc -l" "1" -# assert "/etc/init.d/iptables status | grep -e esp -e ah | grep ACCEPT | wc -l" "2" -# assert "/etc/init.d/iptables status | grep :80 | grep ACCEPT | wc -l " "1" -# assert "/etc/init.d/iptables status | grep :443 | grep ACCEPT | wc -l " "1" -# assert "/etc/init.d/iptables status | grep REJECT | grep all | grep 0.0.0.0/0 | grep icmp-host-prohibited | wc -l" "1" - fi -} - -function test_chkconfig() -{ - - if [ $RHEL == 5 ]; then - new_test "## Verify chkconfig ... " - assert "chkconfig --list | grep crond | cut -f 5" "3:on" - assert "chkconfig --list | grep iptables | cut -f 5" "3:on" - assert "chkconfig --list | grep yum-updatesd | cut -f 5" "3:on" - else - new_test "## Verify chkconfig ... " - assert "chkconfig --list | grep crond | cut -f 5" "3:on" - assert "chkconfig --list | grep iptables | cut -f 5" "3:on" - fi -} - -function test_sshSettings() -{ - new_test "## Verify sshd_config settings ..." - assert "cat /etc/ssh/sshd_config | grep PasswordAuthentication | grep no | wc -l" "1" -} - -function test_libc6-xen.conf() -{ - new_test "## Verify /etc/ld.so.conf.d/libc6-xen.conf is not present ... " - if [ $UNAMEI == "x86_64" ]; then - assert "ls /etc/ld.so.conf.d/libc6-xen.conf" "2" - else - assert "ls /etc/ld.so.conf.d/libc6-xen.conf" "2" - fi -} - -function test_syslog() -{ - new_test "## Verify rsyslog is on ... " - assert "chkconfig --list | grep rsyslog | cut -f 5" "3:on" - new_test "## Verify rsyslog config ... " - if [ $RHEL == 5 ] ; then - assert "md5sum /etc/rsyslog.conf | cut -f 1 -d \" \"" "bd4e328df4b59d41979ef7202a05e074" "15936b6fe4e8fadcea87b54de495f975" - #assert "md5sum /etc/rsyslog.conf | cut -f 1 -d \" \"" "15936b6fe4e8fadcea87b54de495f975" - else - assert "md5sum /etc/rsyslog.conf | cut -f 1 -d \" \"" "dd356958ca9c4e779f7fac13dde3c1b5" - fi -} - -function test_auditd() -{ - new_test "## Verify auditd is on ... " - assert "/sbin/chkconfig --list auditd | grep 3:on" - assert "/sbin/chkconfig --list auditd | grep 5:on" - - new_test "## Verify audit.rules ... " - assert "md5sum /etc/audit/audit.rules | cut -f 1 -d \" \"" "f9869e1191838c461f5b9051c78a638d" - - new_test "## Verify auditd.conf ... " - assert "md5sum /etc/audit/auditd.conf | cut -f 1 -d \" \"" "612ddf28c3916530d47ef56a1b1ed1ed" - - new_test "## Verify auditd sysconfig ... " - assert "md5sum /etc/sysconfig/auditd | cut -f 1 -d \" \"" "123beb3a97a32d96eba4f11509e39da2" -} - -function test_uname() -{ - new_test "## Verify kernel name ... " - assert "/bin/uname -s" Linux - - new_test "## Verify latest installed kernel is running ... " - if [ $RHEL == 5 ] ; then - echo "LATEST_RPM_KERNEL_VERSION=`rpm -q kernel-xen | tail -n 1 | cut -c 12-50| sed 's/\(.*\)..../\1/'`" >> $LOGFILE - LATEST_RPM_KERNEL_VERSION=`rpm -q kernel-xen | tail -n 1 | cut -c 12-50| sed 's/\(.*\)..../\1/'` - echo "CURRENT_UNAME_KERNAL_VERSION=`uname -r | sed 's/\(.*\)......./\1/'`" >> $LOGFILE - CURRENT_UNAME_KERNAL_VERSION=`uname -r | sed 's/\(.*\)......./\1/'` - echo "assert latest rpm kernel = uname -r" >> $LOGFILE - #assert "rpm -q kernel-xen | sort -n | tail -n 1 | cut -c 12-50| sed 's/\(.*\)..../\1/'" $CURRENT_UNAME_KERNAL_VERSION - assert "uname -r | sed 's/\(.*\)......./\1/'" $LATEST_RPM_KERNEL_VERSION - elif [[ $RHEL == 6 ]] && [[ $UNAMEI == "i386" ]] ; then - echo "RHEL VERSION IS $RHEL" >> $LOGFILE - echo "LATEST_RPM_KERNEL_VERSION=rpm -q kernel --last | head -n 1 | cut -c 8-60 | cut -d ' ' -f 1" >> $LOGFILE - LATEST_RPM_KERNEL_VERSION=`rpm -q kernel --last | head -n 1 | cut -c 8-60 | cut -d ' ' -f 1` - echo "CURRENT_UNAME_KERNAL_VERSION=`uname -r | sed 's/\(.*\)...../\1/'`" >> $LOGFILE - CURRENT_UNAME_KERNAL_VERSION=`uname -r | sed 's/\(.*\)...../\1/'` - echo "assert latest rpm kernel = uname -r" >> $LOGFILE - #assert "rpm -q kernel-xen | sort -n | tail -n 1 | cut -c 12-50| sed 's/\(.*\)..../\1/'" $CURRENT_UNAME_KERNAL_VERSION - assert "uname -r | sed 's/\(.*\)...../\1/'" $LATEST_RPM_KERNEL_VERSION - elif [[ $RHEL == 6 ]] && [[ $UNAMEI == "x86_64" ]] ; then - echo "RHEL VERSION IS $RHEL" >> $LOGFILE - echo "LATEST_RPM_KERNEL_VERSION=rpm -q kernel --last | head -n 1 | cut -c 8-60 | cut -d ' ' -f 1" >> $LOGFILE - LATEST_RPM_KERNEL_VERSION=`rpm -q kernel --last | head -n 1 | cut -c 8-60 | cut -d ' ' -f 1` - echo "CURRENT_UNAME_KERNAL_VERSION=`uname -r | sed 's/\(.*\)......./\1/'`" >> $LOGFILE - CURRENT_UNAME_KERNAL_VERSION=`uname -r | sed 's/\(.*\)......./\1/'` - echo "assert latest rpm kernel = uname -r" >> $LOGFILE - #assert "rpm -q kernel-xen | sort -n | tail -n 1 | cut -c 12-50| sed 's/\(.*\)..../\1/'" $CURRENT_UNAME_KERNAL_VERSION - assert "uname -r | sed 's/\(.*\)......./\1/'" $LATEST_RPM_KERNEL_VERSION - fi - - new_test "## Verify latest kenerl is in /boot/grub/menu.1st ... " - assert "cat /boot/grub/menu.lst | grep $LATEST_RPM_KERNEL_VERSION" - - new_test "## Verify operating system ... " - assert "/bin/uname -o" GNU/Linux - - new_test "## Verify /etc/sysconfig/kernel ... " - assert "ls /etc/sysconfig/kernel" - - new_test "## Verify /etc/sysconfig/kernel contains UPDATEDEFAULT ... " - assert "cat /etc/sysconfig/kernel | grep UPDATEDEFAULT=yes" - - new_test "## Verify /etc/sysconfig/kernel contains DEFAULTKERNEL ... " - assert "cat /etc/sysconfig/kernel | grep DEFAULTKERNEL=kernel" - -} - -function resize2fs() -{ - new_test "## Verify resize2fs ... " - if [ $RHEL == 6 ] ; then - rc "resize2fs -p /dev/xvde1 15000M" - fi - if [ $RHEL == 5 ] ; then - rc "resize2fs -p /dev/sda1 15000M" - fi - assert "df -h | grep 13G | wc -l" "1" -} - -function installTestKernel() -{ - new_test "## install custom kernel" - #cat /proc/cpuinfo | grep nonstop_tsc >> $LOGFILE - echo "yumlocalinstall -y /root/kernel/*" >> $LOGFILE - rc "yum localinstall -y /root/kernel/* --nogpgcheck" - - #cat /boot/grub/grub.conf > /boot/grub/menu.lst - #/bin/sed -i -e 's/(hd0,0)/(hd0)/' /boot/grub/menu.lst -} - -function test_grub() -{ - new_test "##test menu.lst ... " - assert "file /boot/grub/menu.lst | grep symbolic | wc -l" "1" - assert "file /boot/grub/menu.lst | grep grub.conf | wc -l" "1" - assert "cat /boot/grub/grub.conf | grep \"(hd0,0)\" | wc -l" "0" -} - -function test_memory() -{ - new_test "##Verify memory match hwp ... " - echo "cat /proc/meminfo | grep MemTotal: | awk '{print $2}'" >> $LOGFILE - MEM=`cat /proc/meminfo | grep "MemTotal:" | awk '{print $2}'` - echo "EXPECTED MINIMUM MEMORY = $MEM_HWP" - echo "MEMORY FOUND = $MEM" - if [[ $MEM -gt $MEM_HWP ]]; then - echo "FOUND MEMORY OF $MEM > hwp MEMORY of $MEM_HWP" >> $LOGFILE - assert "echo true" - else - echo "FAILED!! FOUND MEMORY OF $MEM > hwp MEMORY of $MEM_HWP" >> $LOGFILE - assert "echo false" "1" - fi -} - -function sos_report() -{ - echo "## Create a sosreport ... " - echo "This may take 5 - 10 minutes" - sosreport -a --batch --ticket-number=${BUGZILLA} 1>/dev/null - echo "" - #echo "Please attach the sosreport bz2 in file /tmp to https://bugzilla.redhat.com/show_bug.cgi?id=$BUGZILLA" - -} - -function open_bugzilla() -{ - #echo "######### /etc/rc.local ########" >> $LOGFILE - #cat /etc/rc.local >> $LOGFILE - #echo "######### /etc/rc.local ########" >> $LOGFILE - - BUGZILLACOMMAND=$DIFFDIR/bugzilla-command - new_test "## Open a bugzilla" - echo "" - echo "Logging into bugilla" - echo "" - $BUGZILLACOMMAND --bugzilla=https://bugzilla.redhat.com/xmlrpc.cgi --user=$BUG_USERNAME --password=$BUG_PASSWORD login - if [ -z $BUG_NUM ]; then - BUGZILLA=`$BUGZILLACOMMAND new -p"Cloud Image Validation" -v"RHEL$RHELV" -a"$UNAMEI" -c"images" -l"initial bug opening" -s"$IMAGEID $RHELV $UNAMEI " | cut -b "2-8"` - echo "" - echo "new bug created: $BUGZILLA https://bugzilla.redhat.com/show_bug.cgi?id=$BUGZILLA" - echo "" - else - BUGZILLA=$BUG_NUM - echo $BUGZILLA > /tmp/bugzilla - fi -} - -function bugzilla_comments() -{ - echo "Adding log file contents to bugzilla" - BUG_COMMENTS01=`head -n $(expr $(cat ${LOGFILE} | wc -l ) / 2) ${LOGFILE}` - BUG_COMMENTS02=`tail -n $(expr $(cat ${LOGFILE} | wc -l ) / 2) ${LOGFILE}` - $BUGZILLACOMMAND modify $BUGZILLA -l "${BUG_COMMENTS01}" - $BUGZILLACOMMAND modify $BUGZILLA -l "${BUG_COMMENTS02}" - - echo "Finished with the bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=$BUGZILLA" - -} - -function verify_bugzilla() -{ - echo "If no failures found move bug to verified" - if [ $FAILURES == 0 ];then - echo "MOVING BUG TO VERIFIED: test has $FAILURES failures" - $BUGZILLACOMMAND modify --status="VERIFIED" $BUGZILLA - else - echo "MOVING BUG TO ON_QA: test has $FAILURES failures" - $BUGZILLACOMMAND modify --status="ON_QA" $BUGZILLA - fi - -} - - -function remove_bugzilla_rpms() -{ - echo "" - echo "Removing epel-release and python-bugzilla" - rpm -e epel-release python-bugzilla - rpm -e gpg-pubkey-0608b895-4bd22942 gpg-pubkey-217521f6-45e8a532 - echo "" - echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - echo "Please attach the sosreport bz2 in file /tmp to https://bugzilla.redhat.com/show_bug.cgi?id=$BUGZILLA" - echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" -} - -function setup_rc.local() -{ - echo "####################### cat of /etc/rc.local ##################" >> $LOGFILE - echo "cd /root/valid/src" >> /etc/rc.local - echo "./image_validation_postreboot.sh --imageID=asdf --RHEL=$RHELV --full-yum-suite=no --skip-questions=yes --bugzilla-username=$BUG_USERNAME --bugzilla-password=$BUG_PASSWORD --bugzilla-num=$BUGZILLA --failures=$FAILURES --memory=$MEM_HWP >> /var/log/messages" >> /etc/rc.local - cat /etc/rc.local >> $LOGFILE - -echo "####################### cat of /etc/rc.local ##################" >> $LOGFILE -} - -function postReboot() -{ - echo "###### TEST KERNEL AFTER REBOOT #### " >> $LOGFILE -} - - - -function show_failures() -{ - echo "" | $DLOG - echo "## Summary ##" | $DLOG - echo "FAILURES = ${FAILURES}" | $DLOG - echo $TEST_FAILED >> $PWD/failed_tests - FAILED=`cat $PWD/failed_tests` - echo "FAILED TESTS = ${FAILED}" | $DLOG - echo "LOG FILE = ${LOGFILE}" | $DLOG - echo "## Summary ##" | $DLOG - echo "" | $DLOG -} - -function im_exit() -{ - echo "" - echo "## Summary ##" - echo "FAILURES = ${FAILURES}" - echo "FAILED TESTS = ${FAILED}" - echo "LOG FILE = ${LOGFILE}" - echo "## Summary ##" - echo "" - exit ${FAILURES} -} diff --git a/src/validation.cfg b/src/validation.cfg new file mode 100644 index 0000000..9568e16 --- /dev/null +++ b/src/validation.cfg @@ -0,0 +1,26 @@ +[SSH-Info] +ssh-key-path_useast=/home/kbidarka/cloud-keyuseast-new.pem +ssh-key-name_useast=cloud-keyuseast-new +ssh-key-path_uswest=/home/kbidarka/cloud-keyuswest-new.pem +ssh-key-name_uswest=cloud-keyuswest-new +ssh-key-path_uswest-oregon=/home/kbidarka/cloud-keyuswest-oregon.pem +ssh-key-name_uswest-oregon=cloud-keyuswest-oregon +ssh-key-path_euwest=/home/kbidarka/cloud-keyeuwest-new.pem +ssh-key-name_euwest=cloud-keyeuwest-new +ssh-key-path_apnorth=/home/kbidarka/cloud-keyapnorth-new.pem +ssh-key-name_apnorth=cloud-keyapnorth-new +ssh-key-path_apsouth=/home/kbidarka/cloud-keyapsouth-new.pem +ssh-key-name_apsouth=cloud-keyapsouth-new + +[EC2-Keys] +ec2-key= +ec2-secret-key= + +[Bugzilla-Info] +bugzilla_usr=kbidarka@redhat.com +bugzilla_pwd= + +[Misc-Info] +csv=true +git=false +basedir=/home/kbidarka/full123/valid/src diff --git a/validate.spec b/validate.spec index 3dbc9c8..b1972be 100644 --- a/validate.spec +++ b/validate.spec @@ -1,20 +1,20 @@ Name: validate -Version: 6.1 +Version: 6.1 Release: 1 -Summary: Validates a cloud providers image of Red Hat Enterprise Linux +Summary: Validates a cloud providers image of Red Hat Enterprise Linux Group: Development/Libraries License: GPL -URL: http://github.com/weshayutin/valid +URL: http://github.com/weshayutin/valid Source0: %{name}-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name} BuildArch: noarch -# BuildRequires: -# Requires: +# BuildRequires: +# Requires: %description -A shell script that will run tests to validate that the image of Red Hat Enterprise Linux meets or exceeds the minimum requirements as defined by Red Hat. +A shell script that will run tests to validate that the image of Red Hat Enterprise Linux meets or exceeds the minimum requirements as defined by Red Hat. %prep