示例#1
0
def sniff(what, interface='any', count=1, timeout=60, is_save=False,
          is_remote=False):
    """Executes tcpdump and collects some info depending on argument 'what'
       For example for SNIFF_RADVD one would expect something like
       {'what': 'icmp6', 'count': 3,
        'advertisement': {'count': 2, 'prefixes': ['feee::/64', None]}
        'solicitation': {'count': 1, 'prefixes': ['feee::/64']}
       }
       If run with is_remote to be True, that just compile string representing
       the commmand to be run by external ssh client.
       In this case, one needs to call sniff_analyzer by hands
    """
    import tempfile
    from tempest.common import commands

    cmd = 'tcpdump -vv -n -t -i {i} -c {c} {what}'.format(i=interface,
                                                          what=what,
                                                          c=count)
    if timeout:
        cmd = 'timeout -s SIGINT {0} '.format(timeout) + cmd
    if is_remote:
        return cmd
    if is_save:
        tmp_file_path = tempfile.mktemp('_out.tcpdump')
        commands.sudo_cmd_call(cmd=cmd + ' -w {0}'.format(tmp_file_path))
        return 'Check ' + tmp_file_path

    result = {'what': what, 'count': int(count)}
    capture = commands.sudo_cmd_call(cmd=cmd)
    result.update(sniff_analyzer(what=what, capture=capture))
    return result
示例#2
0
def sniff(what,
          interface='any',
          count=1,
          timeout=60,
          is_save=False,
          is_remote=False):
    """Executes tcpdump and collects some info depending on argument 'what'
       For example for SNIFF_RADVD one would expect something like
       {'what': 'icmp6', 'count': 3,
        'advertisement': {'count': 2, 'prefixes': ['feee::/64', None]}
        'solicitation': {'count': 1, 'prefixes': ['feee::/64']}
       }
       If run with is_remote to be True, that just compile string representing
       the commmand to be run by external ssh client.
       In this case, one needs to call sniff_analyzer by hands
    """
    import tempfile
    from tempest.common import commands

    cmd = 'tcpdump -vv -n -t -i {i} -c {c} {what}'.format(i=interface,
                                                          what=what,
                                                          c=count)
    if timeout:
        cmd = 'timeout -s SIGINT {0} '.format(timeout) + cmd
    if is_remote:
        return cmd
    if is_save:
        tmp_file_path = tempfile.mktemp('_out.tcpdump')
        commands.sudo_cmd_call(cmd=cmd + ' -w {0}'.format(tmp_file_path))
        return 'Check ' + tmp_file_path

    result = {'what': what, 'count': int(count)}
    capture = commands.sudo_cmd_call(cmd=cmd)
    result.update(sniff_analyzer(what=what, capture=capture))
    return result
示例#3
0
文件: radvd.py 项目: zip-code/tempest
def radvd_start_on(iface, prefix):
    from tempest.common import commands
    conf_abs_path = radvd_create_config(iface=iface, prefix=prefix)
    commands.sudo_cmd_call('radvd -C {conf} -p {pid}'.format(
        conf=conf_abs_path, pid=conf_abs_path.replace('.conf', '.pid')))