Ejemplo n.º 1
0
def command(_=None):
    """
    Exchanges the public keys between all VMs to allow direct ssh connections
    between them without user input.
    """
    local, remote = settings.PATHS['configuration']
    local = os.path.join(local, 'authorized_keys')
    remote = os.path.join(remote, 'authorized_keys')

    with shell.ignore_warnings():
        shell.local('rm {0}'.format(local))

    # Collect all keys in one file
    shell.remote('cat $HOME/.ssh/id_rsa.pub >>{0}'.format(remote))

    # Copy first authorized key (host machine) to temp location
    shell.remote('head -1 $HOME/.ssh/authorized_keys ' \
                 '>$HOME/.ssh/authorized_keys.tmp')

    # Append all other keys
    shell.remote('cat {0} >>$HOME/.ssh/authorized_keys.tmp'.format(remote))

    # Move to the original location
    shell.remote('mv $HOME/.ssh/authorized_keys.tmp ' \
                 '$HOME/.ssh/authorized_keys')

    # Add all hosts to the known_hosts file
    shell.remote('cat $HOME/.ssh/authorized_keys | '\
                 'awk -F \' \' \'{print $3}\' | ' \
                 'grep -E \'[0-9.]{7,15}\' | ' \
                 'ssh-keyscan -f - -H -t rsa >$HOME/.ssh/known_hosts')

    shell.local('rm {0}'.format(local))
Ejemplo n.º 2
0
def collect(name, overwrite=False):
    """
    Moves the relevant files to the shared directory by asking to empty the
    destination directory if needed.
    """

    ipaddr = "$(getip eth1)"
    name = "{0}_{1}".format(name, datetime.now().strftime("%Y-%m-%d_%H:%M"))

    guest_local = settings.PATHS["local-measures"][1]
    host_shared, guest_shared = settings.PATHS["shared-measures"]
    destination = os.path.join(guest_shared, name, ipaddr)
    local = os.path.realpath(os.path.join(host_shared, name))

    try:
        if os.listdir(local):
            print "A directory with the same name ({0}) already " "exists.".format(name)

            if overwrite or shell.confirm("Would you like to replace it?"):
                shell.local("rm -rf {0}/*".format(local))
            else:
                raise OSError(errno.ENOTEMPTY, "Directory not empty")
    except OSError as e:
        # If the file or directory don't exist, consume the exception
        if e.errno != errno.ENOENT:
            raise

    shell.remote("chown -R {0}:{0} {1}".format(settings.VM_USER, guest_local), sudo=True)
    shell.remote('mkdir -p "{0}/logs"'.format(destination))
    shell.remote('cp {0}/* "{1}"'.format(guest_local, destination))

    # Copy log files
    for logfile in settings.LOG_FILES:
        shell.remote('chown {0}:{0} "{1}" || true'.format(settings.VM_USER, logfile), sudo=True)
        shell.remote('cp "{0}" "{1}/logs" || true'.format(logfile, destination))
Ejemplo n.º 3
0
def kill():
    """
    Kills ALL running measures on the hosts provided by the context or
    (by default) on all known hosts.
    """
    with shell.ignore_warnings():
        shell.remote('pkill "tshark"', sudo=True)
Ejemplo n.º 4
0
def kill():
    """
    Kills ALL running job managers (and the relative search nodes) on the
    hosts provided by the context or (by default) on all known hosts.
    """
    with shell.ignore_warnings():
        shell.remote('pkill "jobmgr|popc_*"', sudo=True)
Ejemplo n.º 5
0
def start(name, iface="lo", outfile="-", capture_filter=""):
    """
    Starts a new tshark capture in background using a named screen session.
    
    The name of the spawned screen session will be the provided name joined
    with the interface by a dot.
    """
    
    # tshark command, see `man tshark` for further information about the
    # capture_filter syntax
    tshark = 'tshark -i {iface} -t e -w {outfile} {filter}'.format(
        iface=iface,
        outfile=outfile,
        filter=capture_filter
    )
    
    # Execute the tshark command inside a named screen session to allow
    # execution in background and selective termination
    screen = 'screen -dmS {name}.{iface} {command}'.format(
        name=name,
        iface=iface,
        command=tshark
    )
    
    shell.remote(screen, sudo=True)
Ejemplo n.º 6
0
def compile(name, localdir=None, remotedir=None):
    """
    Compiles the given test case on all the hosts in the system.

    The building details and the respect of the convention are enforced by the
    Makefile and not further explained here.
    """
    # Read the defaults from the settings if the arguments are not provided
    if not localdir or not remotedir:
        paths = settings.PATHS['test-cases']

        if not localdir:
            localdir = paths[0]

        if not remotedir:
            remotedir = paths[1]

    local = os.path.join(localdir, name)
    remote = os.path.join(remotedir, name)

    shell.local('rm -f {0}/build/obj.map'.format(local))

    base = os.path.dirname(settings.PATHS['configuration'][1])

    with shell.workon(all_hosts()):
        with shell.cd(remote):
            shell.remote('ENV_BASE={0} make -e clean'.format(base))
            shell.remote('ENV_BASE={0} make -e build'.format(base))
Ejemplo n.º 7
0
def stop(name, interface):
    """
    Stops the named tshark capture session on the given interface.
    
    The final name passed to the screen command will be the name joined with
    the interface by a dot.
    """
    shell.remote('screen -X -S {0}.{1} quit'.format(name, interface), sudo=True)
Ejemplo n.º 8
0
def restart():
    """
    Stops and restarts a currently running JobMgr instance on one or more
    (depending on the current context) remote nodes in a unique command.
    
    This function is intended to be used to restart a single node. To restart
    all nodes of a system, use the startall function, which introduces some
    delays to allow a correct registration of the slaves by the master.
    """
    shell.remote('SXXpopc stop ; SXXpopc start', pty=True, sudo=True)
Ejemplo n.º 9
0
def pcaptoxml(infile, outfile, display_filter=""):
    """
    Converts the pcap input file to XML and writes the output to outfile while
    filtering using the given display filter.
    
    Refer directly to the tshark man page for further informations about the
    display filter syntax.
    """
    shell.remote('tshark -T pdml -r {infile} -t e {filter} >{outfile}'.format(
        infile=infile,
        outfile=outfile,
        filter=display_filter
    ))
Ejemplo n.º 10
0
def execute(name, remotedir=None):
    """
    Executes the given test case on all client hosts (normally onle one).
    """
    if not remotedir:
        remotedir = settings.PATHS['test-cases'][1]

    remote = os.path.join(remotedir, name)

    base = os.path.dirname(settings.PATHS['configuration'][1])

    with shell.workon(role('client')):
        with shell.cd(remote):
            shell.remote('ENV_BASE={0} make -e execute'.format(base))
Ejemplo n.º 11
0
def start():
    """
    Starts a JobMgr instance on one or more (depending on the current context)
    remote nodes.
    
    This function is intended to be used to start a single node. To start all
    nodes of a system, use the startall function, which introduces some delays
    to allow a correct registration of the slaves by the master.
    """
    # Cleanup previsouly created log files
    shell.remote('rm -f {0}'.format(" ".join(settings.LOG_FILES)), sudo=True)
    
    # pty required to be set to true, otherwise the remote invocation hangs
    # and never returns
    shell.remote('SXXpopc start', pty=True, sudo=True)
Ejemplo n.º 12
0
def start(name):
    """
    Start a new named measure session in background on all interested hosts.

    The hosts are retrieved from the ROLES setting directive and a
    measure is started for each one.
    """
    dest = settings.PATHS["local-measures"][1]
    fltr = settings.CAPTURE_FILTER

    for host, interfaces in map_interfaces():
        with shell.workon(host):
            shell.remote("rm -rf {0} ; mkdir {0}".format(dest), sudo=True)

            for i in interfaces:
                mname = "{0}.{1}".format(name, i)
                tshark.start(mname, i, "{0}/{1}.raw".format(dest, mname), fltr)