Exemplo n.º 1
0
class SoftlayerLBTests(unittest.TestCase):
    def setUp(self):

        SoftlayerLBDriver.connectionCls.conn_classes = (SoftLayerMockHttp,
                                                        SoftLayerMockHttp)
        SoftLayerMockHttp.type = None

        self.driver = SoftlayerLBDriver(*SOFTLAYER_PARAMS)

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

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

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

        self.assertEqual(len(balancers), 2)
        self.assertEqual(balancers[0].id, '76185')
        self.assertEqual(balancers[0].extra['datacenter'], 'dal05')
        self.assertEqual(balancers[0].extra['connection_limit'], 50)
        self.assertEqual(balancers[1].id, '76265')
        self.assertEqual(balancers[1].extra['datacenter'], 'par01')
        self.assertEqual(balancers[1].extra['connection_limit'], 50)

    def test_get_balancer(self):
        balancer = self.driver.get_balancer(balancer_id='76185')

        self.assertEqual(balancer.id, '76185')
        self.assertEqual(balancer.state, State.UNKNOWN)
        self.assertEqual(balancer.extra['datacenter'], 'dal05')
        self.assertEqual(balancer.extra['protocol'], 'http')
        self.assertEqual(balancer.extra['algorithm'], Algorithm.ROUND_ROBIN)

    def test_balancer_list_members(self):
        balancer = self.driver.get_balancer(balancer_id='76185')
        members = balancer.list_members()

        self.assertEqual(len(members), 3)
        self.assertEqual(members[0].balancer, balancer)
        self.assertEqual(members[0].id, '226227')
        self.assertEqual(members[0].ip, '10.126.5.34')
        self.assertEqual(members[1].balancer, balancer)
        self.assertEqual(members[1].id, '226229')
        self.assertEqual(members[1].ip, '10.126.5.35')

    def test_balancer_attach_member(self):
        balancer = self.driver.get_balancer(balancer_id='76185')
        member = balancer.attach_member(Member(None, ip='10.126.5.34',
                                               port=8000))

        self.assertEqual(member.id, '226227')
        self.assertEqual(member.ip, '10.126.5.34')
        self.assertEqual(member.port, 8000)

    def test_balancer_detach_member(self):
        balancer = self.driver.get_balancer(balancer_id='76265')
        member = Member('226227', None, None)

        self.assertTrue(balancer.detach_member(member))

    def test_destroy_balancer(self):
        balancer = self.driver.get_balancer(balancer_id='76185')

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

    def test_ex_list_balancer_packages(self):
        packages = self.driver.ex_list_balancer_packages()
        self.assertEqual(len(packages), 9)

    def test_ex_place_balancer_order(self):
        packages = self.driver.ex_list_balancer_packages()
        lb_package = [p for p in packages if p.capacity == 50][0]

        self.assertTrue(self.driver.ex_place_balancer_order(
            lb_package, NodeLocation('dal05', None, None, None)))
class SoftlayerLBTests(unittest.TestCase):
    def setUp(self):

        SoftlayerLBDriver.connectionCls.conn_class = SoftLayerMockHttp
        SoftLayerMockHttp.type = None

        self.driver = SoftlayerLBDriver(*SOFTLAYER_PARAMS)

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

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

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

        self.assertEqual(len(balancers), 2)
        self.assertEqual(balancers[0].id, '76185')
        self.assertEqual(balancers[0].extra['datacenter'], 'dal05')
        self.assertEqual(balancers[0].extra['connection_limit'], 50)
        self.assertEqual(balancers[1].id, '76265')
        self.assertEqual(balancers[1].extra['datacenter'], 'par01')
        self.assertEqual(balancers[1].extra['connection_limit'], 50)

    def test_get_balancer(self):
        balancer = self.driver.get_balancer(balancer_id='76185')

        self.assertEqual(balancer.id, '76185')
        self.assertEqual(balancer.state, State.UNKNOWN)
        self.assertEqual(balancer.extra['datacenter'], 'dal05')
        self.assertEqual(balancer.extra['protocol'], 'http')
        self.assertEqual(balancer.extra['algorithm'], Algorithm.ROUND_ROBIN)

    def test_balancer_list_members(self):
        balancer = self.driver.get_balancer(balancer_id='76185')
        members = balancer.list_members()

        self.assertEqual(len(members), 3)
        self.assertEqual(members[0].balancer, balancer)
        self.assertEqual(members[0].id, '226227')
        self.assertEqual(members[0].ip, '10.126.5.34')
        self.assertEqual(members[1].balancer, balancer)
        self.assertEqual(members[1].id, '226229')
        self.assertEqual(members[1].ip, '10.126.5.35')

    def test_balancer_attach_member(self):
        balancer = self.driver.get_balancer(balancer_id='76185')
        member = balancer.attach_member(Member(None, ip='10.126.5.34',
                                               port=8000))

        self.assertEqual(member.id, '226227')
        self.assertEqual(member.ip, '10.126.5.34')
        self.assertEqual(member.port, 8000)

    def test_balancer_detach_member(self):
        balancer = self.driver.get_balancer(balancer_id='76265')
        member = Member('226227', None, None)

        self.assertTrue(balancer.detach_member(member))

    def test_destroy_balancer(self):
        balancer = self.driver.get_balancer(balancer_id='76185')

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

    def test_ex_list_balancer_packages(self):
        packages = self.driver.ex_list_balancer_packages()
        self.assertEqual(len(packages), 9)

    def test_ex_place_balancer_order(self):
        packages = self.driver.ex_list_balancer_packages()
        lb_package = [p for p in packages if p.capacity == 50][0]

        self.assertTrue(self.driver.ex_place_balancer_order(
            lb_package, NodeLocation('dal05', None, None, None)))
Exemplo n.º 3
0
class SoftlayerLBTests(unittest.TestCase):
    def setUp(self):

        SoftlayerLBDriver.connectionCls.conn_class = SoftLayerMockHttp
        SoftLayerMockHttp.type = None

        self.driver = SoftlayerLBDriver(*SOFTLAYER_PARAMS)

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

        self.assertEqual(len(protocols), 6)
        self.assertTrue("tcp" in protocols)
        self.assertTrue("http" in protocols)

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

        self.assertEqual(len(balancers), 2)
        self.assertEqual(balancers[0].id, "76185")
        self.assertEqual(balancers[0].extra["datacenter"], "dal05")
        self.assertEqual(balancers[0].extra["connection_limit"], 50)
        self.assertEqual(balancers[1].id, "76265")
        self.assertEqual(balancers[1].extra["datacenter"], "par01")
        self.assertEqual(balancers[1].extra["connection_limit"], 50)

    def test_get_balancer(self):
        balancer = self.driver.get_balancer(balancer_id="76185")

        self.assertEqual(balancer.id, "76185")
        self.assertEqual(balancer.state, State.UNKNOWN)
        self.assertEqual(balancer.extra["datacenter"], "dal05")
        self.assertEqual(balancer.extra["protocol"], "http")
        self.assertEqual(balancer.extra["algorithm"], Algorithm.ROUND_ROBIN)

    def test_balancer_list_members(self):
        balancer = self.driver.get_balancer(balancer_id="76185")
        members = balancer.list_members()

        self.assertEqual(len(members), 3)
        self.assertEqual(members[0].balancer, balancer)
        self.assertEqual(members[0].id, "226227")
        self.assertEqual(members[0].ip, "10.126.5.34")
        self.assertEqual(members[1].balancer, balancer)
        self.assertEqual(members[1].id, "226229")
        self.assertEqual(members[1].ip, "10.126.5.35")

    def test_balancer_attach_member(self):
        balancer = self.driver.get_balancer(balancer_id="76185")
        member = balancer.attach_member(
            Member(None, ip="10.126.5.34", port=8000))

        self.assertEqual(member.id, "226227")
        self.assertEqual(member.ip, "10.126.5.34")
        self.assertEqual(member.port, 8000)

    def test_balancer_detach_member(self):
        balancer = self.driver.get_balancer(balancer_id="76265")
        member = Member("226227", None, None)

        self.assertTrue(balancer.detach_member(member))

    def test_destroy_balancer(self):
        balancer = self.driver.get_balancer(balancer_id="76185")

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

    def test_ex_list_balancer_packages(self):
        packages = self.driver.ex_list_balancer_packages()
        self.assertEqual(len(packages), 9)

    def test_ex_place_balancer_order(self):
        packages = self.driver.ex_list_balancer_packages()
        lb_package = [p for p in packages if p.capacity == 50][0]

        self.assertTrue(
            self.driver.ex_place_balancer_order(
                lb_package, NodeLocation("dal05", None, None, None)))