Beispiel #1
0
 def test_XNJSShutDown(self):
     """ Test behaviour when the XNJS side goes away """
     # fork, creating the TSI shepherd and a fake XNJS
     pid = os.fork()
     if pid == 0:
         # child, this is the TSI shepherd process
         command, data = Server.connect(self.config, self.LOG)
         connector = Connector(command, data, self.LOG)
         # read a message
         try:
             self.LOG.info("SERVER: Reading from command socket")
             testmsg = connector.read_message()
             self.LOG.info("SERVER: got test message: %s" % testmsg)
             testmsg = connector.read_message()
             self.LOG.info("SERVER: got test message: %s" % testmsg)
             command.close()
         except IOError:
             print("Got: " + str(sys.exc_info()[1]))
             connector.close()
     else:
         # parent, this is the fake XNJS
         # wait a bit to allow for setup of server socket at TSI
         time.sleep(2)
         # connect to the server
         host = self.config['tsi.my_addr']
         port = self.config['tsi.my_port']
         tsi = socket.create_connection((host, port))
         self.LOG.info("CLIENT: Connected to %s:%s" % (host, port))
         host = self.config['tsi.njs_machine']
         port = 24433
         tsi.sendall(b'newtsiprocess 24433')
         self.LOG.info("CLIENT: waiting for callback on %s:%s" %
                       (host, port))
         server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         server.bind((host, port))
         server.listen(2)
         (command, (_, _)) = server.accept()
         (data, (_, _)) = server.accept()
         time.sleep(2)
         self.LOG.info("CLIENT: connected, now closing sockets.")
         command.close()
         data.close()
         time.sleep(5)
         self.LOG.info("CLIENT: shutting down.")
         tsi.close()
         server.close()
         os.kill(pid, signal.SIGKILL)
Beispiel #2
0
 def test_Connect(self):
     # fork, creating the TSI shepherd and a fake XNJS
     pid = os.fork()
     if pid == 0:
         # child, this is the TSI shepherd process
         command, data = Server.connect(self.config, self.LOG)
         # read a message from the command socket
         test_msg = command.recv(1024)
         self.LOG.info("TESTING: got test message: %s" % test_msg)
     else:
         # parent, this is the fake XNJS
         # wait a bit to allow for setup of server socket at TSI
         time.sleep(2)
         # connect to the server
         host = self.config['tsi.my_addr']
         port = self.config['tsi.my_port']
         tsi = socket.create_connection((host, port))
         self.LOG.info("CLIENT: Connected to %s:%s" % (host, port))
         tsi = SSL.setup_ssl(self.config, tsi, self.LOG, False)
         host = self.config['tsi.njs_machine']
         port = self.config['tsi.njs_port']
         tsi.sendall(b'newtsiprocess 24433')
         self.LOG.info("CLIENT: waiting for callback on %s:%s" %
                       (host, port))
         server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         server = SSL.setup_ssl(self.config, server, self.LOG, True)
         server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         server.bind((host, port))
         server.listen(2)
         (command, (_, _)) = server.accept()
         (data, (_, _)) = server.accept()
         test_msg = b'#TSI_PING\nENDOFMESSAGE'
         self.LOG.info("CLIENT: connected, sending test message: %s" %
                       test_msg)
         command.sendall(test_msg)
         # send shutdown and cleanup
         self.LOG.info("CLIENT: shutdown")
         tsi.sendall(b'shutdown')
         command.close()
         data.close()
         tsi.close()
         server.close()
         os.kill(pid, signal.SIGKILL)