Example #1
0
def threadable_cleanup_final(remote_machines):
    """
  <Purpose>
    Cleans the files created by this script from the remote machine
    
  <Arguments>
    remote_machines:
      a list containing a single tuple of (user, remotehost)

  <Exceptions>
    None.

  <Side Effects>

  <Returns>
    None.
  """
    # Assume single element if it's not a list
    if type(remote_machines) != type([]):
        remote_machines = [remote_machines]

    # for every machine in our list...
    for machine_tuple in remote_machines:

        username = machine_tuple[0]
        machine = machine_tuple[1]

        deploy_logging.log('Final cleanup', 'Final cleanup of  ' + machine)

        # build up our list of files/folders we need to delete
        cmd_list = []
        cmd_list.append('rm -rf runlocaltests.py')
        cmd_list.append('rm -rf hashes.dict')
        cmd_list.append('rm -rf ' + machine + '.deployrun.log')
        cmd_list.append('rm -rf ' + machine + '.deployrun.err.log')
        cmd_list.append('rm -rf testprocess.py')
        cmd_list.append('rm -rf verifyfiles.mix')
        cmd_list.append('rm -rf ' + machine + '.tgz')
        cmd_list.append('rm -rf deploy.tar')
        cmd_list.append('rm -rf cleanup_deploy.py')
        #TODO: cleanup custom scripts as well here?

        # merge the commands into a string that we'll execute
        cmd_str = '; '.join(cmd_list)
        ssh_stdout, ssh_stderr, ssh_errcode = deploy_network.remote_shellexec(
            cmd_str, username, str(machine))

        deploy_logging.print_to_log('Detailed cleanup', ssh_stdout, ssh_stderr,
                                    ssh_errcode)
    return
def threadable_cleanup_final(remote_machines):
  """
  <Purpose>
    Cleans the files created by this script from the remote machine
    
  <Arguments>
    remote_machines:
      a list containing a single tuple of (user, remotehost)

  <Exceptions>
    None.

  <Side Effects>

  <Returns>
    None.
  """
  # Assume single element if it's not a list
  if type(remote_machines) != type([]):
    remote_machines = [remote_machines]
  
  # for every machine in our list...
  for machine_tuple in remote_machines:
    
    username = machine_tuple[0]
    machine = machine_tuple[1]

    deploy_logging.log('Final cleanup', 'Final cleanup of  '+machine)

    # build up our list of files/folders we need to delete
    cmd_list = []
    cmd_list.append('rm -rf runlocaltests.py')
    cmd_list.append('rm -rf hashes.dict')
    cmd_list.append('rm -rf '+machine+'.deployrun.log')
    cmd_list.append('rm -rf '+machine+'.deployrun.err.log')
    cmd_list.append('rm -rf testprocess.py')
    cmd_list.append('rm -rf verifyfiles.mix')
    cmd_list.append('rm -rf '+machine+'.tgz')
    cmd_list.append('rm -rf deploy.tar')
    cmd_list.append('rm -rf cleanup_deploy.py')
    #TODO: cleanup custom scripts as well here?
    
    # merge the commands into a string that we'll execute
    cmd_str = '; '.join(cmd_list)
    ssh_stdout, ssh_stderr, ssh_errcode = deploy_network.remote_shellexec(cmd_str, username, str(machine))

    deploy_logging.print_to_log('Detailed cleanup', ssh_stdout, 
        ssh_stderr, ssh_errcode)
  return
Example #3
0
def remote_runcleanup(user, remote_host):
  """
  <Purpose>
    This function connects to the remote computer and executes the 
    cleanup/setup script.

  <Arguments>
    user:
      the user to log in as
    remote_host:
      the IP of the host to get the logs from

  <Exceptions>
    None.

  <Side Effects>
    None.

  <Returns>
    None.
  """

  # build up the command list that we'll execute on the remote host
  cmd_list = []

  # extract the cleanup script
  cmd_list.append('tar -xf deploy.tar cleanup_deploy.py')
  
  # execute the script
  cmd_list.append('python cleanup_deploy.py '+remote_host)

  # join the list together with '; ' between the entries
  cmd_str = '; '.join(cmd_list)
  
  # our handle to the session
  out, err, returncode = remote_shellexec(cmd_str, user, remote_host)

  deploy_logging.print_to_log('Cleanup/Setup', out, err, returncode)
Example #4
0
def remote_runscript(user, remote_host, custom_script_name = '', run_custom_only = False, tar_filename = 'deploy.tar'):
  """
  <Purpose>
    This function connects to user@remote_host using the specified rsa key.
    Typically, only the user and remote_host fields need to be changed - the 
    RSA key used is the user's default RSA key.  After connecting, this will
    extract runlocaltests.py from the tar_filename and execute it remotely.
     
  <Arguments>
    user:
      the user to log in as on the remote machine.
    remote_host:
      the remote machine's IP to which we'll be uploading files.
    custom_script_name:
      the name(s) as strings of custom scripts to run on the remote machine.
    run_custom_only:
      Should we only run the custom script?
    tar_filename: 
      Optional. Default is deploy.tar. The tar file to upload to the remote 
        host.
    
  <Exceptions>
    None.

  <Side Effects>
    Blocks current thread until remote script is done executing.

  <Returns>
    No returns.
  """

  # We will build up our list of commands as a list of strings, then 
  # join with the ';' to specifify multiple commands on one line.
  cmd_list = []

  # extract out remote setup script that'll figure out where the files need to 
  # be extracted to
  cmd_list.append('tar -xf '+tar_filename+' runlocaltests.py')


  # The following lines execute the script remotely
  # IMPORTANT - SEE runlocaltests.py for args
  # if verbose flag is set, make the runlocaltests.py script also verbose
  
  if run_custom_only:
    cmd_list.append('python runlocaltests.py '+remote_host+' -v '+\
        str(deploy_main.verbosity)+' '+custom_script_name+' 1')
  else: # tell the script we're ONLY running the custom files
    cmd_list.append('python runlocaltests.py '+remote_host+' -v '+\
        str(deploy_main.verbosity)+' '+custom_script_name)

  # Create the one string that we'll execute, join with '; '
  command_string = '; '.join(cmd_list)

  # use helper to execute command_string on user@remote_host
  out, err, returncode = remote_shellexec(command_string, user, remote_host)

  deploy_logging.print_to_log(remote_host, out, err, returncode)

  # Once we're done executing the remote script, lets grab the logs
  remote_get_log(user, remote_host)