예제 #1
0
 def setUp(self):
     BrightboxLBDriver.connectionCls.conn_class = BrightboxLBMockHttp
     BrightboxLBMockHttp.type = None
     BrightboxLBDriver.connectionCls.token = 'test'
     self.driver = BrightboxLBDriver(*LB_BRIGHTBOX_PARAMS)
예제 #2
0
class BrightboxLBTests(unittest.TestCase):
    def setUp(self):
        BrightboxLBDriver.connectionCls.conn_class = BrightboxLBMockHttp
        BrightboxLBMockHttp.type = None
        BrightboxLBDriver.connectionCls.token = 'test'
        self.driver = BrightboxLBDriver(*LB_BRIGHTBOX_PARAMS)

    def test_list_protocols(self):
        protocols = self.driver.list_protocols()

        self.assertEqual(len(protocols), 2)
        self.assertTrue('tcp' in protocols)
        self.assertTrue('http' in protocols)

    def test_list_balancers(self):
        balancers = self.driver.list_balancers()

        self.assertEqual(len(balancers), 1)
        self.assertEqual(balancers[0].id, 'lba-1235f')
        self.assertEqual(balancers[0].name, 'lb1')

    def test_get_balancer(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')

        self.assertEqual(balancer.id, 'lba-1235f')
        self.assertEqual(balancer.name, 'lb1')
        self.assertEqual(balancer.state, State.RUNNING)

    def test_destroy_balancer(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')

        self.assertTrue(self.driver.destroy_balancer(balancer))

    def test_create_balancer(self):
        members = [Member('srv-lv426', None, None)]

        balancer = self.driver.create_balancer(name='lb2',
                                               port=80,
                                               protocol='http',
                                               algorithm=Algorithm.ROUND_ROBIN,
                                               members=members)

        self.assertEqual(balancer.name, 'lb2')
        self.assertEqual(balancer.port, 80)
        self.assertEqual(balancer.state, State.PENDING)

    def test_balancer_list_members(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')
        members = balancer.list_members()

        self.assertEqual(len(members), 1)
        self.assertEqual(members[0].balancer, balancer)
        self.assertEqual('srv-lv426', members[0].id)

    def test_balancer_attach_member(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')
        member = balancer.attach_member(Member('srv-kg983', ip=None,
                                               port=None))

        self.assertEqual(member.id, 'srv-kg983')

    def test_balancer_detach_member(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')
        member = Member('srv-lv426', None, None)

        self.assertTrue(balancer.detach_member(member))
 def setUp(self):
     BrightboxLBDriver.connectionCls.conn_classes = (None,
                                                     BrightboxLBMockHttp)
     BrightboxLBMockHttp.type = None
     self.driver = BrightboxLBDriver(*LB_BRIGHTBOX_PARAMS)
예제 #4
0
 def setUp(self):
     BrightboxLBDriver.connectionCls.conn_classes = (None,
                                                     BrightboxLBMockHttp)
     BrightboxLBMockHttp.type = None
     self.driver = BrightboxLBDriver(*LB_BRIGHTBOX_PARAMS)
class BrightboxLBTests(unittest.TestCase):
    def setUp(self):
        BrightboxLBDriver.connectionCls.conn_classes = (None,
                                                        BrightboxLBMockHttp)
        BrightboxLBMockHttp.type = None
        self.driver = BrightboxLBDriver(*LB_BRIGHTBOX_PARAMS)

    def test_list_protocols(self):
        protocols = self.driver.list_protocols()

        self.assertEqual(len(protocols), 2)
        self.assertTrue('tcp' in protocols)
        self.assertTrue('http' in protocols)

    def test_list_balancers(self):
        balancers = self.driver.list_balancers()

        self.assertEquals(len(balancers), 1)
        self.assertEquals(balancers[0].id, 'lba-1235f')
        self.assertEquals(balancers[0].name, 'lb1')

    def test_get_balancer(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')

        self.assertEquals(balancer.id, 'lba-1235f')
        self.assertEquals(balancer.name, 'lb1')
        self.assertEquals(balancer.state, State.RUNNING)

    def test_destroy_balancer(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')

        self.assertTrue(self.driver.destroy_balancer(balancer))

    def test_create_balancer(self):
        members = [Member('srv-lv426', None, None)]

        balancer = self.driver.create_balancer(name='lb2', port=80,
            protocol='http', algorithm=Algorithm.ROUND_ROBIN, members=members)

        self.assertEquals(balancer.name, 'lb2')
        self.assertEquals(balancer.port, 80)
        self.assertEquals(balancer.state, State.PENDING)

    def test_balancer_list_members(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')
        members = balancer.list_members()

        self.assertEquals(len(members), 1)
        self.assertEquals('srv-lv426', members[0].id)

    def test_balancer_attach_member(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')
        member = balancer.attach_member(Member('srv-kg983', ip=None,
                                               port=None))

        self.assertEquals(member.id, 'srv-kg983')

    def test_balancer_detach_member(self):
        balancer = self.driver.get_balancer(balancer_id='lba-1235f')
        member = Member('srv-lv426', None, None)

        self.assertTrue(balancer.detach_member(member))