예제 #1
0
def test_bigip_refresh(big_ip):
    """Test BIG-IP refresh function."""
    test_pools = []
    for p in big_ip.bigip_data['pools']:
        pool = IcrPool(**p)
        test_pools.append(pool)
    test_virtuals = []
    for v in big_ip.bigip_data['virtuals']:
        test_virtuals.append(VirtualServer(**v))
    test_iapps = []
    for i in big_ip.bigip_data['iapps']:
        test_iapps.append(ApplicationService(**i))
    test_nodes = []
    for n in big_ip.bigip_data['nodes']:
        test_nodes.append(Node(**n))

    # refresh the BIG-IP state
    big_ip.refresh()

    # verify pools and pool members
    assert big_ip.tm.ltm.pools.get_collection.called
    assert len(big_ip._pools) == 2

    assert len(big_ip._pools) == len(test_pools)
    for pool in test_pools:
        assert big_ip._pools[pool.name] == pool
        # Make a change, pools will not be equal
        pool._data['loadBalancingMode'] = 'Not a valid LB mode'
        assert big_ip._pools[pool.name] != pool

    # verify virtual servers
    assert big_ip.tm.ltm.virtuals.get_collection.called
    assert len(big_ip._virtuals) == 2

    assert len(big_ip._virtuals) == len(test_virtuals)
    for v in test_virtuals:
        assert big_ip._virtuals[v.name] == v
        # Make a change, virtuals will not be equal
        v._data['partition'] = 'NoPartition'
        assert big_ip._virtuals[v.name] != v

    # verify application services
    assert big_ip.tm.sys.application.services.get_collection.called
    assert len(big_ip._iapps) == 2

    assert len(big_ip._iapps) == len(test_iapps)
    for i in test_iapps:
        assert big_ip._iapps[i.name] == i
        # Make a change, iapps will not be equal
        i._data['template'] = '/Common/NoTemplate'
        assert big_ip._iapps[i.name] != i

    # verify nodes
    assert big_ip.tm.ltm.nodes.get_collection.called
    assert len(big_ip._nodes) == 4

    assert len(big_ip._nodes) == len(test_nodes)
    for n in test_nodes:
        assert big_ip._nodes[n.name] == n
예제 #2
0
def test_bigip_properties(bigip_proxy):
    """Test BIG-IP properties function."""
    big_ip = bigip_proxy

    test_pools = [
        IcrPool(**p) for p in big_ip.mgmt_root().bigip_data['pools']
        if p['partition'] == 'test'
    ]
    test_virtuals = [
        VirtualServer(default_route_domain=0, **v)
        for v in big_ip.mgmt_root().bigip_data['virtuals']
        if v['partition'] == 'test'
    ]

    # refresh the BIG-IP state
    big_ip.refresh_ltm()

    assert len(big_ip.get_pools()) == len(test_pools)
    for p in test_pools:
        assert big_ip._pools[p.name] == p

    assert len(big_ip.get_virtuals()) == len(test_virtuals)
    for v in test_virtuals:
        assert big_ip._virtuals[v.name] == v

    http_hc = big_ip.get_http_monitors()
    https_hc = big_ip.get_https_monitors()
    tcp_hc = big_ip.get_tcp_monitors()
    udp_hc = big_ip.get_udp_monitors()
    icmp_hc = big_ip.get_icmp_monitors()
예제 #3
0
def test_bigip_properties(bigip_proxy):
    """Test BIG-IP properties function."""
    big_ip = bigip_proxy

    test_pools = []
    for p in big_ip.mgmt_root().bigip_data['pools']:
        pool = IcrPool(**p)
        test_pools.append(pool)
    test_virtuals = []
    for v in big_ip.mgmt_root().bigip_data['virtuals']:
        test_virtuals.append(VirtualServer(**v))

    # refresh the BIG-IP state
    big_ip.refresh()

    assert len(big_ip.get_pools()) == len(test_pools)
    for p in test_pools:
        assert big_ip._pools[p.name] == p

    assert len(big_ip.get_virtuals()) == len(test_virtuals)
    for v in test_virtuals:
        assert big_ip._virtuals[v.name] == v

    http_hc = big_ip.get_http_monitors()
    https_hc = big_ip.get_https_monitors()
    tcp_hc = big_ip.get_tcp_monitors()
    icmp_hc = big_ip.get_icmp_monitors()
예제 #4
0
def test_bigip_refresh_ltm(bigip_proxy):
    """Test BIG-IP refresh_ltm function."""
    big_ip = bigip_proxy.mgmt_root()

    test_pools = [
        IcrPool(**p) for p in big_ip.bigip_data['pools']
        if p['partition'] == 'test'
    ]
    test_virtuals = [
        VirtualServer(default_route_domain=0, **v)
        for v in big_ip.bigip_data['virtuals'] if v['partition'] == 'test'
    ]
    test_iapps = [
        IcrApplicationService(**i) for i in big_ip.bigip_data['iapps']
        if i['partition'] == 'test'
    ]
    test_nodes = [
        IcrNode(default_route_domain=0, **n)
        for n in big_ip.bigip_data['nodes'] if n['partition'] == 'test'
    ]

    # refresh the BIG-IP state
    bigip_proxy.refresh_ltm()

    # verify pools and pool members
    assert big_ip.tm.ltm.pools.get_collection.called
    assert len(bigip_proxy._pools) == 1

    assert len(bigip_proxy._pools) == len(test_pools)
    for pool in test_pools:
        assert bigip_proxy._pools[pool.name] == pool
        # Make a change, pools will not be equal
        pool._data['loadBalancingMode'] = 'Not a valid LB mode'
        assert bigip_proxy._pools[pool.name] != pool

    # verify virtual servers
    assert big_ip.tm.ltm.virtuals.get_collection.called
    assert len(bigip_proxy._virtuals) == 1

    assert len(bigip_proxy._virtuals) == len(test_virtuals)
    for v in test_virtuals:
        assert bigip_proxy._virtuals[v.name] == v
        # Make a change, virtuals will not be equal
        v._data['partition'] = 'NoPartition'
        assert bigip_proxy._virtuals[v.name] != v

    # verify application services
    assert big_ip.tm.sys.application.services.get_collection.called
    assert len(bigip_proxy._iapps) == 2

    assert len(bigip_proxy._iapps) == len(test_iapps)
    for i in test_iapps:
        assert bigip_proxy._iapps[i.name] == i
        # Make a change, iapps will not be equal
        i._data['template'] = '/Common/NoTemplate'
        assert bigip_proxy._iapps[i.name] != i

    # verify nodes
    assert big_ip.tm.ltm.nodes.get_collection.called
    assert len(bigip_proxy._nodes) == 4

    assert len(bigip_proxy._nodes) == len(test_nodes)
    for n in test_nodes:
        assert bigip_proxy._nodes[n.name] == n
예제 #5
0
파일: bigip.py 프로젝트: swapmat-f5/f5-cccl
    def refresh(self):
        """Refresh the internal cache with the BIG-IP state."""
        partition_filter = "$filter=partition+eq+{}".format(self._partition)

        #  Retrieve the list of virtual servers in managed partition.
        query = partition_filter

        #  Retrieve the lists of health monitors
        http_monitors = self.tm.ltm.monitor.https.get_collection(
            requests_params={"params": query})
        https_monitors = self.tm.ltm.monitor.https_s.get_collection(
            requests_params={"params": query})
        tcp_monitors = self.tm.ltm.monitor.tcps.get_collection(
            requests_params={"params": query})
        icmp_monitors = (
            self.tm.ltm.monitor.gateway_icmps.get_collection(
                requests_params={"params": query})
        )
        iapps = self.tm.sys.application.services.get_collection(
            requests_params={"params": query})
        nodes = self.tm.ltm.nodes.get_collection(
            requests_params={"params": query})
        virtual_addresses = self.tm.ltm.virtual_address_s.get_collection(
            requests_params={"params": query})

        #  Retrieve the list of virtuals, pools, and policies in the
        #  managed partition getting all subCollections.
        query = "{}&expandSubcollections=true".format(partition_filter)
        virtuals = self.tm.ltm.virtuals.get_collection(
            requests_params={"params": query})

        pools = self.tm.ltm.pools.get_collection(
            requests_params={"params": query})

        policies = self.tm.ltm.policys.get_collection(
            requests_params={"params": query})

        #  Refresh the virtuals cache.
        self._virtuals = {
            v.name: IcrVirtualServer(**v.raw) for v in virtuals
            if self._manageable_resource(v)
        }

        #  Refresh the virtuals cache.
        self._all_virtuals = {
            v.name: IcrVirtualServer(**v.raw) for v in virtuals
        }

        #  Refresh the virtual address cache.
        self._virtual_addresses = {
            v.name: IcrVirtualAddress(**v.raw) for v in virtual_addresses
            if self._manageable_resource(v)
        }

        #  Refresh the pool cache
        self._pools = {
            p.name: IcrPool(**p.raw) for p in pools
            if self._manageable_resource(p)
        }

        #  Refresh the all-pool cache
        self._all_pools = {
            p.name: IcrPool(**p.raw) for p in pools
        }

        #  Refresh the policy cache
        self._policies = {
            p.name: IcrPolicy(**p.raw) for p in policies
            if self._manageable_resource(p)
        }

        #  Refresh the iapp cache
        self._iapps = {
            i.name: ApplicationService(**i.raw) for i in iapps
            if i.name.startswith(self._prefix)
        }

        #  Refresh the node cache
        self._nodes = {
            n.name: Node(**n.raw) for n in nodes
        }

        #  Refresh the health monitor cache
        self._monitors['http'] = {
            m.name: IcrHTTPMonitor(**m.raw) for m in http_monitors
            if self._manageable_resource(m)
        }
        self._monitors['https'] = {
            m.name: IcrHTTPSMonitor(**m.raw) for m in https_monitors
            if self._manageable_resource(m)
        }
        self._monitors['tcp'] = {
            m.name: IcrTCPMonitor(**m.raw) for m in tcp_monitors
            if self._manageable_resource(m)
        }
        self._monitors['icmp'] = {
            m.name: IcrICMPMonitor(**m.raw) for m in icmp_monitors
            if self._manageable_resource(m)
        }