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')
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')
def compare_file(local_path): """ Compare two files, downloaded and local """ if not os.path.exists(local_path): assert False, 'No local file %s' % local_path outcome = open(world.cfg["test_result_dir"] + '/file_compare', 'w') # first remove all commented and blank lines of both files downloaded_stripped = strip_file(world.cfg["test_result_dir"] + '/downloaded_file') local_stripped = strip_file(local_path) line_number = 1 error_flag = True for i, j in zip(downloaded_stripped, local_stripped): if i != j: outcome.write('Line number: ' + locale.str(line_number) + ' \n\tDownloaded file line: "' + i.rstrip('\n') + '" and local file line: "' + j.rstrip('\n') + '"\n') error_flag = False line_number += 1 if error_flag: remove_local_file(world.cfg["test_result_dir"] + '/file_compare') assert error_flag, 'Downloaded file is NOT the same as local. Check %s/file_compare for details'\ % world.cfg["test_result_dir"] if len(downloaded_stripped) != len(local_stripped): assert len(downloaded_stripped) > len( local_stripped), 'Downloaded file is part of a local file.' assert len(downloaded_stripped) < len( local_stripped), 'Local file is a part of a downlaoded life.'
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')
def compare_file(local_path): """ Compare two files, downloaded and local """ if not os.path.exists(local_path): assert False, 'No local file %s' % local_path outcome = open(world.cfg["dir_name"] + '/file_compare', 'w') # first remove all commented and blank lines of both files downloaded_stripped = strip_file(world.cfg["dir_name"] + '/downloaded_file') local_stripped = strip_file(local_path) line_number = 1 error_flag = True for i, j in zip(downloaded_stripped, local_stripped): if i != j: outcome.write('Line number: ' + locale.str(line_number) + ' \n\tDownloaded file line: "' + i.rstrip('\n') + '" and local file line: "' + j.rstrip('\n') + '"\n') error_flag = False line_number += 1 if error_flag: remove_local_file(world.cfg["dir_name"] + '/file_compare') assert error_flag, 'Downloaded file is NOT the same as local. Check %s/file_compare for details'\ % world.cfg["dir_name"] if len(downloaded_stripped) != len(local_stripped): assert len(downloaded_stripped) > len(local_stripped), 'Downloaded file is part of a local file.' assert len(downloaded_stripped) < len(local_stripped), 'Local file is a part of a downlaoded life.'
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
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
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')
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
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')
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;')
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;')
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"])
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()))
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"])
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"))
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"] = ""
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"] = ""
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"] = ""
def prepare_config_file(cfg): """ Prepare config file from generated world.cfg["cfg_file"] or START/STOP """ tmpfile = cfg + "_processed" conf = open(cfg, "rt") process = open(tmpfile, "w") # Copy input line by line, but skip empty and comment lines for line in conf: line = line.strip() if len(line) < 2: continue if line[0] == "#": continue process.write(line + "\n") conf.close() process.close() remove_local_file(cfg)
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")
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()))
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"])
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"])
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"])
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"])
def convert_cfg_file(cfg): tmpfile = cfg + "_processed" conf = open(cfg, "rt") process = open(tmpfile, "w") tab_flag = False # Copy input line by line, but skip empty and comment lines for line in conf: line = line.strip() if len(line) < 1: continue if line[0] == "#": continue if "}" in line: tab_flag = False if tab_flag: process.write("\t" + line + "\n") if not tab_flag: process.write(line + "\n") if "{" in line: tab_flag = True conf.close() process.close() remove_local_file(cfg)
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'])
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"])
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'])
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'])