Ejemplo n.º 1
0
def clean_leases():
    """
    Function that executes command on DUT, which removes the old lease
    file and creates an empty, new one.
    """
    fabric_run_command('echo y | rm ' + world.clntCfg['leases'])
    fabric_run_command('touch ' + world.clntCfg['leases'])
Ejemplo n.º 2
0
def db_table_contain(table_name, db_type, condition, line, db_name=world.f_cfg.db_name,
                     db_user=world.f_cfg.db_user, db_passwd=world.f_cfg.db_passwd):

    if db_type in ["mysql", "MySQL"]:
        command = 'mysql -u {db_user} -p{db_passwd} -e "select * from {table_name}"' \
                  ' {db_name} --silent --raw > /tmp/mysql_out'.format(**locals())
        fabric_run_command(command)
        result = fabric_sudo_command('grep -c "{line}" /tmp/mysql_out'.format(**locals()))

    elif db_type in ["postgresql", "PostgreSQL"]:
        command = 'psql -U {db_user} -d {db_name} -c "select * from {table_name}" > /tmp/pgsql_out'.format(**locals())
        fabric_run_command(command)
        result = fabric_sudo_command('grep -c "{line}" /tmp/pgsql_out'.format(**locals()))

    elif world.f_cfg.db_type == "cql":
        result = -1
        # command = 'for table_name in dhcp_option_scope host_reservations lease4 lease6;' \
        #           ' do cqlsh --keyspace=keatest --user=keatest --password=keatest -e "TRUNCATE $table_name;"' \
        #           ' ; done'.format(**locals())
        # fabric_run_command(command)
    else:
        assert False, "db type {db_type} not recognized/not supported".format(**locals())

    if condition is not None:
        if int(result) > 0:
            assert False, 'In database {0} table name "{1}" has {2} of: "{3}".' \
                          ' That is to much.'.format(db_type, table_name, result, line)
    else:
        if int(result) < 1:
            assert False, 'In database {0} table name "{1}" has {2} of: "{3}".'.format(db_type,
                                                                                       table_name, result, line)
Ejemplo n.º 3
0
def release_command():
    """
    This command is used when there's a need to sniff a RELEASE message
    sent by dibbler client. That happens when, for example, client is
    shut down. So This is basically the same as starting dibbler-client -
    running a script that executes a command with some delay. Whole thing
    is necessary, because firstly we need to start sniffing for particular
    message. On shutdown, dibbler-client sends exactly one RELEASE message.
    """
    world.clntCfg["script"] = ""
    make_script("stop")
    get_common_logger().debug("Stopping Dibbler Client and waiting for RELEASE.")
    fabric_send_file(world.clntCfg["script"], world.f_cfg.software_install_path+'comm.sh')
    fabric_run_command ('(rm nohup.out; nohup bash ' \
                        + world.f_cfg.software_install_path + 'comm.sh &); sleep 3;')
Ejemplo n.º 4
0
def release_command():
    """
    This command is used when there's a need to sniff a RELEASE message
    sent by dibbler client. That happens when, for example, client is
    shut down. So This is basically the same as starting dibbler-client -
    running a script that executes a command with some delay. Whole thing
    is necessary, because firstly we need to start sniffing for particular
    message. On shutdown, dibbler-client sends exactly one RELEASE message.
    """
    world.clntCfg["script"] = ""
    make_script("stop")
    get_common_logger().debug("Stopping Dibbler Client and waiting for RELEASE.")
    fabric_send_file(world.clntCfg["script"], SOFTWARE_INSTALL_DIR+'comm.sh')
    fabric_run_command ('(rm nohup.out; nohup bash ' \
                        + SOFTWARE_INSTALL_DIR + 'comm.sh &); sleep 3;')
Ejemplo n.º 5
0
def start_clnt(step):
    """
    @step("Client is started.")

    Lettuce step for writing config to file, sending it and starting client.
    """
    world.clntCfg["keep_lease"] = False
    world.clntCfg["log_file"] = "/var/log/dibbler/dibbler-client.log"
    write_clnt_cfg_to_file()
    make_script("start")
    get_common_logger().debug("Starting Dibbler Client with generated config:")
    fabric_send_file(world.clntCfg["Filename"], '/etc/dibbler/client.conf')
    fabric_send_file(world.clntCfg["script"], world.f_cfg.software_install_path+'comm.sh')
    fabric_remove_file_command(world.clntCfg["Filename"])
    # start client with clean log file
    fabric_remove_file_command(world.clntCfg["log_file"])
    fabric_run_command ('(rm nohup.out; nohup bash ' \
                        + world.f_cfg.software_install_path + 'comm.sh &); sleep 3;')
Ejemplo n.º 6
0
def start_clnt(step):
    """
    @step("Client is started.")

    Lettuce step for writing config to file, sending it and starting client.
    """
    world.clntCfg["keep_lease"] = False
    world.clntCfg["log_file"] = "/var/log/dibbler/dibbler-client.log"
    write_clnt_cfg_to_file()
    make_script("start")
    get_common_logger().debug("Starting Dibbler Client with generated config:")
    fabric_send_file(world.clntCfg["Filename"], '/etc/dibbler/client.conf')
    fabric_send_file(world.clntCfg["script"], SOFTWARE_INSTALL_DIR+'comm.sh')
    fabric_remove_file_command(world.clntCfg["Filename"])
    # start client with clean log file
    fabric_remove_file_command(world.clntCfg["log_file"])
    fabric_run_command ('(rm nohup.out; nohup bash ' \
                        + SOFTWARE_INSTALL_DIR + 'comm.sh &); sleep 3;')
Ejemplo n.º 7
0
def remove_from_db_table(table_name, db_type, db_name=world.f_cfg.db_name,
                         db_user=world.f_cfg.db_user, db_passwd=world.f_cfg.db_passwd):

    if db_type in ["mysql", "MySQL"]:
        # that is tmp solution - just clearing not saving.
        command = 'mysql -u {db_user} -p{db_passwd} -e "delete from {table_name}" {db_name}'.format(**locals())
        fabric_run_command(command)
    elif db_type in ["postgresql", "PostgreSQL"]:
        command = 'psql -U {db_user} -d {db_name} -c "delete from {table_name}"'.format(**locals())
        fabric_run_command(command)
    elif 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)
    else:
        assert False, "db type {db_type} not recognized/not supported".format(**locals())
Ejemplo n.º 8
0
def kill_clnt():
    """
    Command that stops every instance of dibbler-client being run on a
    DUT.
    """
    fabric_run_command("sudo killall dibbler-client &>/dev/null")
Ejemplo n.º 9
0
def kill_clnt():
    """
    Command that stops every instance of dibbler-client being run on a
    DUT.
    """
    fabric_run_command("sudo killall dibbler-client &>/dev/null")
Ejemplo n.º 10
0
def stop_clnt():
    """
    This function destroys every running instance of dhclient on DUT.
    """
    fabric_run_command("sudo killall dhclient &>/dev/null")