Exemplo n.º 1
0
    def __init__(self):
        self._current_name = None
        self._current_id = None
        self._channels = {}
        self._max_id = 0
        self._ssh_prompt = '\[.*@.*\] '
        self._ssh_lib = SSHLibrary.SSHLibrary()

        # ignore SSL verify
        self._ssl_context = ssl._create_unverified_context()

        try:
            mod_list = glob.glob(Common.get_renat_path() +
                                 '/hypervisor_mod/*.py')
            keyword_list = []
            for item in mod_list:
                if item.startswith('_'): continue
                mod_name = os.path.basename(item).replace('.py', '')
                mod = import_module('hypervisor_mod.' + mod_name)

                cmd_list = inspect.getmembers(mod, inspect.isfunction)
                for cmd, data in cmd_list:
                    if not cmd.startswith('_') and cmd not in keyword_list:
                        keyword_list.append(cmd)

                        def gen_xrun(cmd):
                            def _xrun(self, *args, **kwargs):
                                return self.xrun(cmd, *args, **kwargs)

                            return _xrun

                        setattr(self, cmd, MethodType(gen_xrun(cmd), self))
        except RobotNotRunningError as e:
            Common.err("WARN: RENAT is not running")
Exemplo n.º 2
0
    def ssh_ex_cmd(self, ip, port, username, password, cmd_list, timeout=3):
        """
            功能:登录设备,连续重启三次,计算平均重启耗时,并返回该值\n
            参数:\n
                ip : 设备的IP地址\n
                port : 设备端口号\n
                username : 设备的用户名,支持中文\n
                password : 设备的密码,支持中文\n
                cmd_list : ssh命令列表\n
                timeout : 截止标志"#"(未出现时)延时等待时间,默认3s\n
            返回值:\n
            无\n
            """
        try:
            demo = SSHLibrary.SSHLibrary()
            demo.open_connection(host=ip, port=port)
            demo.set_client_configuration(timeout=timeout, prompt="#")
            demo.login(username, password)
            for item in cmd_list:
                demo.write(item)
                return_info = demo.read_until_prompt()
                print return_info
            print '%s\tOK\n' % (ip)
            demo.close_connection()

        except Exception, ex:
            print '%s\tError\n' % (ip)
            print Exception, ":", ex
Exemplo n.º 3
0
 def __init__(self):
     # initialize instance of Telnet and SSH lib
     self._telnet = Telnet()
     self._ssh = SSHLibrary.SSHLibrary()
     self._current_id = 0
     self._current_name = ""
     self._max_id = 0
     self._channels = {}
Exemplo n.º 4
0
 def __init__(self):
     # initialize instance of Telnet and SSH lib
     self._telnet = Telnet(timeout='3m')
     self._ssh = SSHLibrary.SSHLibrary(timeout='3m')
     self._current_id = 0
     self._current_name = None
     self._max_id = 0
     self._snap_buffer = {}
     self._channels = {}
Exemplo n.º 5
0
 def __init__(self, os):
     self.os = os
     print 'os: ' + os
     if os!='win':
         '''try:
             os.system('sshpass ')
         except:
             print 'fail'
             os.system('sudo yum -y install sshpass ')
         '''
     self.aoslib = AosLibrary.AosLibrary()
     self.cli = AosCLILibrary.AosCLILibrary()
     self.dte = AosDTELibrary.AosDTELibrary()
     self.ssh = SSHLibrary.SSHLibrary()
Exemplo n.º 6
0
def checkAvamarSanity(server, passwd):

    check_points = [
        'gsan status: up', 'MCS status: up', 'emt status: up',
        'Backup scheduler status: up',
        'Maintenance windows scheduler status: suspended',
        'Unattended startup status: enabled', 'avinstaller status: up',
        'ddrmaint-service status: up'
    ]

    # sleep 30 to wait avinstaller up
    time.sleep(30)

    # there are some issue with runShell for 'dpnctl status'
    # so here using SSHLibrary
    ssh = SSHLibrary.SSHLibrary(timeout=120)
    ssh.open_connection(server)
    ssh.login('admin', passwd)
    ssh.write('dpnctl status')
    output = ssh.read_until("~/>")
    output_arr = output.split('\n')
    ssh.close_all_connections()

    failures = []

    for checkpoint in check_points:
        found = False
        for line in output_arr:
            if re.search(checkpoint, line):
                found = True
                break
        if found is False:
            failures.append(checkpoint)
    # print the results
    print "DPN status:"
    for line in output_arr:
        if not re.search('~/>', line):
            print line

    if len(failures) >= 1:
        print "The following checkpoints have some problems:"
        for checkpoint in failures:
            print checkpoint
        BI_AGENT.fail("Error happened in sanity checking!")
        return False
    return True
Exemplo n.º 7
0
 def __init__(self,
              host=None,
              username=None,
              password=None,
              port=None,
              alias=None,
              timeout=3):
     env = TestEnv()
     config = env.get_env_config('Json Name')
     self.testinput_ip = config.get('data') if host is None else host
     self.testinput_port = config.get('port_info') if port is None else port
     self.testinput_user = config.get(
         'username') if username is None else username
     self.testinput_pw = config.get(
         'passwd') if password is None else password
     self.ssh_testinput = SSHLibrary.SSHLibrary(loglevel="INFO",
                                                timeout=timeout)
     self.promote = '[>#]'
     self.alias = alias or "other_value"
Exemplo n.º 8
0
def handleRootAccess(server, passwd, action='enable'):
    ssh = SSHLibrary.SSHLibrary()
    ssh.open_connection(server)
    # can only use 'admin' account to enable 'root' account
    ssh.login('admin', passwd)
    ssh.write("su -")
    ssh.read_until("Password")
    ssh.write(passwd)
    output = ssh.read_until("/#:")
    if action == 'enable':
        cmd = "sed -i s/^'PermitRootLogin no'/'PermitRootLogin yes'/\
               /etc/ssh/sshd_config"

    else:
        cmd = "sed -i s/^'PermitRootLogin yes'/'PermitRootLogin no'/\
               /etc/ssh/sshd_config"

    ssh.write(cmd)
    ssh.read_until("/#:")
    cmd = "/etc/init.d/sshd restart"
    ssh.write(cmd)
    ssh.read_until("/#:")
    ssh.close_all_connections()
11. Generating SSH key for reflex user 
12. Need to add logging - Need to be Done  
13. Need to add multithreading ***************************
'''
import re
import ConfigParser
#from robot.api import logger 
#from robot.api import logger as trace
from robot.libraries.BuiltIn import BuiltIn
import SSHLibrary
import time
import logging

robo = BuiltIn()

ssh = SSHLibrary()#robo.get_library_instance('SSHLibrary')


#iplist = {"192.168.162.103":"ST103","192.168.162.104":"ST104","192.168.162.105":"ST106"}
#iplist = {"192.168.162.103":"ST103-NEW"}
'''
@Need to mention this is any config file , this configuration need to add in different file
'''

#class Config_RPM():
#    def __init__(self):

config = ConfigParser.RawConfigParser(allow_no_value=True)
config.readfp(open('../config/rpm_config1'))
#print config.readfp(io.BytesIO(sample_config))
setup_nodes = config.sections()
Exemplo n.º 10
0
 def open_connection(self):
     if not self.ssh:
         self.ssh = SSHLibrary.SSHLibrary()
         self.ssh.open_connection(self.host)
         self.ssh.login(self.user, self.pwd)