summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Peck <bpeck@redhat.com>2009-11-09 15:28:50 +0000
committerBill Peck <bpeck@redhat.com>2009-11-09 15:28:50 +0000
commite6b0aa5a8a30efa5a89e4d48c2a990168689b403 (patch)
treea49f91069ffd51ace8ca00fdf68a730b40de7753
parent108859e998f083c1c9cee115ca5772a57722f3a2 (diff)
- Use RHEL5.4 kvm_amd/intel to determine if a host is HVM capable. - use getDriver.sh script to determine Network interface. - Push to Beaker or Legacy RHTS depending on lab controller.
-rw-r--r--Tasks/distribution/inventory/Makefile2
-rw-r--r--Tasks/distribution/inventory/disks.py37
-rwxr-xr-xTasks/distribution/inventory/push-inventory.py239
-rwxr-xr-xTasks/distribution/inventory/pushInventory.py159
-rwxr-xr-xTasks/distribution/inventory/runtest.sh44
5 files changed, 326 insertions, 155 deletions
diff --git a/Tasks/distribution/inventory/Makefile b/Tasks/distribution/inventory/Makefile
index 21615a6..4f69f81 100644
--- a/Tasks/distribution/inventory/Makefile
+++ b/Tasks/distribution/inventory/Makefile
@@ -44,7 +44,7 @@ BUILT_FILES=
# data files, .c files, scripts anything needed to either compile the test and/or run it.
FILES=$(METADATA) runtest.sh Makefile PURPOSE push-inventory.py \
- smolt.py software.py i18n.py
+ smolt.py software.py i18n.py disks.py pushInventory.py
run: $(FILES) build
./runtest.sh
diff --git a/Tasks/distribution/inventory/disks.py b/Tasks/distribution/inventory/disks.py
new file mode 100644
index 0000000..7373759
--- /dev/null
+++ b/Tasks/distribution/inventory/disks.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+import sys
+sys.path.append("/usr/lib/anaconda")
+import isys
+import parted
+
+class Disks(object):
+ def __init__(self):
+ """
+ """
+ self.disks = []
+ for disk in isys.hardDriveDict().keys():
+ self.disks.append(int("%d" % self.disksize(
+ parted.device_get("/dev/%s" % disk))))
+
+ def disksize(self, disk):
+ return (float(disk.heads * disk.cylinders * disk.sectors)
+ / ( 1024 * 1024) * disk.sector_size)
+ def nr_disks(self):
+ return len(self.disks)
+
+ nr_disks = property(nr_disks)
+
+ def diskspace(self):
+ diskspace = 0
+ for disk in self.disks:
+ diskspace += disk
+ return diskspace
+
+ diskspace = property(diskspace)
+
+if __name__ == '__main__':
+ disks = Disks()
+ print disks.nr_disks
+ print disks.disks
+ print disks.diskspace
diff --git a/Tasks/distribution/inventory/push-inventory.py b/Tasks/distribution/inventory/push-inventory.py
index 62153cc..88a2887 100755
--- a/Tasks/distribution/inventory/push-inventory.py
+++ b/Tasks/distribution/inventory/push-inventory.py
@@ -27,168 +27,167 @@ import re
sys.path.append('.')
sys.path.append("/usr/lib/anaconda")
import smolt
-import anaconda_log
-import partedUtils
import network
+from disks import Disks
+import isys
USAGE_TEXT = """
Usage: push-inventory.py [-d] [[-h <HOSTNAME>] [-S server]]
"""
def push_inventory(hostname, inventory):
- client = xmlrpclib.Server(lab_server)
- #test_log = xmlrpclib.Binary(log)
+ session = xmlrpclib.Server(lab_server, allow_none=True)
try:
- resp = client.machines.update(hostname, inventory)
+ resp = getattr(session, method)(hostname, inventory)
if(resp != 0) :
raise NameError, "ERROR: Pushing Inventory for host %s." % hostname
except:
raise
-# some machines just fail to boot with kernel-xen package.. but we need xen
-# kernel to determine the hvm capability of the box correctly. We'll read
-# hvm-capability in xen kernel and the rest in vanilla kernel.
def read_inventory():
# get the data from SMOLT but modify it for how RHTS expects to see it
# Eventually we'll switch over to SMOLT properly.
data = {}
- if ( os.uname()[2].find("xen") == -1 ):
- data['MODULE'] = []
- data['CPUFLAGS'] = []
- data['PCIID'] = []
- data['USBID'] = []
- data['DISK'] = [] # disk space for each disk
- data['BOOTDISK'] = []
- data['DISKSPACE'] = 0 # total combined diskspace
- data['NR_DISKS'] = 0 # number of spindles
- data['NR_ETH'] = 0 # number of ethX interfaces
- data['NR_IB'] = 0 # number of ibX interfaces
-
- cpu_info = smolt.read_cpuinfo()
- memory = smolt.read_memory()
- profile = smolt.Hardware()
-
- data['ARCH'] = cpu_info['platform']
- data['CPUSPEED'] = cpu_info['speed']
- try:
- data['CPUFAMILY'] = cpu_info['model_number']
- except:
- data['CPUFAMILY'] = cpu_info['model_rev']
- data['CPUVENDOR'] = cpu_info['type']
- data['CPUMODEL'] = cpu_info['model']
- data['CPUMODELNUMBER'] = cpu_info['model_ver']
- data['PROCESSORS'] = cpu_info['count']
- data['VENDOR'] = "%s" % profile.host.systemVendor
- data['MODEL'] = "%s" % profile.host.systemModel
- data['FORMFACTOR'] = "%s" % profile.host.formfactor
-
- # Round memory up to the next base 2
- n=0
- memory = int(memory['ram'])
- while memory > ( 2 << n):
- n=n+1
- data['MEMORY'] = 2 << n
-
- for cpuflag in cpu_info['other'].split(" "):
- data['CPUFLAGS'].append(cpuflag)
-
- for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in profile.deviceIter():
- if VendorID and DeviceID:
- if Bus == "pci":
- data['PCIID'].append("%04x:%04x" % ( VendorID, DeviceID))
- if Bus == "usb":
- data['USBID'].append("%04x:%04x" % ( VendorID, DeviceID))
-
- modules = commands.getstatusoutput('/sbin/lsmod')[1].split('\n')[1:]
- for module in modules:
- data['MODULE'].append(module.split()[0])
-
- # Find Active Storage Driver(s)
- bootdisk = None
- bootregex = re.compile(r'/dev/([^ ]+) on /boot')
- disks = commands.getstatusoutput('/bin/mount')[1].split('\n')[1:]
- for disk in disks:
- if bootregex.search(disk):
- bootdisk = bootregex.search(disk).group(1)
-
- if bootdisk:
- drivers = commands.getstatusoutput('./getdriver.sh %s' % bootdisk)[1].split('\n')[1:]
- for driver in drivers:
- data['BOOTDISK'].append(driver)
-
- # Find Active Network interface
- iface = None
- for line in commands.getstatusoutput('route -n')[1].split('\n'):
- if line.find('0.0.0.0') == 0:
- iface = line.split()[-1:][0] #eth0, eth1, etc..
- #Look in /etc/modprobe.conf for driver info..
- if iface and os.path.exists("/etc/modprobe.conf"):
- modprobe = open("/etc/modprobe.conf").read()
- for line in modprobe.split("\n"):
- if line.find(iface) != -1:
- data['NETWORK'] = line.split()[-1:][0]
-
- # calculating available diskspace
- diskset = partedUtils.DiskSet()
- diskset.openDevices()
- for diskname in diskset.disks.keys():
- disksize = int(math.ceil(partedUtils.getDeviceSizeMB(diskset.disks[diskname].dev)))
- data['DISK'].append("%d " % (disksize))
- data['DISKSPACE'] += disksize
- data['NR_DISKS'] += 1
-
- # finding out eth and ib interfaces...
- # TODO: this doesn't check whether or not the interfaces can be brought up on a network.
- # it should probably check that too.
- eth_pat = re.compile ('^eth\d+$')
- ib_pat = re.compile ('^ib\d+$')
- net = network.Network()
- for intname in net.available().keys():
- if eth_pat.match(intname):
- data['NR_ETH'] += 1
- elif ib_pat.match(intname):
- data['NR_IB'] += 1
+ data['MODULE'] = []
+ data['CPUFLAGS'] = []
+ data['PCIID'] = []
+ data['USBID'] = []
+ data['HVM'] = False
+ data['DISK'] = []
+ data['BOOTDISK'] = []
+ data['DISKSPACE'] = 0
+ data['NR_DISKS'] = 0
+ data['NR_ETH'] = 0
+ data['NR_IB'] = 0
+
+ cpu_info = smolt.read_cpuinfo()
+ memory = smolt.read_memory()
+ profile = smolt.Hardware()
+
+ data['ARCH'] = cpu_info['platform']
+ data['CPUSPEED'] = cpu_info['speed']
+ try:
+ data['CPUFAMILY'] = cpu_info['model_number']
+ except:
+ try:
+ data['CPUFAMILY'] = cpu_info['model_rev']
+ except:
+ pass
+ data['CPUVENDOR'] = cpu_info['type']
+ data['CPUMODEL'] = cpu_info['model']
+ data['CPUMODELNUMBER'] = cpu_info['model_ver']
+ data['PROCESSORS'] = cpu_info['count']
+ data['VENDOR'] = "%s" % profile.host.systemVendor
+ data['MODEL'] = "%s" % profile.host.systemModel
+ data['FORMFACTOR'] = "%s" % profile.host.formfactor
+
+ # Round memory up to the next base 2
+ n=0
+ memory = int(memory['ram'])
+ while memory > ( 2 << n):
+ n=n+1
+ data['MEMORY'] = 2 << n
- else:
- data['HVM'] = False
- # checking for whether or not the machine is hvm-enabled.
- caps = ""
- if os.path.exists("/sys/hypervisor/properties/capabilities"):
- caps = open("/sys/hypervisor/properties/capabilities").read()
- if caps.find("hvm") != -1:
- data['HVM'] = True
+ try:
+ for cpuflag in cpu_info['other'].split(" "):
+ data['CPUFLAGS'].append(cpuflag)
+ except:
+ pass
+
+ for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in profile.deviceIter():
+ if VendorID and DeviceID:
+ if Bus == "pci":
+ data['PCIID'].append("%04x:%04x" % ( VendorID, DeviceID))
+ if Bus == "usb":
+ data['USBID'].append("%04x:%04x" % ( VendorID, DeviceID))
+
+ modules = commands.getstatusoutput('/sbin/lsmod')[1].split('\n')[1:]
+ for module in modules:
+ data['MODULE'].append(module.split()[0])
+
+ # Find Active Storage Driver(s)
+ bootdisk = None
+ bootregex = re.compile(r'/dev/([^ ]+) on /boot')
+ disks = commands.getstatusoutput('/bin/mount')[1].split('\n')[1:]
+ for disk in disks:
+ if bootregex.search(disk):
+ # Replace / with !, needed for cciss
+ bootdisk = bootregex.search(disk).group(1).replace('/','!')
+
+ if bootdisk:
+ drivers = commands.getstatusoutput('./getdriver.sh %s' % bootdisk)[1].split('\n')[1:]
+ for driver in drivers:
+ data['BOOTDISK'].append(driver)
+
+ # Find Active Network interface
+ iface = None
+ for line in commands.getstatusoutput('route -n')[1].split('\n'):
+ if line.find('0.0.0.0') == 0:
+ iface = line.split()[-1:][0] #eth0, eth1, etc..
+ if iface:
+ driver = commands.getstatusoutput('./getdriver.sh %s' % iface)[1].split('\n')[1:][0]
+ data['NETWORK'] = driver
+
+ disks = Disks()
+ data['DISK'] = disks.disks
+ data['DISKSPACE'] = disks.diskspace
+ data['NR_DISKS'] = disks.nr_disks
+
+ # finding out eth and ib interfaces...
+ eth_pat = re.compile ('^eth\d+$')
+ ib_pat = re.compile ('^ib\d+$')
+ net = network.Network()
+ for intname in net.available().keys():
+ if isys.getLinkStatus(intname):
+ if eth_pat.match(intname):
+ data['NR_ETH'] += 1
+ elif ib_pat.match(intname):
+ data['NR_IB'] += 1
+
+ # checking for whether or not the machine is hvm-enabled.
+ caps = ""
+ if os.path.exists("/sys/module/kvm_amd") or \
+ os.path.exists("/sys/module/kvm_intel"):
+ data['HVM'] = True
return data
-
+
def usage():
print USAGE_TEXT
sys.exit(-1)
-
+
def main():
- global lab_server, hostname
+ global lab_server, hostname, method
- lab_server = ''
- hostname = ''
+ lab_server = None
+ server = None
+ hostname = None
debug = 0
+ method = "legacypush"
+ rpc = "RPC2"
if ('LAB_SERVER' in os.environ.keys()):
- lab_server = "http://%s/cgi-bin/rhts/xmlrpc.cgi" % os.environ['LAB_SERVER']
+ server = os.environ['LAB_SERVER']
if ('HOSTNAME' in os.environ.keys()):
hostname = os.environ['HOSTNAME']
args = sys.argv[1:]
try:
- opts, args = getopt.getopt(args, 'dh:S:', ['server=', 'debug', 'hostname='])
+ opts, args = getopt.getopt(args, 'dh:S:l', ['server=','legacy'])
except:
usage()
for opt, val in opts:
+ if opt in ('-l', '--legacy'):
+ method = "machines.update"
+ rpc = "cgi-bin/rhts/xmlrpc.cgi"
if opt in ('-d', '--debug'):
debug = 1
if opt in ('-h', '--hostname'):
hostname = val
if opt in ('-S', '--server'):
- lab_server = "http://%s/cgi-bin/rhts/xmlrpc.cgi" % val
+ server = val
+ lab_server = "%s/%s" % (server, rpc)
inventory = read_inventory()
if debug:
print inventory
diff --git a/Tasks/distribution/inventory/pushInventory.py b/Tasks/distribution/inventory/pushInventory.py
new file mode 100755
index 0000000..8ccefc3
--- /dev/null
+++ b/Tasks/distribution/inventory/pushInventory.py
@@ -0,0 +1,159 @@
+#!/usr/bin/python
+# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: Bill Peck
+#
+
+import sys, getopt
+import xmlrpclib
+import string
+import os
+import commands
+import pprint
+
+import smolt
+import procfs
+
+USAGE_TEXT = """
+Usage: push-inventory.py -h <HOSTNAME>
+"""
+
+def push_inventory(hostname, inventory):
+ session = xmlrpclib.Server(lab_server, allow_none=True)
+ try:
+ resp = session.push(hostname, inventory)
+ if(resp != 0) :
+ raise NameError, "ERROR: Pushing Inventory for host %s." % hostname
+ except:
+ raise
+
+def read_inventory():
+ # get the data from SMOLT but modify it for how RHTS expects to see it
+ # Eventually we'll switch over to SMOLT properly.
+ data = {}
+ flags = []
+ data['Devices'] = []
+
+ procCpu = procfs.cpuinfo()
+ smoltCpu = smolt.read_cpuinfo()
+ memory = smolt.read_memory()
+ profile = smolt.Hardware()
+
+ try:
+ for cpuflag in procCpu.tags['flags'].split(" "):
+ flags.append(cpuflag)
+ except:
+ pass
+
+ try:
+ cpu = dict( vendor = smoltCpu['type'],
+ model = int(procCpu.tags['model']),
+ modelName = smoltCpu['model'],
+ speed = float(procCpu.tags['cpu mhz']),
+ processors = int(procCpu.nr_cpus),
+ cores = int(procCpu.nr_cores),
+ sockets = int(procCpu.nr_sockets),
+ CpuFlags = flags
+ )
+ try:
+ cpu['family'] = int(smoltCpu['model_number'])
+ cpu['stepping'] = int(procCpu.tags['stepping'])
+ except:
+ cpu['family'] = int(smoltCpu['model_rev'])
+ cpu['stepping'] = 0
+ pass
+
+ except:
+ #POWERCASE Hack :(
+ cpu = dict( vendor = "IBM",
+ model = str(procCpu.tags['machine']),
+ modelName = str(procCpu.tags['cpu']),
+ speed = str(procCpu.tags['clock']),
+ processors = int(procCpu.nr_cpus),
+ cores = "N/A",
+ sockets = "N/A",
+ CpuFlags = flags,
+ family = str(procCpu.tags['revision']),
+ stepping = 0
+ )
+ pass
+ data['Cpu'] = cpu
+ data['Arch'] = [smoltCpu['platform']]
+ data['vendor'] = "%s" % profile.host.systemVendor
+ data['model'] = "%s" % profile.host.systemModel
+ #data['FORMFACTOR'] = "%s" % profile.host.formfactor
+ data['memory'] = int(memory['ram'])
+
+ for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in profile.deviceIter():
+ device = dict ( vendorID = "%04x" % (VendorID and VendorID or 0),
+ deviceID = "%04x" % (DeviceID and DeviceID or 0),
+ subsysVendorID = "%04x" % (SubsysVendorID and SubsysVendorID or 0),
+ subsysDeviceID = "%04x" % (SubsysDeviceID and SubsysDeviceID or 0),
+ bus = Bus,
+ driver = Driver,
+ type = Type,
+ description = Description)
+ data['Devices'].append(device)
+ return data
+
+def usage():
+ print USAGE_TEXT
+ sys.exit(-1)
+
+def main():
+ global lab_server, hostname
+
+ lab_server = None
+ hostname = None
+ server = None
+ debug = 0
+
+ if ('LAB_SERVER' in os.environ.keys()):
+ server = os.environ['LAB_SERVER']
+ if ('HOSTNAME' in os.environ.keys()):
+ hostname = os.environ['HOSTNAME']
+
+ args = sys.argv[1:]
+ try:
+ opts, args = getopt.getopt(args, 'dh:S:', ['server='])
+ except:
+ usage()
+ for opt, val in opts:
+ if opt in ('-d', '--debug'):
+ debug = 1
+ if opt in ('-h', '--hostname'):
+ hostname = val
+ if opt in ('-S', '--server'):
+ server = val
+
+ if not hostname:
+ print "You must sepcify a hostname with the -h switch"
+ sys.exit(1)
+
+ if not server:
+ print "You must sepcify a lab_server with the -S switch"
+ sys.exit(1)
+
+ lab_server = "%s/RPC2" % (server)
+ inventory = read_inventory()
+ if debug:
+ print inventory
+ else:
+ push_inventory(hostname, inventory)
+
+
+if __name__ == '__main__':
+ main()
+ sys.exit(0)
+
diff --git a/Tasks/distribution/inventory/runtest.sh b/Tasks/distribution/inventory/runtest.sh
index 92788aa..bebe5df 100755
--- a/Tasks/distribution/inventory/runtest.sh
+++ b/Tasks/distribution/inventory/runtest.sh
@@ -15,39 +15,15 @@
#
# Author: Bill Peck, Gurhan Ozen
-arch=$(uname -i)
-
-#Virtualization is only supported on i386, x86_64 or ia64... So we'll seek for
-# hvm data only on those.
-if [[ $arch == "i386" || $arch == "x86_64" || $arch == ia64 ]]; then
-
- if [ -z $REBOOTCOUNT ]; then
- echo "REBOOTCOUNT variable is not set. Are you in rhts??"
- exit 0;
- fi
-
- if [[ $REBOOTCOUNT == 0 ]]; then
- rhts-run-simple-test $TEST/all_but_hvm ./push-inventory.py
- yum -y install kernel-xen
- if ! rpm -q kernel-xen; then
- echo "kernel-xen isn't installed. Can't check for HVM capability"
- report_result ${TEST}/hvm FAIL 0
- exit 0
- fi
- if [[ ${arch} == ia64 ]]; then
- perl -pi.bak -e 's/\tlabel=linux$/\tlabel=linux.old/' /boot/efi/efi/redhat/elilo.conf
- perl -pi.bak2 -e 's/\tlabel=.*?xen$/\tlabel=linux/' /boot/efi/efi/redhat/elilo.conf
- else
- perl -pi.bak -e 's/^default=.*?$/default=0/g' /boot/grub/grub.conf
- fi
- rhts-reboot
- else
- rhts-run-simple-test $TEST/hvm ./push-inventory.py
- fi
-
+hostname=$HOSTNAME
+if [ -z "$LAB_SERVER" ]; then
+ # Push to Inventory server
+ server="https://inventory.engineering.redhat.com"
+ rhts-run-simple-test $TEST "/push-inventory.py --server $server -h $hostname"
+ rhts-run-simple-test $TEST "./pushInventory.py --server $server -h $hostname"
else
-
- rhts-run-simple-test $TEST ./push-inventory.py
-
+ # Push to Legacy Lab Controller
+ server="http://$LAB_SERVER"
+ rhts-run-simple-test $TEST "./push-inventory.py --legacy --server $server -h $hostname"
fi
-
+