Beispiel #1
0
    def __init__(self, url, name, pid = None, supervise = True):
        """Constructor.
        
        Creates a connection to a target process. If no target process
        pid is given the class will automatically hunt for the process
        name.

        Parameters:
            url       -- connection url (tcp://172.17.226.207:22001)
            name      -- the target process name
            pid       -- the target process pid (if known)
            supervise -- attach to the target process (default True)

        Usage:
            >>> import ogre
            >>> proc = ogre.Process('tcp://172.17.226.207:22001', 'ogre_echo')
            >>> proc.send(ogre.Signal(1000))
            >>> proc.close()
        """
        self.conn = None
        self.fd = None
        self.name = name
        self.target_pid = pid
        self.supervise = supervise
        self.attach_ref = None

        self.conn = ogre.create(url, name + '_proxy')
        self.fd = self.conn.get_blocking_object()

        if self.target_pid is None:
            self.conn.hunt(self.name)
        elif self.supervise and self.attach_ref == None:
            self.attach_ref = self.conn.attach(self.target_pid)
   def test_link_down(self):
      # Create a echo stub process
      self.stub = EchoStub(self.url, "my_echo_proc")

      # Hunt the stub  process
      gw = ogre.create(self.url, "testprocess")
      gw.hunt("my_echo_proc")
      pid = gw.receive().sender()

      # Test if working
      sig = ogre_sig.ogre_sync_req()
      sig.t1 = 47
      gw.send(sig, pid)
      rsp = gw.receive()
      self.assertEqual(47, rsp.t1)

      # Kill the node
      gw.send(ogre.UnknownSignal(1), pid)
      print 'Stop the node:'
      print '  telnet %s' % (os.environ['OGRE_NODE'])
      print '  reload'

      # All connection methods shall raise exception now
      self.assertRaises(ogre.ConnectionLostError, gw.receive)
      self.assertRaises(ogre.ConnectionLostError, gw.send, sig, pid)
      self.assertRaises(ogre.ConnectionLostError, gw.hunt, 'kalle')
      gw.close()
Beispiel #3
0
def main():
    """Monitor main function.

    Parse the command line and open a connection to the target system.
    """
    parser = optparse.OptionParser("usage: %prog [options] [<linkhandler> ...]",
                              version="%prog 0.1")
    parser.add_option('-r', '--rel', action="store_true", dest="rel",
                 help="present time stamps using relative times")
    parser.add_option('-q', '--quiet', action="store_true", dest="quiet",
                 help="don't write logs to stdout")
    parser.add_option('-c', '--config', dest="config",
                 help="read configuration from CONFIG")
    parser.add_option('-f', '--file', dest="file",
                 help="write logs to FILE")

    # Parse the command line
    opts, args = parser.parse_args()
    if len(args) < 1:
        args.append('/')  # Default linkhandler

    # Init
    init_logger(opts)
    url = os.environ['OSEGWD_URL'] 

    # Run, ... and restart if connection lost
    while True:
        try:
            with ogre.create(url, "pymonitor") as conn:
                main_loop(conn, args)
        except ogre.ConnectionLostError:
            log.warning("Lost contact with node. Reconnecting...")
        except KeyboardInterrupt:
            log.info("Keyboard interrupt")
            break
Beispiel #4
0
   def setUp(self):
      self.url = '%s://%s:%s' % (os.environ['OGRE_COMM'],
                                 os.environ['OGRE_NODE'],
                                 os.environ['OGRE_PORT'])
      #logging.info('Using URL: %s' % (self.url))
      self.conn = ogre.create(self.url, "testprocess")

      self.stub_pid = EchoStub(self.url, "my_echo_proc").pid()
Beispiel #5
0
 def setUp(self):
    # String used to connect to target
    self.url = '%s://%s:%s' % (os.environ['OGRE_COMM'], os.environ['OGRE_NODE'], os.environ['OGRE_PORT'])
    # Setup connection to target
    self.conn = ogre.create(self.url, "testogre")
    # Hunt for the OGRE process running on the target
    self.conn.hunt("ogre_proc_exec")
    # Save the PID of that process
    self.pid = self.conn.receive().sender()
Beispiel #6
0
   def test_async_receive(self):
      conn1 = ogre.create(self.url, "client1")
      conn2 = ogre.create(self.url, "client2")

      fd1 = conn1.get_blocking_object()
      fd2 = conn2.get_blocking_object()

      # Client 1 send signals to client2
      sync = signals.SyncReq()
      sync.t1 = 1
      conn1.send(sync, conn2.pid())
      conn1.send(sync, conn2.pid())

      # Client 2 send signals to client1
      sync = signals.SyncReq()
      sync.t1 = 2
      conn2.send(sync, conn1.pid())
      conn2.send(sync, conn1.pid())

      # Receive all four signals
      conn1.init_async_receive()
      conn2.init_async_receive()
      no_of_signals  = 0
      while no_of_signals < 4:
         (rfd, wdf, efd) = select.select([fd1, fd2], [], [])
         if fd1 in rfd:
            reply = conn1.async_receive()
            conn1.init_async_receive()
            self.assert_(reply.t1 == 2)
            no_of_signals += 1
         if fd2 in rfd:
            conn2.init_async_receive()
            reply = conn2.async_receive()
            self.assert_(reply.t1 == 1)
            no_of_signals += 1

      # Cleanup
      conn1.cancel_async_receive()
      conn2.cancel_async_receive()
      conn1.close()
      conn2.close()
Beispiel #7
0
   def test_attach(self):
      conn1 = ogre.create(self.url, "kill_proc")
      self.conn.hunt("kill_proc")
      pid = self.conn.receive().sender()
      self.assert_(pid != 0);
      ref = self.conn.attach(pid)

      # Destroy the phantom process and wait for the attach signal
      conn1.close()
      sig = self.conn.receive()
      self.assertEqual(sig.sigNo, ogre.ATTACH_SIG)
      self.conn.detach(ref)
Beispiel #8
0
    def do_connect(self, url, proc):
        if self.gw:
            self.status.error("Already connected")
            return

        try:
            self.gw = ogre.create(url, "siged")
            self.gw.hunt(proc)
            sig = self.gw.receive(timeout=1.0)
            if sig is None:
                self.gw.close()
                self.gw = None
                self.status.error("Can't find %s" % proc)
                return
            self.pid = sig.sender()
            self.log_frame.log_connect(url, proc)
            self.status.info("Connected to %s" % proc)
        except Exception as e:
            self.status.error("Connect error: %s" % e)
Beispiel #9
0
def _send_receive_big_signal(req_size, rsp_size, pid, gw):
      sig = ogre_sig.ogre_big_req()
      sig.requested_data_size = rsp_size
      sig.data_size = req_size
      sig.data[:] = [0x55 for i in range(req_size)]

      gw.send(sig, pid)
      reply = gw.receive()

def tst():
    gw.hunt("ogre_proc")
    pid = gw.receive().sender()
    for i in range(100):
        _send_receive_big_signal(100, 100, pid, gw)
    

url = '%s://%s:%s' % (os.environ['OGRE_COMM'],
                      os.environ['OGRE_NODE'],
                      os.environ['OGRE_PORT'])
gw = ogre.create(url, "testosegw")

gw.hunt("ogre_proc")
pid = gw.receive().sender()
profile.run("tst()")

gw.close()


# End of file
Beispiel #10
0
 def setUp(self):
    self.url = '%s://%s:%s' % (os.environ['OGRE_COMM'],
                               os.environ['OGRE_NODE'],
                               os.environ['OGRE_PORT'])
    self.conn = ogre.create(self.url, "testogre")
Beispiel #11
0
 def test_unpack_nested_array0(self):
    for i in range(1000):
       print "Connect to %s" % self.url
       conn = ogre.create(self.url, "testogre")
       #conn.close()
       time.sleep(0.010)
Beispiel #12
0
 def setUp(self):
     self.url = "%s://%s:%s" % (os.environ["OGRE_COMM"], os.environ["OGRE_NODE"], os.environ["OGRE_PORT"])
     # logging.info('Using URL: %s' % (self.url))
     self.conn = ogre.create(self.url, "testogre")
Beispiel #13
0
	def setUp(self):
		self.linx = ogre.create("linx", TESTSERVER)

		# Hunt for ABSFL model
		self.linx.hunt(ABSFL)
		self.pid_ABSFL = self.linx.receive().sender()