def tearDownClass(cls):
     job = cls.conn.load_balancer.delete_load_balancer(cls.lb)
     job = _job.Job(id=job.job_id)
     resource2.wait_for_status(cls.conn.load_balancer._session,
                               job,
                               "SUCCESS",
                               interval=3,
                               failures=["FAIL"])
 def tearDownClass(cls):
     # delete listener created in setup
     cls.conn.load_balancer.delete_listener(cls.listener)
     # delete load balancer created in setup
     job = cls.conn.load_balancer.delete_load_balancer(cls.lb)
     job = _job.Job(id=job.job_id)
     resource2.wait_for_status(cls.conn.load_balancer._session,
                               job,
                               "SUCCESS",
                               interval=5,
                               failures=["FAIL"])
    def test_operate_members(self):
        members = []
        servers = self.conn.compute.servers()
        for server in servers:
            vpc_list = server.addresses.keys()
            if self.router.id in vpc_list:
                addr = server.addresses[self.router.id][0]["addr"]
                members.append(dict(server_id=server.id, address=addr))
                if len(members) == 2:
                    break

        job = self.conn.load_balancer.add_members_to_listener(
            self.listener, members)
        # waiting for add members job done
        job = _job.Job(id=job.id)
        resource2.wait_for_status(self.conn.load_balancer._session,
                                  job,
                                  "SUCCESS",
                                  interval=5,
                                  failures=["FAIL"])

        added_members = self.conn.load_balancer.listener_members(self.listener)
        self.assertEqual(2, len(list(added_members)))

        member_ids = [member["server_id"] for member in members]
        job = self.conn.load_balancer.remove_members_of_listener(
            self.listener, member_ids)
        job = _job.Job(id=job.id)
        resource2.wait_for_status(self.conn.load_balancer._session,
                                  job,
                                  "SUCCESS",
                                  interval=5,
                                  failures=["FAIL"])

        added_members = self.conn.load_balancer.listener_members(self.listener)
        self.assertEqual(0, len(list(added_members)))
 def test_update_lb(self):
     updated = {
         "description": "lb created by functional test",
         "bandwidth": 2,
         "admin_state_up": True
     }
     job = self.conn.load_balancer.update_load_balancer(self.lb, **updated)
     job = _job.Job(id=job.job_id)
     resource2.wait_for_status(self.conn.load_balancer._session,
                               job,
                               "SUCCESS",
                               interval=3,
                               failures=["FAIL"])
     self.conn.load_balancer.wait_for_status(job, "SUCCESS", interval=2)
     lb = self.conn.load_balancer.get_load_balancer(self.lb)
     self.assertEqual(updated["description"], lb.description)
     self.assertEqual(updated["bandwidth"], lb.bandwidth)
     self.assertEqual(updated["admin_state_up"], lb.is_admin_state_up)
     self.lb = lb
def auto_create_external_lb(conn, name, vpc_id):
    """auto create a lb for functional test

    :param conn:
    :param name:
    :return:
    """
    _lb = {
        "name": name,
        "vpc_id": vpc_id,
        "bandwidth": 1,
        "type": "External",
        "is_admin_state_up": True
    }
    job = conn.load_balancer.create_load_balancer(**_lb)
    job = _job.Job(id=job.job_id)
    resource2.wait_for_status(conn.load_balancer._session,
                              job,
                              "SUCCESS",
                              interval=3,
                              failures=["FAIL"])
    elb_id = job.entities["elb"]["id"]
    return conn.load_balancer.get_load_balancer(elb_id)