예제 #1
0
    def test_cobra_authentication(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60601)
        daemon.setAuthModule(c_auth.CobraAuthenticator())
        daemon.fireThread()

        objname = daemon.shareObject(testobj)

        # Lets fail because of no-auth first
        try:
            p = cobra.CobraProxy('cobra://localhost:60601/%s' % objname)
            raise Exception('Allowed un-authd connection!')
        except cobra.CobraAuthException as e:
            pass

        # Now fail with wrong auth
        try:
            p = cobra.CobraProxy('cobra://localhost:60601/%s' % objname,
                                 authinfo={})
            raise Exception('Allowed bad-auth connection!')
        except cobra.CobraAuthException as e:
            pass

        # Now lets succeed
        authinfo = {'user': '******', 'passwd': 'secret'}
        t = cobra.CobraProxy('cobra://localhost:60601/%s' % objname,
                             authinfo=authinfo)
        c_tests.accessTestObject(t)

        daemon.stopServer()
예제 #2
0
def getDcodeDmon():
    dmon = cobra.CobraDaemon(host='0.0.0.0', port=41923, msgpack=True)
    dmon.fireThread()
    cobra.dcode.enableDcodeServer(daemon=dmon)
    name = cobra.remoteapp.shareRemoteApp('cobra.testclient',
                                          appsrv=Foo(3, 4),
                                          daemon=dmon)
    yield (name, dmon)
    dmon.unshareObject(name)
예제 #3
0
def msgpacktest():

    testobj = c_unittests.TestObject()

    daemon = cobra.CobraDaemon(port=60610, msgpack=True)
    objname = daemon.shareObject( testobj )
    daemon.fireThread()

    t = cobra.CobraProxy('cobra://localhost:60610/%s?msgpack=1' % objname)
    c_unittests.accessTestObject( t )
예제 #4
0
def main():
    if len(sys.argv) != 2:
        usage()

    ip = sys.argv[1]
    q = c_cluster.ClusterQueen(ip)

    daemon = cobra.CobraDaemon(port=c_cluster.queen_port)
    daemon.shareObject(q, 'ClusterQueen')
    daemon.serve_forever()
예제 #5
0
def getCallbackPort():
    """
    If necissary, start a callback daemon.  Return the
    ephemeral port it was bound on.
    """
    global callback_daemon
    if callback_daemon == None:
        callback_daemon = cobra.CobraDaemon(port=0)
        callback_daemon.fireThread()
    return callback_daemon.port
예제 #6
0
def basictest():

    testobj = c_unittests.TestObject()

    daemon = cobra.CobraDaemon(port=60600)
    objname = daemon.shareObject( testobj )
    daemon.fireThread()

    t = cobra.CobraProxy('cobra://localhost:60600/%s' % objname)
    c_unittests.accessTestObject( t )
예제 #7
0
def reftest():

    testobj = c_unittests.TestObject()

    daemon = cobra.CobraDaemon(port=60660)
    objname = daemon.shareObject(testobj, doref=True)
    daemon.fireThread()

    with cobra.CobraProxy('cobra://localhost:60660/%s' % objname) as t:
        c_unittests.accessTestObject(t)

    assert (daemon.getSharedObject(objname) == None)
예제 #8
0
    def test_cobra_proxy(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60600)
        objname = daemon.shareObject(testobj)
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60600/%s' % objname)
        c_tests.accessTestObject(t)

        daemon.stopServer()
예제 #9
0
    def test_cobra_refcount(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60660)
        objname = daemon.shareObject(testobj, doref=True)
        daemon.fireThread()

        with cobra.CobraProxy('cobra://localhost:60660/%s' % objname) as t:
            c_tests.accessTestObject(t)

        self.assertIsNone(daemon.getSharedObject(objname))
        daemon.stopServer()
예제 #10
0
    def test_cobra_newobj(self):

        daemon = cobra.CobraDaemon(port=60500, msgpack=True)
        objname = daemon.shareObject(NewObjectReturn())
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60500/%s?msgpack=1' % objname)

        with t.open() as fd:
            self.assertEqual(fd.read(), b'asdf')

        self.assertEqual(len(daemon.shared.keys()), 1)
        daemon.stopServer()
def shareRemoteApp(name, appsrv=None, daemon=None):
    '''
    Fire an appropriate dcode enabled cobra daemon and share
    the appsrv object with the given name.
    '''
    if appsrv == None:
        appsrv = RemoteAppServer()

    if daemon == None:
        daemon = cobra.CobraDaemon(msgpack=True)
        daemon.fireThread()

    cobra.dcode.enableDcodeServer(daemon=daemon)
    return daemon.shareObject(appsrv, name)
예제 #12
0
    def test_cobra_authentication(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60601)
        daemon.setAuthModule(c_auth.CobraAuthenticator())
        daemon.fireThread()

        objname = daemon.shareObject(testobj)

        # Lets fail because of no-auth first
        try:
            p = cobra.CobraProxy('cobra://localhost:60601/%s' % objname)
            raise Exception('Allowed un-authd connection!')
        except cobra.CobraAuthException, e:
            pass
예제 #13
0
    def test_cobra_msgpack(self):

        try:
            import msgpack
        except ImportError:
            self.skipTest('No msgpack installed!')

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60610, msgpack=True)
        objname = daemon.shareObject(testobj)
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60610/%s?msgpack=1' % objname)
        c_tests.accessTestObject(t)
        daemon.stopServer()
    def __init__(self,
                 name,
                 maxsize=None,
                 docode=False,
                 bindsrc="",
                 cobrad=None):
        """
        The cluster server is the core of the code that manages work units.

        Arguments:
            maxsize - How big should the work queue be before add blocks
            docode  - Should we also be a dcode server?
            bindsrc - Should we bind a src IP for our multicast announcements?
            cobrad  - Should we use an existing cobra daemon to share our objects?
        """
        self.go = True
        self.name = name
        self.queens = []
        self.nextwid = 0
        self.inprog = {}
        self.sharedfiles = {}
        self.maxsize = maxsize
        self.queue = collections.deque()
        self.qcond = threading.Condition()
        self.widiter = iter(xrange(999999999))

        # Initialize a cobra daemon if needed
        if cobrad == None:
            cobrad = cobra.CobraDaemon(host="", port=0)
        self.cobrad = cobrad
        self.cobraname = self.cobrad.shareObject(self)

        # Setup our transmission socket
        self.sendsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sendsock.bind((bindsrc, 0))

        # Set this to a ClusterCallback extension if
        # you want notifications.
        self.callback = None

        if docode:
            dcode.enableDcodeServer(daemon=self.cobrad)

        # Fire the timeout monitor thread...
        thr = threading.Thread(target=self.timerThread)
        thr.setDaemon(True)
        thr.start()
예제 #15
0
    def test_cobra_shadowauth(self):
        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60602)
        shadowfile = c_tests.testFileName('shadowpass.txt')
        authmod = c_auth_shadow.ShadowFileAuth( shadowfile )
        daemon.setAuthModule( authmod )

        daemon.fireThread()

        objname = daemon.shareObject( testobj )

        # Now lets succeed
        authinfo = { 'user':'******', 'passwd':'secret' }
        t = cobra.CobraProxy('cobra://localhost:60602/%s' % objname, authinfo=authinfo)
        c_tests.accessTestObject(t)
        self.assertEqual( t.getUser(), 'invisigoth')
        daemon.stopServer()
예제 #16
0
def shadowauth():

    testobj = c_unittests.TestObject()

    daemon = cobra.CobraDaemon(port=60602)
    shadowfile = os.path.join(os.path.dirname(__file__), 'shadowpass.txt')
    authmod = c_auth_shadow.ShadowFileAuth(shadowfile)
    daemon.setAuthModule(authmod)

    daemon.fireThread()

    objname = daemon.shareObject(testobj)

    # Now lets succeed
    authinfo = {'user': '******', 'passwd': 'secret'}
    t = cobra.CobraProxy('cobra://localhost:60602/%s' % objname,
                         authinfo=authinfo)
    c_unittests.accessTestObject(t)
    assert (t.getUser() == 'invisigoth')
예제 #17
0
class CobraBasicTest(unittest.TestCase):

    #def setUp(self):
    #pass

    #def tearDown(self):
    #pass

    def test_cobra_proxy(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60600)
        objname = daemon.shareObject(testobj)
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60600/%s' % objname)
        c_tests.accessTestObject(t)

        daemon.stopServer()

    def test_cobra_msgpack(self):

        try:
            import msgpack
        except ImportError, e:
            self.skipTest('No msgpack installed!')

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60610, msgpack=True)
        objname = daemon.shareObject(testobj)
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60610/%s?msgpack=1' % objname)
        c_tests.accessTestObject(t)
        daemon.stopServer()
예제 #18
0
def startCobraDaemon():
    if vtrace.cobra_daemon == None:
        vtrace.cobra_daemon = cobra.CobraDaemon(port=vtrace.port)
        vtrace.cobra_daemon.fireThread()
예제 #19
0
import cobra

cobra.verbose = True

class woot:

    def printwoot(self, x):
        print 'WOOT',x
        return 'DID WOOT'

d = cobra.CobraDaemon()
d.shareObject(woot(), 'woot', doref=True)
d.serve_forever()
예제 #20
0
import cobra
'''
# To make the CA key
openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt

# Making the server CSR
openssl genrsa -des3 -out server.key 4096
openssl req -new -key server.key -out server.csr

# Sign the server crt with the CA
openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
'''

cobra.verbose = True


class woot:
    def printwoot(self, x):
        print 'WOOT', x
        return 'DID WOOT'


d = cobra.CobraDaemon(
    sslcrt='server.crt',
    sslkey='server.key',
)
#d = cobra.CobraDaemon(sslcrt='server.crt',sslkey='server.key',sslca='ca.crt')
d.shareObject(woot(), 'woot', doref=True)
d.serve_forever()
예제 #21
0
def runMainServer(dirname='', port=viv_port):
    s = VivServer(dirname=dirname)
    daemon = cobra.CobraDaemon(port=port, msgpack=True)
    daemon.recvtimeout = timeo_sock
    daemon.shareObject(s, 'VivServer')
    daemon.serve_forever()