Пример #1
0
def use_config_set(number):
    if not number in config_file_set:
        assert False, "There is no such config file set"
    make_file('named.conf', config_file_set[number][0])
    make_file('rndc.conf', config_file_set[number][1])
    make_file('fwd.db', config_file_set[number][2])
    make_file('rev.db', config_file_set[number][3])
    world.cfg["dns_log_file"] = '/tmp/dns.log'
    make_file('bind.keys', keys)

    fabric_send_file('named.conf', world.f_cfg.dns_data_path + 'named.conf')
    copy_configuration_file('named.conf', 'dns/DNS_named.conf')
    remove_local_file('named.conf')

    fabric_send_file('rndc.conf', world.f_cfg.dns_data_path + 'rndc.conf')
    copy_configuration_file('rndc.conf', 'dns/DNS_rndc.conf')
    remove_local_file('rndc.conf')

    fabric_send_file('fwd.db', world.f_cfg.dns_data_path + 'namedb/fwd.db')
    copy_configuration_file('fwd.db', 'dns/DNS_fwd.db')
    remove_local_file('fwd.db')

    fabric_send_file('rev.db', world.f_cfg.dns_data_path + 'namedb/rev.db')
    copy_configuration_file('rev.db', 'dns/DNS_rev.db')
    remove_local_file('rev.db')

    fabric_send_file('bind.keys', world.f_cfg.dns_data_path + 'managed-keys.bind')
    copy_configuration_file('bind.keys', 'dns/DNS_managed-keys.bind')
    remove_local_file('bind.keys')
Пример #2
0
    def sendconfiguration(self):
        # pass
        from kea6_server.functions import set_kea_ctrl_config, start_srv

        # set_kea_ctrl_config()
        # cfg4 = '{"Dhcp4":{"control-socket":{"socket-type":"unix","socket-name":"'+world.f_cfg.software_install_path+'etc/kea/control_socket"}},"Logging":{"loggers":[{"name":"kea-dhcp4","output_options":[{"output":"'+world.f_cfg.software_install_path+'var/log/kea.log"}],"debuglevel":99,"severity":"DEBUG"}]}}'
        # netconfdaemoncfg = '{"Dhcp4":{"control-socket":{"socket-type":"unix","socket-name":"'+world.f_cfg.software_install_path+'etc/kea/control_socket"}}}'
        # config = open(world.cfg["cfg_file"], 'w')
        # config.write(cfg4)
        # config.close()

        # config = open(world.cfg["cfg_file"], 'w')
        # config.write(cfg4)
        # config.close()

        destination_address = world.f_cfg.mgmt_address

        copy_configuration_file(world.cfg["cfg_file"] + 'XML',
                                "/yang.xml",
                                destination_host=destination_address)

        copy_configuration_file(world.cfg["cfg_file"],
                                destination_host=destination_address)
        # copy_configuration_file(world.cfg["cfg_file_2"], "/kea_ctrl_config", destination_host=destination_address)
        fabric_send_file(world.cfg["cfg_file"],
                         world.f_cfg.software_install_path +
                         "etc/kea/kea.conf",
                         destination_host=destination_address)
        # fabric_send_file(world.cfg["cfg_file_2"],
        #                  world.f_cfg.software_install_path + "etc/kea/keactrl.conf",
        #                  destination_host=destination_address)
        fabric_send_file(world.cfg["cfg_file"] + 'XML',
                         world.f_cfg.software_install_path +
                         "etc/kea/yang.xml",
                         destination_host=destination_address)
Пример #3
0
def build_and_send_config_files(connection_type,
                                configuration_type="config-file",
                                destination_address=world.f_cfg.mgmt_address):
    check_remote_address(destination_address)
    if configuration_type == "config-file" and connection_type == "SSH":
        world.cfg[
            'leases'] = world.f_cfg.software_install_path + 'var/kea/kea-leases4.csv'
        add_defaults()
        set_kea_ctrl_config()
        cfg_write()
        fabric_send_file(world.cfg["cfg_file"],
                         world.f_cfg.software_install_path +
                         "etc/kea/kea.conf",
                         destination_host=destination_address)
        fabric_send_file(world.cfg["cfg_file_2"],
                         world.f_cfg.software_install_path +
                         "etc/kea/keactrl.conf",
                         destination_host=destination_address)
        copy_configuration_file(world.cfg["cfg_file"],
                                destination_host=destination_address)
        copy_configuration_file(world.cfg["cfg_file_2"],
                                "/kea_ctrl_config",
                                destination_host=destination_address)
        remove_local_file(world.cfg["cfg_file"])
        remove_local_file(world.cfg["cfg_file_2"])
    elif configuration_type == "config-file" and connection_type is None:
        world.cfg[
            'leases'] = world.f_cfg.software_install_path + 'var/kea/kea-leases4.csv'
        add_defaults()
        set_kea_ctrl_config()
        cfg_write()
        copy_configuration_file(world.cfg["cfg_file"],
                                destination_host=destination_address)
        remove_local_file(world.cfg["cfg_file"])
Пример #4
0
def build_and_send_config_files(connection_type, configuration_type="config-file",
                                destination_address=world.f_cfg.mgmt_address):
    """
    Generate final config file, save it to test result directory
    and send it to remote system unless testing step will define differently.
    :param connection_type: for now two values expected: SSH and None for stating if files should be send
    :param configuration_type: for now supported just config-file, generate file and save to results dir
    :param destination_address: address of remote system to which conf file will be send,
    default it's world.f_cfg.mgmt_address
    """

    if configuration_type == "config-file" and connection_type == "SSH":
        world.cfg['leases'] = os.path.join(world.f_cfg.software_install_path, 'var/kea/kea-leases%s.csv' % world.proto[1])
        add_defaults()
        set_kea_ctrl_config()
        cfg_write()
        fabric_send_file(world.cfg["cfg_file"],
                         os.path.join(world.f_cfg.software_install_path, "etc/kea/kea.conf"),
                         destination_host=destination_address)
        fabric_send_file(world.cfg["cfg_file_2"],
                         os.path.join(world.f_cfg.software_install_path, "etc/kea/keactrl.conf"),
                         destination_host=destination_address)
        copy_configuration_file(world.cfg["cfg_file"], destination_host=destination_address)
        copy_configuration_file(world.cfg["cfg_file_2"], "kea_ctrl_config", destination_host=destination_address)
        remove_local_file(world.cfg["cfg_file"])
        remove_local_file(world.cfg["cfg_file_2"])
    elif configuration_type == "config-file" and connection_type is None:
        world.cfg['leases'] = os.path.join(world.f_cfg.software_install_path, 'var/kea/kea-leases%s.csv' % world.proto[1])
        add_defaults()
        set_kea_ctrl_config()
        cfg_write()
        copy_configuration_file(world.cfg["cfg_file"], destination_host=destination_address)
        remove_local_file(world.cfg["cfg_file"])
Пример #5
0
def set_logger():
    file_name = world.name.replace(".", "_")
    type = BIND_LOG_TYPE 
    lvl = BIND_LOG_LVL
    module = BIND_MODULE 

    logger_str = '''
    config add Logging/loggers
    config set Logging/loggers[0]/name "{module}"
    config set Logging/loggers[0]/severity "{type}"
    config set Logging/loggers[0]/debuglevel {lvl}
    config add Logging/loggers[0]/output_options
    config set Logging/loggers[0]/output_options[0]/destination file
    config set Logging/loggers[0]/output_options[0]/output log_file
    config commit
    '''.format(**locals())

    cfg_file = open("logger.cfg", "w")
    cfg_file.write(logger_str)
    cfg_file.close()

    cfg_file = 'logger.cfg'
    prepare_config_file(cfg_file)

    fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
    fabric_run_command('(rm -f log_file | echo "execute file ' + cfg_file + '_processed" | '
                       + world.f_cfg.software_install_path + 'bin/bindctl ); sleep ' + str(world.f_cfg.sleep_time_2))
    remove_local_file(cfg_file + '_processed')
Пример #6
0
    def sendconfiguration(self):
        # pass
        from kea6_server.functions import set_kea_ctrl_config, start_srv

        # set_kea_ctrl_config()
        # cfg4 = '{"Dhcp4":{"control-socket":{"socket-type":"unix","socket-name":"'+world.f_cfg.software_install_path+'var/kea/control_socket"}},"Logging":{"loggers":[{"name":"kea-dhcp4","output_options":[{"output":"'+world.f_cfg.software_install_path+'var/kea/kea.log"}],"debuglevel":99,"severity":"DEBUG"}]}}'
        # netconfdaemoncfg = '{"Dhcp4":{"control-socket":{"socket-type":"unix","socket-name":"'+world.f_cfg.software_install_path+'var/kea/control_socket"}}}'
        # config = open(world.cfg["cfg_file"], 'w')
        # config.write(cfg4)
        # config.close()

        # config = open(world.cfg["cfg_file"], 'w')
        # config.write(cfg4)
        # config.close()

        destination_address = world.f_cfg.mgmt_address

        copy_configuration_file(world.cfg["cfg_file"]+'XML', "/yang.xml", destination_host=destination_address)

        copy_configuration_file(world.cfg["cfg_file"], destination_host=destination_address)
        # copy_configuration_file(world.cfg["cfg_file_2"], "/kea_ctrl_config", destination_host=destination_address)
        fabric_send_file(world.cfg["cfg_file"],
                         world.f_cfg.software_install_path + "etc/kea/kea.conf",
                         destination_host=destination_address)
        # fabric_send_file(world.cfg["cfg_file_2"],
        #                  world.f_cfg.software_install_path + "etc/kea/keactrl.conf",
        #                  destination_host=destination_address)
        fabric_send_file(world.cfg["cfg_file"]+'XML',
                         world.f_cfg.software_install_path + "etc/kea/yang.xml",
                         destination_host=destination_address)
Пример #7
0
def upload_db_reservation(exp_failed=False):
    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd
    fail_spotted = False
    while list_of_all_reservations:
        each_record = list_of_all_reservations.pop()
        each_record.build_script()
        db_reservation = open("db_reservation", 'w')
        db_reservation.write(each_record.configuration_script)
        db_reservation.close()
        remote_db_path = world.f_cfg.tmp_join("db_reservation")
        fabric_send_file("db_reservation", remote_db_path)
        copy_configuration_file("db_reservation")
        remove_local_file("db_reservation")
        result = fabric_sudo_command(
            'mysql -u {db_user} -p{db_passwd} {db_name} < {remote_db_path}'.
            format(**locals()),
            ignore_errors=exp_failed)
        if exp_failed:
            if result.failed:
                fail_spotted = True
        else:
            assert result.succeeded

    if exp_failed:
        assert fail_spotted
Пример #8
0
def upload_db_reservation(exp_failed=False):
    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd
    fail_spotted = False
    while list_of_all_reservations:
        each_record = list_of_all_reservations.pop()
        log.info(each_record.__dict__)
        each_record.build_script()
        db_reservation = open("db_reservation", 'w')
        db_reservation.write(each_record.configuration_script)
        db_reservation.close()
        remote_db_path = world.f_cfg.tmp_join("db_reservation")
        fabric_send_file("db_reservation", remote_db_path)
        copy_configuration_file("db_reservation")
        remove_local_file("db_reservation")
        result = fabric_sudo_command(
            'cqlsh --keyspace=keatest --user=keatest --password=keatest -f ' +
            remote_db_path,
            ignore_errors=True)
        if exp_failed:
            if result.failed:
                fail_spotted = True
        else:
            assert result.succeeded

    if exp_failed:
        assert fail_spotted
Пример #9
0
def upload_db_reservation(exp_failed=False):
    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd
    fail_spotted = False
    while list_of_all_reservations:
        each_record = list_of_all_reservations.pop()
        each_record.build_script()
        db_reservation = open("db_reservation", 'w')
        db_reservation.write(each_record.configuration_script)
        db_reservation.close()
        remote_db_path = world.f_cfg.tmp_join("db_reservation")
        fabric_send_file("db_reservation", remote_db_path)
        copy_configuration_file("db_reservation")
        remove_local_file("db_reservation")
        result = fabric_sudo_command('PGPASSWORD={db_passwd} psql -h localhost -U {db_user} -d {db_name} < {remote_db_path}'.format(**locals()),
                                     ignore_errors=True)
        # pgsql insert do not return non zero status on failed command, we need to check stdout
        if exp_failed:
            if 'ERROR:  current transaction is aborted' in result.stdout:
                fail_spotted = True
        else:
            assert result.succeeded

    if exp_failed:
        assert fail_spotted
Пример #10
0
def use_config_set(number):
    if number not in config_file_set:
        assert False, "There is no such config file set"
    make_file('named.conf', _patch_config(config_file_set[number][0]))
    make_file('rndc.conf', config_file_set[number][1])
    make_file('fwd.db', config_file_set[number][2])
    make_file('rev.db', config_file_set[number][3])
    world.cfg["dns_log_file"] = '/tmp/dns.log'
    make_file('bind.keys', keys)

    fabric_sudo_command('mkdir -p %s' % os.path.join(world.f_cfg.dns_data_path, 'namedb'))

    fabric_send_file('named.conf', os.path.join(world.f_cfg.dns_data_path, 'named.conf'))
    copy_configuration_file('named.conf', 'dns/DNS_named.conf')
    remove_local_file('named.conf')

    fabric_send_file('rndc.conf', os.path.join(world.f_cfg.dns_data_path, 'rndc.conf'))
    copy_configuration_file('rndc.conf', 'dns/DNS_rndc.conf')
    remove_local_file('rndc.conf')

    fabric_send_file('fwd.db', os.path.join(world.f_cfg.dns_data_path, 'namedb/fwd.db'))
    copy_configuration_file('fwd.db', 'dns/DNS_fwd.db')
    remove_local_file('fwd.db')

    fabric_send_file('rev.db', os.path.join(world.f_cfg.dns_data_path, 'namedb/rev.db'))
    copy_configuration_file('rev.db', 'dns/DNS_rev.db')
    remove_local_file('rev.db')

    fabric_send_file('bind.keys', os.path.join(world.f_cfg.dns_data_path, 'managed-keys.bind'))
    copy_configuration_file('bind.keys', 'dns/DNS_managed-keys.bind')
    remove_local_file('bind.keys')
Пример #11
0
def build_and_send_config_files(connection_type, configuration_type="config-file",
                                destination_address=world.f_cfg.mgmt_address):
    """
    Generate final config file, save it to test result directory
    and send it to remote system unless testing step will define differently.
    :param connection_type: for now two values expected: SSH and None for stating if files should be send
    :param configuration_type: for now supported just config-file, generate file and save to results dir
    :param destination_address: address of remote system to which conf file will be send,
    default it's world.f_cfg.mgmt_address
    """
    check_remote_address(destination_address)
    if configuration_type == "config-file" and connection_type == "SSH":
        world.cfg['leases'] = world.f_cfg.software_install_path + 'var/kea/kea-leases6.csv'
        add_defaults()
        set_kea_ctrl_config()
        cfg_write()
        fabric_send_file(world.cfg["cfg_file"],
                         world.f_cfg.software_install_path + "etc/kea/kea.conf",
                         destination_host=destination_address)
        fabric_send_file(world.cfg["cfg_file_2"],
                         world.f_cfg.software_install_path + "etc/kea/keactrl.conf",
                         destination_host=destination_address)
        copy_configuration_file(world.cfg["cfg_file"], destination_host=destination_address)
        copy_configuration_file(world.cfg["cfg_file_2"], "/kea_ctrl_config", destination_host=destination_address)
        remove_local_file(world.cfg["cfg_file"])
        remove_local_file(world.cfg["cfg_file_2"])
    elif configuration_type == "config-file" and connection_type is None:
        world.cfg['leases'] = world.f_cfg.software_install_path + 'var/kea/kea-leases6.csv'
        add_defaults()
        set_kea_ctrl_config()
        cfg_write()
        copy_configuration_file(world.cfg["cfg_file"], destination_host=destination_address)
        remove_local_file(world.cfg["cfg_file"])
Пример #12
0
def use_config_set(number):
    if number not in config_file_set:
        assert False, "There is no such config file set"
    make_file('named.conf', _patch_config(config_file_set[number][0]))
    make_file('rndc.conf', config_file_set[number][1])
    make_file('fwd.db', config_file_set[number][2])
    make_file('rev.db', config_file_set[number][3])
    world.cfg["dns_log_file"] = '/tmp/dns.log'
    make_file('bind.keys', keys)

    fabric_sudo_command('mkdir -p %s' % os.path.join(world.f_cfg.dns_data_path, 'namedb'))

    fabric_send_file('named.conf', os.path.join(world.f_cfg.dns_data_path, 'named.conf'))
    copy_configuration_file('named.conf', 'dns/DNS_named.conf')
    remove_local_file('named.conf')

    fabric_send_file('rndc.conf', os.path.join(world.f_cfg.dns_data_path, 'rndc.conf'))
    copy_configuration_file('rndc.conf', 'dns/DNS_rndc.conf')
    remove_local_file('rndc.conf')

    fabric_send_file('fwd.db', os.path.join(world.f_cfg.dns_data_path, 'namedb/fwd.db'))
    copy_configuration_file('fwd.db', 'dns/DNS_fwd.db')
    remove_local_file('fwd.db')

    fabric_send_file('rev.db', os.path.join(world.f_cfg.dns_data_path, 'namedb/rev.db'))
    copy_configuration_file('rev.db', 'dns/DNS_rev.db')
    remove_local_file('rev.db')

    fabric_send_file('bind.keys', os.path.join(world.f_cfg.dns_data_path, 'managed-keys.bind'))
    copy_configuration_file('bind.keys', 'dns/DNS_managed-keys.bind')
    remove_local_file('bind.keys')
Пример #13
0
def set_logger():
    file_name = world.name.replace(".", "_")
    type = BIND_LOG_TYPE 
    lvl = BIND_LOG_LVL
    module = BIND_MODULE 

    logger_str = '''
    config add Logging/loggers
    config set Logging/loggers[0]/name "{module}"
    config set Logging/loggers[0]/severity "{type}"
    config set Logging/loggers[0]/debuglevel {lvl}
    config add Logging/loggers[0]/output_options
    config set Logging/loggers[0]/output_options[0]/destination file
    config set Logging/loggers[0]/output_options[0]/output log_file
    config commit
    '''.format(**locals())

    cfg_file = open("logger.cfg", "w")
    cfg_file.write(logger_str)
    cfg_file.close()

    cfg_file = 'logger.cfg'
    prepare_config_file(cfg_file)

    fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
    fabric_run_command('(rm -f log_file | echo "execute file ' + cfg_file + '_processed" | '
                       + SOFTWARE_INSTALL_DIR + 'bin/bindctl ); sleep ' + str(SLEEP_TIME_2))
    remove_local_file(cfg_file + '_processed')
Пример #14
0
def use_config_set(number):
    if not number in config_file_set:
        assert False, "There is no such config file set"
    make_file('named.conf', config_file_set[number][0])
    make_file('rndc.conf', config_file_set[number][1])
    make_file('fwd.db', config_file_set[number][2])
    make_file('rev.db', config_file_set[number][3])
    world.cfg["dns_log_file"] = '/tmp/dns.log'
    make_file('bind.keys', keys)

    fabric_send_file('named.conf', DNS_DATA_DIR + 'named.conf')
    copy_configuration_file('named.conf', 'dns/DNS_named.conf')
    remove_local_file('named.conf')

    fabric_send_file('rndc.conf', DNS_DATA_DIR + 'rndc.conf')
    copy_configuration_file('rndc.conf', 'dns/DNS_rndc.conf')
    remove_local_file('rndc.conf')

    fabric_send_file('fwd.db', DNS_DATA_DIR + 'namedb/fwd.db')
    copy_configuration_file('fwd.db', 'dns/DNS_fwd.db')
    remove_local_file('fwd.db')

    fabric_send_file('rev.db', DNS_DATA_DIR + 'namedb/rev.db')
    copy_configuration_file('rev.db', 'dns/DNS_rev.db')
    remove_local_file('rev.db')

    fabric_send_file('bind.keys', DNS_DATA_DIR + 'managed-keys.bind')
    copy_configuration_file('bind.keys', 'dns/DNS_managed-keys.bind')
    remove_local_file('bind.keys')
Пример #15
0
def build_and_send_config_files(connection_type,
                                configuration_type="config-file"):
    if configuration_type == "config-file" and connection_type == "SSH":
        world.cfg[
            'leases'] = world.f_cfg.software_install_path + 'var/kea/kea-leases6.csv'
        add_defaults()
        set_kea_ctrl_config()
        cfg_write()
        fabric_send_file(
            world.cfg["cfg_file"],
            world.f_cfg.software_install_path + "etc/kea/kea.conf")
        fabric_send_file(
            world.cfg["cfg_file_2"],
            world.f_cfg.software_install_path + "etc/kea/keactrl.conf")
        copy_configuration_file(world.cfg["cfg_file"])
        copy_configuration_file(world.cfg["cfg_file_2"], "kea_ctrl_config")
        remove_local_file(world.cfg["cfg_file"])
        remove_local_file(world.cfg["cfg_file_2"])
    elif configuration_type == "config-file" and connection_type is None:
        world.cfg[
            'leases'] = world.f_cfg.software_install_path + 'var/kea/kea-leases6.csv'
        add_defaults()
        set_kea_ctrl_config()
        cfg_write()
        copy_configuration_file(world.cfg["cfg_file"])
        remove_local_file(world.cfg["cfg_file"])
Пример #16
0
def send_file_to_server(local_path, remote_path):
    """
    Send file to remote server via ssh. Address/login/password from init_all
    Two paths required.
    Local - relative to lettuce directory
    Remote - absolute
    """
    fabric_send_file(local_path, remote_path)
Пример #17
0
def send_file_to_server(local_path, remote_path):
    """
    Send file to remote server via ssh. Address/login/password from init_all
    Two paths required.
    Local - relative to lettuce directory
    Remote - absolute
    """
    fabric_send_file(local_path, remote_path)
Пример #18
0
def start_srv(a, b):
    """
    Start ISC-DHCPv6 with generated config.
    """
    cfg_write() 
    stop_srv()
    get_common_logger().debug("Starting Dibbler with generated config:")
    fabric_send_file(world.cfg["cfg_file"], '/etc/dibbler/server.conf')
    remove_local_file(world.cfg["cfg_file"])
    fabric_run_command ('('+world.f_cfg.software_install_path+'sbin/dibbler-server start & ); sleep 4;')
Пример #19
0
def start_srv(a, b):
    """
    Start ISC-DHCPv6 with generated config.
    """
    cfg_write() 
    stop_srv()
    get_common_logger().debug("Starting Dibbler with generated config:")
    fabric_send_file(world.cfg["cfg_file"], '/etc/dibbler/server.conf')
    remove_local_file(world.cfg["cfg_file"])
    fabric_run_command ('('+SOFTWARE_INSTALL_DIR+'sbin/dibbler-server start & ); sleep 4;')
Пример #20
0
def build_and_send_config_files():
    world.cfg['leases'] = SOFTWARE_INSTALL_DIR + 'var/kea/kea-leases4.csv'
    add_defaults()
    set_kea_ctrl_config()
    cfg_write()
    fabric_send_file(world.cfg["cfg_file"], SOFTWARE_INSTALL_DIR + "etc/kea/kea.conf")
    fabric_send_file(world.cfg["cfg_file_2"], SOFTWARE_INSTALL_DIR + "etc/kea/keactrl.conf")
    copy_configuration_file(world.cfg["cfg_file"])
    copy_configuration_file(world.cfg["cfg_file_2"], "kea_ctrl_config")
    remove_local_file(world.cfg["cfg_file"])
    remove_local_file(world.cfg["cfg_file_2"])
Пример #21
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
Пример #22
0
def upload_db_reservation():
    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd
    while list_of_all_reservations:
        each_record = list_of_all_reservations.pop()
        each_record.build_script()
        db_reservation = open("db_reservation", 'w')
        db_reservation.write(each_record.configuration_script)
        db_reservation.close()
        fabric_send_file("db_reservation", os.path.join(world.f_cfg.software_install_path, "etc/kea/db_reservation"))
        copy_configuration_file("db_reservation")
        remove_local_file("db_reservation")
        result = fabric_sudo_command('cat ' + os.path.join(world.f_cfg.software_install_path, 'etc/kea/db_reservation') + ' |  psql -U {db_user} -d {db_name}'.format(**locals()))
Пример #23
0
def upload_db_reservation():
    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd
    while list_of_all_reservations:
        each_record = list_of_all_reservations.pop()
        log.info(each_record.__dict__)
        each_record.build_script()
        db_reservation = open("db_reservation", 'w')
        db_reservation.write(each_record.configuration_script)
        db_reservation.close()
        fabric_send_file("db_reservation", os.path.join(world.f_cfg.software_install_path, "etc/kea/db_reservation"))
        copy_configuration_file("db_reservation")
        remove_local_file("db_reservation")
        result = fabric_sudo_command('cqlsh --keyspace=keatest --user=keatest --password=keatest -f ' + os.path.join(world.f_cfg.software_install_path, "etc/kea/db_reservation"))
Пример #24
0
def start_srv(start, process):
    """
    Start ISC-DHCP with generated config.
    """
    if not "conf_option" in world.cfg:
        world.cfg["conf_option"] = ""

    world.cfg['log_file'] = build_log_path()
    fabric_sudo_command('cat /dev/null >' + world.cfg['log_file'])
    world.cfg["dhcp_log_file"] = world.cfg['log_file']

    log = "local7"
    if world.f_cfg.isc_dhcp_log_facility != "":
        log = world.f_cfg.isc_dhcp_log_facility

    world.cfg['log_facility'] = '''\nlog-facility {log};\n'''.format(
        **locals())

    add_defaults()
    cfg_write()
    log.debug("Start ISC-DHCP with generated config:")
    convert_cfg_file(world.cfg["cfg_file"])
    fabric_send_file(world.cfg["cfg_file"] + '_processed',
                     world.cfg["cfg_file"] + '_processed')
    copy_configuration_file(world.cfg["cfg_file"] + '_processed')
    remove_local_file(world.cfg["cfg_file"])
    #set_ethernet_interface()
    stop_srv()

    world.cfg['leases'] = build_leases_path()

    #fabric_sudo_command('echo y |rm ' + world.cfg['leases'])
    fabric_sudo_command('touch ' + world.cfg['leases'])

    result = fabric_sudo_command(
        '(' + os.path.join(world.f_cfg.software_install_path, 'sbin/dhcpd') +
        ' -cf server.cfg_processed' + ' -lf ' + world.cfg['leases'] +
        '&); sleep ' + str(world.f_cfg.sleep_time_1) + ';')

    check_process_result(start, result, process)

    # clear configs in case we would like make couple configs in one test
    world.cfg["conf_time"] = ""
    world.cfg["log_facility"] = ""
    world.cfg["custom_lines"] = ""
    world.cfg["conf_option"] = ""
    world.cfg["conf_vendor"] = ""
Пример #25
0
def start_srv(start, process):
    """
    Start ISC-DHCP with generated config.
    """

    if not "conf_option" in world.cfg:
        world.cfg["conf_option"] = ""

    world.cfg['log_file'] = build_log_path()
    fabric_sudo_command('cat /dev/null >' + world.cfg['log_file'])
    world.cfg["dhcp_log_file"] = world.cfg['log_file']

    log = "local7"
    if ISC_DHCP_LOG_FACILITY != "":
        log = ISC_DHCP_LOG_FACILITY

    world.cfg['log_facility'] = '''\nlog-facility {log};\n'''.format(**locals())

    add_defaults()
    cfg_write()
    get_common_logger().debug("Start ISC-DHCP with generated config:")
    convert_cfg_file(world.cfg["cfg_file"])
    fabric_send_file(world.cfg["cfg_file"] + '_processed', world.cfg["cfg_file"] + '_processed')
    copy_configuration_file(world.cfg["cfg_file"] + '_processed')
    remove_local_file(world.cfg["cfg_file"])
    #set_ethernet_interface()
    stop_srv()

    world.cfg['leases'] = build_leases_path()

    fabric_sudo_command('echo y |rm ' + world.cfg['leases'])
    fabric_sudo_command('touch ' + world.cfg['leases'])

    result = fabric_sudo_command('(' + SOFTWARE_INSTALL_DIR
                                 + 'sbin/dhcpd -cf server.cfg_processed'
                                 + ' -lf ' + world.cfg['leases']
                                 + '&); sleep ' + str(SLEEP_TIME_1) + ';')

    check_process_result(start, result, process)
    # clear configs in case we would like make couple configs in one test
    world.cfg["conf_time"] = ""
    world.cfg["log_facility"] = ""
    world.cfg["custom_lines"] = ""
    world.cfg["conf_option"] = ""
    world.cfg["conf_vendor"] = ""
Пример #26
0
def start_srv(start, process):
    """
    Start ISC-DHCP with generated config.
    """
    if not "conf_option" in world.cfg:
        world.cfg["conf_option"] = ""

    world.cfg['log_file'] = build_log_path()
    fabric_sudo_command('cat /dev/null >' + world.cfg['log_file'])
    world.cfg["dhcp_log_file"] = world.cfg['log_file']

    log = "local7"
    if world.f_cfg.isc_dhcp_log_facility != "":
        log = world.f_cfg.isc_dhcp_log_facility

    world.cfg['log_facility'] = '''\nlog-facility {log};\n'''.format(**locals())

    add_defaults()
    cfg_write()
    log.debug("Start ISC-DHCP with generated config:")
    convert_cfg_file(world.cfg["cfg_file"])
    fabric_send_file(world.cfg["cfg_file"] + '_processed', world.cfg["cfg_file"] + '_processed')
    copy_configuration_file(world.cfg["cfg_file"] + '_processed')
    remove_local_file(world.cfg["cfg_file"])
    #set_ethernet_interface()
    stop_srv()

    world.cfg['leases'] = build_leases_path()

    #fabric_sudo_command('echo y |rm ' + world.cfg['leases'])
    fabric_sudo_command('touch ' + world.cfg['leases'])

    result = fabric_sudo_command('(' + os.path.join(world.f_cfg.software_install_path, 'sbin/dhcpd') + ' -cf server.cfg_processed'
                                 + ' -lf ' + world.cfg['leases']
                                 + '&); sleep ' + str(world.f_cfg.sleep_time_1) + ';')

    check_process_result(start, result, process)

    # clear configs in case we would like make couple configs in one test
    world.cfg["conf_time"] = ""
    world.cfg["log_facility"] = ""
    world.cfg["custom_lines"] = ""
    world.cfg["conf_option"] = ""
    world.cfg["conf_vendor"] = ""
Пример #27
0
def upload_db_reservation():
    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd
    while list_of_all_reservations:
        each_record = list_of_all_reservations.pop()
        each_record.build_script()
        db_reservation = open("db_reservation", 'w')
        db_reservation.write(each_record.configuration_script)
        db_reservation.close()
        fabric_send_file(
            "db_reservation",
            world.f_cfg.software_install_path + "etc/kea/db_reservation")
        copy_configuration_file("db_reservation")
        remove_local_file("db_reservation")
        result = fabric_sudo_command(
            'cat ' + world.f_cfg.software_install_path +
            'etc/kea/db_reservation |  psql -U {db_user} -d {db_name}'.format(
                **locals()))
Пример #28
0
def upload_db_reservation():
    db_name = world.f_cfg.db_name
    db_user = world.f_cfg.db_user
    db_passwd = world.f_cfg.db_passwd
    while list_of_all_reservations:
        each_record = list_of_all_reservations.pop()
        print each_record.__dict__
        each_record.build_script()
        db_reservation = open("db_reservation", 'w')
        db_reservation.write(each_record.configuration_script)
        db_reservation.close()
        fabric_send_file(
            "db_reservation",
            world.f_cfg.software_install_path + "etc/kea/db_reservation")
        copy_configuration_file("db_reservation")
        remove_local_file("db_reservation")
        result = fabric_sudo_command(
            'cqlsh --keyspace=keatest --user=keatest --password=keatest -f ' +
            world.f_cfg.software_install_path + "etc/kea/db_reservation")
Пример #29
0
def build_and_send_config_files2(cfg, connection_type, configuration_type="config-file",
                                 destination_address=world.f_cfg.mgmt_address):
    if configuration_type == "config-file" and connection_type == "SSH":
        world.cfg['leases'] = os.path.join(world.f_cfg.software_install_path, 'var/kea/kea-leases4.csv')
        set_kea_ctrl_config()
        _write_cfg2(cfg)
        fabric_send_file(world.cfg["cfg_file"],
                         os.path.join(world.f_cfg.software_install_path, "etc/kea/kea.conf"),
                         destination_host=destination_address)
        fabric_send_file(world.cfg["cfg_file_2"],
                         os.path.join(world.f_cfg.software_install_path, "etc/kea/keactrl.conf"),
                         destination_host=destination_address)
        copy_configuration_file(world.cfg["cfg_file"], destination_host=destination_address)
        copy_configuration_file(world.cfg["cfg_file_2"], "kea_ctrl_config", destination_host=destination_address)
        remove_local_file(world.cfg["cfg_file"])
        remove_local_file(world.cfg["cfg_file_2"])
    elif configuration_type == "config-file" and connection_type is None:
        world.cfg['leases'] = os.path.join(world.f_cfg.software_install_path, 'var/kea/kea-leases4.csv')
        set_kea_ctrl_config()
        cfg_write()
        copy_configuration_file(world.cfg["cfg_file"], destination_host=destination_address)
        remove_local_file(world.cfg["cfg_file"])
Пример #30
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
Пример #31
0
def run_bindctl(succeed, opt):
    """
    Run bindctl with prepered config file
    """
    world.cfg[
        'leases'] = world.f_cfg.software_install_path + 'var/bind10/kea-leases4.csv'

    if opt == "clean":
        get_common_logger().debug('cleaning kea configuration')
        cfg_file = 'kea4-stop.cfg'
        prepare_cfg_kea4_for_kea4_stop(cfg_file)
        prepare_config_file(cfg_file)
        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')

    if opt == "start":
        if world.f_cfg.save_logs:
            set_logger()

        get_common_logger().debug('starting fresh kea')
        cfg_file = 'kea4-start.cfg'
        prepare_cfg_kea4_for_kea4_start(cfg_file)
        prepare_config_file(cfg_file)
        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')

    if opt == "configuration":
        get_common_logger().debug('kea configuration')
        cfg_file = world.cfg["cfg_file"]
        prepare_config_file(cfg_file)
        add_last = open(cfg_file + "_processed", 'a')

        # add 'config commit' we don't put it before
        add_last.write("config commit")
        add_last.close()

        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        copy_configuration_file(cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')
        world.cfg["conf"] = ""

    if opt == "restart":
        restart_srv()

    result = fabric_run_command('(echo "execute file ' + cfg_file +
                                '_processed" | ' +
                                world.f_cfg.software_install_path +
                                'bin/bindctl ); sleep 1')

    search_for_errors(succeed, opt, result,
                      ["ImportError:", '"config revert".', "Error"])
    parsing_bind_stdout(result.stdout, opt, ['Broken pipe'])
Пример #32
0
def build_and_send_config_files(connection_type,
                                configuration_type="config-file",
                                destination_address=world.f_cfg.mgmt_address,
                                cfg=None):
    """
    Generate final config file, save it to test result directory
    and send it to remote system unless testing step will define differently.
    :param connection_type: for now two values expected: SSH and None for stating if files should be send
    :param configuration_type: for now supported just config-file, generate file and save to results dir
    :param destination_address: address of remote system to which conf file will be send,
    default it's world.f_cfg.mgmt_address
    """

    #import pudb; pudb.set_trace()

    if world.proto == 'v4':
        add_defaults4()
    else:
        add_defaults6()

    _set_kea_ctrl_config()

    if cfg is None:
        _cfg_write()
    else:
        _write_cfg2(cfg)

    if connection_type == "SSH":
        if world.f_cfg.install_method == 'make':
            fabric_send_file(world.cfg["cfg_file_2"],
                             world.f_cfg.etc_join("keactrl.conf"),
                             destination_host=destination_address)
            kea_conf_file = "kea.conf"
        else:
            fabric_send_file(world.cfg["cfg_file"],
                             world.f_cfg.etc_join('kea-ctrl-agent.conf'),
                             destination_host=destination_address)
            kea_conf_file = "kea-dhcp%s.conf" % world.proto[1]
        fabric_send_file(world.cfg["cfg_file"],
                         world.f_cfg.etc_join(kea_conf_file),
                         destination_host=destination_address)

    copy_configuration_file(world.cfg["cfg_file"],
                            destination_host=destination_address)
    copy_configuration_file(world.cfg["cfg_file_2"],
                            "kea_ctrl_config",
                            destination_host=destination_address)
    remove_local_file(world.cfg["cfg_file"])
    remove_local_file(world.cfg["cfg_file_2"])
Пример #33
0
def run_bindctl (succeed, opt):
    """
    Run bindctl with prepered config file
    """    
    world.cfg['leases'] = SOFTWARE_INSTALL_DIR + 'var/bind10/kea-leases6.csv'

    if opt == "clean":
        get_common_logger().debug('cleaning kea configuration')
        # build configuration file with for:  
        #  - stopping Kea
        #  - cleaning configuration
        #  - default logging
        prepare_cfg_kea6_for_kea6_stop()
        cfg_file = 'kea6stop.cfg'
        prepare_config_file(cfg_file)
        # send file
        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')

    elif opt == "start":
        # build configuration file with for:  
        #  - clean start Kea
        get_common_logger().debug('starting fresh kea')
        prepare_cfg_kea6_for_kea6_start()
        cfg_file = 'kea6start.cfg'
        prepare_config_file(cfg_file)
        # send file
        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')

    elif opt == "configuration":
        # start logging on different file:
        if SAVE_LOGS:
            set_logger()
        # build configuration file with for:  
        #  - configure all needed to test features
        get_common_logger().debug('kea configuration')
        cfg_file = world.cfg["cfg_file"]
        prepare_config_file(cfg_file)
        add_last = open(cfg_file + "_processed", 'a')

        # add 'config commit' we don't put it before
        add_last.write("config commit")
        add_last.close()
        # send file
        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        copy_configuration_file(cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')

    elif opt == "restart":
        # restart server without changing it's configuration
        restart_srv()

    result = fabric_run_command('(echo "execute file ' + cfg_file + '_processed" | '
                                + SOFTWARE_INSTALL_DIR + 'bin/bindctl ); sleep ' + str(SLEEP_TIME_2))

    # now let's test output, looking for errors,
    # some times clean can fail, so we wanna test only start and conf
    # for now we fail test on any presence of stderr, probably this will
    # need some more specific search.
    search_for_errors(succeed, opt, result, ["ImportError:", '"config revert".', "Error"])

    # Error 32: Broken pipe
    # this error needs different aproach then others. Bind10 needs to be restarted.
    parsing_bind_stdout(result.stdout, opt, ['Broken pipe'])
Пример #34
0
def run_bindctl (succeed, opt):
    """
    Run bindctl with prepered config file
    """    
    world.cfg['leases'] = world.f_cfg.software_install_path + 'var/bind10/kea-leases6.csv'

    if opt == "clean":
        get_common_logger().debug('cleaning kea configuration')
        # build configuration file with for:  
        #  - stopping Kea
        #  - cleaning configuration
        #  - default logging
        prepare_cfg_kea6_for_kea6_stop()
        cfg_file = 'kea6stop.cfg'
        prepare_config_file(cfg_file)
        # send file
        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')

    elif opt == "start":
        # build configuration file with for:  
        #  - clean start Kea
        get_common_logger().debug('starting fresh kea')
        prepare_cfg_kea6_for_kea6_start()
        cfg_file = 'kea6start.cfg'
        prepare_config_file(cfg_file)
        # send file
        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')

    elif opt == "configuration":
        # start logging on different file:
        if world.f_cfg.save_logs:
            set_logger()
        # build configuration file with for:  
        #  - configure all needed to test features
        get_common_logger().debug('kea configuration')
        cfg_file = world.cfg["cfg_file"]
        prepare_config_file(cfg_file)
        add_last = open(cfg_file + "_processed", 'a')

        # add 'config commit' we don't put it before
        add_last.write("config commit")
        add_last.close()
        # send file
        fabric_send_file(cfg_file + '_processed', cfg_file + '_processed')
        copy_configuration_file(cfg_file + '_processed')
        remove_local_file(cfg_file + '_processed')

    elif opt == "restart":
        # restart server without changing it's configuration
        restart_srv()

    result = fabric_run_command('(echo "execute file ' + cfg_file + '_processed" | '
                                + world.f_cfg.software_install_path + 'bin/bindctl ); sleep ' + str(world.f_cfg.sleep_time_2))

    # now let's test output, looking for errors,
    # some times clean can fail, so we wanna test only start and conf
    # for now we fail test on any presence of stderr, probably this will
    # need some more specific search.
    search_for_errors(succeed, opt, result, ["ImportError:", '"config revert".', "Error"])

    # Error 32: Broken pipe
    # this error needs different aproach then others. Bind10 needs to be restarted.
    parsing_bind_stdout(result.stdout, opt, ['Broken pipe'])