def _allocateOne(self): client = clientfactory.factory() try: requirement = api.Requirement(imageLabel=LABEL, imageHint=HINT) info = api.AllocationInfo(user='******', purpose='integration test') allocation = client.allocate(dict(it=requirement), info) print "Created allocation, waiting for node inauguration" try: allocation.wait(timeout=7 * 60) print "Allocation successfull, waiting for ssh" nodes = allocation.nodes() assert len(nodes) == 1, nodes it = nodes['it'] it.fetchSerialLog() allocation.fetchPostMortemPack() print "SSH credentials:", it.rootSSHCredentials() ssh = connection.Connection(**it.rootSSHCredentials()) ssh.waitForTCPServer() ssh.connect() print "SSH connected" yield it, ssh, allocation finally: allocation.free() finally: client.close()
def test_it(self): self.client = self.server.createClient() self.assertEquals(self.server.MAXIMUM_VMS, 4) allocation = self.client.allocate( requirements={ 'node1': testlib.defaultRequirement(), 'node2': testlib.defaultRequirement() }, allocationInfo=testlib.whiteboxAllocationInfo()) allocation.wait(timeout=8 * 60) self.assertFalse(allocation.dead()) self.assertTrue(allocation.done()) nodes = allocation.nodes() node1 = nodes['node1'] ssh1 = connection.Connection(**node1.rootSSHCredentials()) ssh1.waitForTCPServer() ssh1.connect() self.assertEquals(ssh1.run.script("echo hello"), "hello") node2 = nodes['node2'] ssh2 = connection.Connection(**node2.rootSSHCredentials()) ssh2.waitForTCPServer() ssh2.connect() self.assertEquals(ssh2.run.script("echo hello"), "hello") allocation.free()
def test_it(self): self.client = self.server.createClient() self.assertEquals(self.server.MAXIMUM_VMS, 4) allocation = self.client.allocate( requirements={'node': testlib.defaultRequirement()}, allocationInfo=testlib.whiteboxAllocationInfo()) allocation.wait(timeout=5 * 60) self.assertFalse(allocation.dead()) self.assertTrue(allocation.done()) nodes = allocation.nodes() self.assertEquals(len(nodes), 1) node = nodes['node'] ssh = connection.Connection(**node.rootSSHCredentials()) ssh.waitForTCPServer() ssh.connect() result = ssh.run.script("echo hello") self.assertEquals(result.strip(), "hello") allocation.free()
def _reclaimByKexec(self): ssh = connection.Connection( **self._hostImplementation.rootSSHCredentials()) ssh.connect() uptime = float(ssh.ftp.getContents("/proc/uptime").split(" ")[0]) if uptime > self._AVOID_RECLAIM_BY_KEXEC_IF_UPTIME_MORE_THAN: raise Exception( "system '%(id)s' is up for way too long, will not kexec. doing cold restart" % dict(id=self._hostImplementation.id())) try: ssh.run.script("kexec -h") except: raise Exception( "kexec does not exist on image on '%(id)s', reverting to cold restart" % dict(id=self._hostImplementation.id())) ssh.ftp.putFile("/tmp/vmlinuz", tftpboot.INAUGURATOR_KERNEL) ssh.ftp.putFile("/tmp/initrd", tftpboot.INAUGURATOR_INITRD) ssh.run.script( "kexec --load /tmp/vmlinuz --initrd=/tmp/initrd --append='%s'" % self._tftpboot.inauguratorCommandLine( self._hostImplementation.primaryMACAddress(), self._hostImplementation.ipAddress(), clearDisk=False)) ssh.run.backgroundScript("sleep 2; kexec -e")
def __init__(self, rackattackNode, name): self.node = rackattackNode self.name = name self.ssh = connection.Connection(** rackattackNode.rootSSHCredentials()) self.__plugins = {}
with open(args.rackYaml) as f: rackYaml = yaml.load(f) targetNode = [n for n in rackYaml['HOSTS'] if n['id'] == args.targetNode][0] client = clientfactory.factory() logging.info("Allocating master node") allocationInfo = api.AllocationInfo(user=args.rackattackUser, purpose="dryrun") label = subprocess.check_output( ["solvent", "printlabel", "--thisProject", "--product=rootfs"]).strip() requirements = dict( master=api.Requirement(imageLabel=label, imageHint="rootfs-basic")) allocation = client.allocate(requirements, allocationInfo) allocation.wait(timeout=5 * 60) logging.info("Allocation successful, waiting for ssh") masterNode = allocation.nodes()['master'] ssh = connection.Connection(**masterNode.rootSSHCredentials()) ssh.waitForTCPServer() ssh.connect() logging.info("Connected to ssh") ssh.ftp.putFile("/tmp/master.egg", "build/master.egg") try: print ssh.run.script( "PYTHONPATH=/tmp/master.egg " "strace -fF -o /tmp/trace " "python -m rackattack.dryrun.master.main " "--hostID=%(targetNodeID)s --macAddress=%(macAddress)s " "--ipmiHost=%(ipmiHost)s --ipmiUsername=%(ipmiUsername)s " "--ipmiPassword=%(ipmiPassword)s --osmosisServerIP=%(osmosisServerIP)s " "--ipAddress=%(ipAddress)s --label=%(label)s" % dict( targetNodeID=targetNode['id'], macAddress=targetNode['primaryMAC'],
hint = 'rootfs-basic' label = subprocess.check_output([ "solvent", "printlabel", "--product", "rootfs", "--repositoryBasename", "rootfs-basic" ]).strip() client = clientfactory.factory() try: requirement = api.Requirement(imageLabel=label, imageHint=hint) info = api.AllocationInfo(user='******', purpose='integration test') allocation = client.allocate(dict(it=requirement), info) print "Created allocation, waiting for node inauguration" allocation.wait(timeout=7 * 60) print "Allocation successfull, waiting for ssh" try: nodes = allocation.nodes() assert len(nodes) == 1, nodes it = nodes['it'] ssh = connection.Connection(**it.rootSSHCredentials()) ssh.waitForTCPServer() ssh.connect() print "SSH connected" pdb.set_trace() echo = ssh.run.script("echo hello") assert 'hello' in echo, echo finally: allocation.free() finally: client.close()
}, allocationInfo=api.AllocationInfo( user=args.user, purpose="playaround", nice=args.nice)) allocation.wait(timeout=8 * 60) assert allocation.done(), "Allocation failed" print "Done allocating, Waiting for boot to finish" try: node = allocation.nodes()['node'] credentials = dict(port=22) credentials.update(node.rootSSHCredentials()) print "ROOT SSH Credentials:" print credentials if not args.noSSH: ssh = connection.Connection(**credentials) ssh.waitForTCPServer() ssh.connect() ssh.close() try: ssh = connection.Connection(**credentials) ssh.waitForTCPServer() ssh.connect() ssh.close() except: try: log = node.fetchSerialLog() open("/tmp/serial.log", "w").write(log) print "serial log stored in /tmp/serial.log" except Exception as e: print "Unable to fetch serial log: %s" % e