def test_preserveDeadHostStats(self):
        """

        """
        time = None
        ht1 = HostTracking(self.group1)
        s1 = schedulerFactory(ht1.group.lbType, ht1)
        # let's cycle through all the hosts twice
        fakeSenderFactories = [object() for x in xrange(8)]
        sequence = [ht1.getHost(x) for x in fakeSenderFactories]
        # check the stats
        stats = ht1.getStats()
        self.assertEquals(len(stats['bad'].keys()), 0)
        self.assertEquals(sum(stats['openconns'].values()), 8)
        self.assertEquals(sum(stats['totals'].values()), 0)
        # finish them up
        [ht1.doneHost(x) for x in fakeSenderFactories]
        # check the clenaup stats
        stats = ht1.getStats()
        self.assertEquals(len(stats['bad'].keys()), 0)
        self.assertEquals(sum(stats['openconns'].values()), 0)
        self.assertEquals(sum(stats['totals'].values()), 8)
        # now let's do a bad host
        fakeSenderFactory = object()
        host = ht1.getHost(fakeSenderFactory)
        stats = ht1.getStats()
        # make sure that the bad host is listed in the open connections
        self.assertEquals(sum(stats['openconns'].values()), 1)
        ht1.openconns[fakeSenderFactory] = (time, host)
        ht1.deadHost(fakeSenderFactory, doLog=False)
        stats = ht1.getStats()
        # make sure that the previous stats for the bad host are not deleted
        self.assertEquals(sum(stats['totals'].values()), 8)
Beispiel #2
0
    def test_preserveDeadHostStats(self):
        """

        """
        time = None
        ht1 = HostTracking(self.group1)
        s1 = schedulerFactory(ht1.group.lbType, ht1)
        # let's cycle through all the hosts twice
        fakeSenderFactories = [object() for x in xrange(8)]
        sequence = [ht1.getHost(x) for x in fakeSenderFactories]
        # check the stats
        stats = ht1.getStats()
        self.assertEquals(len(stats['bad'].keys()), 0)
        self.assertEquals(sum(stats['openconns'].values()), 8)
        self.assertEquals(sum(stats['totals'].values()), 0)
        # finish them up
        [ht1.doneHost(x) for x in fakeSenderFactories]
        # check the clenaup stats
        stats = ht1.getStats()
        self.assertEquals(len(stats['bad'].keys()), 0)
        self.assertEquals(sum(stats['openconns'].values()), 0)
        self.assertEquals(sum(stats['totals'].values()), 8)
        # now let's do a bad host
        fakeSenderFactory = object()
        host = ht1.getHost(fakeSenderFactory)
        stats = ht1.getStats()
        # make sure that the bad host is listed in the open connections
        self.assertEquals(sum(stats['openconns'].values()), 1)
        ht1.openconns[fakeSenderFactory] = (time, host)
        ht1.deadHost(fakeSenderFactory, doLog=False)
        stats = ht1.getStats()
        # make sure that the previous stats for the bad host are not deleted
        self.assertEquals(sum(stats['totals'].values()), 8)
 def test_initialStats(self):
     """
     We can't use self.ht1, because it might be contaminated by other tests.
     """
     ht1 = HostTracking(self.group1)
     s1 = schedulerFactory(ht1.group.lbType, ht1)
     stats = ht1.getStats()
     self.assertEquals(len(stats['bad'].keys()), 0)
     self.assertEquals(sum(stats['openconns'].values()), 0)
     self.assertEquals(sum(stats['totals'].values()), 0)
Beispiel #4
0
 def test_initialStats(self):
     """
     We can't use self.ht1, because it might be contaminated by other tests.
     """
     ht1 = HostTracking(self.group1)
     s1 = schedulerFactory(ht1.group.lbType, ht1)
     stats = ht1.getStats()
     self.assertEquals(len(stats['bad'].keys()), 0)
     self.assertEquals(sum(stats['openconns'].values()), 0)
     self.assertEquals(sum(stats['totals'].values()), 0)
    def setUp(self):
        """

        """
        group1 = model.ProxyGroup('test_group1', roundr, True)
        group1.addHost(model.ProxyHost('goodhost1', 'ip1', 1))
        group1.addHost(model.ProxyHost('goodhost2', 'ip1', 2))
        group1.addHost(model.ProxyHost('badhost1', 'ip1', 3))
        group1.addHost(model.ProxyHost('badhost2', 'ip1', 4))
        self.group1 = group1

        group2 = model.ProxyGroup('test_group2', leastc, True)
        group2.addHost(model.ProxyHost('goodhost3', 'ip1', 5))
        group2.addHost(model.ProxyHost('goodhost4', 'ip1', 6))
        group2.addHost(model.ProxyHost('badhost3', 'ip1', 7))
        group2.addHost(model.ProxyHost('badhost4', 'ip1', 8))
        self.group2 = group2

        self.ht1 = HostTracking(self.group1)
        self.ht2 = HostTracking(self.group2)

        self.s1 = schedulerFactory(self.ht1.group.lbType, self.ht1)
        self.s2 = schedulerFactory(self.ht2.group.lbType, self.ht2)
Beispiel #6
0
    def setUp(self):
        """

        """
        group1 = model.ProxyGroup('test_group1', roundr, True)
        group1.addHost(model.ProxyHost('goodhost1', 'ip1', 1))
        group1.addHost(model.ProxyHost('goodhost2', 'ip1', 2))
        group1.addHost(model.ProxyHost('badhost1', 'ip1', 3))
        group1.addHost(model.ProxyHost('badhost2', 'ip1', 4))
        self.group1 = group1

        group2 = model.ProxyGroup('test_group2', leastc, True)
        group2.addHost(model.ProxyHost('goodhost3', 'ip1', 5))
        group2.addHost(model.ProxyHost('goodhost4', 'ip1', 6))
        group2.addHost(model.ProxyHost('badhost3', 'ip1', 7))
        group2.addHost(model.ProxyHost('badhost4', 'ip1', 8))
        self.group2 = group2

        self.ht1 = HostTracking(self.group1)
        self.ht2 = HostTracking(self.group2)

        self.s1 = schedulerFactory(self.ht1.group.lbType, self.ht1)
        self.s2 = schedulerFactory(self.ht2.group.lbType, self.ht2)
    def test_deadHostStats(self):
        """

        """
        badHost = ('ip1', 3)
        time = None
        fakeSenderFactory = object()
        ht1 = HostTracking(self.group1)
        s1 = schedulerFactory(ht1.group.lbType, ht1)
        ht1.openconns[fakeSenderFactory] = (time, badHost)
        ht1.deadHost(fakeSenderFactory, doLog=False)
        stats = ht1.getStats()
        self.assertEquals(len(stats['bad'].keys()), 1)
        self.assertEquals(sum(stats['openconns'].values()), 0)
        self.assertEquals(sum(stats['totals'].values()), 0)
Beispiel #8
0
    def test_deadHostStats(self):
        """

        """
        badHost = ('ip1', 3)
        time = None
        fakeSenderFactory = object()
        ht1 = HostTracking(self.group1)
        s1 = schedulerFactory(ht1.group.lbType, ht1)
        ht1.openconns[fakeSenderFactory] = (time, badHost)
        ht1.deadHost(fakeSenderFactory, doLog=False)
        stats = ht1.getStats()
        self.assertEquals(len(stats['bad'].keys()), 1)
        self.assertEquals(sum(stats['openconns'].values()), 0)
        self.assertEquals(sum(stats['totals'].values()), 0)
Beispiel #9
0
def proxyManagerFactory(services):
    """
    This factory is for simplifying the common task of creating a proxy manager
    with presets for many attributes and/or much data.
    """
    # check to see what got passed, in case we need to convert it
    if isinstance(services[0], model.HostMapper):
        services = model.convertMapperToModel(services)
    # create the manager
    pm = ProxyManager(services)
    for serviceName, service in pm.getServices():
        # set up the trackers for each group
        for groupName, group in pm.getGroups(serviceName):
            tracker = HostTracking(group)
            scheduler = schedulers.schedulerFactory(group.lbType, tracker)
            pm.addTracker(serviceName, groupName, tracker)
        # now let's setup actual proxies for the hosts in the enabled group
        group = service.getEnabledGroup()
        # XXX maybe won't need this next line
        #enabledTracker = pm.getTracker(service.name, group.name)
        for host, port in service.addresses:
            pm.createProxy(serviceName, host, port)
        # return proxy manager
    return pm
Beispiel #10
0
def proxyManagerFactory(services):
    """
    This factory is for simplifying the common task of creating a proxy manager
    with presets for many attributes and/or much data.
    """
    # check to see what got passed, in case we need to convert it
    if isinstance(services[0], model.HostMapper):
        services = model.convertMapperToModel(services)
    # create the manager
    pm = ProxyManager(services)
    for serviceName, service in pm.getServices():
        # set up the trackers for each group
        for groupName, group in pm.getGroups(serviceName):
            tracker = HostTracking(group)
            scheduler = schedulers.schedulerFactory(group.lbType, tracker)
            pm.addTracker(serviceName, groupName, tracker)
        # now let's setup actual proxies for the hosts in the enabled group
        group = service.getEnabledGroup()
        # XXX maybe won't need this next line
        #enabledTracker = pm.getTracker(service.name, group.name)
        for host, port in service.addresses:
            pm.createProxy(serviceName, host, port)
        # return proxy manager
    return pm
Beispiel #11
0
 def setScheduler(self, lbType, tracker):
     """
     A convenience method for creating the appropriate scheduler, given a
     load-balancing type and its tracker.
     """
     self.scheduler = schedulers.schedulerFactory(lbType, tracker)
Beispiel #12
0
 def setScheduler(self, lbType, tracker):
     """
     A convenience method for creating the appropriate scheduler, given a
     load-balancing type and its tracker.
     """
     self.scheduler = schedulers.schedulerFactory(lbType, tracker)