Ejemplo n.º 1
0
def clear_leases(db_name=world.f_cfg.db_name,
                 db_user=world.f_cfg.db_user,
                 db_passwd=world.f_cfg.db_passwd,
                 destination_address=world.f_cfg.mgmt_address):

    if world.f_cfg.db_type == "mysql":
        # that is tmp solution - just clearing not saving.
        command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6 logs; ' \
                  'do mysql -u {db_user} -p{db_passwd} -e' \
                  ' "SET foreign_key_checks = 0; delete from $table_name" {db_name}; done'.format(**locals())
        fabric_run_command(command, destination_host=destination_address)
    elif world.f_cfg.db_type == "postgresql":
        command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6 logs;' \
                  ' do psql -U {db_user} -d {db_name} -c "delete from $table_name" ; done'.format(**locals())
        fabric_run_command(command, destination_host=destination_address)
    elif world.f_cfg.db_type == "cql":
        # TODO: hardcoded passwords for now in cassandra, extend it in some time :)
        command = 'for table_name in dhcp_option_scope host_reservations lease4 lease6 logs;' \
                  ' do cqlsh --keyspace=keatest --user=keatest --password=keatest -e "TRUNCATE $table_name;"' \
                  ' ; done'.format(**locals())
        fabric_run_command(command, destination_host=destination_address)
    elif world.f_cfg.db_type in ["memfile", ""]:
        fabric_remove_file_command(world.f_cfg.get_leases_path(),
                                   destination_host=destination_address)
    else:
        raise Exception('Unsupported db type %s' % world.f_cfg.db_type)
Ejemplo n.º 2
0
def clear_all():
    # TODO we should consider moving it to multi_server_functions, and set just world.cfg["dhcp_log_file"]
    #  and world.cfg["leases"] in every supported server files
    try:
        # ISC_DHCP logs using syslog/rsyslog (OS dependent). DO NOT delete the log file as
        # not all implementations will re-create it.
        # fabric_remove_file_command(world.cfg["dhcp_log_file"])
        fabric_remove_file_command(world.cfg["leases"])
    except:
        pass
Ejemplo n.º 3
0
def clear_all(tmp_db_type=None, destination_address=world.f_cfg.mgmt_address):
    clear_logs(destination_address)

    if world.f_cfg.db_type in ["memfile", ""]:
        fabric_remove_file_command(world.cfg['leases'] + "*",
                                   destination_host=destination_address)
    elif world.f_cfg.db_type in ["mysql", "postgresql", "cql"]:
        # that is tmp solution - just clearing not saving.
        clear_leases(destination_address=world.f_cfg.mgmt_address)
    else:
        assert False, "If you see that error, something went very wrong."
Ejemplo n.º 4
0
def clear_all(tmp_db_type=None, destination_address=world.f_cfg.mgmt_address):
    clear_logs(destination_address)

    if world.f_cfg.db_type in ["memfile", ""]:
        fabric_remove_file_command(world.cfg['leases']+"*",
                                   destination_host=destination_address)
    elif world.f_cfg.db_type in ["mysql", "postgresql", "cql"]:
        # that is tmp solution - just clearing not saving.
        clear_leases(destination_address=world.f_cfg.mgmt_address)
    else:
        assert False, "If you see that error, something went very wrong."
    _clear_db_config(destination_address=world.f_cfg.mgmt_address)
Ejemplo n.º 5
0
def send_ctrl_cmd_via_socket(command,
                             socket_name=None,
                             destination_address=world.f_cfg.mgmt_address,
                             exp_result=0,
                             exp_failed=False):
    # if command is expected to fail it does not make sense to check response details
    if exp_failed:
        # expected result should be default (0) or None
        assert exp_result in [0, None]
        # force expected result to None so it is not checked
        exp_result = None

    log.info(pprint.pformat(command))
    if isinstance(command, dict):
        command = json.dumps(command)
    command_file = open(world.cfg["test_result_dir"] + '/command_file', 'w')
    try:
        command_file.write(command)
    except:
        command_file.close()
        command_file = open(world.cfg["test_result_dir"] + '/command_file',
                            'wb')  # TODO: why 'w' / 'wb'
        command_file.write(command)
    command_file.close()
    fabric_send_file(world.cfg["test_result_dir"] + '/command_file',
                     'command_file',
                     destination_host=destination_address)

    if socket_name is not None:
        socket_path = world.f_cfg.run_join(socket_name)
    else:
        socket_path = world.f_cfg.run_join('control_socket')
    cmd = 'socat -t 5 UNIX:' + socket_path + ' - <command_file'

    attempts = 0
    while attempts < 3:
        response = fabric_sudo_command(cmd,
                                       hide_all=True,
                                       destination_host=destination_address,
                                       ignore_errors=exp_failed)
        if exp_failed:
            assert response.failed
        else:
            assert response.succeeded
        if str(response) != '':
            break
        attempts += 1

    fabric_remove_file_command('command_file')

    result = _process_ctrl_response(response, exp_result)
    return result
Ejemplo n.º 6
0
def clear_all():
    # TODO we should consider moving it to multi_server_functions, and set just world.cfg["dhcp_log_file"]
    #  and world.cfg["leases"] in every supported server files
    try:
        # ISC_DHCP logs using syslog/rsyslog (OS dependent). DO NOT delete the log file as
        # not all implementations will re-create it.
        # fabric_remove_file_command(world.cfg["dhcp_log_file"])
        fabric_remove_file_command(world.cfg["leases"])
        fabric_remove_file_command(
            world.cfg['leases'],
            world.cfg["test_result_dir"] + '/dhcpd6.leases')
    except:
        pass
Ejemplo n.º 7
0
def clear_leases():
    db_name = DB_NAME
    db_user = DB_USER
    db_passwd = DB_PASSWD

    if DB_TYPE == "mysql":
        # that is tmp solution - just clearing not saving.
        command = '''mysql -u {db_user} -p{db_passwd} -Nse 'show tables' {db_name} | while read table; do mysql -u {db_user} -p{db_passwd} -e "truncate table $table" {db_name}; done'''.format(**locals())
        fabric_run_command(command)
    elif DB_TYPE == "postgresql":
        pointer_start = '{'
        pointer_end = '}'
        command = """psql -U {db_user} -d {db_name} -c "\\\\dtvs" -t  | awk '{pointer_start}print $3{pointer_end}' | while read table; do if [ ! -z "$table" -a "$table" != " " ]; then psql -U {db_user} -d {db_name} -c "truncate $table"; fi done""".format(**locals())
        fabric_run_command(command)
    else:
        fabric_remove_file_command(world.cfg['leases'])
Ejemplo n.º 8
0
def clear_all(tmp_db_type=None):
    fabric_remove_file_command(world.f_cfg.software_install_path +
                               'var/kea/kea.log*')

    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd
    if world.f_cfg.db_type in ["memfile", ""]:
        fabric_remove_file_command(world.cfg['leases'])
    elif world.f_cfg.db_type == "mysql":
        #command = '''mysql -u {db_user} -p{db_passwd} -Nse 'show tables' {db_name} | while read table; do mysql -u {db_user} -p{db_passwd} -e "truncate table $table" {db_name}; done'''.format(**locals())
        command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6; do mysql -u {db_user} -p{db_passwd} -e "delete from $table_name" {db_name}; done'.format(
            **locals())
        fabric_run_command(command)
    elif world.f_cfg.db_type == "postgresql":
        pointer_start = '{'
        pointer_end = '}'
        command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6; do psql -U {db_user} -d {db_name} -c "delete from $table_name" ; done'.format(
            **locals())
        fabric_run_command(command)
Ejemplo n.º 9
0
def clear_leases():
    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd

    if world.f_cfg.db_type == "mysql":
        # that is tmp solution - just clearing not saving.
        #command = '''mysql -u {db_user} -p{db_passwd} -Nse 'show tables' {db_name} | while read table; do mysql -u {db_user} -p{db_passwd} -e "truncate table $table" {db_name}; done'''.format(**locals())
        command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6; do mysql -u {db_user} -p{db_passwd} -e "delete from $table_name" {db_name}; done'.format(
            **locals())
        fabric_run_command(command)
    elif world.f_cfg.db_type == "postgresql":
        pointer_start = '{'
        pointer_end = '}'
        #command = """psql -U {db_user} -d {db_name} -c "\\\\dtvs" -t  | awk '{pointer_start}print $3{pointer_end}' | while read table; do if [ ! -z "$table" -a "$table" != " " ]; then psql -U {db_user} -d {db_name} -c "truncate $table"; fi done""".format(**locals())
        command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6; do psql -U {db_user} -d {db_name} -c "delete from $table_name" ; done'.format(
            **locals())
        fabric_run_command(command)
    else:
        fabric_remove_file_command(world.cfg['leases'])
Ejemplo n.º 10
0
def clear_leases(db_name=world.f_cfg.db_name, db_user=world.f_cfg.db_user, db_passwd=world.f_cfg.db_passwd,
                 destination_address=world.f_cfg.mgmt_address):

    if world.f_cfg.db_type == "mysql":
        # that is tmp solution - just clearing not saving.
        command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6 logs; ' \
                  'do mysql -u {db_user} -p{db_passwd} -e' \
                  ' "SET foreign_key_checks = 0; delete from $table_name" {db_name}; done'.format(**locals())
        fabric_run_command(command, destination_host=destination_address)
    elif world.f_cfg.db_type == "postgresql":
        command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6 logs;' \
                  ' do psql -U {db_user} -d {db_name} -c "delete from $table_name" ; done'.format(**locals())
        fabric_run_command(command, destination_host=destination_address)
    elif world.f_cfg.db_type == "cql":
        # TODO: hardcoded passwords for now in cassandra, extend it in some time :)
        command = 'for table_name in dhcp_option_scope host_reservations lease4 lease6 logs;' \
                  ' do cqlsh --keyspace=keatest --user=keatest --password=keatest -e "TRUNCATE $table_name;"' \
                  ' ; done'.format(**locals())
        fabric_run_command(command, destination_host=destination_address)
    else:
        fabric_remove_file_command(world.cfg['leases'], destination_host=destination_address)
Ejemplo n.º 11
0
def clear_all(destination_address=world.f_cfg.mgmt_address, remove_logs=True):
    stop_srv(value=True, destination_address=destination_address)
    if remove_logs:
        fabric_remove_file_command('/tmp/dns.log',
                                   destination_host=destination_address)
    fabric_remove_file_command(os.path.join(world.f_cfg.dns_data_path,
                                            'namedb/*'),
                               destination_host=destination_address)
    fabric_remove_file_command(os.path.join(world.f_cfg.dns_data_path,
                                            '*.conf'),
                               destination_host=destination_address)
    fabric_remove_file_command(os.path.join(world.f_cfg.dns_data_path,
                                            'managed-keys.bind'),
                               destination_host=destination_address)
Ejemplo n.º 12
0
def send_through_socket_server_site(socket_path, command, destination_address=world.f_cfg.mgmt_address):
    if type(command) is unicode:
        command = command.encode('ascii', 'ignore')
    command_file = open(world.cfg["dir_name"] + '/command_file', 'w')
    try:
        command_file.write(command)
    except:
        command_file.close()
        command_file = open(world.cfg["dir_name"] + '/command_file', 'wb')  # TODO: why 'w' / 'wb'
        command_file.write(command)
    command_file.close()
    fabric_send_file(world.cfg["dir_name"] + '/command_file', 'command_file', destination_host=destination_address)
    world.control_channel = fabric_sudo_command('socat UNIX:' + socket_path + ' - <command_file', hide_all=True,
                                                destination_host=destination_address)
    fabric_remove_file_command('command_file')
    try:
        result = json.loads(world.control_channel)
        log.info(json.dumps(result, sort_keys=True, indent=2, separators=(',', ': ')))
        world.cmd_resp = result
    except:
        log.exception('Problem with parsing json: %s', str(world.control_channel))
        world.cmd_resp = world.control_channel
    return world.cmd_resp
Ejemplo n.º 13
0
def clear_all():
    fabric_remove_file_command(SOFTWARE_INSTALL_DIR + 'var/kea/kea.log')
    if world.ddns_enable:
        fabric_remove_file_command(SOFTWARE_INSTALL_DIR + 'var/kea/kea.log_ddns')

    db_name = DB_NAME
    db_user = DB_USER
    db_passwd = DB_PASSWD
    if DB_TYPE in ["memfile", ""]:
        fabric_remove_file_command(world.cfg['leases'])
    elif DB_TYPE == "mysql":
        command = '''mysql -u {db_user} -p{db_passwd} -Nse 'show tables' {db_name} | while read table; do mysql -u {db_user} -p{db_passwd} -e "truncate table $table" {db_name}; done'''.format(**locals())
        fabric_run_command(command)
    elif DB_TYPE == "postgresql":
        pointer_start = '{'
        pointer_end = '}'
        command = """psql -U {db_user} -d {db_name} -c "\\\\dtvs" -t  | awk '{pointer_start}print $3{pointer_end}' | while read table; do if [ ! -z "$table" -a "$table" != " " ]; then psql -U {db_user} -d {db_name} -c "truncate $table"; fi done""".format(**locals())
        fabric_run_command(command)
Ejemplo n.º 14
0
def clear_all(destination_address=world.f_cfg.mgmt_address):
    stop_srv(value=True, destination_address=destination_address)
    fabric_remove_file_command('/tmp/dns.log', destination_host=destination_address)
    fabric_remove_file_command(os.path.join(world.f_cfg.dns_data_path, 'namedb/*'), destination_host=destination_address)
    fabric_remove_file_command(os.path.join(world.f_cfg.dns_data_path, '*.conf'), destination_host=destination_address)
    fabric_remove_file_command(os.path.join(world.f_cfg.dns_data_path, 'managed-keys.bind'), destination_host=destination_address)
Ejemplo n.º 15
0
def clear_leases():
    fabric_download_file(world.cfg['leases'], world.cfg["dir_name"] + '/dhcpd6.leases')
    fabric_remove_file_command(world.cfg["leases"])
    fabric_run_command('echo y |rm ' + world.cfg['leases'])
Ejemplo n.º 16
0
def clear_logs(destination_address=world.f_cfg.mgmt_address):
    fabric_remove_file_command(world.f_cfg.software_install_path +
                               'var/kea/kea.log*',
                               destination_host=destination_address)
Ejemplo n.º 17
0
def clear_logs(destination_address=world.f_cfg.mgmt_address):
    fabric_remove_file_command(world.f_cfg.log_join('kea.log*'),
                               destination_host=destination_address)
Ejemplo n.º 18
0
def clear_all():
    fabric_remove_file_command('/tmp/dns.log')
    fabric_remove_file_command(DNS_DATA_DIR + 'namedb/*')
Ejemplo n.º 19
0
def clear_leases():
    fabric_download_file(world.cfg['leases'],
                         world.cfg["test_result_dir"] + '/dhcpd6.leases')
    fabric_remove_file_command(world.cfg["leases"])
    fabric_run_command('echo y |rm ' + world.cfg['leases'])
Ejemplo n.º 20
0
def clear_all():
    fabric_remove_file_command('log_file')
    fabric_remove_file_command(world.cfg['leases'])
Ejemplo n.º 21
0
def remove_file_from_server(remote_path):
    """
    Remove file from remote server.
    """
    fabric_remove_file_command(remote_path)
Ejemplo n.º 22
0
def clear_all():
    fabric_remove_file_command('log_file')
    fabric_remove_file_command(world.cfg['leases'])
Ejemplo n.º 23
0
def clear_all(destination_address=world.f_cfg.mgmt_address):
    stop_srv(value=True, destination_address=destination_address)
    fabric_remove_file_command('/tmp/dns.log', destination_host=destination_address)
    fabric_remove_file_command(world.f_cfg.dns_data_path + 'namedb/*', destination_host=destination_address)
    fabric_remove_file_command(world.f_cfg.dns_data_path + '/*', destination_host=destination_address)
Ejemplo n.º 24
0
def remove_file_from_server(remote_path):
    """
    Remove file from remote server.
    """
    fabric_remove_file_command(remote_path)
Ejemplo n.º 25
0
def clear_logs(destination_address=world.f_cfg.mgmt_address):
    fabric_remove_file_command(os.path.join(world.f_cfg.software_install_path, 'var/kea/kea.log*'),
                               destination_host=destination_address)