def _getPid(self): for i in xrange(10): try: return self._host.ssh.ftp.getContents("/tmp/pid%s.txt" % self._unique).strip() except: time.sleep(0.1) return self._host.ssh.ftp.getContents("/tmp/pid%s.txt" % self._unique).strip() def poll(self): if 'DEAD' not in self._host.ssh.run.script("test -d /proc/%s || echo DEAD" % self._pid): return None if 'FAILED' in self._host.ssh.run.script( "test -e /tmp/result%s.pickle || echo FAILED" % self._unique): return False return True def result(self): return cPickle.loads(self._host.ssh.ftp.getContents("/tmp/result%s.pickle" % self._unique)) def output(self): return self._host.ssh.ftp.getContents("/tmp/output%s.txt" % self._unique) def kill(self, signalNameOrNumber=None): if signalNameOrNumber is None: signalNameOrNumber = 'TERM' self._host.ssh.run.script("kill -%s %s" % (str(signalNameOrNumber), self._pid)) plugins.register('seed', Seed)
from strato.racktest.hostundertest import plugins class Ping: def __init__(self, host): self._host = host def once(self, host): self._host.ssh.run.script("ping -c 1 %s" % host.node.ipAddress()) plugins.register('ping', Ping)
time.sleep(0.1) return self._host.ssh.ftp.getContents("/tmp/pid%s.txt" % self._unique).strip() def poll(self): if 'DEAD' not in self._host.ssh.run.script( "test -d /proc/%s || echo DEAD" % self._pid): return None if 'FAILED' in self._host.ssh.run.script( "test -e /tmp/result%s.pickle || echo FAILED" % self._unique): return False return True def result(self): return cPickle.loads( self._host.ssh.ftp.getContents("/tmp/result%s.pickle" % self._unique)) def output(self): return self._host.ssh.ftp.getContents("/tmp/output%s.txt" % self._unique) def kill(self, signalNameOrNumber=None): if signalNameOrNumber is None: signalNameOrNumber = 'TERM' self._host.ssh.run.script("kill -%s %s" % (str(signalNameOrNumber), self._pid)) plugins.register('seed', Seed)
serialContent = self._host.node.fetchSerialLog() tempDir = tempfile.mkdtemp() serialFilePath = os.path.join(tempDir, "serial.txt") self._writeUnicodeFile(serialContent, serialFilePath) return serialFilePath def _safeFilename(self, unsafe): SAFE = string.ascii_letters + string.digits return "".join(c if c in SAFE else '_' for c in unsafe) def _configure(self): config = logbeamfromlocalhost.logbeamConfigurationForPeer( self._myIPForHost(), under=self._host.name) self._host.ssh.ftp.putContents("/etc/logbeam.config", config) self._configured = True def _myIPForHost(self): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: s.connect((self._host.node.ipAddress(), 1)) return s.getsockname()[0] finally: s.close() def _writeUnicodeFile(self, content, filePath): with open(filePath, 'wb') as f: f.write(content) plugins.register('logbeam', LogBeamPlugin)
(" ".join(packageList))) def makeYUMCachePointToTestRunner(self): ip = self._myIPForHost() self._host.ssh.run.script("sed -i 's/127.0.0.1/%s/' /etc/yum.conf" % ip) def _retryInstallPackageSinceAtBootTimeMightBeLocked(self, basename): RETRIES = 20 for i in xrange(RETRIES): try: self._host.ssh.run.script("rpm -i --force ./%s" % basename) return except Exception as e: if i < RETRIES - 1 and 'yum status database is locked by another process' in str( e): time.sleep(0.5) continue raise def _myIPForHost(self): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: s.connect((self._host.node.ipAddress(), 1)) return s.getsockname()[0] finally: s.close() plugins.register('rpm', RPM)
if isinstance(packageList, str): packageList = [packageList] self._host.ssh.run.script("yum install %s --assumeyes" % (" ".join(packageList))) def makeYUMCachePointToTestRunner(self): ip = self._myIPForHost() self._host.ssh.run.script("sed -i 's/127.0.0.1/%s/' /etc/yum.conf" % ip) def _retryInstallPackageSinceAtBootTimeMightBeLocked(self, basename): RETRIES = 20 for i in xrange(RETRIES): try: self._host.ssh.run.script("rpm -i --force ./%s" % basename) return except Exception as e: if i < RETRIES - 1 and 'yum status database is locked by another process' in str(e): time.sleep(0.5) continue raise def _myIPForHost(self): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: s.connect((self._host.node.ipAddress(), 1)) return s.getsockname()[0] finally: s.close() plugins.register('rpm', RPM)
def _saveSerial(self): serialContent = self._host.node.fetchSerialLog() tempDir = tempfile.mkdtemp() serialFilePath = os.path.join(tempDir, "serial.txt") self._writeUnicodeFile(serialContent, serialFilePath) return serialFilePath def _safeFilename(self, unsafe): SAFE = string.ascii_letters + string.digits return "".join(c if c in SAFE else "_" for c in unsafe) def _configure(self): config = logbeamfromlocalhost.logbeamConfigurationForPeer(self._myIPForHost(), under=self._host.name) self._host.ssh.ftp.putContents("/etc/logbeam.config", config) self._configured = True def _myIPForHost(self): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: s.connect((self._host.node.ipAddress(), 1)) return s.getsockname()[0] finally: s.close() def _writeUnicodeFile(self, content, filePath): with open(filePath, "wb") as f: f.write(content) plugins.register("logbeam", LogBeamPlugin)
def _commandLine(self, label, osmosisServerIP, append): if osmosisServerIP is None: osmosisServerIP = self._host.node.networkInfo()['osmosisServerIP'] result = _INAUGURATOR_COMMAND_LINE % dict( macAddress=self._host.node.primaryMACAddress(), ipAddress=self._host.node.ipAddress(), netmask=self._host.node.networkInfo()['netmask'], gateway=self._host.node.networkInfo()['gateway'], osmosisServerIP=osmosisServerIP, label=label, rootPassword=self._host.node.rootSSHCredentials()['password']) if append is not None: result += ' --inauguratorPassthrough="%s"' % append return result _INAUGURATOR_COMMAND_LINE = \ "console=ttyS0,115200n8 " \ "--inauguratorWithLocalObjectStore " \ "--inauguratorSource=network " \ "--inauguratorUseNICWithMAC=%(macAddress)s " \ "--inauguratorOsmosisObjectStores=%(osmosisServerIP)s:1010 " \ "--inauguratorNetworkLabel=%(label)s " \ "--inauguratorIPAddress=%(ipAddress)s " \ "--inauguratorNetmask=%(netmask)s " \ "--inauguratorGateway=%(gateway)s " \ "--inauguratorChangeRootPassword=%(rootPassword)s" plugins.register('inaugurator', InauguratorPlugin)
osmosisServerIP = self._host.node.networkInfo()["osmosisServerIP"] result = _INAUGURATOR_COMMAND_LINE % dict( macAddress=self._host.node.primaryMACAddress(), ipAddress=self._host.node.ipAddress(), netmask=self._host.node.networkInfo()["netmask"], gateway=self._host.node.networkInfo()["gateway"], osmosisServerIP=osmosisServerIP, label=label, rootPassword=self._host.node.rootSSHCredentials()["password"], ) if append is not None: result += ' --inauguratorPassthrough="%s"' % append return result _INAUGURATOR_COMMAND_LINE = ( "console=ttyS0,115200n8 " "--inauguratorWithLocalObjectStore " "--inauguratorSource=network " "--inauguratorUseNICWithMAC=%(macAddress)s " "--inauguratorOsmosisObjectStores=%(osmosisServerIP)s:1010 " "--inauguratorNetworkLabel=%(label)s " "--inauguratorIPAddress=%(ipAddress)s " "--inauguratorNetmask=%(netmask)s " "--inauguratorGateway=%(gateway)s " "--inauguratorChangeRootPassword=%(rootPassword)s" ) plugins.register("inaugurator", InauguratorPlugin)