Beispiel #1
0
def test_eq():
    """Test Application Service equality."""
    partition = 'Common'
    name = 'app_svc'

    appsvc1 = ApplicationService(
        **cfg_test
    )
    appsvc2 = ApplicationService(
        **cfg_test
    )
    cfg_test3 = deepcopy(cfg_test)
    cfg_test3['variables'][0]['value'] = 'changed'
    appsvc3 = ApplicationService(
        **cfg_test3
    )
    pool = Pool(
        name=name,
        partition=partition
    )
    assert appsvc1
    assert appsvc2
    assert appsvc3
    assert appsvc1 == appsvc2

    # not equal
    assert appsvc1 != appsvc3

    # different objects
    with pytest.raises(ValueError):
        assert appsvc1 != pool 
Beispiel #2
0
def test_hash():
    """Test Application Service hash."""
    appsvc = ApplicationService(
        **cfg_test
    )
    appsvc1 = ApplicationService(
        **cfg_test
    )
    cfg_changed = copy(cfg_test)
    cfg_changed['name'] = 'test'
    appsvc2 = ApplicationService(
        **cfg_changed
    )
    cfg_changed = copy(cfg_test)
    cfg_changed['partition'] = 'other'
    appsvc3 = ApplicationService(
        **cfg_changed
    )
    assert appsvc
    assert appsvc1
    assert appsvc2
    assert appsvc3

    assert hash(appsvc) == hash(appsvc1)
    assert hash(appsvc) != hash(appsvc2)
    assert hash(appsvc) != hash(appsvc3)
Beispiel #3
0
def test_uri_path(bigip):
    """Test Application Service URI."""
    appsvc = ApplicationService(
        **cfg_test
    )
    assert appsvc

    assert appsvc._uri_path(bigip) == bigip.tm.sys.application.services.service
Beispiel #4
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
Beispiel #5
0
def test_create_app_service(bigip, mock_resource):
    """Test Application Service creation."""
    appsvc = ApplicationService(
        **cfg_test
    )
    assert appsvc

    # verify all cfg items
    expected = cfg_test
    expected.update(cfg_test['options'])
    del expected['options']
    for k,v in expected.items():
        assert appsvc.data[k] == v

    appsvc.create(bigip)

    # verify that 'create' was called with expected dict
    assert Resource.create.called
Beispiel #6
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)
        }
Beispiel #7
0
    def read_config(self, service_config):
        """Read the service configuration and save as resource object."""
        config_dict = dict()
        config_dict['http_monitors'] = dict()
        config_dict['https_monitors'] = dict()
        config_dict['icmp_monitors'] = dict()
        config_dict['tcp_monitors'] = dict()

        virtuals = service_config.get('virtualServers', list())
        config_dict['virtuals'] = {
            v['name']: ApiVirtualServer(partition=self._partition, **v)
            for v in virtuals
        }

        # Get the list of explicitly defined virtual addresses.
        virtual_addresses = service_config.get('virtualAddresses', list())
        config_dict['virtual_addresses'] = {
            va['name']: ApiVirtualAddress(partition=self._partition, **va)
            for va in virtual_addresses
        }

        pools = service_config.get('pools', list())
        config_dict['pools'] = {
            p['name']: ApiPool(partition=self._partition, **p)
            for p in pools
        }

        policies = service_config.get('l7Policies', list())
        config_dict['l7policies'] = {
            p['name']: ApiPolicy(partition=self._partition, **p)
            for p in policies
        }

        monitors = service_config.get('monitors', list())
        for monitor in monitors:
            monitor_type = monitor.get('type', None)
            monitor_name = monitor.get('name', None)
            if monitor_type == "http":
                config_dict['http_monitors'].update(
                    {monitor_name: ApiHTTPMonitor(
                        partition=self._partition,
                        **monitor)})
            if monitor_type == "https":
                config_dict['https_monitors'].update(
                    {monitor_name: ApiHTTPSMonitor(
                        partition=self._partition,
                        **monitor)})
            if monitor_type == "icmp":
                config_dict['icmp_monitors'].update(
                    {monitor_name: ApiICMPMonitor(
                        partition=self._partition,
                        **monitor)})
            if monitor_type == "tcp":
                config_dict['tcp_monitors'].update(
                    {monitor_name: ApiTCPMonitor(
                        partition=self._partition,
                        **monitor)})

        iapps = service_config.get('iapps', list())
        config_dict['iapps'] = {
            i['name']: ApplicationService(partition=self._partition, **i)
            for i in iapps
        }

        return config_dict