Beispiel #1
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)
Beispiel #2
0
def restart_clnt(step):
    """
    This function shut downs and later starts dibbler-client on DUT.
    @step("Restart client.")
    """
    fabric_sudo_command("("+world.f_cfg.software_install_path+"dibbler-client stop); sleep 1;")
    fabric_sudo_command("("+world.f_cfg.software_install_path+"dibbler-client start); sleep 1;")
Beispiel #3
0
def restart_clnt(step):
    """
    This function shut downs and later starts dibbler-client on DUT.
    @step("Restart client.")
    """
    fabric_sudo_command("("+SOFTWARE_INSTALL_DIR+"dibbler-client stop); sleep 1;")
    fabric_sudo_command("("+SOFTWARE_INSTALL_DIR+"dibbler-client start); sleep 1;")
Beispiel #4
0
def restart_clnt(step):
    """
    This function shut downs and later starts dhclient on DUT.
    @step("Restart client.")
    """
    stop_clnt()
    # clean_leases()  ## ?
    fabric_sudo_command('(rm nohup.out; nohup ' + \
                        world.clntCfg["command"] + ' & ); sleep 1;')
Beispiel #5
0
def release_command():
    """
    Function that executes a previously generated command with "-r" 
    option, which results in sending by dhclient RELEASE repeatedly, until
    REPLY is received. There's no need to execute it with delay like in
    dibbler-client's case, since message will being retransmitted.
    """
    fabric_sudo_command('(rm nohup.out; nohup ' + \
                        world.clntCfg["command"] + ' -r & ); sleep 1;')
Beispiel #6
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')
        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')
    print json.dumps(json.loads(world.control_channel),
                     sort_keys=True,
                     indent=2,
                     separators=(',', ': '))
Beispiel #7
0
def start_clnt(step):
    """
    @step("Client is started.")

    Lettuce step for writing config to file, sending it and starting client.
    """
    write_clnt_cfg_to_file()
    make_script()
    get_common_logger().debug("Start dhclient6 with generated config:")
    clean_leases()
    world.clntCfg["keep_lease"] = False
    fabric_send_file(world.clntCfg["Filename"], SOFTWARE_INSTALL_DIR + "dhclient.conf")
    fabric_send_file(world.clntCfg["script"], SOFTWARE_INSTALL_DIR + "comm.sh")
    fabric_remove_file_command(world.clntCfg["Filename"])
    fabric_remove_file_command(world.clntCfg["log_file"])
    fabric_sudo_command('(rm nohup.out; nohup bash ' + \
                        SOFTWARE_INSTALL_DIR + 'comm.sh &); sleep 1;')
Beispiel #8
0
def regular_file_contain(file_name, condition, line):

    result = fabric_sudo_command('grep -c \"' + line + '\" ' + file_name)
    if condition is not None:
        if result.succeeded:
            assert False, 'File {0} contains line/phrase: {1} But it should NOT.'.format(file_name, line)
    else:
        if result.failed:
            assert False, 'File {0} does NOT contain line/phrase: {1} .'.format(file_name, line)
Beispiel #9
0
def log_contains_count(step, server_type, count, line):
    if server_type == "DHCP":
        log_file = world.cfg["dhcp_log_file"]
    elif server_type == "DNS":
        log_file = world.cfg["dns_log_file"]
    else:
        assert False, "No such name as: {server_type}".format(**locals())

    result = fabric_sudo_command('grep -c \"' + line + '\" ' + log_file)

    if count != result:
        assert False, 'Log has {0} of expected {1} of line: "{2}".'.format(result, count, line)
Beispiel #10
0
def log_contains(step, server_type, condition, line):
    if server_type == "DHCP":
        log_file = world.cfg["dhcp_log_file"]
    elif server_type == "DNS":
        log_file = world.cfg["dns_log_file"]
    else:
        assert False, "No such name as: {server_type}".format(**locals())

    result = fabric_sudo_command('grep -c \"' + line + '\" ' + log_file)

    if condition is not None:
        if result.succeeded:
            assert False, 'Log contains line: "%s" But it should NOT.' % line
    else:
        if result.failed:
            assert False, 'Log does NOT contain line: "%s"' % line
Beispiel #11
0
def execute_shell_script(path, arguments):
    result = fabric_sudo_command(path + ' ' + arguments, False)

    file_name = path.split("/")[-1] + '_output'
    file_name = generate_file_name(1, file_name)

    # assert False, type(result.stdout)
    if not os.path.exists(world.cfg["dir_name"]):
        os.makedirs(world.cfg["dir_name"])

    myfile = open(world.cfg["dir_name"] + '/' + file_name, 'w')
    myfile.write(unicode('Script: ' + path))
    if arguments == '':
        arguments = "no arguments used!"
    myfile.write(unicode('\nwith arguments: ' + arguments + '\n'))
    if result.failed:
        myfile.write(unicode('\nStatus: FAILED\n'))
    else:
        myfile.write(unicode('\nStatus: SUCCEED\n'))

    myfile.write(unicode('\nScript stdout:\n' + result.stdout))
    myfile.close()
    forge_sleep(3, "seconds")
Beispiel #12
0
def stop_clnt():
    """
    Command that shut downs one instance of running dibbler-client on DUT.
    """
    fabric_sudo_command ("("+world.f_cfg.software_install_path+"dibbler-client stop); sleep 1;")
Beispiel #13
0
def execute_shell_command(command):
    fabric_sudo_command(command, hide_all=False)
Beispiel #14
0
def connect_socket(command):
    fabric_sudo_command(command, False)
Beispiel #15
0
def execute_shell_command(command):
    fabric_sudo_command(command, False)
Beispiel #16
0
def connect_socket(command):
    fabric_sudo_command(command, hide_all=False)
Beispiel #17
0
def stop_clnt():
    """
    Command that shut downs one instance of running dibbler-client on DUT.
    """
    fabric_sudo_command ("("+SOFTWARE_INSTALL_DIR+"dibbler-client stop); sleep 1;")