def run_qdrouterd_as_daemon(self, config_file_name, pid_file_name):
        """
        Runs qdrouterd as a daemon, using the provided config_file_name
        in order to ensure router is able to load it, be it using a
        full or relative path.

        :param config_file_name: The configuration file name to be written
        :param pid_file_name: PID file name (must be full path)
        :return:
        """
        pipe = self.popen([
            os.path.join(os.environ.get('BUILD_DIR'), 'router', 'qdrouterd'),
            '-d', '-I',
            os.path.join(os.environ.get('SOURCE_DIR'), 'python'), '-c',
            self.config.write(config_file_name), '-P', pid_file_name
        ],
                          stdout=PIPE,
                          stderr=STDOUT,
                          expect=Process.EXIT_OK,
                          universal_newlines=True)
        out = pipe.communicate()[0]
        wait_port(CommandLineTest.testport)

        try:
            pipe.teardown()
            # kill qdrouterd running as a daemon
            with open(pid_file_name, 'r') as pidfile:
                for line in pidfile:
                    os.kill(int(line), signal.SIGTERM)
            pidfile.close()
        except OSError as ex:
            raise Exception("%s\n%s" % (ex, out))
    def run_qdrouterd_as_daemon(self, config_file_name, pid_file_name):
        """
        Runs qdrouterd as a daemon, using the provided config_file_name
        in order to ensure router is able to load it, be it using a
        full or relative path.

        :param config_file_name: The configuration file name to be written
        :param pid_file_name: PID file name (must be full path)
        :return:
        """
        pipe = self.popen(
            [os.path.join(os.environ.get('BUILD_DIR'), 'router', 'qdrouterd'), '-d',
             '-I', os.path.join(os.environ.get('SOURCE_DIR'), 'python'),
             '-c', self.config.write(config_file_name), '-P', pid_file_name],
            stdout=PIPE, stderr=STDOUT, expect=Process.EXIT_OK,
            universal_newlines=True)
        out = pipe.communicate()[0]
        wait_port(CommandLineTest.testport)

        try:
            pipe.teardown()
            # kill qdrouterd running as a daemon
            with open(pid_file_name, 'r') as pidfile:
                for line in pidfile:
                    os.kill(int(line), signal.SIGTERM)
            pidfile.close()
        except OSError as ex:
            raise Exception("%s\n%s" % (ex, out))
 def run(self, host=None, port=None, pf=None):
     if port:
         wait_port(port, protocol_family=pf)
         if pf and pf.lower() == 'ipv6':
             self._addr = "amqp://[%s]:%s" % (host, port)
         else:
             self._addr = "amqp://%s:%s" % (host, port)
     else:
         self._addr = self._router.addresses[0]
     Container(self).run()
Exemplo n.º 4
0
    def test_zzz_create_delete_listener(self):
        long_type = "org.apache.qpid.dispatch.listener"
        name = "ealistener"

        listener_port = self.get_port()

        listener = self.create(long_type, name, str(listener_port))
        self.assertEquals(listener["type"], long_type)
        self.assertEquals(listener["name"], name)

        exception_occurred = False

        try:
            # Try to connect to the port that was closed, it should not return an error
            wait_port(listener_port, timeout=2)
        except Exception as e:
            exception_occurred = True

        self.assertFalse(exception_occurred)

        delete_command = "DELETE --type=" + long_type + " --name=" + name
        self.run_qdmanage(delete_command)

        exception_occurred = False
        try:
            # Try deleting an already deleted connector, this should raise an exception
            self.run_qdmanage(delete_command)
        except Exception as e:
            exception_occurred = True
            self.assertTrue("NotFoundStatus: No entity with name='" + name + "'" in e.message)

        self.assertTrue(exception_occurred)

        try:
            # Try to connect to that port, it should not return an error
            wait_port(listener_port, timeout=2)
        except Exception as e:
            exception_occurred = True

        self.assertTrue(exception_occurred)

        # Now try the same thing with a short_type
        short_type = "listener"

        listener_port = self.get_port()

        listener = self.create(long_type, name, str(listener_port))
        self.assertEquals(listener["type"], long_type)
        self.assertEquals(listener["name"], name)

        delete_command = "DELETE --type=" + short_type + " --name=" + name
        self.run_qdmanage(delete_command)

        exception_occurred = False

        try:
            # Try to connect to that port, it should not return an error
            wait_port(listener_port, timeout=2)
        except Exception as e:
            exception_occurred = True

        self.assertTrue(exception_occurred)
    def test_zzz_create_delete_listener(self):
        long_type = 'org.apache.qpid.dispatch.listener'
        name = 'ealistener'

        listener_port = self.get_port()

        listener = self.create(long_type, name, str(listener_port))
        self.assertEquals(listener['type'], long_type)
        self.assertEquals(listener['name'], name)

        exception_occurred = False

        try:
            # Try to connect to the port that was closed, it should not return an error
            wait_port(listener_port, timeout=2)
        except Exception as e:
            exception_occurred = True

        self.assertFalse(exception_occurred)

        delete_command = 'DELETE --type=' + long_type + ' --name=' + name
        self.run_qdmanage(delete_command)

        exception_occurred = False
        try:
            # Try deleting an already deleted connector, this should raise an exception
            self.run_qdmanage(delete_command)
        except Exception as e:
            exception_occurred = True
            self.assertTrue("NotFoundStatus: No entity with name='" + name +
                            "'" in e.message)

        self.assertTrue(exception_occurred)

        try:
            # Try to connect to that port, it should not return an error
            wait_port(listener_port, timeout=2)
        except Exception as e:
            exception_occurred = True

        self.assertTrue(exception_occurred)

        # Now try the same thing with a short_type
        short_type = 'listener'

        listener_port = self.get_port()

        listener = self.create(long_type, name, str(listener_port))
        self.assertEquals(listener['type'], long_type)
        self.assertEquals(listener['name'], name)

        delete_command = 'DELETE --type=' + short_type + ' --name=' + name
        self.run_qdmanage(delete_command)

        exception_occurred = False

        try:
            # Try to connect to that port, it should not return an error
            wait_port(listener_port, timeout=2)
        except Exception as e:
            exception_occurred = True

        self.assertTrue(exception_occurred)