[libvirt] [test-API 0/3] Destroy class for utils/check.py
Just as what we did for utils/utils.py, we don't benifit from the class use at all. Osier Yang (3): remove importing of unused check module Destroy class of utils/check.py Destroy use of check class repos/domain/balloon_memory.py | 3 +- repos/domain/dump.py | 4 +- repos/domain/install_linux_check.py | 15 +- repos/snapshot/file_flag.py | 7 +- repos/snapshot/flag_check.py | 3 +- utils/check.py | 649 +++++++++++++++++------------------ utils/xmlgenerator.py | 1 - 7 files changed, 335 insertions(+), 347 deletions(-) -- 1.7.7.3
--- utils/xmlgenerator.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/utils/xmlgenerator.py b/utils/xmlgenerator.py index d93f58c..7f5839b 100644 --- a/utils/xmlgenerator.py +++ b/utils/xmlgenerator.py @@ -26,7 +26,6 @@ sys.path.append("../utils") import xml.dom.minidom import utils -import check import commands def domain_xml(params, install = False): -- 1.7.7.3
On 04/17/2012 09:44 PM, Osier Yang wrote:
--- utils/xmlgenerator.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/utils/xmlgenerator.py b/utils/xmlgenerator.py index d93f58c..7f5839b 100644 --- a/utils/xmlgenerator.py +++ b/utils/xmlgenerator.py @@ -26,7 +26,6 @@ sys.path.append("../utils")
import xml.dom.minidom import utils -import check import commands
def domain_xml(params, install = False):
ACK Guannan Ren
Just as utils/utils.py, it's bad idea to use class in utils. --- utils/check.py | 649 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 322 insertions(+), 327 deletions(-) diff --git a/utils/check.py b/utils/check.py index 9734fc9..1db49e7 100644 --- a/utils/check.py +++ b/utils/check.py @@ -29,369 +29,364 @@ import commands import signal import pexpect -class Check(object): - """Basic check operation for test""" - def support_virt(self): - cmd = "cat /proc/cpuinfo | egrep '(vmx|svm)'" - if commands.getoutput(cmd) is None: - print 'CPU does not support VT.' - return False - else: - return True +def support_virt(self): + cmd = "cat /proc/cpuinfo | egrep '(vmx|svm)'" + if commands.getoutput(cmd) is None: + print 'CPU does not support VT.' + return False + else: + return True - def __init__( self, subproc_pid = 0, subproc_flag = 0 ): - self.subproc_flag = subproc_flag +def subproc(a, b): + subproc_flag = 1 - def subproc(self, a, b): - self.subproc_flag = 1 +def remote_exec(hostname, username, password, cmd): + """Remote execution on specified host""" + pid, fd = pty.fork() + if pid == 0: + try: + os.execv("/usr/bin/ssh", ["/usr/bin/ssh", "-l", + username, hostname, cmd]) + except OSError, e: + print "OSError: " + str(e) + return -1 + else: + signal.signal(signal.SIGCHLD, subproc) + try: + timeout = 50 + i = 0 + while i <= timeout: - def remote_exec(self, hostname, username, password, cmd): - """Remote execution on specified host""" - pid, fd = pty.fork() - if pid == 0: - try: - os.execv("/usr/bin/ssh", ["/usr/bin/ssh", "-l", - username, hostname, cmd]) - except OSError, e: - print "OSError: " + str(e) - return -1 - else: - signal.signal(signal.SIGCHLD, self.subproc) - try: - timeout = 50 - i = 0 - while i <= timeout: + time.sleep(1) + str = os.read(fd, 10240) - time.sleep(1) - str = os.read(fd, 10240) + if re.search('(yes\/no)', str): + os.write(fd, "yes\r") - if re.search('(yes\/no)', str): - os.write(fd, "yes\r") + elif re.search('password:', str): + os.write(fd, password + "\r") - elif re.search('password:', str): - os.write(fd, password + "\r") + elif subproc_flag == 1: + ret = string.strip(str) + break + elif i == timeout: + print "TIMEOUT!!!!" + return -1 - elif self.subproc_flag == 1: - ret = string.strip(str) - break - elif i == timeout: - print "TIMEOUT!!!!" - return -1 + i = i+1 - i = i+1 + subproc_flag = 0 + return ret + except Exception, e: + subproc_flag = 0 + return -1 - self.subproc_flag = 0 - return ret - except Exception, e: - self.subproc_flag = 0 - return -1 +def remote_exec_pexpect(hostname, username, password, cmd): + """Remote exec function via pexpect""" + user_hostname = "%s@%s" % (username, hostname) + child = pexpect.spawn("/usr/bin/ssh", [user_hostname, cmd], + timeout = 60, maxread = 2000, logfile = None) + #child.logfile = sys.stdout + while True: + index = child.expect(['(yes\/no)', 'password:', pexpect.EOF, + pexpect.TIMEOUT]) + if index == 0: + child.sendline("yes") + elif index == 1: + child.sendline(password) + elif index == 2: + return string.strip(child.before) + elif index == 3: + return "TIMEOUT!!!" - def remote_exec_pexpect(self, hostname, username, password, cmd): - """Remote exec function via pexpect""" - user_hostname = "%s@%s" % (username, hostname) - child = pexpect.spawn("/usr/bin/ssh", [user_hostname, cmd], - timeout = 60, maxread = 2000, logfile = None) - #child.logfile = sys.stdout - while True: - index = child.expect(['(yes\/no)', 'password:', pexpect.EOF, - pexpect.TIMEOUT]) - if index == 0: - child.sendline("yes") - elif index == 1: - child.sendline(password) - elif index == 2: - return string.strip(child.before) - elif index == 3: - return "TIMEOUT!!!" +def get_remote_vcpus(hostname, username, password): + """Get cpu number of specified host""" + cmd = "cat /proc/cpuinfo | grep processor | wc -l" + cpunum = -1 + i = 0 + while i < 3: + i += 1 + cpunum = int(remote_exec(hostname, username, password, cmd)) + if cpunum == -1: + continue + else: + break + return cpunum - def get_remote_vcpus(self, hostname, username, password): - """Get cpu number of specified host""" - cmd = "cat /proc/cpuinfo | grep processor | wc -l" - cpunum = -1 - i = 0 - while i < 3: - i += 1 - cpunum = int(self.remote_exec(hostname, username, password, cmd)) - if cpunum == -1: - continue - else: - break - return cpunum +def get_remote_memory(hostname, username, password): + """Get memory statics of specified host""" + cmd = "free -m | grep -i mem | awk '{print $2}'" + memsize = -1 + i = 0 + while i < 3: + i += 1 + memsize = \ + int(remote_exec_pexpect(hostname, username, password, cmd)) * 1024 + if memsize == -1: + continue + else: + break + return memsize - def get_remote_memory(self, hostname, username, password): - """Get memory statics of specified host""" - cmd = "free -m | grep -i mem | awk '{print $2}'" - memsize = -1 - i = 0 - while i < 3: - i += 1 - memsize = \ - int(self.remote_exec_pexpect(hostname, username, password, cmd)) * 1024 - if memsize == -1: - continue - else: - break - return memsize +def get_remote_kernel(hostname, username, password): + """Get kernel info of specified host""" + cmd = "uname -r" + kernel = None + i = 0 + while i < 3: + i += 1 + kernel = remote_exec(hostname, username, password, cmd) + if kernel: + break + else: + continue + return kernel - def get_remote_kernel(self, hostname, username, password): - """Get kernel info of specified host""" - cmd = "uname -r" - kernel = None - i = 0 - while i < 3: - i += 1 - kernel = self.remote_exec(hostname, username, password, cmd) - if kernel: - break +def install_package(package = ''): + """Install specified package""" + if package: + cmd = "rpm -qa " + package + output = commands.getoutput(cmd) + pkg = output.split('\n')[0] + if pkg: + os.system("yum -y -q update " + package) + return pkg + else: + ret = os.system("yum -y -q install " + package) + if ret == 0: + output = commands.getoutput(cmd) + pkg = output.split('\n')[0] + if pkg: + return pkg else: - continue - return kernel + return "failed to install package" + else: + return "please input package name" - def install_package(self, package = ''): - """Install specified package""" - if package: - cmd = "rpm -qa " + package - output = commands.getoutput(cmd) - pkg = output.split('\n')[0] - if pkg: - os.system("yum -y -q update " + package) - return pkg +def libvirt_version(latest_ver = ''): + """Get libvirt version info""" + query_virt_ver = 'rpm -qa|grep libvirt' + ret = commands.getoutput(query_virt_ver) + if ret: + mas_ver = ret.split('-')[-2] + sec_ver = (ret.split('-')[-1]) + curr_ver = mas_ver + '-' + sec_ver + if latest_ver != '': + if curr_ver != latest_ver: + return (False, curr_ver) else: - ret = os.system("yum -y -q install " + package) - if ret == 0: - output = commands.getoutput(cmd) - pkg = output.split('\n')[0] - if pkg: - return pkg - else: - return "failed to install package" + return (True, curr_ver) else: - return "please input package name" + return curr_ver + else: + return (False, '') - def libvirt_version(self, latest_ver = ''): - """Get libvirt version info""" - query_virt_ver = 'rpm -qa|grep libvirt' - ret = commands.getoutput(query_virt_ver) - if ret: - mas_ver = ret.split('-')[-2] - sec_ver = (ret.split('-')[-1]) - curr_ver = mas_ver + '-' + sec_ver - if latest_ver != '': - if curr_ver != latest_ver: - return (False, curr_ver) - else: - return (True, curr_ver) - else: - return curr_ver +def create_dir(hostname, username, password): + """Create new dir""" + cmd = "mkdir /tmp/test" + mkdir_ret = remote_exec_pexpect(hostname, username, password, cmd) + if mkdir_ret == '': + cmd = "ls -d /tmp/test" + check_str = remote_exec_pexpect(hostname, username, + password, cmd) + if check_str == "/tmp/test": + return 0 else: - return (False, '') + print "check_str = ", check_str + return 1 + else: + print "mkdir_ret = ", mkdir_ret + return 1 - def create_dir(self, hostname, username, password): - """Create new dir""" - cmd = "mkdir /tmp/test" - mkdir_ret = self.remote_exec_pexpect(hostname, username, password, cmd) - if mkdir_ret == '': - cmd = "ls -d /tmp/test" - check_str = self.remote_exec_pexpect(hostname, username, - password, cmd) - if check_str == "/tmp/test": - return 0 - else: - print "check_str = ", check_str - return 1 +def write_file(hostname, username, password): + """Simple test for writting file on specified host""" + test_string = 'hello word testing' + cmd = """echo '%s'>/tmp/test/test.log""" % (test_string) + write_file_ret = remote_exec_pexpect(hostname, username, + password, cmd) + if write_file_ret == '': + cmd = """grep '%s' /tmp/test/test.log""" % ("hello") + check_str = remote_exec_pexpect(hostname, username, + password, cmd) + if check_str == test_string: + return 0 else: - print "mkdir_ret = ", mkdir_ret + print "check_str = ", check_str return 1 + else: + print "write_file_ret = ", write_file_ret + return 1 - def write_file(self, hostname, username, password): - """Simple test for writting file on specified host""" - test_string = 'hello word testing' - cmd = """echo '%s'>/tmp/test/test.log""" % (test_string) - write_file_ret = self.remote_exec_pexpect(hostname, username, - password, cmd) - if write_file_ret == '': - cmd = """grep '%s' /tmp/test/test.log""" % ("hello") - check_str = self.remote_exec_pexpect(hostname, username, - password, cmd) - if check_str == test_string: - return 0 - else: - print "check_str = ", check_str - return 1 +def run_mount_app(hostname, username, password, + target_mount, mount_point): + """Simple test for mount operation on specified host""" + cmd = """mount %s %s""" % (target_mount, mount_point) + mount_ret = remote_exec(hostname, username, password, cmd) + if mount_ret == '': + cmd = """df | grep '%s'""" % (target_mount) + check_str = remote_exec(hostname, username, password, cmd) + if check_str != '': + return 0 else: - print "write_file_ret = ", write_file_ret + print "mount check fail" return 1 + else: + print "mount fail" + return 1 - def run_mount_app(self, hostname, username, password, - target_mount, mount_point): - """Simple test for mount operation on specified host""" - cmd = """mount %s %s""" % (target_mount, mount_point) - mount_ret = self.remote_exec(hostname, username, password, cmd) - if mount_ret == '': - cmd = """df | grep '%s'""" % (target_mount) - check_str = self.remote_exec(hostname, username, password, cmd) - if check_str != '': - return 0 - else: - print "mount check fail" - return 1 +def run_wget_app(hostname, username, password, file_url, logger): + """Simple test for wget app on specified host""" + cmd_line = "wget -P /tmp %s -o /tmp/wget.log" % (file_url) + logger.info("Command: %s" % (cmd_line)) + wget_ret = remote_exec_pexpect(hostname, username, + password, cmd_line) + cmd_line = "grep %s %s" % ('100%', '/tmp/wget.log') + check_ret = remote_exec_pexpect(hostname, username, + password, cmd_line) + if check_ret == "": + logger.info("grep output is nothing") + return 1 + else: + if re.search("100%", check_ret): + logger.info("wget is running successfully") + logger.info("check_retrun: %s" % (check_ret)) + return 0 else: - print "mount fail" + logger.info("can not find 100% in wget output") + logger.info("check_retrun: %s" % (check_ret)) return 1 - def run_wget_app(self, hostname, username, password, file_url, logger): - """Simple test for wget app on specified host""" - cmd_line = "wget -P /tmp %s -o /tmp/wget.log" % (file_url) - logger.info("Command: %s" % (cmd_line)) - wget_ret = self.remote_exec_pexpect(hostname, username, - password, cmd_line) - cmd_line = "grep %s %s" % ('100%', '/tmp/wget.log') - check_ret = self.remote_exec_pexpect(hostname, username, - password, cmd_line) - if check_ret == "": - logger.info("grep output is nothing") - return 1 +def validate_remote_nic_type(hostname, username, + password, nic_type, logger): + """Validate network interface type on specified host""" + nic_type_to_name_dict = {'e1000': + '82540EM Gigabit Ethernet Controller', + 'rtl8139': + 'RTL-8139/8139C/8139C+', + 'virtio':'Virtio network device'} + nic_type_to_driver_dict = {'e1000':'e1000', 'rtl8139':'8139cp', + 'virtio':'virtio_net'} + nic_name = nic_type_to_name_dict[nic_type] + nic_driver = nic_type_to_driver_dict[nic_type] + logger.info("nic_name = %s" % (nic_name)) + logger.info("nic_driver = %s" % (nic_driver)) + lspci_cmd = "lspci" + lsmod_cmd = "lsmod" + lspci_cmd_ret = remote_exec_pexpect(hostname, username, + password, lspci_cmd) + lsmod_cmd_ret = remote_exec_pexpect(hostname, username, + password, lsmod_cmd) + logger.info("------------") + logger.info("lspci_cmd_ret:\n %s" % (lspci_cmd_ret)) + logger.info("------------") + logger.info("lsmod_cmd_ret:\n %s" % (lsmod_cmd_ret)) + logger.info("------------") + if lspci_cmd_ret != "" and lsmod_cmd_ret != "": + cmd1 = """echo "%s" | grep '%s'""" % (lspci_cmd_ret, nic_name) + cmd2 = """echo "%s" | grep '%s'""" % (lsmod_cmd_ret, nic_driver) + status1, output1 = commands.getstatusoutput(cmd1) + status2, output2 = commands.getstatusoutput(cmd2) + if status1 == 0 and status2 == 0: + # other nic should not be seen in guest + nic_type_to_name_dict.pop(nic_type) + for key in nic_type_to_name_dict.keys(): + logger.info("now try to grep other nic type \ + in lspci output: %s" % key) + other_name_cmd = """echo '%s' | grep '%s'""" % \ + (lspci_cmd_ret, nic_type_to_name_dict[key]) + ret, out = commands.getstatusoutput(other_name_cmd) + if ret == 0: + logger.info("unspecified nic name is seen in \ + guest's lspci command: \n %s \n" % out) + return 1 + + nic_type_to_driver_dict.pop(nic_type) + for key in nic_type_to_driver_dict.keys(): + logger.info("now try to grep other nic type \ + in lsmod output: %s" % key) + other_driver_cmd = """echo '%s' | grep '%s'""" % \ + (lsmod_cmd_ret, + nic_type_to_driver_dict[key]) + ret1, out1 = commands.getstatusoutput(other_driver_cmd) + if ret1 == 0: + logger.info("unspecified nic driver is seen \ + in guest's lsmod command: %s" % out) + return 1 + + logger.info("lspci ouput about nic is: \n %s; \n \ + lsmod output about nic is \n %s \n" % + (output1,output2)) + return 0 else: - if re.search("100%", check_ret): - logger.info("wget is running successfully") - logger.info("check_retrun: %s" % (check_ret)) - return 0 - else: - logger.info("can not find 100% in wget output") - logger.info("check_retrun: %s" % (check_ret)) - return 1 + logger.info("lspci and lsmod and grep fail") + return 1 + else: + logger.info("lspci and lsmod return nothing") + return 1 - def validate_remote_nic_type(self, hostname, username, - password, nic_type, logger): - """Validate network interface type on specified host""" - nic_type_to_name_dict = {'e1000': - '82540EM Gigabit Ethernet Controller', - 'rtl8139': - 'RTL-8139/8139C/8139C+', - 'virtio':'Virtio network device'} - nic_type_to_driver_dict = {'e1000':'e1000', 'rtl8139':'8139cp', - 'virtio':'virtio_net'} - nic_name = nic_type_to_name_dict[nic_type] - nic_driver = nic_type_to_driver_dict[nic_type] - logger.info("nic_name = %s" % (nic_name)) - logger.info("nic_driver = %s" % (nic_driver)) - lspci_cmd = "lspci" - lsmod_cmd = "lsmod" - lspci_cmd_ret = self.remote_exec_pexpect(hostname, username, - password, lspci_cmd) - lsmod_cmd_ret = self.remote_exec_pexpect(hostname, username, - password, lsmod_cmd) - logger.info("------------") - logger.info("lspci_cmd_ret:\n %s" % (lspci_cmd_ret)) - logger.info("------------") - logger.info("lsmod_cmd_ret:\n %s" % (lsmod_cmd_ret)) - logger.info("------------") - if lspci_cmd_ret != "" and lsmod_cmd_ret != "": - cmd1 = """echo "%s" | grep '%s'""" % (lspci_cmd_ret, nic_name) - cmd2 = """echo "%s" | grep '%s'""" % (lsmod_cmd_ret, nic_driver) +def validate_remote_blk_type(hostname, username, password, + blk_type, logger): + """Validate block device type on specified host""" + blk_type_to_name_dict = {'ide':'Intel Corporation 82371SB PIIX3 IDE', + 'virtio':'Virtio block device'} + blk_type_to_driver_dict = {'ide':'unknow', 'virtio':'virtio_blk'} + lspci_cmd = "lspci" + lsmod_cmd = "lsmod" + lspci_cmd_ret = remote_exec_pexpect(hostname, username, + password, lspci_cmd) + lsmod_cmd_ret = remote_exec_pexpect(hostname, username, + password, lsmod_cmd) + logger.info("------------") + logger.info("lspci_cmd_ret:\n %s" % (lspci_cmd_ret)) + logger.info("------------") + logger.info("lsmod_cmd_ret: \n %s" % (lsmod_cmd_ret)) + logger.info("------------") + if lspci_cmd_ret != "" and lsmod_cmd_ret != "": + if blk_type == "virtio": + blk_name = blk_type_to_name_dict[blk_type] + blk_driver = blk_type_to_driver_dict[blk_type] + logger.info("blk_name = %s \n blk_driver = %s" % + (blk_name, blk_driver)) + cmd1 = """echo "%s" | grep '%s'""" % (lspci_cmd_ret, blk_name) + cmd2 = """echo "%s" | grep '%s'""" % (lsmod_cmd_ret, blk_driver) status1, output1 = commands.getstatusoutput(cmd1) status2, output2 = commands.getstatusoutput(cmd2) if status1 == 0 and status2 == 0: - # other nic should not be seen in guest - nic_type_to_name_dict.pop(nic_type) - for key in nic_type_to_name_dict.keys(): - logger.info("now try to grep other nic type \ - in lspci output: %s" % key) - other_name_cmd = """echo '%s' | grep '%s'""" % \ - (lspci_cmd_ret, nic_type_to_name_dict[key]) - ret, out = commands.getstatusoutput(other_name_cmd) - if ret == 0: - logger.info("unspecified nic name is seen in \ - guest's lspci command: \n %s \n" % out) - return 1 - - nic_type_to_driver_dict.pop(nic_type) - for key in nic_type_to_driver_dict.keys(): - logger.info("now try to grep other nic type \ - in lsmod output: %s" % key) - other_driver_cmd = """echo '%s' | grep '%s'""" % \ - (lsmod_cmd_ret, - nic_type_to_driver_dict[key]) - ret1, out1 = commands.getstatusoutput(other_driver_cmd) - if ret1 == 0: - logger.info("unspecified nic driver is seen \ - in guest's lsmod command: %s" % out) - return 1 - - logger.info("lspci ouput about nic is: \n %s; \n \ - lsmod output about nic is \n %s \n" % - (output1,output2)) + logger.info("block device type is virtio") return 0 else: - logger.info("lspci and lsmod and grep fail") return 1 - else: - logger.info("lspci and lsmod return nothing") - return 1 - def validate_remote_blk_type(self, hostname, username, password, - blk_type, logger): - """Validate block device type on specified host""" - blk_type_to_name_dict = {'ide':'Intel Corporation 82371SB PIIX3 IDE', - 'virtio':'Virtio block device'} - blk_type_to_driver_dict = {'ide':'unknow', 'virtio':'virtio_blk'} - lspci_cmd = "lspci" - lsmod_cmd = "lsmod" - lspci_cmd_ret = self.remote_exec_pexpect(hostname, username, - password, lspci_cmd) - lsmod_cmd_ret = self.remote_exec_pexpect(hostname, username, - password, lsmod_cmd) - logger.info("------------") - logger.info("lspci_cmd_ret:\n %s" % (lspci_cmd_ret)) - logger.info("------------") - logger.info("lsmod_cmd_ret: \n %s" % (lsmod_cmd_ret)) - logger.info("------------") - if lspci_cmd_ret != "" and lsmod_cmd_ret != "": - if blk_type == "virtio": - blk_name = blk_type_to_name_dict[blk_type] - blk_driver = blk_type_to_driver_dict[blk_type] - logger.info("blk_name = %s \n blk_driver = %s" % - (blk_name, blk_driver)) - cmd1 = """echo "%s" | grep '%s'""" % (lspci_cmd_ret, blk_name) - cmd2 = """echo "%s" | grep '%s'""" % (lsmod_cmd_ret, blk_driver) - status1, output1 = commands.getstatusoutput(cmd1) - status2, output2 = commands.getstatusoutput(cmd2) - if status1 == 0 and status2 == 0: - logger.info("block device type is virtio") - return 0 - else: + # this check will not check ide type block device + if blk_type == "ide": + # virtio block device should not be seen in guest + blk_type_to_name_dict.pop(blk_type) + for key in blk_type_to_name_dict.keys(): + logger.info( + "now try to grep other blk type in lspci output: %s" % + key) + other_name_cmd = """echo "%s" | grep '%s'""" % \ + (lspci_cmd_ret, blk_type_to_name_dict[key]) + ret, out = commands.getstatusoutput(other_name_cmd) + if ret == 0: + logger.info("unspecified blk name is seen in guest's \ + lspci command: \n %s \n" % out) return 1 - - # this check will not check ide type block device - if blk_type == "ide": - # virtio block device should not be seen in guest - blk_type_to_name_dict.pop(blk_type) - for key in blk_type_to_name_dict.keys(): - logger.info( - "now try to grep other blk type in lspci output: %s" % - key) - other_name_cmd = """echo "%s" | grep '%s'""" % \ - (lspci_cmd_ret, blk_type_to_name_dict[key]) - ret, out = commands.getstatusoutput(other_name_cmd) - if ret == 0: - logger.info("unspecified blk name is seen in guest's \ - lspci command: \n %s \n" % out) - return 1 - blk_type_to_driver_dict.pop(blk_type) - for key in blk_type_to_driver_dict.keys(): - logger.info( - "now try to grep other blk type in lsmod output: %s" % - key) - other_driver_cmd = """echo '%s' | grep '%s'""" % \ - (lsmod_cmd_ret, - blk_type_to_driver_dict[key]) - ret1, out1 = commands.getstatusoutput(other_driver_cmd) - if ret1 == 0: - logger.info("unspecified blk driver is seen \ - in guest's lsmod command: \n %s \n" % out) - return 1 - logger.info("block device type is ide") - return 0 - else: - logger.info("lspci and lsmod return nothing") - return 1 + blk_type_to_driver_dict.pop(blk_type) + for key in blk_type_to_driver_dict.keys(): + logger.info( + "now try to grep other blk type in lsmod output: %s" % + key) + other_driver_cmd = """echo '%s' | grep '%s'""" % \ + (lsmod_cmd_ret, + blk_type_to_driver_dict[key]) + ret1, out1 = commands.getstatusoutput(other_driver_cmd) + if ret1 == 0: + logger.info("unspecified blk driver is seen \ + in guest's lsmod command: \n %s \n" % out) + return 1 + logger.info("block device type is ide") + return 0 + else: + logger.info("lspci and lsmod return nothing") + return 1 -- 1.7.7.3
--- I see much TODO for cleaning up/refactoring, will come step by step in near future. --- repos/domain/balloon_memory.py | 3 +-- repos/domain/dump.py | 4 +--- repos/domain/install_linux_check.py | 15 +++++++-------- repos/snapshot/file_flag.py | 7 +++---- repos/snapshot/flag_check.py | 3 +-- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/repos/domain/balloon_memory.py b/repos/domain/balloon_memory.py index 25b8318..de18b87 100644 --- a/repos/domain/balloon_memory.py +++ b/repos/domain/balloon_memory.py @@ -23,8 +23,7 @@ def get_mem_size(ip): username = 'root' password = 'redhat' - checking = check.Check() - current_memory = checking.get_remote_memory(ip, username, password) + current_memory = check.get_remote_memory(ip, username, password) return current_memory def compare_memory(expect_memory, actual_memory): diff --git a/repos/domain/dump.py b/repos/domain/dump.py index 37cfac9..01bdc93 100644 --- a/repos/domain/dump.py +++ b/repos/domain/dump.py @@ -35,8 +35,6 @@ def check_guest_kernel(*args): """Check guest kernel version""" (guestname, logger) = args - chk = check.Check() - mac = utils.get_dom_mac_addr(guestname) logger.debug("guest mac address: %s" %mac) @@ -47,7 +45,7 @@ def check_guest_kernel(*args): logger.debug("guest ip address: %s" %ipaddr) - kernel = chk.get_remote_kernel(ipaddr, "root", "redhat") + kernel = check.get_remote_kernel(ipaddr, "root", "redhat") logger.debug("current kernel version: %s" %kernel) if kernel: diff --git a/repos/domain/install_linux_check.py b/repos/domain/install_linux_check.py index 1c27fc1..351bba5 100644 --- a/repos/domain/install_linux_check.py +++ b/repos/domain/install_linux_check.py @@ -82,7 +82,6 @@ def install_linux_check(params): domain_name=guestname blk_type=params['hdmodel'] nic_type=params['nicmodel'] - chk = check.Check() Test_Result = 0 # Ping guest from host @@ -96,9 +95,9 @@ def install_linux_check(params): # Creat file and read file in guest. logger.info("check point2: creat and read dirctory/file in guest") - if chk.create_dir(ipaddr, "root", "redhat") == 0: + if check.create_dir(ipaddr, "root", "redhat") == 0: logger.info("create dir - /tmp/test successfully") - if chk.write_file(ipaddr, "root", "redhat") == 0: + if check.write_file(ipaddr, "root", "redhat") == 0: logger.info("write and read file: /tmp/test/test.log successfully") else: logger.error("Error: fail to write/read file - /tmp/test/test.log") @@ -115,7 +114,7 @@ def install_linux_check(params): vcpunum_expect = int(utils.get_num_vcpus(domain_name)) logger.info("vcpu number in domain config xml - %s is %s" % \ (domain_name, vcpunum_expect)) - vcpunum_actual = int(chk.get_remote_vcpus(ipaddr, "root", "redhat")) + vcpunum_actual = int(check.get_remote_vcpus(ipaddr, "root", "redhat")) logger.info("The actual vcpu number in guest - %s is %s" % (domain_name, vcpunum_actual)) if vcpunum_expect == vcpunum_actual: @@ -133,7 +132,7 @@ def install_linux_check(params): mem_expect = utils.get_size_mem(domain_name) logger.info("current mem size in domain config xml - %s is %s" % (domain_name, mem_expect)) - mem_actual = chk.get_remote_memory(ipaddr, "root", "redhat") + mem_actual = check.get_remote_memory(ipaddr, "root", "redhat") logger.info("The actual mem size in guest - %s is %s" % (domain_name, mem_actual)) diff_range = int(mem_expect) * 0.07 @@ -156,7 +155,7 @@ def install_linux_check(params): envparser = env_parser.Envparser(envfile) file_url = envparser.get_value("other", "wget_url") - if chk.run_wget_app(ipaddr, "root", "redhat", file_url, logger) == 0: + if check.run_wget_app(ipaddr, "root", "redhat", file_url, logger) == 0: logger.info("run wget successfully in guest.") else: logger.error("Error: fail to run wget in guest") @@ -167,9 +166,9 @@ def install_linux_check(params): if 'kvm' in guesttype or 'xenfv' in guesttype: logger.info("check point6: check nic and blk driver in guest is \ expected as your config:") - if chk.validate_remote_nic_type(ipaddr, "root", "redhat", + if check.validate_remote_nic_type(ipaddr, "root", "redhat", nic_type, logger) == 0 and \ - chk.validate_remote_blk_type(ipaddr, "root", "redhat", + check.validate_remote_blk_type(ipaddr, "root", "redhat", blk_type, logger) == 0: logger.info("nic type - %s and blk type - %s check successfully" % (nic_type, blk_type)) diff --git a/repos/snapshot/file_flag.py b/repos/snapshot/file_flag.py index 4d88416..f2257f6 100644 --- a/repos/snapshot/file_flag.py +++ b/repos/snapshot/file_flag.py @@ -33,9 +33,9 @@ def check_domain_running(conn, guestname, logger): else: return True -def make_flag(chk, ipaddr, username, password, logger): +def make_flag(ipaddr, username, password, logger): """ enter guest OS, create a file in /tmp folder """ - ret = chk.remote_exec_pexpect(ipaddr, username, password, MAKE_FLAG) + ret = check.remote_exec_pexpect(ipaddr, username, password, MAKE_FLAG) if ret == "TIMEOUT!!!": logger.error("connecting to guest OS timeout") return False @@ -55,7 +55,6 @@ def file_flag(params): username = params['username'] password = params['password'] - chk = check.Check() conn = sharedmod.libvirtobj['conn'] if not check_domain_running(conn, guestname, logger): @@ -81,7 +80,7 @@ def file_flag(params): logger.info("vm %s failed to get ip address" % guestname) return 1 - if not make_flag(chk, ipaddr, username, password, logger): + if not make_flag(ipaddr, username, password, logger): logger.error("making flag in guest %s failed" % guestname) return 1 else: diff --git a/repos/snapshot/flag_check.py b/repos/snapshot/flag_check.py index 7bdc14c..218d7e4 100644 --- a/repos/snapshot/flag_check.py +++ b/repos/snapshot/flag_check.py @@ -44,7 +44,6 @@ def flag_check(params): else: expected_result = "exist" - chk = check.Check() conn = sharedmod.libvirtobj['conn'] if not check_domain_running(conn, guestname, logger): @@ -70,7 +69,7 @@ def flag_check(params): logger.info("vm %s failed to get ip address" % guestname) return 1 - ret = chk.remote_exec_pexpect(ipaddr, username, password, FLAG_CHECK) + ret = check.remote_exec_pexpect(ipaddr, username, password, FLAG_CHECK) if ret == "TIMEOUT!!!": logger.error("connecting to guest OS timeout") return 1 -- 1.7.7.3
On 04/17/2012 09:44 PM, Osier Yang wrote:
Just as what we did for utils/utils.py, we don't benifit from the class use at all.
Osier Yang (3): remove importing of unused check module Destroy class of utils/check.py Destroy use of check class
repos/domain/balloon_memory.py | 3 +- repos/domain/dump.py | 4 +- repos/domain/install_linux_check.py | 15 +- repos/snapshot/file_flag.py | 7 +- repos/snapshot/flag_check.py | 3 +- utils/check.py | 649 +++++++++++++++++------------------ utils/xmlgenerator.py | 1 - 7 files changed, 335 insertions(+), 347 deletions(-)
I don't need the check.py anymore, it should be depreciated. It works as the utils.py more or less, we probably need to remove it. and move the valuable function into utils.py ACK with these changes, but need to remove the file later. Guannan Ren
On 2012年04月18日 15:07, Guannan Ren wrote:
On 04/17/2012 09:44 PM, Osier Yang wrote:
Just as what we did for utils/utils.py, we don't benifit from the class use at all.
Osier Yang (3): remove importing of unused check module Destroy class of utils/check.py Destroy use of check class
repos/domain/balloon_memory.py | 3 +- repos/domain/dump.py | 4 +- repos/domain/install_linux_check.py | 15 +- repos/snapshot/file_flag.py | 7 +- repos/snapshot/flag_check.py | 3 +- utils/check.py | 649 +++++++++++++++++------------------ utils/xmlgenerator.py | 1 - 7 files changed, 335 insertions(+), 347 deletions(-)
I don't need the check.py anymore, it should be depreciated. It works as the utils.py more or less, we probably need to remove it. and move the valuable function into utils.py
That was in my TOTO list, really no need to have a standalone check.py, useful functions should be in utils.py.
ACK with these changes, but need to remove the file later.
Guannan Ren
Thanks, Pushed the set. Osier
participants (2)
-
Guannan Ren -
Osier Yang