Example #1
0
def test_HA_load_balancing_both_scopes_for_primary(dhcp_version, backend):
    # HA SERVER 1
    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    if dhcp_version == "v6":
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::20')
        world.dhcp_cfg["subnet6"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet6"][0]["pools"].append({
            "pool":
            "2001:db8:1::100-2001:db8:1::120",
            "client-class":
            "HA_server2"
        })
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.20')
        world.dhcp_cfg["subnet4"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet4"][0]["pools"].append({
            "pool":
            "192.168.50.100-192.168.50.120",
            "client-class":
            "HA_server2"
        })
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address)
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(LOAD_BALANCING)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 100,
        "max-response-delay": 1500,
        "max-unacked-clients": 2,
        "this-server-name": "server1"
    })

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    # we don't need it, server1 wont detect server2 and will go straight to partner-down

    resp = wait_until_ha_state('partner-down', dhcp_version=dhcp_version)
    # wait_until_ha_state('load-balancing', dhcp_version=dhcp_version, dest=world.f_cfg.mgmt_address_2)
    assert "server2" in resp["arguments"]["scopes"]
    assert "server1" in resp["arguments"]["scopes"]
    misc.test_procedure()
    # get 10 leases some form server1 and some from server2
    l_count = 40
    set_of_leases_1 = generate_leases(leases_count=l_count,
                                      iaid=1,
                                      iapd=0,
                                      dhcp_version=dhcp_version)
    assert l_count == len(
        set_of_leases_1), "Server didn't give us all leases it had configured"
    srv_msg.check_leases(set_of_leases_1)
Example #2
0
def test_HA_passive_backup_sync(dhcp_version, backend):
    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    if dhcp_version == 'v6':
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::ffff')
    elif dhcp_version == 'v4':
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.200')
    srv_control.open_control_channel()
    srv_control.agent_control_channel()

    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(PASSIVE_BACKUP)
    srv_control.update_ha_hook_parameter({"this-server-name": "server1"})

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    # we have to clear data on second system, before test forge does not know that we have multiple systems
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)
    if dhcp_version == 'v6':
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::ffff')
    elif dhcp_version == 'v4':
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.200')
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address_2)

    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(PASSIVE_BACKUP)
    srv_control.update_ha_hook_parameter({"this-server-name": "server2"})

    srv_control.build_and_send_config_files(dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    wait_until_ha_state('passive-backup', dhcp_version=dhcp_version)
    set_of_leases_1 = generate_leases(leases_count=5,
                                      iaid=3,
                                      iapd=2,
                                      dhcp_version=dhcp_version)
    # we have no confirmation in syncing so just let's wait a bit
    srv_msg.forge_sleep(2, 'seconds')
    # check synced leases
    srv_msg.check_leases(set_of_leases_1, backend=backend)
    srv_msg.check_leases(set_of_leases_1,
                         backend=backend,
                         dest=world.f_cfg.mgmt_address_2)
Example #3
0
def test_v4_all_hooks_start():

    misc.test_setup()
    srv_control.config_srv_subnet('192.168.50.0/24',
                                  '192.168.50.1-192.168.50.1')
    # flex id
    srv_control.host_reservation_in_subnet('hostname', 'reserved-hostname',
                                           '0', 'flex-id', '\'docsis3.0\'')
    srv_control.host_reservation_in_subnet_add_value('0', '0', 'address',
                                                     '192.168.50.10')
    srv_control.add_line(
        '"host-reservation-identifiers": [ "flex-id","hw-address" ]')
    srv_control.add_hooks('libdhcp_flex_id.so')
    srv_control.add_parameter_to_hook('1', 'identifier-expression',
                                      'option[60].hex')
    # legal log
    srv_control.add_hooks('libdhcp_legal_log.so')
    srv_control.add_hooks('libdhcp_host_cmds.so')
    srv_control.add_hooks('libdhcp_stat_cmds.so')
    srv_control.add_hooks('libdhcp_subnet_cmds.so')
    srv_control.add_hooks('libdhcp_host_cache.so')
    srv_control.add_hooks('libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('libdhcp_ha.so')
    srv_control.add_parameter_to_ha_hook('this-server-name', '"server1"')
    srv_control.add_parameter_to_ha_hook('mode', '"load-balancing"')
    srv_control.add_parameter_to_ha_hook('heartbeat-delay', '1000')
    srv_control.add_parameter_to_ha_hook('max-response-delay', '1001')
    srv_control.add_parameter_to_ha_hook('max-unacked-clients', '0')
    srv_control.add_parameter_to_ha_hook('max-ack-delay', '0')

    srv_control.add_parameter_to_ha_hook(
        'peers',
        '{"name":"server1","url":"http://$(MGMT_ADDRESS):8080/","role":"primary","auto-failover":true}'
    )
    srv_control.add_parameter_to_ha_hook(
        'peers',
        '{"name":"server2","url":"http://$(MGMT_ADDRESS_2):8080/","role":"secondary","auto-failover":true}'
    )

    srv_control.open_control_channel()
    srv_control.build_and_send_config_files('SSH', 'config-file')

    srv_control.start_srv('DHCP', 'started')
    srv_msg.send_ctrl_cmd_via_socket(
        '{"command": "list-commands","arguments": {}}')
Example #4
0
def test_v4_all_hooks_start():

    misc.test_setup()
    srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.1')
    # flex id
    srv_control.host_reservation_in_subnet('hostname',
                                           'reserved-hostname',
                                           '0',
                                           'flex-id',
                                           '\'docsis3.0\'')
    srv_control.host_reservation_in_subnet_add_value('0', '0', 'address', '192.168.50.10')
    srv_control.add_line('"host-reservation-identifiers": [ "flex-id","hw-address" ]')
    srv_control.add_hooks('$(SOFTWARE_INSTALL_DIR)/lib/kea/hooks/libdhcp_flex_id.so')
    srv_control.add_parameter_to_hook('1', 'identifier-expression', 'option[60].hex')
    # legal log
    srv_control.add_hooks('$(SOFTWARE_INSTALL_DIR)/lib/kea/hooks/libdhcp_legal_log.so')
    srv_control.add_hooks('$(SOFTWARE_INSTALL_DIR)/lib/kea/hooks/libdhcp_host_cmds.so')
    srv_control.add_hooks('$(SOFTWARE_INSTALL_DIR)/lib/kea/hooks/libdhcp_stat_cmds.so')
    srv_control.add_hooks('$(SOFTWARE_INSTALL_DIR)/lib/kea/hooks/libdhcp_subnet_cmds.so')
    srv_control.add_hooks('$(SOFTWARE_INSTALL_DIR)/lib/kea/hooks/libdhcp_host_cache.so')
    srv_control.add_hooks('$(SOFTWARE_INSTALL_DIR)/lib/kea/hooks/libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('$(SOFTWARE_INSTALL_DIR)/lib/kea/hooks/libdhcp_ha.so')
    srv_control.add_parameter_to_ha_hook('this-server-name', '"server1"')
    srv_control.add_parameter_to_ha_hook('mode', '"load-balancing"')
    srv_control.add_parameter_to_ha_hook('heartbeat-delay', '1000')
    srv_control.add_parameter_to_ha_hook('max-response-delay', '1001')
    srv_control.add_parameter_to_ha_hook('max-unacked-clients', '0')
    srv_control.add_parameter_to_ha_hook('max-ack-delay', '0')

    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server1","url":"http://$(MGMT_ADDRESS):8080/","role":"primary","auto-failover":true}')
    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server2","url":"http://$(MGMT_ADDRESS_2):8080/","role":"secondary","auto-failover":true}')

    srv_control.open_control_channel('unix', '$(SOFTWARE_INSTALL_DIR)/var/kea/control_socket')
    srv_control.build_and_send_config_files('SSH', 'config-file')

    srv_control.start_srv('DHCP', 'started')
    srv_msg.send_through_socket_server_site('$(SOFTWARE_INSTALL_DIR)/var/kea/control_socket',
                                            '{"command": "list-commands","arguments": {}}')
Example #5
0
def test_HA_load_balancing_both_scopes_for_secondary(dhcp_version, backend):
    # HA SERVER 1
    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    if dhcp_version == "v6":
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::20')
        world.dhcp_cfg["subnet6"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet6"][0]["pools"].append({
            "pool":
            "2001:db8:1::100-2001:db8:1::120",
            "client-class":
            "HA_server2"
        })
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.20')
        world.dhcp_cfg["subnet4"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet4"][0]["pools"].append({
            "pool":
            "192.168.50.100-192.168.50.120",
            "client-class":
            "HA_server2"
        })
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address)
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(LOAD_BALANCING)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1500,
        "max-unacked-clients": 0,
        "this-server-name": "server1"
    })

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    # we have to clear data on second system, before test forge does not know that we have multiple systems
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)

    if dhcp_version == "v6":
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::20')
        world.dhcp_cfg["subnet6"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet6"][0]["pools"].append({
            "pool":
            "2001:db8:1::100-2001:db8:1::120",
            "client-class":
            "HA_server2"
        })
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.20')
        world.dhcp_cfg["subnet4"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet4"][0]["pools"].append({
            "pool":
            "192.168.50.100-192.168.50.120",
            "client-class":
            "HA_server2"
        })
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address_2)
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(LOAD_BALANCING)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1500,
        "max-unacked-clients": 0,
        "this-server-name": "server2"
    })  # this is now secondary!

    srv_control.build_and_send_config_files(dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    wait_until_ha_state('load-balancing', dhcp_version=dhcp_version)
    wait_until_ha_state('load-balancing',
                        dhcp_version=dhcp_version,
                        dest=world.f_cfg.mgmt_address_2)

    # kill server1 and wait for secondary to go partner-down
    srv_control.start_srv('DHCP', 'stopped')
    resp = wait_until_ha_state('partner-down',
                               dhcp_version=dhcp_version,
                               dest=world.f_cfg.mgmt_address_2)
    assert "server2" in resp["arguments"]["scopes"]
    assert "server1" in resp["arguments"]["scopes"]
    misc.test_procedure()
    # get 10 leases some form server1 and some from server2
    l_count = 40
    set_of_leases_1 = generate_leases(leases_count=l_count,
                                      iaid=1,
                                      iapd=0,
                                      dhcp_version=dhcp_version)
    assert l_count == len(
        set_of_leases_1), "Server gave us %d leases, we wanted %d" % (
            len(set_of_leases_1), l_count)
    srv_msg.check_leases(set_of_leases_1, dest=world.f_cfg.mgmt_address_2)
Example #6
0
def test_HA_load_balancing_sync(dhcp_version, backend):
    # HA SERVER 1
    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    if dhcp_version == "v6":
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::5')
        world.dhcp_cfg["subnet6"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet6"][0]["pools"].append({
            "pool":
            "2001:db8:1::100-2001:db8:1::110",
            "client-class":
            "HA_server2"
        })
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.5')
        world.dhcp_cfg["subnet4"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet4"][0]["pools"].append({
            "pool":
            "192.168.50.20-192.168.50.30",
            "client-class":
            "HA_server2"
        })
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address)
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(LOAD_BALANCING)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1500,
        "max-unacked-clients": 0,
        "this-server-name": "server1"
    })

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    # we have to clear data on second system, before test forge does not know that we have multiple systems
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)

    if dhcp_version == "v6":
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::5')
        world.dhcp_cfg["subnet6"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet6"][0]["pools"].append({
            "pool":
            "2001:db8:1::100-2001:db8:1::110",
            "client-class":
            "HA_server2"
        })
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.5')
        world.dhcp_cfg["subnet4"][0]["pools"][0].update(
            {"client-class": "HA_server1"})
        world.dhcp_cfg["subnet4"][0]["pools"].append({
            "pool":
            "192.168.50.20-192.168.50.30",
            "client-class":
            "HA_server2"
        })
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address_2)
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(LOAD_BALANCING)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1500,
        "max-unacked-clients": 0,
        "this-server-name": "server2"
    })

    srv_control.build_and_send_config_files(dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    wait_until_ha_state('load-balancing', dhcp_version=dhcp_version)
    wait_until_ha_state('load-balancing',
                        dhcp_version=dhcp_version,
                        dest=world.f_cfg.mgmt_address_2)

    misc.test_procedure()
    # get 10 leases
    set_of_leases_1 = generate_leases(leases_count=10,
                                      iaid=1,
                                      iapd=0,
                                      dhcp_version=dhcp_version)

    # check if there are indeed saved
    srv_msg.check_leases(set_of_leases_1, backend=backend)
    # check if those were propagated to other system
    srv_msg.check_leases(set_of_leases_1,
                         dest=world.f_cfg.mgmt_address_2,
                         backend=backend)
    # turn off server2
    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)
    # dump leases and logs of server2
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)
    # start clean server2
    wait_until_ha_state('partner-down', dhcp_version=dhcp_version)
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)
    # let's wait for full synchronization of server2
    wait_until_ha_state('load-balancing', sleep=2, dhcp_version=dhcp_version)
    # check leases on server2
    srv_msg.check_leases(set_of_leases_1,
                         dest=world.f_cfg.mgmt_address_2,
                         backend=backend)

    # turn off server1
    srv_control.start_srv('DHCP', 'stopped')
    # dump leases and logs of server2
    srv_control.clear_some_data('all')
    # start clean server1
    wait_until_ha_state('partner-down',
                        dhcp_version=dhcp_version,
                        dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'started')
    # let's wait for full synchronization of server1
    wait_until_ha_state('load-balancing', sleep=2, dhcp_version=dhcp_version)
    # check leases on server1
    srv_msg.check_leases(set_of_leases_1, backend=backend)
Example #7
0
def test_v6_hooks_HA_page_size_sync_mulitple_NA():
    # HA SERVER 1
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64',
                                  '2001:db8:1::1-2001:db8:1::ffff')
    srv_control.config_srv_prefix('2001:db8:2::', 0, 48, 91)
    srv_control.config_srv_id('LLT',
                              '00:01:00:02:52:7b:a8:f0:08:00:27:58:f1:e8')
    srv_control.open_control_channel()
    srv_control.agent_control_channel('$(MGMT_ADDRESS)')
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(HOT_STANDBY)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1500,
        "max-unacked-clients": 0,
        'sync-page-limit': 2,
        "this-server-name": "server1"
    })

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)

    srv_control.config_srv_subnet('2001:db8:1::/64',
                                  '2001:db8:1::1-2001:db8:1::ffff')
    srv_control.config_srv_prefix('2001:db8:2::', 0, 48, 91)
    srv_control.config_srv_id('LLT',
                              '00:01:00:02:52:7b:a8:f0:08:00:27:58:99:99')
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address_2)
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(HOT_STANDBY)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1500,
        "max-unacked-clients": 0,
        'sync-page-limit': 2,
        "this-server-name": "server2"
    })

    srv_control.build_and_send_config_files(dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    wait_until_ha_state('hot-standby')
    misc.test_procedure()

    set_of_leases_1 = generate_leases(leases_count=5, iaid=3, iapd=2)
    srv_msg.check_leases(set_of_leases_1)
    srv_msg.check_leases(set_of_leases_1, dest=world.f_cfg.mgmt_address_2)
    # srv_msg.forge_sleep(2, 'seconds')

    # srv_msg.remote_log_includes_line(world.f_cfg.mgmt_address_2,
    #                                  '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log-CA',
    #                                  None,
    #                                  'Bulk apply of 4 IPv6 leases completed.')
    srv_control.start_srv('DHCP', 'stopped')
    wait_until_ha_state('partner-down', dest=world.f_cfg.mgmt_address_2)

    set_of_leases_2 = generate_leases(leases_count=5,
                                      iaid=3,
                                      iapd=2,
                                      mac="02:02:0c:03:0a:00")

    srv_control.start_srv('DHCP', 'started')
    wait_until_ha_state('hot-standby')

    srv_msg.check_leases(set_of_leases_1)
    srv_msg.check_leases(set_of_leases_2)
Example #8
0
def test_HA_hot_standby_different_page_size_sync(dhcp_version, backend):

    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    # we have to clear data on second system, before test forge does not know that we have multiple systems
    if dhcp_version == 'v6':
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::ffff')
    elif dhcp_version == 'v4':
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.200')
    srv_control.open_control_channel()
    srv_control.agent_control_channel()
    srv_control.configure_loggers('kea-dhcp6.dhcpsrv', 'DEBUG', 99)
    srv_control.configure_loggers('kea-dhcp6.ha-hooks', 'DEBUG', 99)
    srv_control.configure_loggers('kea-ctrl-agent', 'DEBUG', 99,
                                  'kea.log-CTRL')

    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(HOT_STANDBY)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1500,
        "max-unacked-clients": 0,
        "sync-page-limit": 10,
        "this-server-name": "server1"
    })

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')
    # HA SERVER 2
    misc.test_setup()
    srv_control.define_temporary_lease_db_backend(backend)
    # we have to clear data on second system, before test forge does not know that we have multiple systems
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)

    if dhcp_version == 'v6':
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::ffff')
    elif dhcp_version == 'v4':
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.200')
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address_2)
    srv_control.configure_loggers('kea-dhcp6.dhcpsrv', 'DEBUG', 99)
    srv_control.configure_loggers('kea-dhcp6.ha-hooks', 'DEBUG', 99)
    srv_control.configure_loggers('kea-ctrl-agent', 'DEBUG', 99,
                                  'kea.log-CTRL2')

    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')

    world.dhcp_cfg["hooks-libraries"][1].update(HOT_STANDBY)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1500,
        "max-unacked-clients": 0,
        "sync-page-limit": 15,
        "this-server-name": "server2"
    })

    srv_control.build_and_send_config_files(dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    wait_until_ha_state('hot-standby', dhcp_version=dhcp_version)
    set_of_leases_1 = generate_leases(leases_count=50,
                                      iaid=1,
                                      iapd=1,
                                      dhcp_version=dhcp_version)

    # turn off server2
    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)
    # dump leases and logs of server2
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)
    # start clean server2
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)
    # let's wait for full synchronization of server2
    wait_until_ha_state('hot-standby', sleep=2, dhcp_version=dhcp_version)

    # misc.pass_criteria()
    # if dhcp_version == 'v6':
    #     srv_msg.log_contains('DHCPSRV_MEMFILE_GET_PAGE6 obtaining at most 15 IPv6 leases starting')
    #     srv_msg.remote_log_includes_line(world.f_cfg.mgmt_address_2,
    #                                      '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
    #                                      None,
    #                                      'HA_LEASES_SYNC_LEASE_PAGE_RECEIVED received 15 leases from server1')
    #     srv_msg.remote_log_includes_line(world.f_cfg.mgmt_address_2,
    #                                      '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
    #                                      'NOT ',
    #                                      'DHCPSRV_MEMFILE_GET_PAGE6 obtaining at most 10 IPv6 leases starting from address 2001:')
    #     srv_msg.log_doesnt_contain('HA_LEASES_SYNC_LEASE_PAGE_RECEIVED received 10 leases from')
    #     srv_msg.remote_log_includes_line(world.f_cfg.mgmt_address_2,
    #                                      '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
    #                                      None,
    #                                      'HA_SYNC_SUCCESSFUL lease database synchronization with server1 completed successfully')
    # else:
    #     srv_msg.log_contains('DHCPSRV_MEMFILE_GET_PAGE4 obtaining at most 15 IPv4 leases starting')
    #     srv_msg.remote_log_includes_line(world.f_cfg.mgmt_address_2,
    #                                      '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
    #                                      None,
    #                                      'HA_LEASES_SYNC_LEASE_PAGE_RECEIVED received 15 leases from server1')
    #     srv_msg.remote_log_includes_line(world.f_cfg.mgmt_address_2,
    #                                      '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
    #                                      'NOT ',
    #                                      'DHCPSRV_MEMFILE_GET_PAGE6 obtaining at most 10 IPv4 leases starting from address =')
    #     srv_msg.log_doesnt_contain('HA_LEASES_SYNC_LEASE_PAGE_RECEIVED received 10 leases from')
    #     srv_msg.remote_log_includes_line(world.f_cfg.mgmt_address_2,
    #                                      '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
    #                                      None,
    #                                      'HA_SYNC_SUCCESSFUL lease database synchronization with server1 completed successfully')

    # check if all leases are synced
    srv_msg.check_leases(set_of_leases_1,
                         dest=world.f_cfg.mgmt_address_2,
                         backend=backend)
    # stop server1
    srv_control.start_srv('DHCP', 'stopped')
    # dump leases and logs from server1
    srv_control.clear_some_data('all')
    # let's wait until secondary system switch status, we don't need elapsed time increased
    # due to server settings
    wait_until_ha_state('partner-down',
                        dest=world.f_cfg.mgmt_address_2,
                        dhcp_version=dhcp_version)

    # create leases in HA 2
    set_of_leases_2 = generate_leases(leases_count=50,
                                      iaid=1,
                                      iapd=1,
                                      dhcp_version=dhcp_version,
                                      mac="02:02:0c:03:0a:00")

    # start server1
    srv_control.start_srv('DHCP', 'started')
    # let's wait for full synchronization of server2
    wait_until_ha_state('hot-standby', sleep=2, dhcp_version=dhcp_version)

    # check synced leaases
    srv_msg.check_leases(set_of_leases_1, backend=backend)
    srv_msg.check_leases(set_of_leases_2, backend=backend)
Example #9
0
def test_v6_hooks_HA_page_size_sync_large():
    # This is to big to be run in forge setup, run manually, if by mistake someone will start it - uncomment lines at the bottom

    # HA SERVER 1
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::ffff')
    srv_control.open_control_channel()
    srv_control.agent_control_channel('$(MGMT_ADDRESS)')
    srv_control.configure_loggers('kea-dhcp6.dhcpsrv', 'DEBUG', '99')
    srv_control.configure_loggers('kea-dhcp6.ha-hooks', 'DEBUG', '99')
    srv_control.configure_loggers('kea-ctrl-agent', 'DEBUG', '99', 'kea.log-CTRL')

    srv_control.add_hooks('libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('libdhcp_ha.so')

    srv_control.add_parameter_to_ha_hook('this-server-name', '"server1"')
    srv_control.add_parameter_to_ha_hook('mode', '"hot-standby"')
    srv_control.add_parameter_to_ha_hook('heartbeat-delay', '1000')
    srv_control.add_parameter_to_ha_hook('max-response-delay', '1001')
    srv_control.add_parameter_to_ha_hook('max-unacked-clients', '0')
    srv_control.add_parameter_to_ha_hook('max-ack-delay', '0')

    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server1","url":"http://$(MGMT_ADDRESS):8000/","role":"primary","auto-failover":true}')
    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server2","url":"http://$(MGMT_ADDRESS_2):8000/","role":"standby","auto-failover":true}')

    srv_control.build_and_send_config_files('SSH', 'config-file')
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::ffff')
    srv_control.open_control_channel()
    srv_control.agent_control_channel('$(MGMT_ADDRESS_2)')
    srv_control.configure_loggers('kea-dhcp6', 'DEBUG', '99')
    srv_control.configure_loggers('kea-ctrl-agent', 'DEBUG', '99', 'kea.log-CTRL2')

    srv_control.add_hooks('libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('libdhcp_ha.so')
    srv_control.add_parameter_to_ha_hook('this-server-name', '"server2"')
    srv_control.add_parameter_to_ha_hook('mode', '"hot-standby"')
    srv_control.add_parameter_to_ha_hook('heartbeat-delay', '1000')
    srv_control.add_parameter_to_ha_hook('max-response-delay', '1001')
    srv_control.add_parameter_to_ha_hook('max-unacked-clients', '0')
    srv_control.add_parameter_to_ha_hook('max-ack-delay', '0')

    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server1","url":"http://$(MGMT_ADDRESS):8000/","role": "primary","auto-failover":true}')
    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server2","url":"http://$(MGMT_ADDRESS_2):8000/","role": "standby","auto-failover":true}')
    srv_control.build_and_send_config_files_dest_addr('SSH', 'config-file', '$(MGMT_ADDRESS_2)')
    srv_control.remote_start_srv('DHCP', 'started', '$(MGMT_ADDRESS_2)')

    srv_msg.forge_sleep('3', 'seconds')
    # UNCOMMENT:
    # Exchange messages SOLICIT - REPLY 200000 times.

    srv_control.start_srv('DHCP', 'started')
Example #10
0
def test_v6_hooks_HA_page_size_sync_2():

    # HA SERVER 1
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::ffff')
    srv_control.open_control_channel()
    srv_control.agent_control_channel('$(MGMT_ADDRESS)')
    srv_control.configure_loggers('kea-dhcp6.dhcpsrv', 'DEBUG', '99')
    srv_control.configure_loggers('kea-dhcp6.ha-hooks', 'DEBUG', '99')
    srv_control.configure_loggers('kea-ctrl-agent', 'DEBUG', '99', 'kea.log-CTRL')

    srv_control.add_hooks('libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('libdhcp_ha.so')

    srv_control.add_parameter_to_ha_hook('this-server-name', '"server1"')
    srv_control.add_parameter_to_ha_hook('mode', '"hot-standby"')
    srv_control.add_parameter_to_ha_hook('heartbeat-delay', '1000')
    srv_control.add_parameter_to_ha_hook('max-response-delay', '1001')
    srv_control.add_parameter_to_ha_hook('max-unacked-clients', '0')
    srv_control.add_parameter_to_ha_hook('max-ack-delay', '0')

    srv_control.add_parameter_to_ha_hook('sync-page-limit', '10')

    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server1","url":"http://$(MGMT_ADDRESS):8000/","role":"primary","auto-failover":true}')
    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server2","url":"http://$(MGMT_ADDRESS_2):8000/","role":"standby","auto-failover":true}')

    srv_control.build_and_send_config_files('SSH', 'config-file')
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::ffff')
    srv_control.open_control_channel()
    srv_control.agent_control_channel('$(MGMT_ADDRESS_2)')
    srv_control.configure_loggers('kea-dhcp6.dhcpsrv', 'DEBUG', '99')
    srv_control.configure_loggers('kea-dhcp6.ha-hooks', 'DEBUG', '99')
    srv_control.configure_loggers('kea-ctrl-agent', 'DEBUG', '99', 'kea.log-CTRL2')

    srv_control.add_hooks('libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('libdhcp_ha.so')
    srv_control.add_parameter_to_ha_hook('this-server-name', '"server2"')
    srv_control.add_parameter_to_ha_hook('mode', '"hot-standby"')
    srv_control.add_parameter_to_ha_hook('heartbeat-delay', '1000')
    srv_control.add_parameter_to_ha_hook('max-response-delay', '1001')
    srv_control.add_parameter_to_ha_hook('max-unacked-clients', '0')
    srv_control.add_parameter_to_ha_hook('max-ack-delay', '0')

    srv_control.add_parameter_to_ha_hook('sync-page-limit', '15')

    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server1","url":"http://$(MGMT_ADDRESS):8000/","role": "primary","auto-failover":true}')
    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server2","url":"http://$(MGMT_ADDRESS_2):8000/","role": "standby","auto-failover":true}')

    srv_control.build_and_send_config_files_dest_addr('SSH', 'config-file', '$(MGMT_ADDRESS_2)')

    misc.test_procedure()
    srv_msg.forge_sleep('3', 'seconds')

    # create leases in HA 1
    srv_msg.loops('SOLICIT', 'REPLY', '100')

    srv_control.remote_start_srv('DHCP', 'started', '$(MGMT_ADDRESS_2)')
    # sync HA 2 with HA 1
    srv_msg.forge_sleep('10', 'seconds')

    misc.pass_criteria()
    srv_msg.log_contains('DHCPSRV_MEMFILE_GET_PAGE6 obtaining at most 15 IPv6 leases starting from address 2001:db8:1::5')
    srv_msg.remote_log_includes_line('$(MGMT_ADDRESS_2)',
                                     '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
                                     None,
                                     'HA_LEASES_SYNC_LEASE_PAGE_RECEIVED received 15 leases from server1')
    srv_msg.remote_log_includes_line('$(MGMT_ADDRESS_2)',
                                     '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
                                     None,
                                     'DHCPSRV_MEMFILE_GET_ADDR6 obtaining IPv6 lease for address 2001:db8:1::65 and lease type IA_NA')

    srv_msg.remote_log_includes_line('$(MGMT_ADDRESS_2)',
                                     '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
                                     'NOT ',
                                     'DHCPSRV_MEMFILE_GET_PAGE6 obtaining at most 10 IPv6 leases starting from address 2001:')
    srv_msg.log_doesnt_contain('HA_LEASES_SYNC_LEASE_PAGE_RECEIVED received 10 leases from')
    srv_msg.remote_log_includes_line('$(MGMT_ADDRESS_2)',
                                     '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
                                     None,
                                     'HA_SYNC_SUCCESSFUL lease database synchronization with server1 completed successfully')

    # stop HA !
    srv_control.start_srv('DHCP', 'stopped')

    misc.test_procedure()
    srv_msg.forge_sleep('3', 'seconds')

    # create leases in HA 2
    srv_msg.loops('SOLICIT', 'REPLY', '100')
    srv_control.clear_leases('logs')

    srv_control.start_srv('DHCP', 'started')

    srv_msg.forge_sleep('10', 'seconds')

    misc.pass_criteria()
    srv_msg.log_contains('DHCPSRV_MEMFILE_ADD_ADDR6 adding IPv6 lease with address 2001:db8:1::c9')
Example #11
0
def test_v6_hooks_HA_page_size_sync_mulitple_NA():
    # HA SERVER 1
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::ffff')
    srv_control.config_srv_prefix('2001:db8:2::', '0', '48', '91')
    srv_control.config_srv_id('LLT', '00:01:00:02:52:7b:a8:f0:08:00:27:58:f1:e8')
    srv_control.open_control_channel()
    srv_control.agent_control_channel('$(MGMT_ADDRESS)')
    srv_control.configure_loggers('kea-dhcp6.dhcpsrv', 'DEBUG', '99')
    srv_control.configure_loggers('kea-dhcp6.ha-hooks', 'DEBUG', '99')
    srv_control.configure_loggers('kea-ctrl-agent', 'DEBUG', '99', 'kea.log-CTRL')

    srv_control.add_hooks('libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('libdhcp_ha.so')

    srv_control.add_parameter_to_ha_hook('this-server-name', '"server1"')
    srv_control.add_parameter_to_ha_hook('mode', '"hot-standby"')
    srv_control.add_parameter_to_ha_hook('heartbeat-delay', '1000')
    srv_control.add_parameter_to_ha_hook('max-response-delay', '1001')
    srv_control.add_parameter_to_ha_hook('max-unacked-clients', '0')
    srv_control.add_parameter_to_ha_hook('max-ack-delay', '0')

    srv_control.add_parameter_to_ha_hook('sync-page-limit', '2')

    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server1","url":"http://$(MGMT_ADDRESS):8000/","role":"primary","auto-failover":true}')
    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server2","url":"http://$(MGMT_ADDRESS_2):8000/","role":"standby","auto-failover":true}')

    srv_control.build_and_send_config_files('SSH', 'config-file')
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::ffff')
    srv_control.config_srv_prefix('2001:db8:2::', '0', '48', '91')
    srv_control.config_srv_id('LLT', '00:01:00:02:52:7b:a8:f0:08:00:27:58:99:99')
    srv_control.open_control_channel()
    srv_control.agent_control_channel('$(MGMT_ADDRESS_2)')
    srv_control.configure_loggers('kea-dhcp6.dhcpsrv', 'DEBUG', '99')
    srv_control.configure_loggers('kea-dhcp6.ha-hooks', 'DEBUG', '99')
    srv_control.configure_loggers('kea-ctrl-agent', 'DEBUG', '99', 'kea.log-CTRL2')
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')
    srv_control.add_parameter_to_ha_hook('this-server-name', '"server2"')
    srv_control.add_parameter_to_ha_hook('mode', '"hot-standby"')
    srv_control.add_parameter_to_ha_hook('heartbeat-delay', '1000')
    srv_control.add_parameter_to_ha_hook('max-response-delay', '1001')
    srv_control.add_parameter_to_ha_hook('max-unacked-clients', '0')
    srv_control.add_parameter_to_ha_hook('max-ack-delay', '0')
    srv_control.add_parameter_to_ha_hook('sync-page-limit', '2')

    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server1","url":"http://$(MGMT_ADDRESS):8000/","role": "primary","auto-failover":true}')
    srv_control.add_parameter_to_ha_hook('peers',
                                         '{"name":"server2","url":"http://$(MGMT_ADDRESS_2):8000/","role": "standby","auto-failover":true}')

    srv_control.build_and_send_config_files_dest_addr('SSH', 'config-file', '$(MGMT_ADDRESS_2)')
    srv_control.remote_start_srv('DHCP', 'started', '$(MGMT_ADDRESS_2)')

    misc.test_procedure()
    srv_msg.forge_sleep('2', 'seconds')

    tmp = world.f_cfg.show_packets_from
    world.f_cfg.show_packets_from = ""
    duid = "00:03:00:01:ff:ff:ff:ff:ff:0"
    test_range = 5
    for each in range(9):
        ia_1 = random.randint(1, 9009)

        misc.test_procedure()
        srv_msg.client_sets_value('Client', 'DUID', duid + str(each))
        srv_msg.client_does_include('Client', None, 'client-id')
        for each_ia in range(test_range):
            srv_msg.client_sets_value('Client', 'ia_id', ia_1 + each_ia)
            srv_msg.client_does_include('Client', None, 'IA-NA')

        for each_pd in range(test_range):
            srv_msg.client_sets_value('Client', 'ia_pd', ia_1 + each_pd)
            srv_msg.client_does_include('Client', None, 'IA-PD')
        srv_msg.client_send_msg('SOLICIT')

        misc.pass_criteria()
        srv_msg.send_wait_for_message('MUST', None, 'ADVERTISE')

        misc.test_procedure()
        srv_msg.client_sets_value('Client', 'DUID', duid + str(each))
        srv_msg.client_does_include('Client', None, 'client-id')

        for each_ia in range(test_range):
            srv_msg.client_sets_value('Client', 'ia_id', ia_1 + each_ia)
            srv_msg.client_does_include('Client', None, 'IA-NA')

        for each_pd in range(test_range):
            srv_msg.client_sets_value('Client', 'ia_pd', ia_1 + each_pd)
            srv_msg.client_does_include('Client', None, 'IA-PD')

        srv_msg.client_copy_option('server-id')
        srv_msg.client_send_msg('REQUEST')

        misc.pass_criteria()
        srv_msg.send_wait_for_message('MUST', None, 'REPLY')
        srv_msg.response_check_include_option('Response', None, '2')
        srv_msg.response_check_option_content('Response',
                                              '2',
                                              None,
                                              'duid',
                                              '00:01:00:02:52:7b:a8:f0:08:00:27:58:f1:e8')
    srv_msg.forge_sleep('2', 'seconds')
    world.f_cfg.show_packets_from = tmp

    srv_msg.remote_log_includes_line('$(MGMT_ADDRESS_2)',
                                     '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
                                     None,
                                     'DHCPSRV_MEMFILE_GET_ADDR6 obtaining IPv6 lease '
                                     'for address 2001:db8:2::aa0:0:0 and lease type IA_PD')
    srv_msg.remote_log_includes_line('$(MGMT_ADDRESS_2)',
                                     '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log',
                                     None,
                                     'DHCPSRV_MEMFILE_UPDATE_ADDR6 updating IPv6 lease for address 2001:db8:2::aa0:0:0')
    srv_msg.remote_log_includes_line('$(MGMT_ADDRESS_2)',
                                     '$(SOFTWARE_INSTALL_DIR)/var/log/kea.log-CTRL2',
                                     None,
                                     'Bulk apply of 10 IPv6 leases completed.')
    srv_control.start_srv('DHCP', 'stopped')
    srv_msg.forge_sleep('2', 'seconds')

    tmp = world.f_cfg.show_packets_from
    world.f_cfg.show_packets_from = ""
    duid = "00:03:00:01:ff:ff:ff:ff:00:0"
    for each in range(9):
        ia_1 = random.randint(1, 9009)

        misc.test_procedure()
        srv_msg.client_sets_value('Client', 'DUID', duid + str(each))
        srv_msg.client_does_include('Client', None, 'client-id')
        for each_ia in range(test_range):
            srv_msg.client_sets_value('Client', 'ia_id', ia_1 + each_ia)
            srv_msg.client_does_include('Client', None, 'IA-NA')

        for each_pd in range(test_range):
            srv_msg.client_sets_value('Client', 'ia_pd', ia_1 + each_pd)
            srv_msg.client_does_include('Client', None, 'IA-PD')
        srv_msg.client_send_msg('SOLICIT')

        misc.pass_criteria()
        srv_msg.send_wait_for_message('MUST', None, 'ADVERTISE')

        misc.test_procedure()
        srv_msg.client_sets_value('Client', 'DUID', duid + str(each))
        srv_msg.client_does_include('Client', None, 'client-id')

        for each_ia in range(test_range):
            srv_msg.client_sets_value('Client', 'ia_id', ia_1 + each_ia)
            srv_msg.client_does_include('Client', None, 'IA-NA')

        for each_pd in range(test_range):
            srv_msg.client_sets_value('Client', 'ia_pd', ia_1 + each_pd)
            srv_msg.client_does_include('Client', None, 'IA-PD')

        srv_msg.client_copy_option('server-id')
        srv_msg.client_send_msg('REQUEST')

        misc.pass_criteria()
        srv_msg.send_wait_for_message('MUST', None, 'REPLY')

        srv_msg.response_check_include_option('Response', None, '2')
        srv_msg.response_check_option_content('Response',
                                              '2',
                                              None,
                                              'duid',
                                              '00:01:00:02:52:7b:a8:f0:08:00:27:58:99:99')
    srv_control.start_srv('DHCP', 'started')
    srv_msg.forge_sleep('4', 'seconds')
Example #12
0
def test_HA_hot_standby_hold_state_always(dhcp_version):

    # HA SERVER 1
    misc.test_setup()
    if dhcp_version == 'v6':
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::1')
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.1')
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address)

    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')
    world.dhcp_cfg["hooks-libraries"][1].update(HOT_STANDBY)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1100,
        "max-unacked-clients": 0,
        "this-server-name": "server1",
        "state-machine": {
            "states": [{
                "state": "waiting",
                "pause": "always"
            }, {
                "state": "syncing",
                "pause": "always"
            }, {
                "state": "ready",
                "pause": "always"
            }, {
                "state": "hot-standby",
                "pause": "always"
            }, {
                "state": "partner-down",
                "pause": "always"
            }]
        }
    })

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)
    if dhcp_version == 'v6':
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::1')
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.1')
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address_2)

    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.add_ha_hook('libdhcp_ha.so')
    world.dhcp_cfg["hooks-libraries"][1].update(HOT_STANDBY)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1100,
        "max-unacked-clients": 0,
        "this-server-name": "server2",
        "state-machine": {
            "states": []
        }
    })

    srv_control.build_and_send_config_files(dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    srv_msg.forge_sleep(3, 'seconds')

    _send_message(dhcp=dhcp_version, expect_answer=False)

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "waiting"

    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "waiting"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "waiting"

    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "waiting"

    # continue server1 from WAITING
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'

    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "syncing"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "waiting"

    # continue server1 from SYNCING
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'

    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "ready"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    _send_message(dhcp=dhcp_version, expect_answer=False)

    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "ready"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    _send_message(dhcp=dhcp_version, expect_answer=False)

    # continue server1 from READY
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'

    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "hot-standby"

    _send_message(dhcp=dhcp_version)

    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)

    srv_msg.forge_sleep(3, 'seconds')

    # server1 has to keep hot-standby
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"

    # continue server1 from hot-standby
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'
    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"

    _send_message(dhcp=dhcp_version)

    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"
    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    # continue server1 from partner-down
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "hot-standby"

    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"

    # continue AGAIN from hot-standby
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "hot-standby"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "hot-standby"

    _send_message(dhcp=dhcp_version)
Example #13
0
def test_HA_load_balancing_hold_state_once(dhcp_version):

    # HA SERVER 1
    misc.test_setup()
    if dhcp_version == 'v6':
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::1')
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.1')
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address)
    srv_control.add_hooks('libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('libdhcp_ha.so')
    world.dhcp_cfg["hooks-libraries"][1].update(LOAD_BALANCING)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1100,
        "max-unacked-clients": 0,
        "this-server-name": "server1",
        "state-machine": {
            "states": [{
                "state": "waiting",
                "pause": "once"
            }, {
                "state": "syncing",
                "pause": "once"
            }, {
                "state": "ready",
                "pause": "once"
            }, {
                "state": "load-balancing",
                "pause": "once"
            }, {
                "state": "partner-down",
                "pause": "once"
            }]
        }
    })

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    # HA SERVER 2
    misc.test_setup()
    srv_control.clear_some_data('all', dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)
    if dhcp_version == 'v6':
        srv_control.config_srv_subnet('2001:db8:1::/64',
                                      '2001:db8:1::1-2001:db8:1::1')
    else:
        srv_control.config_srv_subnet('192.168.50.0/24',
                                      '192.168.50.1-192.168.50.1')
    srv_control.open_control_channel()
    srv_control.agent_control_channel(world.f_cfg.mgmt_address_2)
    srv_control.add_hooks('libdhcp_lease_cmds.so')

    srv_control.add_ha_hook('libdhcp_ha.so')
    world.dhcp_cfg["hooks-libraries"][1].update(LOAD_BALANCING)
    srv_control.update_ha_hook_parameter({
        "heartbeat-delay": 1000,
        "max-ack-delay": 0,
        "max-response-delay": 1100,
        "max-unacked-clients": 0,
        "this-server-name": "server2",
        "state-machine": {
            "states": []
        }
    })

    srv_control.build_and_send_config_files(dest=world.f_cfg.mgmt_address_2)
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)
    srv_msg.forge_sleep(3, 'seconds')

    # check that both servers keep waiting (server1 is paused, server2 is waiting for server1
    _send_message(dhcp=dhcp_version, expect_answer=False)
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "waiting"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "waiting"
    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "waiting"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "waiting"

    # continue server1 from WAITING
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'
    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "syncing"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "waiting"

    # continue server1 from SYNCING
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'

    # keep in ready
    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "ready"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"
    _send_message(dhcp=dhcp_version, expect_answer=False)
    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "ready"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"
    _send_message(dhcp=dhcp_version, expect_answer=False)

    # continue server1 from READY
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'
    wait_until_ha_state("load-balancing", dhcp_version=dhcp_version)
    wait_until_ha_state("load-balancing",
                        dest=world.f_cfg.mgmt_address_2,
                        dhcp_version=dhcp_version)

    _send_message(dhcp=dhcp_version)

    # stop server2, server1 should not move to partner-down
    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)
    srv_msg.forge_sleep(3, 'seconds')

    # server1 has to keep load-balancing
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "load-balancing"
    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "load-balancing"
    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "load-balancing"

    # continue server1 from load-balancing
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'
    wait_until_ha_state("partner-down", dhcp_version=dhcp_version)
    srv_msg.forge_sleep(3, 'seconds')
    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"

    _send_message(dhcp=dhcp_version)

    # start second server, first should stay in partner-down
    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"
    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"
    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_heartbeat(
        dhcp_version=dhcp_version,
        dest=world.f_cfg.mgmt_address_2)["arguments"]["state"] == "ready"

    # continue from partner down
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine continues.'

    srv_msg.forge_sleep(3, 'seconds')
    wait_until_ha_state("load-balancing", dhcp_version=dhcp_version)
    wait_until_ha_state("load-balancing",
                        dhcp_version=dhcp_version,
                        dest=world.f_cfg.mgmt_address_2)

    srv_control.start_srv('DHCP', 'stopped', dest=world.f_cfg.mgmt_address_2)
    srv_msg.forge_sleep(3, 'seconds')

    # this time - no paused states!
    wait_until_ha_state("partner-down", dhcp_version=dhcp_version)
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine is not paused.'
    srv_msg.forge_sleep(3, 'seconds')

    assert send_heartbeat(
        dhcp_version=dhcp_version)["arguments"]["state"] == "partner-down"
    assert send_command(dhcp_version=dhcp_version,
                        cmd={"command": "ha-continue"
                             })["text"] == 'HA state machine is not paused.'
    srv_msg.forge_sleep(3, 'seconds')

    srv_control.start_srv('DHCP', 'started', dest=world.f_cfg.mgmt_address_2)

    wait_until_ha_state("load-balancing", dhcp_version=dhcp_version)
    wait_until_ha_state("load-balancing",
                        dhcp_version=dhcp_version,
                        dest=world.f_cfg.mgmt_address_2)

    _send_message(dhcp=dhcp_version)