示例#1
0
    def testStartAutoDiscoveryClient(self):
        '''Try to start a bootstrap node with autodiscovery on.
        '''
        
        log.msg("---------------------- BEGIN testStartAutoDiscoveryClient -------------- ")
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []

        # Create Bootstrap
        port = 12345
        enclaveStr = 'testclave'
        bsNodeLocation = NodeLocation(None, self.myIP, port)
        bootstrapNodeList = [ bsNodeLocation ]
        (self.bsClient, self.bsNetwork, d) = self.startBootstrapNode(enclaveStr, self.myIP, port, "authenticate:succeed", bootstrapNodeList)
        yield d
        
        # Now try and join with autodiscovery
        yield self.startClientNodeAutoDiscovery(None, self.myIP, port+1, enclaveStr, bootstrapNodeList)

        # Shut it all down
        for (clientAPI, networkAPI) in self.allNodes:
            yield networkAPI.disconnect()
            
        yield self.bsNetwork.disconnect()     
        
        # Try and wait for connection cache to finish disconnects (just in case).
        yield TestUtils.waitForConnectionCache()        
示例#2
0
    def testStartAutoDiscoveryClientTimeout(self):
        '''Try to start a bootstrap node with autodiscovery on.
           This should show a failure notice.
        '''
        
        log.msg("---------------------- BEGIN testStartAutoDiscoveryClientTimeout -------------- ")
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []

        # Create Bootstrap
        port = 12345
        enclaveStr = 'testclave'
        
        # Now try and join with autodiscovery
        d = defer.Deferred()
        
        clientAPI = SampleClient(self.myIP, port, None)
        networkAPI = classChordNetworkChord(clientAPI, port, self.myIP)
        nodeID = networkAPI.generateNodeID(str(port), enclaveStr) # Get the ID with the bits on it we need. Use "port" because it'll be uniq for tests
        
        # Join the network
        callFunc = lambda result, payload: self.shouldFailCallback(result, payload, d)
        networkAPI.start(callFunc, nodeID, enclaveStr, "authenticate:succeed", None, False, True)
        
        yield d
        
        yield TestUtils.waitForConnectionCache()        
示例#3
0
    def testMultipleBSNodesAutoDiscoveryClient(self):
        '''Try to start multiple bootstrap nodes then a client and make sure it connects to one of them.
        '''
        
        log.msg("---------------------- BEGIN testMultipleBSNodesAutoDiscoveryClient -------------- ")
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []


        
        # Create Bootstrap
        port = 12345
        enclaveStr = 'testclave'
        bootstrapNodeList = [ NodeLocation(None, self.myIP, port), NodeLocation(None, self.myIP, port+1)]
        
        (self.bsClient1, self.bsNetwork1, d) = self.startBootstrapNode(enclaveStr, self.myIP, port, "authenticate:succeed", bootstrapNodeList)
        yield d

        (self.bsClient2, self.bsNetwork2, d) = self.startBootstrapNode(enclaveStr, self.myIP, port+1, "authenticate:succeed", None)
        yield d
                
        # Now try and join with autodiscovery
        yield self.startClientNodeAutoDiscovery(None, self.myIP, port+2, enclaveStr, bootstrapNodeList)

        # Shut it all down
        for (clientAPI, networkAPI) in self.allNodes:
            yield networkAPI.disconnect()
            
        yield self.bsNetwork1.disconnect()
        yield self.bsNetwork2.disconnect()  
                        
        yield TestUtils.waitForConnectionCache()        
示例#4
0
    def testDisconnectedBootstraps(self):
        '''Create a BS node and some clients. Create another bootstrap node and some clients (so we essentially have two rings). 
           Verify, that the bootstrap nodes autodiscover each other and connect together            
        '''
        global startingPort
        
        # Create Bootstrap
        port = 12345
        bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
        bootstrapNodeLocation2 = NodeLocation(None, self.myIP, port+1)
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []

        # Build the BS node
        (status, bsClientAPI, bsNetworkAPI) = yield TestUtils.startNodeUsingAPI(bootstrapNodeLocation.ip, bootstrapNodeLocation.port, None, 'theEnclave', True, True)
        self.allMetricsObservers.append(MetricsMessageObserver(bsNetworkAPI.chordNode))
        self.assertTrue(status, 'Could not build bootstrap node')

        # Build second BS node
        (status, bsClientAPI2, bsNetworkAPI2) = yield TestUtils.startNodeUsingAPI(bootstrapNodeLocation2.ip, bootstrapNodeLocation2.port, None, 'theEnclave', True, True)
        self.allMetricsObservers.append(MetricsMessageObserver(bsNetworkAPI2.chordNode))
        self.assertTrue(status, 'Could not build bootstrap node 2')

                
        # Build the client node
        (status, clClientAPI, clNetworkAPI) = yield TestUtils.startNodeUsingAPI(self.myIP, port+2, bootstrapNodeLocation, 'theEnclave', False, False)
        self.allMetricsObservers.append(MetricsMessageObserver(clNetworkAPI.chordNode))        
        self.assertTrue(status, 'Could not build client node')
                
        # Build the client node
        (status, clClientAPI2, clNetworkAPI2) = yield TestUtils.startNodeUsingAPI(self.myIP, port+3, bootstrapNodeLocation2, 'theEnclave', False, False)
        self.allMetricsObservers.append(MetricsMessageObserver(clNetworkAPI2.chordNode))
        self.assertTrue(status, 'Could not build client node')


        # Wait for flooding to reach all the nodes
        waiter = ConnectivityCounter()
        yield waiter.waitForConnectivity(3, clNetworkAPI.chordNode) # Does not count clNode itself.
        
                
        # Now shut everything down
        yield clNetworkAPI.disconnect()
        yield clNetworkAPI2.disconnect()
        yield bsNetworkAPI.disconnect()
        yield bsNetworkAPI2.disconnect()
        
        if Config.USE_CONNECTION_CACHE:
            yield TestUtils.waitForConnectionCache()
        else:        
            yield TestUtils.wait(5)
            
        defer.returnValue(True)
示例#5
0
 def testStartAutoDiscoverySameNodeError(self):
     '''Try to start a bootstrap node and then two clients on the same port with autodiscovery on.        
        Should log an error when the second node attempts to join.
     '''
     
     log.msg("---------------------- BEGIN testStartAutoDiscoverySameNodeError -------------- ")
     self.allNodes = []
     self.allMetricsObservers = []
     self.allTestObservers = []
     
     # Create Bootstrap
     port = 12345
     enclaveStr = 'testclave'
     bsNodeLocation = NodeLocation(None, self.myIP, port)
     bootstrapNodeList = [ bsNodeLocation ]
             
     (self.bsClient, self.bsNetwork, d) = self.startBootstrapNode(enclaveStr, self.myIP, port, "authenticate:succeed", bootstrapNodeList)
     yield d
     
     # Now startup one client which will succeed
     d2 = defer.Deferred()
     port = port + 1
     
     clientAPI = SampleClient(self.myIP, port, None)
     networkAPI = classChordNetworkChord(clientAPI, port, self.myIP)
     nodeID = networkAPI.generateNodeID(str(port), enclaveStr) # Get the ID with the bits on it we need. Use "port" because it'll be uniq for tests
     
     # Join the network
     callFunc = lambda result, payload: self.shouldSucceedCallback(result, payload, d2, networkAPI)
     networkAPI.start(callFunc, nodeID, enclaveStr, "authenticate:succeed", bootstrapNodeList, False, True)
     
     yield d2
             
     # Now startup one which should fail due to duplicate port
     d3 = defer.Deferred()
     
     clientAPI2 = SampleClient(self.myIP, port, None)
     networkAPI2 = classChordNetworkChord(clientAPI2, port, self.myIP)
     nodeID = networkAPI.generateNodeID(str(port), enclaveStr) # Get the ID with the bits on it we need. Use "port" because it'll be uniq for tests
     
     # Join the network
     callFunc2 = lambda result, payload: self.shouldFailureCallback(result, payload, d3)
     networkAPI2.start(callFunc2, nodeID, enclaveStr, "authenticate:succeed",bootstrapNodeList, False, True)
     
     yield d3
     
     yield networkAPI.disconnect()
     #yield networkAPI2.disconnect()
     yield self.bsNetwork.disconnect()
     
     # Try and wait for connection cache to finish disconnects (just in case).
     yield TestUtils.waitForConnectionCache()        
示例#6
0
 def testNodeAuth(self):
     log.msg("---> Starting BootstrapNode")
     yield self.startBootStrapNode()
     
     log.msg("---> Creating Good Client")
     yield self.startClientNode(self.myIP, 12350, self.bootstrapNodeLocation, self.enclaveStr)
     
     log.msg("---> Creating Bad Client")
     yield self.startBadClientNode(self.myIP, 12351, self.bootstrapNodeLocation, self.enclaveStr)
                 
     # Shut it all down
     for (clientAPI, networkAPI) in self.allNodes:
         yield networkAPI.disconnect()
     
     yield self.bsNetwork.disconnect()
     
     if Config.USE_CONNECTION_CACHE:
         yield TestUtils.waitForConnectionCache()
     else:
         yield TestUtils.wait(2)
     
     defer.returnValue(True)
示例#7
0
    def testAutoDiscoveryRebootstrap(self):
        '''Try to start a bootstrap node and client with autodiscovery on.
           Then start another bootstrap node.
           Then kill first bootstrap node and have client try to re-bootstrap to
           new bootstrap node.            
        '''
        
        log.msg("---------------------- BEGIN testAutoDiscoveryRebootstrap -------------- ")
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []

        # Create Bootstrap
        port = 12345
        enclaveStr = 'testclave'
        bsNodeLocation = NodeLocation(None, self.myIP, port)
        bootstrapNodeList = [ bsNodeLocation ]

        log.msg("Starting bootstrap... \n\n")
        (self.bsClient, self.bsNetwork, d) = self.startBootstrapNode(enclaveStr, self.myIP, port, "authenticate:succeed", bootstrapNodeList)
        yield d
        
        # Now try and join with autodiscovery
        yield TestUtils.wait(1)
        log.msg("Starting client... \n\n")
        yield self.startClientNodeAutoDiscovery(None, self.myIP, port+1, enclaveStr, bootstrapNodeList)

        # Now start a second bootstrap node
        #NOT DONE YET
        log.msg("Shutting down client... \n\n")
        
        # Shut it all down
        for (clientAPI, networkAPI) in self.allNodes:
            yield networkAPI.disconnect()
            
        yield self.bsNetwork.disconnect()  
                        
        # Try and wait for connection cache to finish disconnects (just in case).
        yield TestUtils.waitForConnectionCache()        
示例#8
0
    def testStartAutoDiscoveryMultipleClients(self):
        '''Try to start a bootstrap node and the many many clients all at once with autodiscovery on.        '''
        
        log.msg("---------------------- BEGIN testStartAutoDiscoveryMultipleClients -------------- ")
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []
        
        numNodes = 15

        # Create Bootstrap
        port = 12345
        enclaveStr = 'testclave'
        bootstrapNodeList = [ NodeLocation(None, self.myIP, port) ]
        (self.bsClient, self.bsNetwork, d) = self.startBootstrapNode(enclaveStr, self.myIP, port, "authenticate:succeed", bootstrapNodeList)
        yield d
        
        # Now try and join a bunch of nodes with autodiscovery
        allDefs = [] # A list of deferreds
        for counter in range(numNodes):
            allDefs.append(self.startClientNodeAutoDiscovery(None, self.myIP, port+1+counter, enclaveStr, bootstrapNodeList))
            
        dl = defer.DeferredList(allDefs)
        yield dl # Wait for all deferred joins to complete
        
        # Shut it all down
        for (clientAPI, networkAPI) in self.allNodes:
            yield networkAPI.disconnect()
            
        yield self.bsNetwork.disconnect()    

        if Config.USE_CONNECTION_CACHE:
            # Try and wait for connection cache to finish disconnects (just in case).
            yield TestUtils.waitForConnectionCache()        
        else:
            # Wait a few seconds for network timeouts
            yield TestUtils.wait(5)
示例#9
0
    def testReBootstrap(self):
        '''Create a BS node, then a client node, then kill the BS Node, wait, restart a BS node and 
           check for re-Bootstrap
        '''
        global startingPort
        
        # Create Bootstrap
        port = 12345
        bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []

        # Build the BS node
        log.msg("building BS node...")
        (status, bsClientAPI, bsNetworkAPI) = yield TestUtils.startNodeUsingAPI(self.myIP, port, None, 'theEnclave', False, True)
        self.assertTrue(status, 'Could not build bootstrap node')
                
        # Build the client node
        log.msg("building client node...")
        (status, clClientAPI, clNetworkAPI) = yield TestUtils.startNodeUsingAPI(self.myIP, port+1, bootstrapNodeLocation, 'theEnclave', False, False)
        self.assertTrue(status, 'Could not build client node')
        
        # Check that the client is connected to something
        connected = yield clNetworkAPI.isConnected()
        self.assertTrue(connected, "Client did not connect to the bootstrap node in testReBootstrap!")
        
        # Now kill the BS node
        yield bsNetworkAPI.disconnect()
        bsNetworkAPI = None
        bsClientAPI = None
        
        # Gotta wait for disconnect to really finish
        yield TestUtils.waitForConnectionCache()
        
        # Check that the client is connected to something
        connected = yield clNetworkAPI.isConnected()
        self.assertTrue(not connected, "Client remains connected to the bootstrap node in testReBootstrap after killing BS node!")
        
        # Now startup another bootstrap node
        log.msg("building BS node...")
        (status, bsClientAPI, bsNetworkAPI) = yield TestUtils.startNodeUsingAPI(self.myIP, port, None, 'theEnclave', False, True)
        self.assertTrue(status, 'Could not build second bootstrap node')
         
        # Wait for it to connect or fail -- basically waiting for the
        # maintenance call to run correctly.
        for _ in range(10):
            # Check that the client is connected to something
            connected = yield clNetworkAPI.isConnected()
            if connected:
                break
            yield TestUtils.wait(1)
   
        self.assertTrue(connected, "Client could not re-bootstrap!")

        
        # Now shut everything down
        
        log.msg("\n\ntestReBootstrap: Shutting down now...\n\n")
        yield clNetworkAPI.disconnect()
        yield bsNetworkAPI.disconnect()

        if Config.USE_CONNECTION_CACHE:
            yield TestUtils.waitForConnectionCache()
        else:        
            yield TestUtils.wait(5)

        defer.returnValue(True)