def my_first_test_method(ip=None, username=None, password=None):
    """
    Description: This description will be displayed in the test run output and should
    explain this test's objectives, progression, any artifacts it creates/removes, dependencies,
    etc..
    This test attempts to ssh into a remote device (in practice this might be a VM/instance)
     and verify the end host is alive by executing 2 commands; 'hostname' and 'uptime', verifies
     the return code of the commands to be '0', and prints the output out at debug level.
    """
    ip = ip or  testcase.args.test_ip # this is the arg we added above
    password = password or testcase.args.instance_password # instance_password provided
    username = username or testcase.args.instance_user or 'root' # so is instance_user
    if not ip or not password:
        raise ValueError('Need ip and password to run this ssh test! ip={0}, password={1}'
                         .format(ip, password))
    # Create an ssh connection using the ip. Using a short timeout and no retry since this
    # is an example, otherwise defaults are usually good.
    ssh = SshConnection(host=ip, username=username, password=password, timeout=10, retry=0,
                        verbose=True)

    # SshConnection.sys() will execute a cmd on the remote system, 'code' will check the return
    # code of the command and throw an exception if it does not match the value provided.
    # By default the returned output is a list of lines, but can also be returned as a single
    # string buffer using 'listformat=False')
    # The command is monitored and the session will be torn down and a timeout exception will be
    # thrown if it does not return by 'timeout' seconds.
    output = ssh.sys('hostname && uptime', listformat=False, code=0, timeout=20)


    # default logger writes to stdout and it's debug level method can be used such as...
    testcase.debug('my_first_test_method passed yay!!')
    testcase.debug('Heres the output of our two commands:\n{0}'.format(output))
Exemple #2
0
 def test3_download(self):
     """
     Attempts to download the SOS reports from each host in the cloud and store in a local
     directory
     """
     error_msg = ""
     count = 0
     err_count = 0
     host_count = len(self.ip_list)
     for ip in self.ip_list:
         if self.tc:
             if ip in self.tc.sysadmin.eucahosts.keys():
                 host = self.tc.sysadmin.eucahosts.get(ip)
                 ssh = host.ssh
             else:
                 ssh = SshConnection(host=ip, password=self.args.password)
         try:
             remote_tarball_path = ssh.sys(
                 "ls -1 {0}/*.xz | grep {1}".format(self.remote_dir,
                                                    self.ticket_number),
                 code=0)[0]
             tarball_name = os.path.basename(remote_tarball_path)
             local_name = "sosreport-{0}.{1}{2}".format(
                 ip, self.ticket_number,
                 tarball_name.split(str(self.ticket_number))[1])
             local_tarball_path = os.path.join(self.args.local_dir,
                                               local_name)
             self.log.debug("Downloading file to: " + local_tarball_path)
             ssh.sftp_get(localfilepath=local_tarball_path,
                          remotefilepath=remote_tarball_path)
         except Exception, e:
             err_count += 1
             msg = '\nError Downloading from: {0}. Error:"{0}"\n'.format(
                 ip, e)
             self.log.error("{0}\n{1}".format(get_traceback(), msg))
             error_msg += msg
         else:
             count += 1
             self.log.info(
                 markup('Downloaded SOS report {0}/{1} to:{2}'.format(
                     count, host_count, local_tarball_path),
                        markups=[
                            ForegroundColor.WHITE, BackGroundColor.BG_GREEN
                        ]))
Exemple #3
0
 def test3_download(self):
     """
     Attempts to download the SOS reports from each host in the cloud and store in a local
     directory
     """
     error_msg = ""
     count = 0
     err_count = 0
     host_count = len(self.ip_list)
     for ip in self.ip_list:
         if self.tc:
             if ip in self.tc.sysadmin.eucahosts.keys():
                 host = self.tc.sysadmin.eucahosts.get(ip)
                 ssh = host.ssh
             else:
                 ssh = SshConnection(host=ip, password=self.args.password)
         try:
             remote_tarball_path = ssh.sys("ls -1 {0}/*.xz | grep {1}"
                                            .format(self.remote_dir, self.ticket_number),
                                            code=0)[0]
             tarball_name = os.path.basename(remote_tarball_path)
             local_name = "sosreport-{0}.{1}{2}".format(ip, self.ticket_number,
                                              tarball_name.split(str(self.ticket_number))[1])
             local_tarball_path = os.path.join(self.args.local_dir, local_name)
             self.log.debug("Downloading file to: " + local_tarball_path)
             ssh.sftp_get(localfilepath=local_tarball_path,
                               remotefilepath=remote_tarball_path)
         except Exception, e:
             err_count += 1
             msg = '\nError Downloading from: {0}. Error:"{0}"\n'.format(ip, e)
             self.log.error("{0}\n{1}".format(get_traceback(), msg))
             error_msg += msg
         else:
             count += 1
             self.log.info(markup('Downloaded SOS report {0}/{1} to:{2}'
                                  .format(count, host_count, local_tarball_path),
                                  markups=[ForegroundColor.WHITE, BackGroundColor.BG_GREEN]))