Exemplo n.º 1
0
 def start_simpleHTTPserver(self, servers):
     output = ''
     for server in servers:
         with hide('everything'):
             with settings(host_string='%s@%s' %
                           (self.inputs.username, server.vm_node_ip),
                           password=self.inputs.password,
                           warn_only=True,
                           abort_on_prompts=False):
                 cmd1 = 'sudo hostname > index.html'
                 cmd2 = 'sudo python -m SimpleHTTPServer 80 & sleep 600'
                 output = run_fab_cmd_on_node(
                     host_string='%s@%s' %
                     (server.vm_username, server.local_ip),
                     password=server.vm_password,
                     cmd=cmd1,
                     as_sudo=False)
                 output = run_fab_cmd_on_node(
                     host_string='%s@%s' %
                     (server.vm_username, server.local_ip),
                     password=server.vm_password,
                     cmd=cmd2,
                     as_sudo=False,
                     timeout=2)
     return
Exemplo n.º 2
0
 def start_simpleHTTPserver(self, servers):
     output = ''
     for server in servers:
         with hide('everything'):
             with settings(host_string='%s@%s' % (self.inputs.username,server.vm_node_ip),
                           password=self.inputs.password, warn_only=True,abort_on_prompts= False):
                 cmd1 = 'sudo hostname > index.html'
                 cmd2 = 'sudo python -m SimpleHTTPServer 80 & sleep 600'
                 output = run_fab_cmd_on_node(host_string = '%s@%s'%(server.vm_username,server.local_ip),
                                         password = server.vm_password, cmd = cmd1, as_sudo=False)
                 output = run_fab_cmd_on_node(host_string = '%s@%s'%(server.vm_username,server.local_ip),
                                     password = server.vm_password, cmd = cmd2, as_sudo=False, timeout=2)
     return
Exemplo n.º 3
0
    def runcmd(self, cmd):
        """Run remote command."""
        output = None
#        keyfile = self.get_sshkey()
#        ssh_cmd = 'ssh -o StrictHostKeyChecking=no -i %s %s@%s \"%s\"' % (
#                  keyfile, self.rhost.user, self.rhost.ip, cmd)
        with hide('everything'):
            with settings(
                host_string='%s@%s' % (self.lhost.user, self.lhost.ip),
                    password=self.lhost.password, warn_only=True, abort_on_prompts=False):
                self.log.debug("Executing: %s", cmd)
                retry = 6
                while True:
                    output = ''
#                    output=run(ssh_cmd)
                    output = run_fab_cmd_on_node(
                        host_string='%s@%s' % (self.rhost.user, self.rhost.ip),
                        password='******', as_sudo=True, cmd=cmd)
                    if ("Connection timed out" in output or
                            "Connection refused" in output) and retry:
                        self.log.debug(
                            "SSH timeout, sshd might not be up yet. will retry after 5 secs.")
                        sleep(5)
                        retry -= 1
                        continue
                    elif "Connection timed out" in output:
                        raise SSHError(output)
                    else:
                        break
        self.log.debug(output)
        return output
Exemplo n.º 4
0
 def execute_in_vm(self, cmd, host):
     output = None
     with hide('everything'):
         with settings(host_string='%s@%s' % (self.pkgsrc.user, host),
                       password=self.pkgsrc.password,
                       warn_only=True,
                       abort_on_prompts=False):
             retry = 6
             while True:
                 output = ''
                 output = run_fab_cmd_on_node(
                     host_string='%s@%s' %
                     (self.pkgdst.user, self.pkgdst.host),
                     password=self.pkgdst.password,
                     cmd=cmd,
                     as_sudo=True,
                     logger=self.log)
                 if ("Connection timed out" in output
                         or "Connection refused" in output) and retry:
                     self.log.debug(
                         "SSH timeout, sshd might not be up yet. will retry after 5 secs."
                     )
                     sleep(5)
                     retry -= 1
                     continue
                 elif "Connection timed out" in output:
                     raise SSHError(output)
                 else:
                     break
     self.log.debug(output)
     return output
Exemplo n.º 5
0
 def execute_in_vm(self, cmd, host):
     output = None
     with hide('everything'):
         with settings(host_string='%s@%s' % (self.pkgsrc.user, host),
                       password=self.pkgsrc.password, warn_only=True,
                       abort_on_prompts=False):
             retry = 6
             while True:
                 output = ''
                 output = run_fab_cmd_on_node(
                     host_string='%s@%s' % (
                         self.pkgdst.user, self.pkgdst.host),
                     password=self.pkgdst.password, cmd=cmd,
                     as_sudo=True)
                 if ("Connection timed out" in output or
                         "Connection refused" in output) and retry:
                     self.log.debug(
                         "SSH timeout, sshd might not be up yet. will retry after 5 secs.")
                     sleep(5)
                     retry -= 1
                     continue
                 elif "Connection timed out" in output:
                     raise SSHError(output)
                 else:
                     break
     self.log.debug(output)
     return output
Exemplo n.º 6
0
 def run_wget(self, vm, vip):
     response = ''
     out = ''
     result = False
     with hide('everything'):
         with settings(host_string='%s@%s' %
                       (self.inputs.username, vm.vm_node_ip),
                       password=self.inputs.password,
                       warn_only=True,
                       abort_on_prompts=False):
             cmd1 = 'sudo wget http://%s' % vip
             cmd2 = 'cat index.html'
             cmd3 = 'rm -rf index.html'
             result = run_fab_cmd_on_node(host_string='%s@%s' %
                                          (vm.vm_username, vm.local_ip),
                                          password=vm.vm_password,
                                          cmd=cmd1,
                                          as_sudo=False)
             if result.count('200 OK'):
                 result = True
                 self.logger.info("connections to vip %s successful" %
                                  (vip))
                 response = run_fab_cmd_on_node(
                     host_string='%s@%s' % (vm.vm_username, vm.local_ip),
                     password=vm.vm_password,
                     cmd=cmd2,
                     as_sudo=False)
                 out = run_fab_cmd_on_node(host_string='%s@%s' %
                                           (vm.vm_username, vm.local_ip),
                                           password=vm.vm_password,
                                           cmd=cmd3,
                                           as_sudo=False)
                 self.logger.info("Request went to server: %s" % (response))
             else:
                 self.logger.error(
                     "Error in response on connecting to vip %s. Error is %s"
                     % (vip, result))
                 result = False
             return (result, response)
Exemplo n.º 7
0
    def run_wget(self, vm, vip):
        response = ''
        out = ''
        result = False
        with hide('everything'):
            with settings(host_string='%s@%s' % (self.inputs.username,vm.vm_node_ip),
                             password=self.inputs.password, warn_only=True,abort_on_prompts= False):
                cmd1 = 'sudo wget http://%s' % vip
                cmd2 = 'cat index.html'
                cmd3 = 'rm -rf index.html'
                result = run_fab_cmd_on_node(host_string = '%s@%s'%(vm.vm_username,vm.local_ip),
                                        password = vm.vm_password, cmd = cmd1, as_sudo=False)
                if result.count('200 OK'):
                    result = True
                    self.logger.info("connections to vip %s successful" % (vip))
                    response = run_fab_cmd_on_node(host_string = '%s@%s'%(vm.vm_username,vm.local_ip),
                                                  password = vm.vm_password, cmd = cmd2, as_sudo=False)
                    out = run_fab_cmd_on_node(host_string = '%s@%s'%(vm.vm_username,vm.local_ip),
                                              password = vm.vm_password, cmd = cmd3, as_sudo=False)
                    self.logger.info("Request went to server: %s" % (response))

                return (result,response)
Exemplo n.º 8
0
 def runcmd(self, cmd):
     """Run remote command."""
     output = None
     #        keyfile = self.get_sshkey()
     #        ssh_cmd = 'ssh -o StrictHostKeyChecking=no -i %s %s@%s \"%s\"' % (
     #                  keyfile, self.rhost.user, self.rhost.ip, cmd)
     self.log.debug('On host %s exec: %s' % (self.rhost.ip, cmd))
     with hide('everything'):
         with settings(host_string='%s@%s' %
                       (self.lhost.user, self.lhost.ip),
                       password=self.lhost.password,
                       warn_only=True,
                       abort_on_prompts=False):
             self.log.debug("Executing: %s", cmd)
             retry = 6
             while True:
                 output = ''
                 #                    output=run(ssh_cmd)
                 output = run_fab_cmd_on_node(
                     host_string='%s@%s' % (self.rhost.user, self.rhost.ip),
                     password='******',
                     as_sudo=True,
                     cmd=cmd,
                     logger=self.log)
                 if (not output) and retry:
                     self.log.error(
                         "Scapy issue while sending/receiving packets. Will retry after 5 secs."
                     )
                     sleep(5)
                     retry -= 1
                     continue
                 if ("Connection timed out" in output
                         or "Connection refused" in output) and retry:
                     self.log.debug(
                         "SSH timeout, sshd might not be up yet. will retry after 5 secs."
                     )
                     sleep(5)
                     retry -= 1
                     continue
                 elif "Connection timed out" in output:
                     raise SSHError(output)
                 else:
                     break
     self.log.debug(output)
     return output