def handle_init_registry(bigip, icd_configuration,
                         create_mock_rpc=create_default_mock_rpc_plugin):
    register_device(bigip)
    icontroldriver = configure_icd(icd_configuration, create_mock_rpc)
    start_registry = register_device(bigip)

    return icontroldriver, start_registry
Example #2
0
def setup_bigip_devices(request, bigip, bigip2, vcmp_uris, makelogdir):
    lb_uris = set(vcmp_uris['vcmp_lb_uris'])
    listener_uris = set(vcmp_uris['vcmp_listener_uris'])
    cluster_uris = set(vcmp_uris['vcmp_cluster_uris'])

    class test_bigip(object):
        def __init__(self, device, pretest_snapshot):
            self.device = device
            self.pretest_snapshot = frozenset(pretest_snapshot)

    bigips = [
        test_bigip(bigip, register_device(bigip)),
        test_bigip(bigip2, register_device(bigip2))
    ]
    logname = os.path.join(makelogdir, request.function.__name__)
    loghandler = _get_nolevel_handler(logname)

    def remove_test_created_elements():
        for bigip in bigips:
            posttest_registry = register_device(bigip.device)
            created = frozenset(posttest_registry) - bigip.pretest_snapshot
            remove_elements(bigip.device, created, vlan=True)

    rootlogger = logging.getLogger()
    rootlogger.removeHandler(loghandler)
    for bigip in bigips:
        try:
            remove_elements(bigip.device,
                            lb_uris | listener_uris | cluster_uris,
                            vlan=True)
        finally:
            rootlogger.info('removing pre-existing config on bigip {}'.format(
                bigip.device.hostname))
    request.addfinalizer(remove_test_created_elements)
    return loghandler
Example #3
0
def setup_bigip_devices(request, bigip, bigip2, vcmp_uris, makelogdir):
    lb_uris = set(vcmp_uris['vcmp_lb_uris'])
    listener_uris = set(vcmp_uris['vcmp_listener_uris'])
    cluster_uris = set(vcmp_uris['vcmp_cluster_uris'])

    class test_bigip(object):
        def __init__(self, device, pretest_snapshot):
            self.device = device
            self.pretest_snapshot = frozenset(pretest_snapshot)

    bigips = [test_bigip(bigip, register_device(bigip)),
              test_bigip(bigip2, register_device(bigip2))]
    logname = os.path.join(makelogdir, request.function.__name__)
    loghandler = _get_nolevel_handler(logname)

    def remove_test_created_elements():
        for bigip in bigips:
            posttest_registry = register_device(bigip.device)
            created = frozenset(posttest_registry) - bigip.pretest_snapshot
            remove_elements(bigip.device, created, vlan=True)

    rootlogger = logging.getLogger()
    rootlogger.removeHandler(loghandler)
    for bigip in bigips:
        try:
            remove_elements(
                bigip.device, lb_uris | listener_uris | cluster_uris,
                vlan=True)
        finally:
            rootlogger.info('removing pre-existing config on bigip {}'.format(
                bigip.device.hostname))
    request.addfinalizer(remove_test_created_elements)
    return loghandler
def handle_init_registry(bigip, icd_configuration,
                         create_mock_rpc=create_default_mock_rpc_plugin):
    init_registry = register_device(bigip)
    icontroldriver = configure_icd(icd_configuration, create_mock_rpc)
    start_registry = register_device(bigip)

    return icontroldriver, start_registry
Example #5
0
def handle_init_registry(bigip,
                         icd_configuration,
                         create_mock_rpc=create_default_mock_rpc_plugin):
    init_registry = register_device(bigip)
    icontroldriver = configure_icd(icd_configuration, create_mock_rpc)
    start_registry = register_device(bigip)
    assert set(start_registry.keys()) - set(init_registry.keys()) ==\
        AGENT_INIT_URIS
    return icontroldriver, start_registry
def handle_init_registry(bigip, icd_configuration,
                         create_mock_rpc=create_default_mock_rpc_plugin):
    LOG.debug(type(bigip))
    init_registry = register_device(bigip)
    icontroldriver = configure_icd(icd_configuration, create_mock_rpc)
    LOG.debug(bigip.raw)
    start_registry = register_device(bigip)
    assert set(start_registry.keys()) - set(init_registry.keys()) == \
        AGENT_INIT_URIS
    return icontroldriver, start_registry
def handle_init_registry(bigip, icd_configuration,
                         create_mock_rpc=create_default_mock_rpc_plugin):
    LOG.debug(type(bigip))
    init_registry = register_device(bigip)
    icontroldriver = configure_icd(icd_configuration, create_mock_rpc)
    LOG.debug(bigip.raw)
    start_registry = register_device(bigip)
    if icd_configuration['f5_global_routed_mode'] == False:
        assert set(start_registry.keys()) - set(init_registry.keys()) == \
            AGENT_INIT_URIS
    return icontroldriver, start_registry
Example #8
0
def test_vcmp_deletelb(setup_bigip_devices, bigip, vcmp_setup, vcmp_uris):
    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-bigip-12.0.int.lineratesystems.com-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20'),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            deepcopy(DELETELB),
            delete_partition=True)
    # After the deletelb is called above, the vcmp guest should no longer
    bigip_vlans = [v.fullPath for v in bigip.tm.net.vlans.get_collection()]
    assert GUEST_VLAN not in bigip_vlans
    assert COMMON_VLAN not in bigip_vlans
    vcmp_host[0]['guest'].refresh()
    assert not hasattr(vcmp_host[0]['guest'], 'vlans')
    assert not vcmp_host[0]['bigip'].tm.net.vlans.vlan.exists(
        name='vlan-1-1-46', partition='Common')
Example #9
0
def test_vcmp_createlb(setup_bigip_devices, bigip, vcmp_setup, vcmp_uris):
    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-bigip-12.0.int.lineratesystems.com-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20'),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    # Since the loadbalancer was not deleted via a service object, we should
    # have a leftover VLAN on the vCMP host and the VLAN should be associated
    # with the guest, and the VLAN from within the guest should be there
    bigip_vlans = [v.fullPath for v in bigip.tm.net.vlans.get_collection()]
    assert GUEST_VLAN in bigip_vlans
    assert COMMON_VLAN not in bigip_vlans
    vcmp_host[0]['guest'].refresh()
    assert COMMON_VLAN in vcmp_host[0]['guest'].vlans
    assert vcmp_host[0]['bigip'].tm.net.vlans.vlan.exists(name='vlan-1-1-46',
                                                          partition='Common')
def test_featureoff_withsegid_lb(track_bigip_cfg, setup_l2adjacent_test,
                                 bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_OFF)
    service = deepcopy(SEGID_CREATELB)

    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = UrlSnips.strip_version(
        set(after_create_registry.keys()) - set(start_registry.keys()))
    assert create_uris == SEG_INDEPENDENT_LB_URIS | SEG_DEPENDENT_LB_URIS
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    assert rpc.get_port_by_name.call_args_list == [
        call(port_name=u'local-{}-ce69e293-56e7-43b8-b51c-01b91d66af20'.format(
            icontrol_fqdn)),
        call(port_name=u'snat-traffic-group-local-only-'
             'ce69e293-56e7-43b8-b51c-01b91d66af20_0')
    ]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
def test_nosegid_listener_timeout(setup_l2adjacent_test, bigip):
    def create_mock_rpc_plugin():
        mock_rpc_plugin = mock.MagicMock(name='mock_rpc_plugin')
        mock_rpc_plugin.get_port_by_name.return_value = [
            {'fixed_ips': [{'ip_address': '10.2.2.134'}]}
        ]
        mock_rpc_plugin.get_all_loadbalancers.return_value = [
            {'lb_id': u'50c5d54a-5a9e-4a80-9e74-8400a461a077'}
        ]
        service = deepcopy(NOSEGID_CREATELISTENER)
        service['loadbalancer']['provisioning_status'] = "ACTIVE"
        mock_rpc_plugin.get_service_by_loadbalancer_id.return_value = service
        return mock_rpc_plugin
    # Configure
    icontroldriver, start_registry = handle_init_registry(
        bigip, FEATURE_ON, create_mock_rpc_plugin)
    gtimeout = icontroldriver.conf.f5_network_segment_gross_timeout
    poll_interval = icontroldriver.conf.f5_network_segment_polling_interval
    service = deepcopy(NOSEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test,
            icontroldriver._common_service_handler,
            service)
    # Set timers
    start_time = time.time()
    timeout = start_time + gtimeout
    # Begin operations
    while time.time() < (timeout + (2*poll_interval)):
        time.sleep(poll_interval)
        create_registry = register_device(bigip)
        create_uris = set(create_registry.keys()) - set(start_registry.keys())
        assert create_uris == SEG_INDEPENDENT_LB_URIS | NOSEG_LISTENER_URIS
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    assert ERROR_MSG_TIMEOUT in open(logfilename).read()

    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    # check for the expected number of calls to each rpc
    all_list = []
    for rpc_call in rpc.get_all_loadbalancers.call_args_list:
        all_list.append(str(rpc_call))
    assert len(all_list) > gtimeout+1
    one_list = []
    for rpc_call in rpc.get_service_by_loadbalancer_id.call_args_list:
        one_list.append(str(rpc_call))
    assert len(one_list) == gtimeout+1
    # check for the expected number of unique calls to each rpc
    assert len(set(all_list)) == 1
    assert len(set(one_list)) == 1
    # check for the expected status transitions
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'OFFLINE'),
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ERROR', 'OFFLINE')
    ]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'OFFLINE'),
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'OFFLINE'),
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ERROR', 'OFFLINE')
    ]
Example #12
0
def test_vcmp_create_listener(setup_bigip_devices, bigip, vcmp_setup,
                              vcmp_uris):
    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELISTENER)
    logcall(setup_bigip_devices, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == (set(vcmp_uris['vcmp_lb_uris'])
                           | set(vcmp_uris['vcmp_listener_uris']))
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-bigip-12.0.int.lineratesystems.com-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20'),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE')
    ]
    bigip_vlans = [v.fullPath for v in bigip.tm.net.vlans.get_collection()]
    assert GUEST_VLAN in bigip_vlans
    assert COMMON_VLAN not in bigip_vlans
    vcmp_host[0]['guest'].refresh()
    assert COMMON_VLAN in vcmp_host[0]['guest'].vlans
    assert vcmp_host[0]['bigip'].tm.net.vlans.vlan.exists(name='vlan-1-1-46',
                                                          partition='Common')
Example #13
0
def remove_elements(bigip, uris, vlan=False):
    for t in bigip.tm.net.fdb.tunnels.get_collection():
        if t.name != 'http-tunnel' and t.name != 'socks-tunnel':
            t.update(records=[])
    registry = register_device(bigip)
    ordered = order_by_weights(uris, AGENT_LB_DEL_ORDER)
    for selfLink in ordered:
        try:
            if selfLink in registry:
                registry[selfLink].delete()
        except iControlUnexpectedHTTPError as exc:
            sc = exc.response.status_code
            if sc == 404:
                logging.debug(sc)
            elif sc == 400 and 'fdb/tunnel' in selfLink and vlan:
                # If testing VLAN (with vCMP) the fdb tunnel cannot be deleted
                # directly. It goes away when the net tunnel is deleted
                continue
            elif sc == 400\
              and 'mgmt/tm/net/tunnels/tunnel/' in selfLink\
              and 'tunnel-vxlan' in selfLink:
                for t in bigip.tm.net.fdb.tunnels.get_collection():
                    if t.name != 'http-tunnel' and t.name != 'socks-tunnel':
                        t.update(records=[])
                registry[selfLink].delete()
            else:
                raise
Example #14
0
def test_vcmp_deletelb(track_bigip_cfg, setup_bigip_devices, bigip, vcmp_setup,
                       vcmp_uris):
    '''Create and delete lb with vcmp turned on.'''

    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-{}-ce69e293-56e7-43b8-'
              'b51c-01b91d66af20'.format(
                  pytest.symbols.icontrol_vcmp_host1['guest_hostname'])),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            deepcopy(DELETELB),
            delete_partition=True)
    # After the deletelb is called above, the vcmp guest should no longer
    # have the vlan attached
    check_host_and_guest_vlans_on_delete(vcmp_host[0], bigip)
    assert not hasattr(vcmp_host[0]['guest'], 'vlans')
def test_vcmp_createlb(setup_bigip_devices, bigip, vcmp_setup, vcmp_uris):
    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-bigip-12.0.int.lineratesystems.com-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20'),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    # Since the loadbalancer was not deleted via a service object, we should
    # have a leftover VLAN on the vCMP host and the VLAN should be associated
    # with the guest, and the VLAN from within the guest should be there
    bigip_vlans = [v.fullPath for v in bigip.tm.net.vlans.get_collection()]
    assert GUEST_VLAN in bigip_vlans
    assert COMMON_VLAN not in bigip_vlans
    vcmp_host[0]['guest'].refresh()
    assert COMMON_VLAN in vcmp_host[0]['guest'].vlans
    assert vcmp_host[0]['bigip'].tm.net.vlans.vlan.exists(
        name='vlan-1-1-46', partition='Common')
def test_withsegid_listener(setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_ON)
    service = deepcopy(SEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == (SEG_INDEPENDENT_LB_URIS | SEG_DEPENDENT_LB_URIS
                           | SEG_LISTENER_URIS)
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    assert rpc.get_port_by_name.call_args_list == [
        call(port_name=u'local-' + icontrol_fqdn +
             '-ce69e293-56e7-43b8-b51c-01b91d66af20'),
        call(port_name=u'snat-traffic-group-local-only-'
             'ce69e293-56e7-43b8-b51c-01b91d66af20_0')
    ]
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE')
    ]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
Example #17
0
def test_vcmp_createlb(track_bigip_cfg, setup_bigip_devices, bigip, vcmp_setup,
                       vcmp_uris):
    '''Create lb with vcmp turned on.'''

    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-{}-ce69e293-56e7-43b8-b51c'
              '-01b91d66af20'.format(
                  pytest.symbols.icontrol_vcmp_host1['guest_hostname'])),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    # Since the loadbalancer was not deleted via a service object, we should
    # have a leftover VLAN on the vCMP host and the VLAN should be associated
    # with the guest, and the VLAN from within the guest should be there
    check_host_and_guest_vlans_on_create(vcmp_host[0], bigip)
def test_vcmp_deletelb(setup_bigip_devices, bigip, vcmp_setup, vcmp_uris):
    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-bigip-12.0.int.lineratesystems.com-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20'),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            deepcopy(DELETELB),
            delete_partition=True)
    # After the deletelb is called above, the vcmp guest should no longer
    bigip_vlans = [v.fullPath for v in bigip.tm.net.vlans.get_collection()]
    assert GUEST_VLAN not in bigip_vlans
    assert COMMON_VLAN not in bigip_vlans
    vcmp_host[0]['guest'].refresh()
    assert not hasattr(vcmp_host[0]['guest'], 'vlans')
    assert not vcmp_host[0]['bigip'].tm.net.vlans.vlan.exists(
        name='vlan-1-1-46', partition='Common')
Example #19
0
def remove_elements(bigip, uris, vlan=False):
    for t in bigip.tm.net.fdb.tunnels.get_collection():
        if t.name != 'http-tunnel' and t.name != 'socks-tunnel':
            t.update(records=[])
    registry = register_device(bigip)
    ordered = order_by_weights(uris, AGENT_LB_DEL_ORDER)
    for selfLink in ordered:
        try:
            if selfLink in registry:
                registry[selfLink].delete()
        except iControlUnexpectedHTTPError as exc:
            sc = exc.response.status_code
            if sc == 404:
                logging.debug(sc)
            elif sc == 400 and 'fdb/tunnel' in selfLink and vlan:
                # If testing VLAN (with vCMP) the fdb tunnel cannot be deleted
                # directly. It goes away when the net tunnel is deleted
                continue
            elif sc == 400\
              and 'mgmt/tm/net/tunnels/tunnel/' in selfLink\
              and 'tunnel-vxlan' in selfLink:
                for t in bigip.tm.net.fdb.tunnels.get_collection():
                    if t.name != 'http-tunnel' and t.name != 'socks-tunnel':
                        t.update(records=[])
                registry[selfLink].delete()
            else:
                raise
Example #20
0
def test_vcmp_deletelb(track_bigip_cfg, setup_bigip_devices, bigip, vcmp_setup,
                       vcmp_uris):
    '''Create and delete lb with vcmp turned on.'''

    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-{}-ce69e293-56e7-43b8-'
              'b51c-01b91d66af20'.format(
                  pytest.symbols.icontrol_vcmp_host1['guest_hostname'])),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            deepcopy(DELETELB),
            delete_partition=True)
    # After the deletelb is called above, the vcmp guest should no longer
    # have the vlan attached
    check_host_and_guest_vlans_on_delete(vcmp_host[0], bigip)
    assert not hasattr(vcmp_host[0]['guest'], 'vlans')
def test_featureoff_grm_listener(setup_l2adjacent_test, bigip):
    def create_mock_rpc_plugin():
        mock_rpc_plugin = mock.MagicMock(name='mock_rpc_plugin')
        mock_rpc_plugin.get_port_by_name.return_value = [
            {'fixed_ips': [{'ip_address': '10.2.2.134'}]}
        ]
        mock_rpc_plugin.get_all_loadbalancers.return_value = [
            {'lb_id': u'50c5d54a-5a9e-4a80-9e74-8400a461a077',
             'tenant_id': u'128a63ef33bc4cf891d684fad58e7f2d'
            }
        ]
        return mock_rpc_plugin

    icontroldriver, start_registry = handle_init_registry(bigip,
                                                          FEATURE_OFF_GRM,
                                                          create_mock_rpc_plugin)

    service = deepcopy(SEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    empty_set = set()

    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == (SEG_INDEPENDENT_LB_URIS_GRM | NOSEG_LB_URIS |
                           NOSEG_LISTENER_URIS)

    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
Example #22
0
def test_vcmp_create_listener(track_bigip_cfg, setup_bigip_devices, bigip,
                              vcmp_setup, vcmp_uris):
    '''Create listener with vcmp turned on.'''

    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELISTENER)
    logcall(setup_bigip_devices, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == (set(vcmp_uris['vcmp_lb_uris'])
                           | set(vcmp_uris['vcmp_listener_uris']))
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-{}-ce69e293-56e7-43b8-b51c'
              '-01b91d66af20'.format(
                  pytest.symbols.icontrol_vcmp_host1['guest_hostname'])),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE')
    ]
    check_host_and_guest_vlans_on_create(vcmp_host[0], bigip)
def test_vcmp_create_listener(
        setup_bigip_devices, bigip, vcmp_setup, vcmp_uris):
    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELISTENER)
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == (
        set(vcmp_uris['vcmp_lb_uris']) | set(vcmp_uris['vcmp_listener_uris']))
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-bigip-12.0.int.lineratesystems.com-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20'),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE')
    ]
    bigip_vlans = [v.fullPath for v in bigip.tm.net.vlans.get_collection()]
    assert GUEST_VLAN in bigip_vlans
    assert COMMON_VLAN not in bigip_vlans
    vcmp_host[0]['guest'].refresh()
    assert COMMON_VLAN in vcmp_host[0]['guest'].vlans
    assert vcmp_host[0]['bigip'].tm.net.vlans.vlan.exists(
        name='vlan-1-1-46', partition='Common')
def test_featureoff_grm_listener(setup_l2adjacent_test, bigip):
    def create_mock_rpc_plugin():
        mock_rpc_plugin = mock.MagicMock(name='mock_rpc_plugin')
        mock_rpc_plugin.get_port_by_name.return_value = [{
            'fixed_ips': [{
                'ip_address': '10.2.2.134'
            }]
        }]
        mock_rpc_plugin.get_all_loadbalancers.return_value = [{
            'lb_id':
            u'50c5d54a-5a9e-4a80-9e74-8400a461a077',
            'tenant_id':
            u'128a63ef33bc4cf891d684fad58e7f2d'
        }]
        return mock_rpc_plugin

    icontroldriver, start_registry = handle_init_registry(
        bigip, FEATURE_OFF_GRM, create_mock_rpc_plugin)

    service = deepcopy(SEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    empty_set = set()

    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == (SEG_INDEPENDENT_LB_URIS_GRM | NOSEG_LB_URIS
                           | NOSEG_LISTENER_URIS)

    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
def test_withsegid_listener(setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_ON)
    service = deepcopy(SEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == (SEG_INDEPENDENT_LB_URIS |
                           SEG_DEPENDENT_LB_URIS |
                           SEG_LISTENER_URIS)
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    assert rpc.get_port_by_name.call_args_list == [
        call(port_name=u'local-' + icontrol_fqdn + '-ce69e293-56e7-43b8-b51c-01b91d66af20'),
        call(port_name=u'snat-traffic-group-local-only-'
                       'ce69e293-56e7-43b8-b51c-01b91d66af20_0')
    ]
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE')
    ]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
Example #26
0
def test_vcmp_create_listener(
        track_bigip_cfg, setup_bigip_devices, bigip, vcmp_setup, vcmp_uris):
    '''Create listener with vcmp turned on.'''

    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELISTENER)
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == (
        set(vcmp_uris['vcmp_lb_uris']) | set(vcmp_uris['vcmp_listener_uris']))
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-{}-ce69e293-56e7-43b8-b51c'
              '-01b91d66af20'.format(
                  pytest.symbols.icontrol_vcmp_host1['guest_hostname'])),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE')
    ]
    check_host_and_guest_vlans_on_create(vcmp_host[0], bigip)
Example #27
0
def test_vcmp_createlb(track_bigip_cfg, setup_bigip_devices, bigip, vcmp_setup,
                       vcmp_uris):
    '''Create lb with vcmp turned on.'''

    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-{}-ce69e293-56e7-43b8-b51c'
              '-01b91d66af20'.format(
                  pytest.symbols.icontrol_vcmp_host1['guest_hostname'])),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    # Since the loadbalancer was not deleted via a service object, we should
    # have a leftover VLAN on the vCMP host and the VLAN should be associated
    # with the guest, and the VLAN from within the guest should be there
    check_host_and_guest_vlans_on_create(vcmp_host[0], bigip)
def test_nosegid_lb(setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_ON)
    service = deepcopy(NOSEGID_CREATELB)
    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == SEG_INDEPENDENT_LB_URIS
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    assert not rpc.update_loadbalancer_status.called
def test_nosegid_lb(setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_ON)
    service = deepcopy(NOSEGID_CREATELB)
    logcall(setup_l2adjacent_test,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == SEG_INDEPENDENT_LB_URIS
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    assert not rpc.update_loadbalancer_status.called
Example #30
0
def setup_neutronless_test(request, bigip, makelogdir, vlan=False):
    pretest_snapshot = frozenset(register_device(bigip))

    logname = os.path.join(makelogdir, request.function.__name__)
    loghandler = _get_nolevel_handler(logname)

    def remove_test_created_elements():
        posttest_registry = register_device(bigip)
        created = frozenset(posttest_registry) - pretest_snapshot
        remove_elements(bigip, created, vlan)
        rootlogger = logging.getLogger()
        rootlogger.removeHandler(loghandler)

    request.addfinalizer(remove_test_created_elements)
    return loghandler
Example #31
0
def setup_neutronless_test(request, bigip, makelogdir, vlan=False):
    pretest_snapshot = frozenset(register_device(bigip))

    logname = os.path.join(makelogdir, request.function.__name__)
    loghandler = _get_nolevel_handler(logname)

    def remove_test_created_elements():
        posttest_registry = register_device(bigip)
        created = frozenset(posttest_registry) - pretest_snapshot
        remove_elements(bigip, created, vlan)
        rootlogger = logging.getLogger()
        rootlogger.removeHandler(loghandler)

    request.addfinalizer(remove_test_created_elements)
    return loghandler
def test_featureoff_nosegid_listener(setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_OFF)
    service = deepcopy(NOSEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == SEG_INDEPENDENT_LB_URIS
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_MISCONFIG in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ERROR', 'OFFLINE')
    ]
def test_featureoff_nosegid_listener(setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_OFF)
    service = deepcopy(NOSEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == SEG_INDEPENDENT_LB_URIS
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_MISCONFIG in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ERROR', 'OFFLINE')
    ]
Example #34
0
 def reset_device_to_pretest_snapshot(self):
     posttest_snapshot = register_device(self.bigip)
     test_diff = frozenset(posttest_snapshot) - \
         frozenset(self.pretest_snapshot)
     uris = order_by_weights(test_diff, URI_ORDER)
     filtered = [u for u in uris for a in URI_ORDER if a in u]
     for selfLink in filtered:
         try:
             if selfLink in test_diff:
                 posttest_snapshot[selfLink].delete()
         except iControlUnexpectedHTTPError as exc:
             if 'fdb/tunnel' in selfLink:
                 for t in self.bigip.tm.net.fdb.tunnels.get_collection():
                     if t.name != 'http-tunnel' \
                             and t.name != 'socks-tunnel':
                         t.update(records=[])
                 posttest_snapshot[selfLink].delete()
             else:
                 raise exc
Example #35
0
def test_nosegid_listener(setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_ON)
    service = deepcopy(NOSEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == SEG_INDEPENDENT_LB_URIS | NOSEG_LISTENER_URIS
    rpc = icontroldriver.plugin_rpc
    print(rpc.method_calls)
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'OFFLINE')
    ]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'OFFLINE')
    ]
    def reset_device_to_pretest_snapshot(self):
        posttest_snapshot = register_device(self.bigip)
        test_diff = frozenset(posttest_snapshot) - \
            frozenset(self.pretest_snapshot)
        uris = order_by_weights(test_diff, URI_ORDER)

        # Delete all tunnel records, if any exist
        for t in self.bigip.tm.net.fdb.tunnels.get_collection():
            if t.name != 'http-tunnel' \
                    and t.name != 'socks-tunnel':
                t.modify(records=None)

        # Delete resources from device
        for selfLink in uris:
            if selfLink in test_diff:
                if 'fdb' in selfLink:
                    continue
                if 'snat-translation' in selfLink:
                    continue
                posttest_snapshot[selfLink].delete()
def test_featureoff_nosegid_common_lb_net(track_bigip_cfg,
                                          setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = \
        handle_init_registry(bigip, FEATURE_OFF_COMMON_NET)
    service = deepcopy(NOSEGID_CREATELB)
    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = UrlSnips.strip_version(
        set(after_create_registry.keys()) - set(start_registry.keys()))
    assert create_uris == SEG_INDEPENDENT_LB_URIS_COMMON_NET | \
        SEG_INDEPENDENT_LB_URIS | \
        NOSEG_LB_URIS
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
Example #38
0
def test_vcmp_deletelb_with_mgmt_vlan(
        track_bigip_cfg, setup_bigip_devices, bigip, vcmp_setup, vcmp_uris,
        mgmt_vlan):
    '''Create and delete lb with vcmp turned on and mgmt vlan exists.

    We need to ensure a pre-existing management vlan, which is associated
    with the guest outside of the agent's control, actually stays associated
    once the last loadbalancer is torn down.
    '''

    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-{}-ce69e293-56e7-43b8-'
              'b51c-01b91d66af20'.format(
                  pytest.symbols.icontrol_vcmp_host1['guest_hostname'])),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            deepcopy(DELETELB),
            delete_partition=True)
    # After the deletelb is called above, the vcmp guest should no longer
    # have vlan-46
    check_host_and_guest_vlans_on_delete(vcmp_host[0], bigip)
    # mgmt_vlan should remain associated with guest
    assert vcmp_host[0]['guest'].vlans == ['/Common/mgmt_vlan']
Example #39
0
def test_vcmp_deletelb_with_mgmt_vlan(
        track_bigip_cfg, setup_bigip_devices, bigip, vcmp_setup, vcmp_uris,
        mgmt_vlan):
    '''Create and delete lb with vcmp turned on and mgmt vlan exists.

    We need to ensure a pre-existing management vlan, which is associated
    with the guest outside of the agent's control, actually stays associated
    once the last loadbalancer is torn down.
    '''

    vcmp_host = vcmp_setup
    icontroldriver, start_registry = handle_init_registry(bigip, VCMP_CONFIG)
    service = deepcopy(CREATELB)
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == set(vcmp_uris['vcmp_lb_uris'])
    rpc = icontroldriver.plugin_rpc
    assert rpc.get_port_by_name.call_args_list == \
        [call(port_name=u'local-{}-ce69e293-56e7-43b8-'
              'b51c-01b91d66af20'.format(
                  pytest.symbols.icontrol_vcmp_host1['guest_hostname'])),
         call(port_name=u'snat-traffic-group-local-only-ce69e293-'
              '56e7-43b8-b51c-01b91d66af20_0')]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    logcall(setup_bigip_devices,
            icontroldriver._common_service_handler,
            deepcopy(DELETELB),
            delete_partition=True)
    # After the deletelb is called above, the vcmp guest should no longer
    # have vlan-46
    check_host_and_guest_vlans_on_delete(vcmp_host[0], bigip)
    # mgmt_vlan should remain associated with guest
    assert vcmp_host[0]['guest'].vlans == ['/Common/mgmt_vlan']
def test_featureoff_nosegid_create_listener_common_lb_net(setup_l2adjacent_test, bigip):
    icontroldriver, start_registry = handle_init_registry(bigip, FEATURE_OFF_COMMON_NET)
    service = deepcopy(NOSEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test,
            icontroldriver._common_service_handler,
            service)
    after_create_registry = register_device(bigip)
    create_uris = (set(after_create_registry.keys()) -
                   set(start_registry.keys()))
    assert create_uris == SEG_INDEPENDENT_LB_URIS_COMMON_NET | \
        SEG_INDEPENDENT_LB_URIS | \
        NOSEG_LB_URIS | NOSEG_LISTENER_URIS

    logfilename = setup_l2adjacent_test.baseFilename
    assert not ERROR_MSG_MISCONFIG in open(logfilename).read()
    rpc = icontroldriver.plugin_rpc

    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    ]
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE')
    ]
Example #41
0
def setup_registry_snapshot(bigip):
    # Setup device registries
    pp('inside setup_registry_snapshot')
    return frozenset(register_device(bigip))
Example #42
0
 def remove_test_created_elements():
     for bigip in bigips:
         posttest_registry = register_device(bigip.device)
         created = frozenset(posttest_registry) - bigip.pretest_snapshot
         remove_elements(bigip.device, created, vlan=True)
def test_nosegid_to_segid(setup_l2adjacent_test, bigip):
    def create_swing_mock_rpc_plugin():
        # set up mock to return segid after 3 polling attempts
        mock_rpc_plugin = mock.MagicMock(name='swing_mock_rpc_plugin')
        mock_rpc_plugin.get_port_by_name.return_value = [
            {'fixed_ips': [{'ip_address': '10.2.2.134'}]}
        ]
        no_lb = []
        one_lb = [{'lb_id': '50c5d54a-5a9e-4a80-9e74-8400a461a077'}]
        mock_rpc_plugin.get_all_loadbalancers.side_effect = [
            no_lb, no_lb, no_lb, no_lb,
            one_lb, one_lb, one_lb, one_lb, one_lb, one_lb, one_lb, one_lb
        ]
        miss = deepcopy(NOSEGID_CREATELISTENER)
        miss['loadbalancer']['provisioning_status'] = "ACTIVE"
        hit = deepcopy(SEGID_CREATELISTENER)
        hit['loadbalancer']['provisioning_status'] = "ACTIVE"
        mock_rpc_plugin.get_service_by_loadbalancer_id.side_effect = [
            miss, deepcopy(miss), deepcopy(miss),
            hit, deepcopy(hit), deepcopy(hit), deepcopy(hit), deepcopy(hit),
            deepcopy(hit), deepcopy(hit), deepcopy(hit), deepcopy(hit)
        ]
        return mock_rpc_plugin
    # Configure
    icontroldriver, start_registry = handle_init_registry(
        bigip, FEATURE_ON, create_swing_mock_rpc_plugin)
    gtimeout = icontroldriver.conf.f5_network_segment_gross_timeout
    # Begin operations
    service = deepcopy(NOSEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test,
            icontroldriver._common_service_handler,
            service)
    # Before gtimeout
    time.sleep(gtimeout)
    create_registry = register_device(bigip)
    create_uris = set(create_registry.keys()) - set(start_registry.keys())

    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    # check for the expected number of calls to each rpc
    all_list = []
    for rpc_call in rpc.get_all_loadbalancers.call_args_list:
        all_list.append(str(rpc_call))
    assert len(all_list) > gtimeout
    one_list = []
    for rpc_call in rpc.get_service_by_loadbalancer_id.call_args_list:
        one_list.append(str(rpc_call))
    assert len(one_list) >= gtimeout
    # check for the expected number of unique calls to each rpc
    assert len(set(all_list)) == 1
    assert len(set(one_list)) == 1
    assert create_uris == (SEG_INDEPENDENT_LB_URIS |
                           SEG_DEPENDENT_LB_URIS |
                           SEG_LISTENER_URIS)
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_TIMEOUT not in open(logfilename).read()
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    # check that the last status update takes the object online
    assert list(rpc.update_loadbalancer_status.call_args_list)[-1] == (
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE')
    )
    assert rpc.update_listener_status.call_args_list[-1] == (
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE')
    )
Example #44
0
 def remove_test_created_elements():
     posttest_registry = register_device(bigip)
     created = frozenset(posttest_registry) - pretest_snapshot
     remove_elements(bigip, created, vlan)
     rootlogger = logging.getLogger()
     rootlogger.removeHandler(loghandler)
Example #45
0
 def remove_test_created_elements():
     for device in bigips:
         pretest_snapshot = frozenset(register_device(device))
         posttest_registry = register_device(device)
         created = frozenset(posttest_registry) - pretest_snapshot
         remove_elements(device, created, vlan=True)
Example #46
0
 def remove_test_created_elements():
     for bigip in bigips:
         posttest_registry = register_device(bigip.device)
         created = frozenset(posttest_registry) - bigip.pretest_snapshot
         remove_elements(bigip.device, created, vlan=True)
Example #47
0
 def remove_test_created_elements():
     for device in bigips:
         pretest_snapshot = frozenset(register_device(device))
         posttest_registry = register_device(device)
         created = frozenset(posttest_registry) - pretest_snapshot
         remove_elements(device, created, vlan=True)
Example #48
0
 def remove_test_created_elements():
     posttest_registry = register_device(bigip)
     created = frozenset(posttest_registry) - pretest_snapshot
     remove_elements(bigip, created, vlan)
     rootlogger = logging.getLogger()
     rootlogger.removeHandler(loghandler)
 def snapshot_device(self):
     self.pretest_snapshot = register_device(self.bigip)
Example #50
0
 def remove_test_created_elements():
     posttest_registry = register_device(bigip)
     created = frozenset(posttest_registry) - pretest_snapshot
     ordered = _deletion_order(created)
     for selfLink in ordered:
         posttest_registry[selfLink].delete()
def test_nosegid_listener_timeout(setup_l2adjacent_test, bigip):
    def create_mock_rpc_plugin():
        mock_rpc_plugin = mock.MagicMock(name='mock_rpc_plugin')
        mock_rpc_plugin.get_port_by_name.return_value = [{
            'fixed_ips': [{
                'ip_address': '10.2.2.134'
            }]
        }]
        mock_rpc_plugin.get_all_loadbalancers.return_value = [{
            'lb_id':
            u'50c5d54a-5a9e-4a80-9e74-8400a461a077'
        }]
        service = deepcopy(NOSEGID_CREATELISTENER)
        service['loadbalancer']['provisioning_status'] = "ACTIVE"
        mock_rpc_plugin.get_service_by_loadbalancer_id.return_value = service
        return mock_rpc_plugin

    # Configure
    icontroldriver, start_registry = handle_init_registry(
        bigip, FEATURE_ON, create_mock_rpc_plugin)
    gtimeout = icontroldriver.conf.f5_network_segment_gross_timeout
    poll_interval = icontroldriver.conf.f5_network_segment_polling_interval
    service = deepcopy(NOSEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    # Set timers
    start_time = time.time()
    timeout = start_time + gtimeout
    # Begin operations
    while time.time() < (timeout + (2 * poll_interval)):
        time.sleep(poll_interval)
        create_registry = register_device(bigip)
        create_uris = set(create_registry.keys()) - set(start_registry.keys())
        assert create_uris == (SEG_INDEPENDENT_LB_URIS | NOSEG_LISTENER_URIS
                               | NOSEG_LB_URIS)
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    assert ERROR_MSG_TIMEOUT in open(logfilename).read()

    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    # check for the expected number of calls to each rpc
    all_list = []
    for rpc_call in rpc.get_all_loadbalancers.call_args_list:
        all_list.append(str(rpc_call))
    assert len(all_list) > gtimeout + 1
    one_list = []
    for rpc_call in rpc.get_service_by_loadbalancer_id.call_args_list:
        one_list.append(str(rpc_call))
    assert len(one_list) == gtimeout + 1
    # check for the expected number of unique calls to each rpc
    assert len(set(all_list)) == 1
    assert len(set(one_list)) == 1
    # check for the expected status transitions
    assert rpc.update_listener_status.call_args_list == [
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'OFFLINE'),
        call(u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ERROR', 'OFFLINE')
    ]
    assert rpc.update_loadbalancer_status.call_args_list == [
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'OFFLINE'),
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'OFFLINE'),
        call(u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ERROR', 'OFFLINE')
    ]
def test_nosegid_to_segid(setup_l2adjacent_test, bigip):
    def create_swing_mock_rpc_plugin():
        # set up mock to return segid after 3 polling attempts
        mock_rpc_plugin = mock.MagicMock(name='swing_mock_rpc_plugin')
        mock_rpc_plugin.get_port_by_name.return_value = [{
            'fixed_ips': [{
                'ip_address': '10.2.2.134'
            }]
        }]
        no_lb = []
        one_lb = [{'lb_id': '50c5d54a-5a9e-4a80-9e74-8400a461a077'}]
        mock_rpc_plugin.get_all_loadbalancers.side_effect = [
            no_lb, no_lb, no_lb, no_lb, one_lb, one_lb, one_lb, one_lb, one_lb,
            one_lb, one_lb, one_lb
        ]
        miss = deepcopy(NOSEGID_CREATELISTENER)
        miss['loadbalancer']['provisioning_status'] = "ACTIVE"
        hit = deepcopy(SEGID_CREATELISTENER)
        hit['loadbalancer']['provisioning_status'] = "ACTIVE"
        mock_rpc_plugin.get_service_by_loadbalancer_id.side_effect = [
            miss,
            deepcopy(miss),
            deepcopy(miss), hit,
            deepcopy(hit),
            deepcopy(hit),
            deepcopy(hit),
            deepcopy(hit),
            deepcopy(hit),
            deepcopy(hit),
            deepcopy(hit),
            deepcopy(hit)
        ]
        return mock_rpc_plugin

    # Configure
    icontroldriver, start_registry = handle_init_registry(
        bigip, FEATURE_ON, create_swing_mock_rpc_plugin)
    gtimeout = icontroldriver.conf.f5_network_segment_gross_timeout
    # Begin operations
    service = deepcopy(NOSEGID_CREATELISTENER)
    logcall(setup_l2adjacent_test, icontroldriver._common_service_handler,
            service)
    # Before gtimeout
    time.sleep(gtimeout)
    create_registry = register_device(bigip)
    create_uris = set(create_registry.keys()) - set(start_registry.keys())

    rpc = icontroldriver.plugin_rpc
    LOG.debug(rpc.method_calls)
    # check for the expected number of calls to each rpc
    all_list = []
    for rpc_call in rpc.get_all_loadbalancers.call_args_list:
        all_list.append(str(rpc_call))
    assert len(all_list) > gtimeout
    one_list = []
    for rpc_call in rpc.get_service_by_loadbalancer_id.call_args_list:
        one_list.append(str(rpc_call))
    assert len(one_list) >= gtimeout
    # check for the expected number of unique calls to each rpc
    assert len(set(all_list)) == 1
    assert len(set(one_list)) == 1
    assert create_uris == (SEG_INDEPENDENT_LB_URIS | SEG_DEPENDENT_LB_URIS
                           | SEG_LISTENER_URIS)
    logfilename = setup_l2adjacent_test.baseFilename
    assert ERROR_MSG_TIMEOUT not in open(logfilename).read()
    assert ERROR_MSG_VXLAN_TUN not in open(logfilename).read()
    assert ERROR_MSG_MISCONFIG not in open(logfilename).read()
    # check that the last status update takes the object online
    assert list(rpc.update_loadbalancer_status.call_args_list)[-1] == (call(
        u'50c5d54a-5a9e-4a80-9e74-8400a461a077', 'ACTIVE', 'ONLINE'))
    assert rpc.update_listener_status.call_args_list[-1] == (call(
        u'105a227a-cdbf-4ce3-844c-9ebedec849e9', 'ACTIVE', 'ONLINE'))