def test_create_machines_for_test_interface(): np = Building.get_unique(sess, 'np') assert isinstance(np, Building), 'no building in %s' % func_name() hp = Vendor.get_unique(sess, 'hp') assert isinstance(hp, Vendor), 'no vendor in %s' % func_name() am = Model.get_unique(sess, name='bl45p', vendor=hp) assert isinstance(am, Model), 'no model in %s' % func_name() cpu = sess.query(Cpu).first() assert isinstance(cpu, Cpu), 'no cpu in %s' % func_name() for i in xrange(NUM_MACHINES): machine = Machine(label='%s%s' % (MACHINE_NAME_PREFIX, i), location=np, model=am, cpu=cpu, cpu_quantity=2, memory=32768) create(sess, machine) machines = sess.query(Machine).filter( Machine.label.like(MACHINE_NAME_PREFIX + '%')).all() eq_(len(machines), NUM_MACHINES)
def test_create_machines_for_hosts(): np = Building.get_unique(sess, name='np', compel=True) am = Model.get_unique(sess, name='vm', compel=True) a_cpu = Cpu.get_unique(sess, name='aurora_cpu', compel=True) for i in xrange(NUM_HOSTS): machine = Machine(label='%s%s' % (MACHINE_NAME, i), location=np, model=am, cpu=a_cpu, cpu_quantity=8, memory=32768) create(sess, machine) machines = sess.query(Machine).filter( Machine.label.like(MACHINE_NAME + '%')).all() assert len(machines) is NUM_MACHINES print 'created %s esx machines' % len(machines)
def test_create_vm(): #vend = Vendor.get_unique(sess, 'virtual') mod = Model.get_unique(sess, name='vm', compel=True) proc = Cpu.get_unique(sess, name='virtual_cpu', speed=0, compel=True) np = Building.get_unique(sess, 'np', compel=True) for i in xrange(NUM_MACHINES): vm = Machine(label='%s%s' % (VM_NAME, i), location=np, model=mod, cpu=proc, cpu_quantity=1, memory=4196) create(sess, vm) machines = sess.query(Machine).filter(Machine.label.like(VM_NAME + '%')).all() assert len(machines) is NUM_MACHINES print 'created %s machines' % (len(machines))
def add_machine(sess, name, model=MODEL): """ Shorthand to create machines created for the purposes of reuse among all the various tests that require them """ mchn = sess.query(Machine).filter_by(label=name).first() if mchn: return mchn model = Model.get_unique(sess, name=model, compel=True) proc = sess.query(Cpu).first() assert proc, "Can't find a cpu" rack = sess.query(Rack).first() assert rack, "Can't find a rack" mchn = Machine(label=name, model=model, location=rack, cpu=proc) add(sess, mchn) commit(sess) return mchn
def create_machine(session, machine, dblocation, dbmodel, cpuname=None, cpuvendor=None, cpuspeed=None, cpucount=None, memory=None, serial=None, comments=None): # Figure out a CPU... dbcpu = None if not (cpuname or cpuvendor or cpuspeed is not None): if not dbmodel.machine_specs: raise ArgumentError("Model %s does not have machine specification " "defaults, please specify --cpuvendor, " "--cpuname, and --cpuspeed." % dbmodel.name) dbcpu = dbmodel.machine_specs.cpu else: # Was there enough on the command line to specify one? q = session.query(Cpu) if cpuname: q = q.filter(Cpu.name.like(cpuname.lower() + '%')) if cpuspeed is not None: q = q.filter_by(speed=cpuspeed) if cpuvendor: q = q.join('vendor').filter_by(name=cpuvendor.lower()) cpulist = q.all() if not cpulist: raise ArgumentError("Could not find a CPU with the given " "attributes.") if len(cpulist) == 1: # Found it exactly. dbcpu = cpulist[0] elif dbmodel.machine_specs: # Not exact, but see if the specs match the default. dbcpu = dbmodel.machine_specs.cpu if ((cpuname and not dbcpu.name.startswith(cpuname.lower())) or (cpuspeed is not None and dbcpu.speed != cpuspeed) or (cpuvendor and dbcpu.vendor.name != cpuvendor.lower())): raise ArgumentError("Could not uniquely identify a CPU with " "the attributes given.") else: raise ArgumentError("Could not uniquely identify a CPU with the " "attributes given.") if cpucount is None: if dbmodel.machine_specs: cpucount = dbmodel.machine_specs.cpu_quantity else: raise ArgumentError("Model %s does not have machine specification " "defaults, please specify --cpucount." % dbmodel.name) if memory is None: if dbmodel.machine_specs: memory = dbmodel.machine_specs.memory else: raise ArgumentError("Model %s does not have machine specification " "defaults, please specify --memory (in MB)." % dbmodel.name) dbmachine = Machine(location=dblocation, model=dbmodel, label=machine, cpu=dbcpu, cpu_quantity=cpucount, memory=memory, serial_no=serial, comments=comments) session.add(dbmachine) if dbmodel.machine_specs and dbmodel.machine_type != 'aurora_node' \ and dbmodel.machine_specs.disk_type == 'local': specs = dbmodel.machine_specs dbdisk = LocalDisk(machine=dbmachine, device_name=specs.disk_name, controller_type=specs.controller_type, capacity=specs.disk_capacity, bootable=True) session.add(dbdisk) session.flush() return dbmachine