Ejemplo n.º 1
0
def server_vm_check(server_ip, client_floatingip):
    for i in range(20):
        check_result = SshCommand.ssh_tperf_exec(CONF.openstack()['key_file'],
                                                 CONF.openstack()['tperf_vm_username'],
                                                 client_floatingip,
                                                 'ping -c 1 ' + server_ip + ' | grep transmitted',
                                                 timeout=2)
        if ' 0% packet loss' in check_result.split(','):
            return True
        else:
            LOG.error('[Server Network Check Fail and Retry %d', i)
            time.sleep(1)
    return False
Ejemplo n.º 2
0
    def ssh_exec(cls, username, node, command):
        cmd = 'ssh %s %s@%s %s' % (cls.ssh_options(), username, node, command)

        try:
            result = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
            output, error = result.communicate()

            if result.returncode != 0:
                LOG.error("\'%s\' SSH_Cmd Fail, cause => %s", node, error)
                return
            else:
                # LOG.info("ssh command execute successful \n%s", output)
                return output
        except:
            LOG.exception()
Ejemplo n.º 3
0
    def sql_execute(cls, sql, conn=None):
        try:
            if conn == None:
                with cls.connection() as conn:
                    conn.cursor().execute(sql)
                    conn.commit()

                conn.close()
            else:
                conn.cursor().execute(sql)
                conn.commit()

            return 'SUCCESS'
        except sqlite3.OperationalError, err:
            LOG.error(err.message)
            return err.message
Ejemplo n.º 4
0
    def ssh_pexpect(cls, username, node, onos_ip, command):
        cmd = 'ssh %s %s@%s' % (cls.ssh_options(), username, node)

        try:
            LOG.info('ssh_pexpect cmd = ' + cmd)
            ssh_conn = pexpect.spawn(cmd)

            rt1 = ssh_conn.expect(['#', '\$', pexpect.EOF],
                                  timeout=CONF.ssh_conn()['ssh_req_timeout'])

            if rt1 == 0:
                cmd = 'ssh -p 8101 karaf@' + onos_ip + ' ' + command

                LOG.info('ssh_pexpect cmd = ' + cmd)
                ssh_conn.sendline(cmd)
                rt2 = ssh_conn.expect(
                    ['Password:'******'ssh_req_timeout'])

                if rt2 == 0:
                    ssh_conn.sendline('karaf')
                    ssh_conn.expect(['#', '\$', pexpect.EOF],
                                    timeout=CONF.ssh_conn()['ssh_req_timeout'])

                    str_output = str(ssh_conn.before)

                    ret = ''
                    for line in str_output.splitlines():
                        if (line.strip() == '') or ('#' in line) or (
                                '$' in line) or ('~' in line) or ('@' in line):
                            continue

                        ret = ret + line + '\n'

                    return ret
                else:
                    return "fail"
            elif rt1 == 1:
                LOG.error('%s', ssh_conn.before)
            elif rt1 == 2:
                LOG.error("[ssh_pexpect] connection timeout")

            return "fail"
        except:
            LOG.exception()
            return "fail"
Ejemplo n.º 5
0
    def onos_ssh_exec(cls, node_ip, command):
        local_ssh_options = cls.ssh_options() + " -p 8101"

        cmd = 'ssh %s %s %s' % (local_ssh_options, node_ip, command)

        try:
            result = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
            output, error = result.communicate()

            if result.returncode != 0:
                LOG.error("ONOS(%s) SSH_Cmd Fail, cause => %s", node_ip, error)
                return
            else:
                # LOG.info("ONOS ssh command execute successful \n%s", output)
                return output
        except:
            LOG.exception()
Ejemplo n.º 6
0
    def ssh_tperf_exec(cls, keypair, username, node_ip, command, timeout):
        ssh_options = '-o StrictHostKeyChecking=no ' \
                      '-o ConnectTimeout=' + str(timeout)

        if not os.path.exists(keypair):
            LOG.error('[SSH Fail] keypaire file not exist. ---')
            return 'fail'
        cmd = 'ssh %s -i %s %s@%s %s' % (ssh_options, keypair, username, node_ip, command)
        LOG.info("[SB SSH CMD] cmd = %s", cmd)

        try:
            result = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
            (output, error) = result.communicate()

            if result.returncode != 0:
                LOG.error("\'%s\' SSH_Cmd Fail, cause(%d) => %s", node_ip, result.returncode, str(error))
                return 'fail'
            else:
                LOG.info("ssh command execute successful \n >> [%s]", output)
                return output
        except:
            LOG.exception()

        pass