Esempio n. 1
0
def kill_kea_on_second_system():
    # kill kea and clear data at the beginning and at the end
    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)
    yield
    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)
Esempio n. 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)
Esempio n. 3
0
def test_ddns6_all_levels_resend_without_ddns():
    misc.test_setup()
    srv_control.open_control_channel()
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.config_srv_subnet('2001:db8:a::/64', '2001:db8:a::1-2001:db8:a::1')
    srv_control.config_srv_another_subnet_no_interface('2001:db8:b::/64',
                                                       '2001:db8:b::1-2001:db8:b::1')

    world.dhcp_cfg["subnet6"][0].update({"ddns-send-updates": True,
                                         "ddns-generated-prefix": "six",
                                         "ddns-qualifying-suffix": "example.com"})

    srv_control.shared_subnet('2001:db8:a::/64', 0)
    srv_control.shared_subnet('2001:db8:b::/64', 0)
    srv_control.set_conf_parameter_shared_subnet('name', '"name-abc"', 0)
    srv_control.set_conf_parameter_shared_subnet('interface', '"$(SERVER_IFACE)"', 0)

    srv_control.add_ddns_server('127.0.0.1', '53001')
    srv_control.add_ddns_server_options('enable-updates', True)
    srv_control.add_forward_ddns('six.example.com.', 'EMPTY_KEY')
    srv_control.add_reverse_ddns('a.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.', 'EMPTY_KEY')

    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')
    srv_control.start_srv('DNS', 'started', config_set=31)

    _get_address_and_update_ddns(duid='00:03:00:01:ff:ff:ff:ff:ff:01', fqdn='sth6.six.example.com.',
                                 address='2001:db8:a::1',
                                 arpa='1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.a.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.')

    _get_address(duid='00:03:00:01:ff:ff:ff:ff:ff:02', fqdn=None)

    _check_fqdn_record("some.abc.example.com.", expect='empty')

    # stop bind, remove data files, start bind with empty zones
    srv_control.start_srv('DNS', 'stopped')
    srv_control.clear_some_data('all', service='DNS')
    srv_control.start_srv('DNS', 'started', config_set=31)
    # check is all records were removed
    _check_fqdn_record("sth6.six.example.com.", expect='empty')
    _check_fqdn_record("some.abc.example.com.", expect='empty')
    _check_fqdn_record("record.xyz.example.com.", expect='empty')

    response = _resend_ddns('2001:db8:b::1', exp_result=1)
    assert response["text"] == 'Lease for: 2001:db8:b::1, has no hostname, nothing to update'
    response = _resend_ddns('2001:db8:a::1', exp_result=0)
    assert response["text"] == "NCR generated for: 2001:db8:a::1, hostname: sth6.six.example.com."

    _check_fqdn_record("sth6.six.example.com.", address='2001:db8:a::1')

    _check_address_record("sth6.six.example.com.",
                          '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.a.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.')
    _check_fqdn_record("some.abc.example.com.", expect='empty')
Esempio n. 4
0
def test_ddns4_notsig_forw_and_rev_update_success_Sflag():

    misc.test_setup()
    srv_control.config_srv_subnet('192.168.50.0/24',
                                  '192.168.50.10-192.168.50.10')
    srv_control.add_ddns_server('127.0.0.1', '53001')
    srv_control.add_ddns_server_options('enable-updates', True)
    srv_control.add_ddns_server_options('generated-prefix', 'four')
    srv_control.add_ddns_server_options('qualifying-suffix', 'example.com')
    srv_control.add_forward_ddns('four.example.com.', 'EMPTY_KEY')
    srv_control.add_reverse_ddns('50.168.192.in-addr.arpa.', 'EMPTY_KEY')
    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    srv_control.use_dns_set_number(20)
    srv_control.start_srv('DNS', 'started')

    misc.test_procedure()
    srv_msg.dns_question_record('aa.four.example.com', 'A', 'IN')
    srv_msg.client_send_dns_query()

    misc.pass_criteria()
    srv_msg.send_wait_for_query('MUST')
    srv_msg.dns_option('ANSWER', expect_include=False)

    misc.test_procedure()
    srv_msg.client_requests_option(1)
    srv_msg.client_send_msg('DISCOVER')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'OFFER')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_content('yiaddr', '192.168.50.10')
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')

    misc.test_procedure()
    srv_msg.client_copy_option('server_id')
    srv_msg.client_does_include_with_value('requested_addr', '192.168.50.10')
    srv_msg.client_requests_option(1)
    srv_msg.client_sets_value('Client', 'FQDN_domain_name',
                              'aa.four.example.com.')
    srv_msg.client_sets_value('Client', 'FQDN_flags', 'S')
    srv_msg.client_does_include('Client', 'fqdn')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ACK')
    srv_msg.response_check_content('yiaddr', '192.168.50.10')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
    srv_msg.response_check_include_option(81)
    srv_msg.response_check_option_content(81, 'flags', 1)
    srv_msg.response_check_option_content(81, 'fqdn', 'aa.four.example.com.')

    misc.test_procedure()
    srv_msg.dns_question_record('aa.four.example.com', 'A', 'IN')
    srv_msg.client_send_dns_query()

    misc.pass_criteria()
    srv_msg.send_wait_for_query('MUST')
    srv_msg.dns_option('ANSWER')
    srv_msg.dns_option_content('ANSWER', 'rdata', '192.168.50.10')
    srv_msg.dns_option_content('ANSWER', 'rrname', 'aa.four.example.com.')

    misc.test_procedure()
    srv_msg.dns_question_record('10.50.168.192.in-addr.arpa.', 'PTR', 'IN')
    srv_msg.client_send_dns_query()

    misc.pass_criteria()
    srv_msg.send_wait_for_query('MUST')
    srv_msg.dns_option('ANSWER')
    srv_msg.dns_option_content('ANSWER', 'rdata', 'aa.four.example.com.')
    srv_msg.dns_option_content('ANSWER', 'rrname',
                               '10.50.168.192.in-addr.arpa.')

    misc.test_setup()
    srv_control.start_srv('DHCP', 'stopped')
    srv_control.clear_some_data('leases')

    misc.test_setup()
    srv_control.config_srv_subnet('192.168.50.0/24',
                                  '192.168.50.11-192.168.50.11')
    srv_control.add_ddns_server('127.0.0.1', '53001')
    srv_control.add_ddns_server_options('enable-updates', True)
    srv_control.add_ddns_server_options('generated-prefix', 'four')
    srv_control.add_ddns_server_options('qualifying-suffix', 'example.com')
    srv_control.add_forward_ddns('four.example.com.', 'EMPTY_KEY')
    srv_control.add_reverse_ddns('50.168.192.in-addr.arpa.', 'EMPTY_KEY')
    srv_control.build_and_send_config_files()
    srv_control.start_srv('DHCP', 'started')

    misc.test_procedure()
    srv_msg.dns_question_record('aa.four.example.com', 'A', 'IN')
    srv_msg.client_send_dns_query()

    misc.pass_criteria()
    srv_msg.send_wait_for_query('MUST')
    srv_msg.dns_option('ANSWER')
    srv_msg.dns_option_content('ANSWER', 'rdata', '192.168.50.10')
    srv_msg.dns_option_content('ANSWER', 'rrname', 'aa.four.example.com.')

    misc.test_procedure()
    srv_msg.dns_question_record('10.50.168.192.in-addr.arpa.', 'PTR', 'IN')
    srv_msg.client_send_dns_query()

    misc.pass_criteria()
    srv_msg.send_wait_for_query('MUST')
    srv_msg.dns_option('ANSWER')
    srv_msg.dns_option_content('ANSWER', 'rdata', 'aa.four.example.com.')
    srv_msg.dns_option_content('ANSWER', 'rrname',
                               '10.50.168.192.in-addr.arpa.')

    misc.test_procedure()
    srv_msg.client_requests_option(1)
    srv_msg.client_send_msg('DISCOVER')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'OFFER')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_content('yiaddr', '192.168.50.11')
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')

    misc.test_procedure()
    srv_msg.client_copy_option('server_id')
    srv_msg.client_does_include_with_value('requested_addr', '192.168.50.11')
    srv_msg.client_requests_option(1)
    srv_msg.client_sets_value('Client', 'FQDN_domain_name',
                              'aa.four.example.com.')
    srv_msg.client_sets_value('Client', 'FQDN_flags', 'S')
    srv_msg.client_does_include('Client', 'fqdn')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ACK')
    srv_msg.response_check_content('yiaddr', '192.168.50.11')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
    srv_msg.response_check_include_option(81)
    srv_msg.response_check_option_content(81, 'flags', 1)
    srv_msg.response_check_option_content(81, 'fqdn', 'aa.four.example.com.')

    misc.test_procedure()
    srv_msg.dns_question_record('aa.four.example.com', 'A', 'IN')
    srv_msg.client_send_dns_query()

    misc.pass_criteria()
    srv_msg.send_wait_for_query('MUST')
    srv_msg.dns_option('ANSWER')
    srv_msg.dns_option_content('ANSWER', 'rdata', '192.168.50.11')
    srv_msg.dns_option_content('ANSWER', 'rrname', 'aa.four.example.com.')

    misc.test_procedure()
    srv_msg.dns_question_record('11.50.168.192.in-addr.arpa.', 'PTR', 'IN')
    srv_msg.client_send_dns_query()

    misc.pass_criteria()
    srv_msg.send_wait_for_query('MUST')
    srv_msg.dns_option('ANSWER')
    srv_msg.dns_option_content('ANSWER', 'rdata', 'aa.four.example.com.')
    srv_msg.dns_option_content('ANSWER', 'rrname',
                               '11.50.168.192.in-addr.arpa.')
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
0
def test_v6_sanity_check_subnet_id_del():
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', 666, 0)
    srv_control.set_conf_parameter_global('sanity-checks',
                                          {"lease-checks": "del"})
    srv_control.open_control_channel()
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.build_and_send_config_files()

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

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '1234567')
    srv_msg.client_does_include('Client', 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ADVERTISE')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'REPLY')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    # lease should be available via lease6-get
    resp = srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease6-get","arguments":{"ip-address": "2001:db8::1"}}')
    assert resp['arguments']['subnet-id'] == 666

    # it should be in lease file as well
    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

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

    srv_control.clear_some_data('logs')

    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', 999, 0)
    srv_control.set_conf_parameter_global('sanity-checks',
                                          {"lease-checks": "del"})
    srv_control.open_control_channel()
    srv_control.add_hooks('libdhcp_lease_cmds.so')
    srv_control.build_and_send_config_files()

    srv_control.start_srv('DHCP', 'started')
    srv_msg.forge_sleep(2, 'seconds')

    srv_msg.log_contains(
        'DHCPSRV_LEASE_SANITY_FAIL_DISCARD The lease 2001:db8::1 with subnet-id 666 failed subnet-id checks (the lease should have subnet-id 999) and was dropped.'
    )

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '7654321')
    srv_msg.client_does_include('Client', 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ADVERTISE')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'REPLY')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    # old lease from subnet-id 666 should not be available while new lease from subnet-id 999 should be
    resp = srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease6-get","arguments":{"ip-address": "2001:db8::1"}}')
    assert resp['arguments']['subnet-id'] == 999
    # explict query for old lease should return error
    srv_msg.send_ctrl_cmd_via_socket(
        '{"command":"lease6-get","arguments":{"subnet-id":666,"identifier-type":"duid", "identifier": "00:03:00:01:f6:f5:f4:f3:f2:01"}}',
        exp_result=3)

    # old lease should not be present in the lease file
    # bug: #1618, closed as designed
    srv_msg.lease_file_doesnt_contain(
        '2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_doesnt_contain(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')
    # new one should be in the lease file
    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.lease_file_contains(
        '999,3000,0,7654321,128,0,0,,f6:f5:f4:f3:f2:22,0')
Esempio n. 12
0
def test_v6_sanity_check_subnet_id_del_renew():
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', 666, 0)
    srv_control.set_conf_parameter_global('sanity-checks',
                                          {"lease-checks": "del"})
    srv_control.open_control_channel()

    srv_control.build_and_send_config_files()

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

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '1234567')
    srv_msg.client_does_include('Client', 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ADVERTISE')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'REPLY')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

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

    srv_control.clear_some_data('logs')

    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', 999, 0)
    srv_control.set_conf_parameter_global('sanity-checks',
                                          {"lease-checks": "del"})
    srv_control.open_control_channel()

    srv_control.build_and_send_config_files()

    srv_control.start_srv('DHCP', 'started')
    srv_msg.forge_sleep(2, 'seconds')

    srv_msg.log_contains(
        'DHCPSRV_LEASE_SANITY_FAIL_DISCARD The lease 2001:db8::1 with subnet-id 666 failed subnet-id checks (the lease should have subnet-id 999) and was dropped.'
    )

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_send_msg('RENEW')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'REPLY')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '1234567')
    srv_msg.client_does_include('Client', 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ADVERTISE')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 13)
    srv_msg.response_check_suboption_content(13, 3, 'statuscode', 2)

    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '999,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

    srv_msg.lease_file_doesnt_contain(
        '2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:22')
    srv_msg.lease_file_doesnt_contain(
        '999,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:22')
Esempio n. 13
0
def test_v6_sanity_check_subnet_id_fix_del_unable():
    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', 666, 0)
    srv_control.set_conf_parameter_global('sanity-checks',
                                          {"lease-checks": "fix-del"})
    srv_control.open_control_channel()

    srv_control.build_and_send_config_files()

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

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_sets_value('Client', 'ia_id', '1234567')
    srv_msg.client_does_include('Client', 'IA-NA')
    srv_msg.client_send_msg('SOLICIT')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'ADVERTISE')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)

    misc.test_procedure()
    srv_msg.client_sets_value('Client', 'DUID',
                              '00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.client_copy_option('IA_NA')
    srv_msg.client_copy_option('server-id')
    srv_msg.client_does_include('Client', 'client-id')
    srv_msg.client_send_msg('REQUEST')

    misc.pass_criteria()
    srv_msg.send_wait_for_message('MUST', 'REPLY')
    srv_msg.response_check_include_option(1)
    srv_msg.response_check_include_option(2)
    srv_msg.response_check_include_option(3)
    srv_msg.response_check_option_content(3, 'sub-option', 5)
    srv_msg.response_check_suboption_content(5, 3, 'addr', '2001:db8::1')

    srv_msg.lease_file_contains('2001:db8::1,00:03:00:01:f6:f5:f4:f3:f2:01')
    srv_msg.lease_file_contains(
        '666,3000,0,1234567,128,0,0,,f6:f5:f4:f3:f2:01')

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

    srv_control.clear_some_data('logs')

    misc.test_setup()
    srv_control.config_srv_subnet('2001:db8::/64', '2001:db8::1-2001:db8::1')
    srv_control.set_conf_parameter_subnet('id', 999, 0)
    srv_control.set_conf_parameter_global('sanity-checks',
                                          {"lease-checks": "fix-del"})
    srv_control.open_control_channel()

    srv_control.build_and_send_config_files()

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