Beispiel #1
0
 def __init__(self, serverDir,
         proxyTo,
         plainPort=None,
         sslPort=None,
         sslCertAndKey=None,
         ):
     self.serverDir = os.path.abspath(serverDir)
     self.proxyTo = proxyTo
     self.plainPort = plainPort if plainPort else sock_utils.findPorts(num=1)[0]
     if sslCertAndKey:
         self.sslCert, self.sslKey = sslCertAndKey
         if sslPort:
             self.sslPort = sslPort
         else:
             self.sslPort = sock_utils.findPorts(num=1)[0]
     else:
         self.sslCert = self.sslKey = None
         self.sslPort = 0
     self.configPath = os.path.join(self.serverDir, 'nginx.conf')
     self.accessLog = os.path.join(self.serverDir, 'access.log')
     self.errorLog = os.path.join(self.serverDir, 'error.log')
     if not os.path.isdir(self.serverDir):
         os.makedirs(self.serverDir)
     self.server = subprocutil.GenericSubprocess(
         args=['nginx',
             '-c', self.configPath,
             '-p', self.serverDir,
             ],
         stderr=open(self.errorLog, 'a'),
         )
 def __init__(self, port=None):
     self.port = port if port else sock_utils.findPorts(num=1)[0]
     self.server = subprocutil.GenericSubprocess(
             args=['memcached',
                 '-p', str(self.port),
                 ],
             )
Beispiel #3
0
 def __init__(self, serverDir,
         application,
         port='UNIX',
         workers=2,
         timeout=None,
         environ=(),
         ):
     self.serverDir = os.path.abspath(serverDir)
     if port == 'UNIX':
         self.socketPath = os.path.join(self.serverDir, 'uwsgi.sock')
         self.port = None
         self.proxyTo = 'unix://' + self.socketPath
         bindTo = self.socketPath
     else:
         self.socketPath = None
         self.port = port if port else sock_utils.findPorts(num=1)[0]
         self.proxyTo = '127.0.0.1:%d' % self.port
         bindTo = ':%d' % self.port
     self.errorLog = os.path.join(self.serverDir, 'error.log')
     self.server = subprocutil.GenericSubprocess(
             args=['uwsgi',
                 '--master',
                 '--uwsgi-socket', bindTo,
                 '--need-app',
                 '-p', str(workers),
                 '-t', str(timeout or 0),
                 '--wsgi', application,
                 ],
             environ=environ,
             )
Beispiel #4
0
    def _testApiRpcServe(self, forking):
        port = sock_utils.findPorts(1)[0]
        uri = 'http://localhost:%s/conary/' % port
        server = TestServer(uri, forkByDefault=forking)
        client = TestClient(uri)

        pid = os.fork()
        if not pid:
            time.sleep(.1)
            client.ping(True)
            os._exit(0)
        else:
            server.server.handle_request()
            self.waitThenKill(pid)


        pid = os.fork()
        if not pid:
            try:
                server.server.handle_request()
                server.server.handle_request()
                server.server.handle_request()
            finally:
                os._exit(0)
        else:
            assert((client.getPid() == pid) == (not forking))
            assert(client.getPidForking() != pid)
            assert(client.getPidNoForking() == pid)
            self.waitThenKill(pid)

        uri = 'unix://%s/socket' % self.workDir
        server = TestServer(uri)
        client = TestClient(uri)
        pid = os.fork()
        if not pid:
            time.sleep(.1)
            client.ping2(deps.parseFlavor('foo'))
            os._exit(0)
        else:
            server.server.handle_request()
            self.waitThenKill(pid)

        # verify that the unix SO_PEERCRED authentication gets the client
        # side pid,uid,gid as the peer credentials
        uri = 'unix://%s/socket2' % self.workDir
        server = TestServer(uri, forkByDefault=forking)
        client = TestClient(uri)
        pid = os.fork()
        if not pid:
            time.sleep(.1)
            server.server.handle_request()
            os._exit(0)
        else:
            time.sleep(.1)
            auth = tuple(client.getAuth())
            self.failUnless(auth == (os.getpid(), os.getuid(), os.getgid()))
            self.waitThenKill(pid)
Beispiel #5
0
    def testStart(self):
        raise testhelp.SkipTestException('Failing test in bamboo')
        startFile = self.workDir + '/startFile'
        if os.path.exists(startFile):
            os.remove(startFile)
        stopFile = self.workDir + '/stopFile'
        #sys.argv[0] = 'python ./testsuite.py'
        #sys.argv[0] = 'daemontest.py'
        self.rmakeCfg.pluginDirs = resources.get_plugin_dirs()
        self.rmakeCfg.usePlugins = False
        self.rmakeCfg.usePlugin['multinode'] = False
        reposPort, proxyPort = sock_utils.findPorts(2)
        self.rmakeCfg.reposUrl = 'http://LOCAL:%s' % reposPort
        self.rmakeCfg.proxyUrl = 'http://LOCAL:%s' % proxyPort

        util.mkdirChain(self.rmakeCfg.lockDir)
        util.mkdirChain(self.rmakeCfg.buildDir)
        pid = os.fork()
        if not pid:
            self.rmakeCfg.writeToFile(self.workDir + '/rmakecfg')
            daemon.rMakeDaemon.configClass.getSocketPath = lambda x: self.rootDir + '/socket'
            daemon.rMakeDaemon.configClass.getServerUri = lambda x: 'unix://' + self.rootDir + '/socket'

            logFile = logfile.LogFile(startFile)
            logFile.redirectOutput()
            try:
                try:
                    daemon.main([
                        'rmake-server', 'start', '-n', '--skip-default-config',
                        '--config-file', self.workDir + '/rmakecfg'
                    ])
                except SystemExit, err:
                    if err.code == 0:
                        os._exit(0)
            finally:
                os._exit(1)
        timeSlept = 0
        while timeSlept < 5:
            if os.path.exists(startFile):
                log = open(startFile).read()
                if 'Started rMake Server at pid %s' % pid in log:
                    break
            time.sleep(.1)
            timeSlept += .1
        assert (timeSlept < 5)
        # wait for fail current jobs process to stop.
        time.sleep(1)
        try:
            logFile = logfile.LogFile(stopFile)
            logFile.redirectOutput()
            daemon.main([
                'rmake-server', 'stop', '--skip-default-config',
                '--config-file', self.workDir + '/rmakecfg'
            ])
        except SystemExit, err:
            if err.code:
                raise
Beispiel #6
0
    def _testApiRpcServe(self, forking):
        port = sock_utils.findPorts(1)[0]
        uri = 'http://localhost:%s/conary/' % port
        server = TestServer(uri, forkByDefault=forking)
        client = TestClient(uri)

        pid = os.fork()
        if not pid:
            time.sleep(.1)
            client.ping(True)
            os._exit(0)
        else:
            server.server.handle_request()
            self.waitThenKill(pid)

        pid = os.fork()
        if not pid:
            try:
                server.server.handle_request()
                server.server.handle_request()
                server.server.handle_request()
            finally:
                os._exit(0)
        else:
            assert ((client.getPid() == pid) == (not forking))
            assert (client.getPidForking() != pid)
            assert (client.getPidNoForking() == pid)
            self.waitThenKill(pid)

        uri = 'unix://%s/socket' % self.workDir
        server = TestServer(uri)
        client = TestClient(uri)
        pid = os.fork()
        if not pid:
            time.sleep(.1)
            client.ping2(deps.parseFlavor('foo'))
            os._exit(0)
        else:
            server.server.handle_request()
            self.waitThenKill(pid)

        # verify that the unix SO_PEERCRED authentication gets the client
        # side pid,uid,gid as the peer credentials
        uri = 'unix://%s/socket2' % self.workDir
        server = TestServer(uri, forkByDefault=forking)
        client = TestClient(uri)
        pid = os.fork()
        if not pid:
            time.sleep(.1)
            server.server.handle_request()
            os._exit(0)
        else:
            time.sleep(.1)
            auth = tuple(client.getAuth())
            self.failUnless(auth == (os.getpid(), os.getuid(), os.getgid()))
            self.waitThenKill(pid)
Beispiel #7
0
    def testStart(self):
        raise testhelp.SkipTestException('Failing test in bamboo')
        startFile = self.workDir + '/startFile'
        if os.path.exists(startFile):
            os.remove(startFile)
        stopFile = self.workDir + '/stopFile'
        #sys.argv[0] = 'python ./testsuite.py'
        #sys.argv[0] = 'daemontest.py'
        self.rmakeCfg.pluginDirs = resources.get_plugin_dirs()
        self.rmakeCfg.usePlugins = False
        self.rmakeCfg.usePlugin['multinode'] = False
        reposPort, proxyPort = sock_utils.findPorts(2)
        self.rmakeCfg.reposUrl = 'http://LOCAL:%s' % reposPort
        self.rmakeCfg.proxyUrl = 'http://LOCAL:%s' % proxyPort

        util.mkdirChain(self.rmakeCfg.lockDir)
        util.mkdirChain(self.rmakeCfg.buildDir)
        pid = os.fork()
        if not pid:
            self.rmakeCfg.writeToFile(self.workDir + '/rmakecfg')
            daemon.rMakeDaemon.configClass.getSocketPath = lambda x: self.rootDir + '/socket'
            daemon.rMakeDaemon.configClass.getServerUri = lambda x: 'unix://' + self.rootDir + '/socket'


            logFile = logfile.LogFile(startFile)
            logFile.redirectOutput()
            try:
                try:
                    daemon.main(['rmake-server', 'start', '-n', '--skip-default-config', '--config-file', self.workDir + '/rmakecfg'])
                except SystemExit, err:
                    if err.code == 0:
                        os._exit(0)
            finally:
                os._exit(1)
        timeSlept = 0
        while timeSlept < 5:
            if os.path.exists(startFile):
                log = open(startFile).read()
                if 'Started rMake Server at pid %s' % pid in log:
                    break
            time.sleep(.1)
            timeSlept += .1
        assert(timeSlept < 5)
        # wait for fail current jobs process to stop.
        time.sleep(1)
        try:
            logFile = logfile.LogFile(stopFile)
            logFile.redirectOutput()
            daemon.main(['rmake-server', 'stop', '--skip-default-config', '--config-file', self.workDir + '/rmakecfg'])
        except SystemExit, err:
            if err.code:
                raise
 def __init__(self, serverDir, application, port=None, workers=2, timeout=None, environ=()):
     self.serverDir = os.path.abspath(serverDir)
     self.port = port if port else sock_utils.findPorts(num=1)[0]
     self.accessLog = os.path.join(self.serverDir, "access.log")
     self.errorLog = os.path.join(self.serverDir, "error.log")
     self.server = subprocutil.GenericSubprocess(
         args=[
             "gunicorn",
             "--bind",
             "[::]:%d" % self.port,
             "--workers",
             str(workers),
             "--timeout",
             str(timeout or 0),
             "--access-logfile",
             self.accessLog,
             "--log-file",
             self.errorLog,
             application,
         ],
         environ=environ,
     )
Beispiel #9
0
 def initPort(self):
     self.port, self.plainPort = sock_utils.findPorts(num = 2)