def get_host_info(self, hostname): """Fetch values for the host ID, available memory and cores, the bitness of the virt system installed on the host, the vendor ID of the last guest running on the host Arguments: hostname -- Name of the host system """ hostname = checks.chk_hostname(hostname) self.cursor.execute(''' SELECT host_id, host_memory, host_cores, last_vendor_id, last_subject_id, is_64bit, is_enabled FROM host WHERE host_name=?''', (hostname, )) result = self.cursor.fetchone() if result == None: raise ValueError('No such host.') self.host['name'] = hostname self.host['ip'] = gethostbyname(hostname) self.host['id'], self.resources['memory'], self.resources['cores'], \ self.resources['lastvendor'], self.resources['lastsubject'], \ self.resources['bitness'], state = result if int(self.resources["memory"] * 0.1) > minmem: self.resources['memory'] -= int(self.resources["memory"] * 0.1) else: self.resources['memory'] -= minmem self.resources['cores'] += 1 if state != 1: raise ValueError('The chosen host is currently disabled.')
def add(self, args): """Add a new host to the database. Arguments: hostname -- Name of the host system memory -- Amount of memory available on the host system cores -- Amount of CPU cores available on the host system bitness -- Bitness of the host OS (0 = 32-bit, 1 = 64-bit) """ checks.chk_arg_count(args, 4) hostname, memory, cores, bitness = args hostname = checks.chk_hostname(hostname) memory = checks.chk_memory(memory) cores = checks.chk_cores(cores) bitness = checks.chk_bitness(bitness) try: self.cursor.execute(''' INSERT INTO host (host_name, host_memory, host_cores, is_64bit) VALUES (?,?,?,?)''', (hostname, memory, cores, bitness)) except sqlite3.IntegrityError: raise ValueError('Host already exists.') self.cursor.execute(''' INSERT INTO host_schedule (host_id, test_id, image_id) SELECT host_id, test_id, image_id FROM host LEFT JOIN image LEFT JOIN test ON test.os_type_id=image.os_type_id WHERE host_name=? AND test_id NOT NULL AND image_id NOT NULL''', (hostname, )) self.connection.commit()
def do_command(self, args): """Validate the number of given arguments, write guest configurations, and ouput a YAML precondition string """ if len(args) == 1: hostname = chk_hostname(args[0]) subjectops = preparation.SubjectPreparation(hostname) subjectops.gen_precondition() elif len(args) == 3: hostname = chk_hostname(args[0]) subject = chk_subject(args[1]) bitness = chk_bitness(args[2]) subjectops = preparation.SubjectPreparation( hostname, subject, bitness) subjectops.gen_precondition() else: raise ValueError('Wrong number of arguments.')
def run(self): """Take all steps required to start all guests on the host """ self.stage = 'Generating tests' try: self.host = chk_hostname(self.host) self.testrun = generator.TestRunGenerator(self.host) except ValueError, err: self.error_handler(err[0])
def __init__(self, host, subject=False, bitness=False): """ @param host : Name of the test machine @type host : str @param subject: Name of the test subject (optional) @type subject: str @param bitness: Bitness of the test subject (optional) @type bitness: int """ self.host = chk_hostname(host) self.testrun = generator.TestRunGenerator( self.host, True, subject, bitness) self.dry_mode = 0
def __get_host_id(self, hostname): """Get the database ID of a given hostname. Arguments: hostname -- Name of the host system Returns: The database ID of the host system """ hostname = checks.chk_hostname(hostname) self.cursor.execute(''' SELECT host_id FROM host WHERE host_name=?''', (hostname, )) hostid = self.cursor.fetchone() if hostid == None: raise ValueError('No such host.') return hostid[0]
def do_command(self, args): """Validate the number of given arguments and generate guest configurations """ hostlist = [] threads = [] environment = '' getenv = '(grep -q "^kvm " /proc/modules && echo "kvm") || ' \ '(/usr/sbin/xend status >/dev/null 2>&1 && echo "xen") || ' \ 'echo "bare"' if len(args) == 0: raise ValueError('No arguments given.') sys.stdout.write( 'Starting to prepare hosts. ' 'Please wait, this may take a while...\n') for host in args: host = chk_hostname(host) if host not in hostlist: hostlist.append(host) process = Popen(['/usr/bin/ssh', '-o PasswordAuthentication=no', 'root@%s' % (host, ), getenv], stderr=None, stdout=PIPE) retval = process.wait() if retval == 0: output = process.communicate()[0].strip().split('\n') if len(output) == 1 and output[0] in ('xen', 'kvm'): environment = output[0] if environment == 'xen': threads.append(preparation.XenHostPreparation(self, host)) elif environment == 'kvm': threads.append(preparation.KvmHostPreparation(self, host)) else: self.failed = 1 sys.stderr.write( 'Preparation of host %s failed\n' 'Reason:\n' 'Could not determine the test environment.\n' % (host, )) for thread in threads: thread.start() for thread in threads: thread.join() if self.failed == 1: raise ValueError('Preparation of some hosts failed.')