diff options
Diffstat (limited to 'tempest/scenario/test_load_balancer_basic.py')
-rw-r--r-- | tempest/scenario/test_load_balancer_basic.py | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/tempest/scenario/test_load_balancer_basic.py b/tempest/scenario/test_load_balancer_basic.py index 5e83ff9c9..9e404c86e 100644 --- a/tempest/scenario/test_load_balancer_basic.py +++ b/tempest/scenario/test_load_balancer_basic.py @@ -18,17 +18,17 @@ import tempfile import time import urllib2 -from tempest.api.network import common as net_common from tempest.common import commands from tempest import config from tempest import exceptions from tempest.scenario import manager +from tempest.services.network import resources as net_resources from tempest import test config = config.CONF -class TestLoadBalancerBasic(manager.NeutronScenarioTest): +class TestLoadBalancerBasic(manager.NetworkScenarioTest): """ This test checks basic load balancing. @@ -38,9 +38,8 @@ class TestLoadBalancerBasic(manager.NeutronScenarioTest): 2. SSH to the instance and start two servers 3. Create a load balancer with two members and with ROUND_ROBIN algorithm associate the VIP with a floating ip - 4. Send 10 requests to the floating ip and check that they are shared - between the two servers and that both of them get equal portions - of the requests + 4. Send NUM requests to the floating ip and check that they are shared + between the two servers. """ @classmethod @@ -58,8 +57,8 @@ class TestLoadBalancerBasic(manager.NeutronScenarioTest): raise cls.skipException(msg) @classmethod - def setUpClass(cls): - super(TestLoadBalancerBasic, cls).setUpClass() + def resource_setup(cls): + super(TestLoadBalancerBasic, cls).resource_setup() cls.check_preconditions() cls.servers_keypairs = {} cls.members = [] @@ -67,6 +66,7 @@ class TestLoadBalancerBasic(manager.NeutronScenarioTest): cls.server_ips = {} cls.port1 = 80 cls.port2 = 88 + cls.num = 50 def setUp(self): super(TestLoadBalancerBasic, self).setUp() @@ -89,7 +89,7 @@ class TestLoadBalancerBasic(manager.NeutronScenarioTest): if tenant_net: tenant_subnet = self._list_subnets(tenant_id=self.tenant_id)[0] - self.subnet = net_common.DeletableSubnet( + self.subnet = net_resources.DeletableSubnet( client=self.network_client, **tenant_subnet) self.network = tenant_net @@ -101,7 +101,7 @@ class TestLoadBalancerBasic(manager.NeutronScenarioTest): # should instead pull a subnet id from config, which is set by # devstack/admin/etc. subnet = self._list_subnets(network_id=self.network['id'])[0] - self.subnet = net_common.AttributeDict(subnet) + self.subnet = net_resources.AttributeDict(subnet) def _create_security_group_for_test(self): self.security_group = self._create_security_group( @@ -287,26 +287,21 @@ class TestLoadBalancerBasic(manager.NeutronScenarioTest): def _check_load_balancing(self): """ - 1. Send 10 requests on the floating ip associated with the VIP - 2. Check that the requests are shared between - the two servers and that both of them get equal portions - of the requests + 1. Send NUM requests on the floating ip associated with the VIP + 2. Check that the requests are shared between the two servers """ self._check_connection(self.vip_ip) - self._send_requests(self.vip_ip, set(["server1", "server2"])) - - def _send_requests(self, vip_ip, expected, num_req=10): - count = 0 - while count < num_req: - resp = [] - for i in range(len(self.members)): - resp.append( - urllib2.urlopen( - "http://{0}/".format(vip_ip)).read()) - count += 1 - self.assertEqual(expected, - set(resp)) + self._send_requests(self.vip_ip, ["server1", "server2"]) + + def _send_requests(self, vip_ip, servers): + counters = dict.fromkeys(servers, 0) + for i in range(self.num): + server = urllib2.urlopen("http://{0}/".format(vip_ip)).read() + counters[server] += 1 + # Assert that each member of the pool gets balanced at least once + for member, counter in counters.iteritems(): + self.assertGreater(counter, 0, 'Member %s never balanced' % member) @test.services('compute', 'network') def test_load_balancer_basic(self): |