Ejemplo n.º 1
0
def test_hash():
    """Test Node Server hash."""
    node = Node(
        **cfg_test
    )
    node1 = Node(
        **cfg_test
    )
    cfg_changed = copy(cfg_test)
    cfg_changed['name'] = 'test'
    node2 = Node(
        **cfg_changed
    )
    cfg_changed = copy(cfg_test)
    cfg_changed['partition'] = 'other'
    node3 = Node(
        **cfg_changed
    )
    assert node
    assert node1
    assert node2
    assert node3

    assert hash(node) == hash(node1)
    assert hash(node) != hash(node2)
    assert hash(node) != hash(node3)
Ejemplo n.º 2
0
def test_uri_path(bigip):
    """Test Node URI."""
    node = Node(
        **cfg_test
    )
    assert node

    assert node._uri_path(bigip) == bigip.tm.ltm.nodes.node
Ejemplo n.º 3
0
def test_uri_path(bigip):
    """Test Node URI."""
    node = Node(
        default_route_domain=2,
        **cfg_test
    )
    assert node

    assert node._uri_path(bigip) == bigip.tm.ltm.nodes.node
Ejemplo n.º 4
0
def test_update_node():
    node = Node(default_route_domain=2, **cfg_test)

    assert 'address' in node.data

    # Verify that immutable 'address' is not passed to parent method
    with patch.object(Resource, 'update') as mock_method:
        node.update(bigip)
        assert 1 == mock_method.call_count
        assert 'address' not in mock_method.call_args[1]['data']
Ejemplo n.º 5
0
def test_update_node():
    node = Node(
        default_route_domain=2,
        **cfg_test
    )

    assert 'address' in node.data

    # Verify that immutable 'address' is not passed to parent method
    with patch.object(Resource, 'update') as mock_method:
        node.update(bigip)
        assert 1 == mock_method.call_count
        assert 'address' not in mock_method.call_args[1]['data']
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def test_create_node():
    """Test Node creation."""
    node = Node(default_route_domain=2, **cfg_test)
    assert node

    # verify all cfg items
    for k, v in list(cfg_test.items()):
        assert node._data[k] == v
Ejemplo n.º 8
0
def test_create_node():
    """Test Node creation."""
    node = Node(**cfg_test)
    assert node

    # verify all cfg items
    for k, v in cfg_test.items():
        assert node.data[k] == v
Ejemplo n.º 9
0
    def _desired_nodes(self):
        """Desired nodes is inferred from the active pool members."""
        desired_nodes = dict()
        nodes = self._bigip.get_nodes()
        pools = self._bigip.get_pools(True)
        for pool in pools:
            for member in pools[pool].members:
                addr = member.name.split('%3A')[0]
                # make a copy to iterate over, then delete from 'nodes'
                node_list = list(nodes.keys())
                for key in node_list:
                    if nodes[key].data['address'] == addr:
                        node = {
                            'name': key,
                            'partition': nodes[key].partition,
                            'address': addr,
                            'state': 'user-up',
                            'session': 'user-enabled'
                        }
                        desired_nodes[key] = Node(**node)

        return desired_nodes
Ejemplo n.º 10
0
def test_eq():
    """Test Node equality."""
    partition = 'Common'
    name = 'node_1'

    node = Node(default_route_domain=2, **cfg_test)
    node2 = Node(default_route_domain=2, **cfg_test)
    pool = Pool(name=name, partition=partition)
    assert node
    assert node2
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-enabled'
    assert node == node2

    node2.data['state'] = 'unchecked'
    node2.data['session'] = 'monitor-enabled'
    assert node == node2

    # not equal
    node2.data['state'] = 'user-down'
    node2.data['session'] = 'user-enabled'
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-disabled'
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-enabled'
    node2.data['address'] = '10.10.0.10'
    assert node != node2

    # different objects
    assert node != pool
Ejemplo n.º 11
0
def test_eq():
    """Test Node equality."""
    partition = 'Common'
    name = 'node_1'

    node = Node(
        **cfg_test
    )
    node2 = Node(
        **cfg_test
    )
    pool = Pool(
        name=name,
        partition=partition
    )
    assert node
    assert node2
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-enabled'
    assert node == node2

    node2.data['state'] = 'unchecked'
    node2.data['session'] = 'monitor-enabled'
    assert node == node2

    # not equal
    node2.data['state'] = 'user-down'
    node2.data['session'] = 'user-enabled'
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-disabled'
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-enabled'
    node2.data['address'] = '10.10.0.10'
    assert node != node2

    # different objects
    with pytest.raises(ValueError):
        assert node != pool 
Ejemplo n.º 12
0
def test_eq():
    """Test Node equality."""
    partition = 'Common'
    name = 'node_1'

    node = Node(
        default_route_domain=2,
        **cfg_test
    )
    node2 = Node(
        default_route_domain=2,
        **cfg_test
    )
    pool = Pool(
        name=name,
        partition=partition
    )
    assert node
    assert node2
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-enabled'
    assert node == node2

    node2.data['state'] = 'unchecked'
    node2.data['session'] = 'monitor-enabled'
    assert node == node2

    # not equal
    node2.data['state'] = 'user-down'
    node2.data['session'] = 'user-enabled'
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-disabled'
    assert node != node2

    node2.data['state'] = 'up'
    node2.data['session'] = 'user-enabled'
    node2.data['address'] = '10.10.0.10'
    assert node != node2

    # different objects
    assert node != pool
Ejemplo n.º 13
0
    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)
        }