diff options
Diffstat (limited to 'testsuites/vstf/vstf_scripts/vstf/agent/env/basic')
9 files changed, 116 insertions, 55 deletions
diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/__init__.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/__init__.py index df7d24d0..83b8d15d 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/__init__.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/__init__.py @@ -6,4 +6,3 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## - diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/collect.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/collect.py index 126a7d55..1d39d7b7 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/collect.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/collect.py @@ -31,11 +31,11 @@ class Collect(object): """the base _system info {'os info':{'_system':'ubuntu', 'kernel': '3.13.3'}}""" return {const.OS_INFO: - { - '_system': open('/etc/issue.net').readline().strip(), - 'kernel': platform.uname()[2] - } - } + { + '_system': open('/etc/issue.net').readline().strip(), + 'kernel': platform.uname()[2] + } + } def _memery(self): """ Return the information in /proc/meminfo @@ -46,11 +46,11 @@ class Collect(object): meminfo[line.split(':')[0]] = line.split(':')[1].strip() return {const.MEMORY_INFO: - { - "Mem Total": meminfo['MemTotal'], - "Mem Swap": meminfo['SwapTotal'] - } - } + { + "Mem Total": meminfo['MemTotal'], + "Mem Swap": meminfo['SwapTotal'] + } + } def _lscpu(self): ret = {} @@ -68,18 +68,19 @@ class Collect(object): ret.append(cpuinfo) cpuinfo = OrderedDict() elif len(line.split(':')) == 2: - cpuinfo[line.split(':')[0].strip()] = line.split(':')[1].strip() + cpuinfo[line.split(':')[0].strip()] = line.split(':')[ + 1].strip() else: log.error("_cpu info unknow format <%(c)s>", {'c': line}) return {const.CPU_INFO: - dict( - { - "Model Name": ret[0]['model name'], - "Address sizes": ret[0]['address sizes'] - }, - **(self._lscpu()) - ) - } + dict( + { + "Model Name": ret[0]['model name'], + "Address sizes": ret[0]['address sizes'] + }, + **(self._lscpu()) + ) + } def _hw_sysinfo(self): cmdline = "dmidecode | grep -A 2 'System Information' | grep -v 'System Information'" @@ -90,14 +91,15 @@ class Collect(object): for tmp in output.strip().split('\n'): if tmp is None or tmp is "": continue - # split the items + # split the items tmp = tmp.split(":") if len(tmp) >= 2: # first item as key, and the other as value result[tmp[0].strip("\t")] = ";".join(tmp[1:]) return {const.HW_INFO: result} else: - return {const.HW_INFO: "get hw info failed. check the host by cmd: dmidecode"} + return { + const.HW_INFO: "get hw info failed. check the host by cmd: dmidecode"} def collect_host_info(self): return [self._system, self._cpu, self._memery(), self._hw_sysinfo()] diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py index e4df9b27..29dd2c02 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/commandline.py @@ -16,6 +16,7 @@ LOG = logging.getLogger(__name__) class CommandLine(object): + def __init__(self): super(CommandLine, self).__init__() self.proc = None diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/device_manager.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/device_manager.py index 8b5387fe..c34f5e06 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/device_manager.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/device_manager.py @@ -21,6 +21,7 @@ default_drivers = { class LspciHelper(object): + def __init__(self): self.bdf_desc_map = {} self.bdf_device_map = {} @@ -45,7 +46,8 @@ class LspciHelper(object): for bdf, desc in self.bdf_desc_map.items(): device = get_device_name(bdf) if device is None: - LOG.info("cann't find device name for bdf:%s, no driver is available.", bdf) + LOG.info( + "cann't find device name for bdf:%s, no driver is available.", bdf) try: self._load_driver(desc) except: @@ -66,13 +68,17 @@ class LspciHelper(object): def _get_ip_macs(self): for device, bdf in self.device_bdf_map.items(): buf = check_output("ip addr show dev %s" % device, shell=True) - macs = re.compile("[A-F0-9]{2}(?::[A-F0-9]{2}){5}", re.IGNORECASE | re.MULTILINE) + macs = re.compile( + "[A-F0-9]{2}(?::[A-F0-9]{2}){5}", + re.IGNORECASE | re.MULTILINE) for mac in macs.findall(buf): if mac.lower() in ('00:00:00:00:00:00', 'ff:ff:ff:ff:ff:ff'): continue else: break - ips = re.compile(r"inet (\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}/\d{1,2})", re.MULTILINE) + ips = re.compile( + r"inet (\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}/\d{1,2})", + re.MULTILINE) ip = ips.findall(buf) if ip: self.bdf_ip_map[bdf] = ip[0] @@ -93,6 +99,7 @@ class LspciHelper(object): class DeviceManager(object): + def __init__(self): super(DeviceManager, self).__init__() mgr = netns.NetnsManager() diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/image_manager.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/image_manager.py index c3b5c6b3..4bae49d2 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/image_manager.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/image_manager.py @@ -19,6 +19,7 @@ class _ImageManager(object): A qemu-img wrapper to create qcow2 child image from a parent image. """ + def __init__(self, parent_image_path, child_image_dir): """ :param parent_image_path str: the parent image path. @@ -31,7 +32,11 @@ class _ImageManager(object): assert os.path.isfile(self.parent_image_path) assert os.path.isdir(self.child_image_dir) - def create_child_image(self, child_name, full_clone=False, image_type='qcow2'): + def create_child_image( + self, + child_name, + full_clone=False, + image_type='qcow2'): """ create a child image and put it in self.child_image_dir. @@ -39,16 +44,25 @@ class _ImageManager(object): :return: return the path of child image. """ - image_path = os.path.join(self.child_image_dir, child_name) + '.' + image_type + image_path = os.path.join( + self.child_image_dir, + child_name) + '.' + image_type if full_clone: - cmd = self._convert_str % {'image_type': image_type, 'child_path': image_path, 'parent_path': self.parent_image_path} + cmd = self._convert_str % { + 'image_type': image_type, + 'child_path': image_path, + 'parent_path': self.parent_image_path} else: - cmd = self._create_child_str % {'child_path': image_path, 'parent_path': self.parent_image_path, 'image_type':image_type} + cmd = self._create_child_str % { + 'child_path': image_path, + 'parent_path': self.parent_image_path, + 'image_type': image_type} check_call(cmd.split()) return image_path class ImageManager(object): + def __init__(self, cfg): """ ImageManager creates images from configuration context. @@ -74,13 +88,22 @@ class ImageManager(object): @staticmethod def _check_cfg(cfg): - for key in ('parent_image', 'dst_location', 'full_clone', 'type', 'names'): + for key in ( + 'parent_image', + 'dst_location', + 'full_clone', + 'type', + 'names'): if key not in cfg: raise Exception("does't find %s config" % key) if cfg['type'] not in ('raw', 'qcow2'): - raise Exception("type:%s not supported, only support 'raw' and 'qcow2'" % cfg['type']) + raise Exception( + "type:%s not supported, only support 'raw' and 'qcow2'" % + cfg['type']) if not cfg['full_clone'] and cfg['type'] == 'raw': - raise Exception("only support 'qcow2' for not full_clone image creation" % cfg['type']) + raise Exception( + "only support 'qcow2' for not full_clone image creation" % + cfg['type']) return cfg def create_all(self): @@ -90,7 +113,8 @@ class ImageManager(object): :return: True for success, False for failure. """ for name in self.names: - image = self.mgr.create_child_image(name, self.full_clone, self.image_type) + image = self.mgr.create_child_image( + name, self.full_clone, self.image_type) LOG.info("image: %s created", image) return True @@ -101,7 +125,8 @@ class ImageManager(object): :return: True for success. Raise exception otherwise. """ for name in self.names: - image_path = os.path.join(self.image_dir, name + '.' + self.image_type) + image_path = os.path.join( + self.image_dir, name + '.' + self.image_type) try: os.unlink(image_path) LOG.info("remove:%s successfully", image_path) @@ -114,7 +139,12 @@ if __name__ == '__main__': import argparse import json parser = argparse.ArgumentParser() - parser.add_argument('action', choices = ('create','clean'), help='action:create|clean') + parser.add_argument( + 'action', + choices=( + 'create', + 'clean'), + help='action:create|clean') parser.add_argument('--config', help='config file to parse') args = parser.parse_args() logging.basicConfig(level=logging.INFO) @@ -124,5 +154,3 @@ if __name__ == '__main__': mgr.create_all() if args.action == 'clean': mgr.clean_all() - - diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/source_manager.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/source_manager.py index 6edd14ca..5aca5368 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/source_manager.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/source_manager.py @@ -27,6 +27,7 @@ def my_chdir(file_path): class SourceCodeManager(object): + def __init__(self): super(SourceCodeManager, self).__init__() self.base_path = '/opt/vstf/' diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm9pfs.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm9pfs.py index 7364f8b2..4b7b31b1 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm9pfs.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm9pfs.py @@ -69,7 +69,9 @@ class VMConfigBy9pfs(object): return ret == constant.VM_CMD_EXCUTE_SUCCES_FLAG_CONTENT def _wait_command_done(self): - done = self._wait_flag_file_to_exist(constant.VM_CMD_DONE_FLAG_FILE, constant.VM_COMMON_CMD_EXCUTE_TIME_OUT) + done = self._wait_flag_file_to_exist( + constant.VM_CMD_DONE_FLAG_FILE, + constant.VM_COMMON_CMD_EXCUTE_TIME_OUT) if done: return self._get_cmd_return_code() else: @@ -86,7 +88,8 @@ class VMConfigBy9pfs(object): raise Exception("9pfs command failure: timeout.") def wait_up(self): - return self._wait_flag_file_to_exist(constant.VM_UP_Flag_FILE, constant.VM_UP_TIME_OUT) + return self._wait_flag_file_to_exist( + constant.VM_UP_Flag_FILE, constant.VM_UP_TIME_OUT) def config_ip(self, mac, ip): cmd = 'config_ip %s %s' % (mac, ip) @@ -118,7 +121,13 @@ class VMConfigBy9pfs(object): cmd = 'recover_nic_binding ' + mac_str return self._set_cmd(cmd) - def config_amqp(self, identity, server, port=5672, user="guest", passwd="guest"): + def config_amqp( + self, + identity, + server, + port=5672, + user="guest", + passwd="guest"): data = { 'server': server, 'port': port, @@ -135,7 +144,7 @@ class VMConfigBy9pfs(object): id=%(id)s''' % data file_name = "amqp.ini" dedented_text = textwrap.dedent(content) - self._write(file_name, header+dedented_text) + self._write(file_name, header + dedented_text) cmd = 'config_amqp %s' % file_name return self._set_cmd(cmd) diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm_manager.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm_manager.py index 60a3b37b..d0a2060d 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm_manager.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm_manager.py @@ -93,8 +93,14 @@ class VMControlOperation(object): @staticmethod def check_required_options(context): - for key in ('vm_name', 'vm_memory', 'vm_cpu', 'image_path', 'image_type', 'taps'): - if not context.has_key(key): + for key in ( + 'vm_name', + 'vm_memory', + 'vm_cpu', + 'image_path', + 'image_type', + 'taps'): + if key not in context: raise Exception("vm config error, must set %s option" % key) def set_vm_defaults(self, context): @@ -117,14 +123,18 @@ class VMControlOperation(object): context.setdefault(k, v) def _shutdown_vm(self): - out = check_output("virsh list | sed 1,2d | awk '{print $2}'", shell=True) + out = check_output( + "virsh list | sed 1,2d | awk '{print $2}'", + shell=True) vm_set = set(out.split()) for vm in vm_set: check_call("virsh shutdown %s" % vm, shell=True) timeout = 60 # wait for gracefully shutdown while timeout > 0: - out = check_output("virsh list | sed 1,2d | awk '{print $2}'", shell=True) + out = check_output( + "virsh list | sed 1,2d | awk '{print $2}'", + shell=True) vm_set = set(out.split()) if len(vm_set) == 0: break @@ -135,7 +145,9 @@ class VMControlOperation(object): for vm in vm_set: check_call("virsh destroy %s" % vm, shell=True) # undefine all - out = check_output("virsh list --all | sed 1,2d | awk '{print $2}'", shell=True) + out = check_output( + "virsh list --all | sed 1,2d | awk '{print $2}'", + shell=True) vm_set = set(out.split()) for vm in vm_set: check_call("virsh undefine %s" % vm, shell=True) @@ -177,7 +189,8 @@ class VMControlOperation(object): vm9pctrl = self.vm_9p_controllers[vm_name] ret = vm9pctrl.wait_up() if ret not in (True,): - raise Exception('vm running but stuck in boot process, please manully check.') + raise Exception( + 'vm running but stuck in boot process, please manully check.') LOG.debug('waitVM %s up ok, ret:%s', vm_name, ret) return True @@ -193,12 +206,14 @@ class VMControlOperation(object): # print self.vm_9p_controllers init_cfg = vm_cfg['init_config'] if "ctrl_ip_setting" in init_cfg: - ret = vm9pctrl.config_ip(vm_cfg['ctrl_mac'], init_cfg['ctrl_ip_setting']) - assert ret == True + ret = vm9pctrl.config_ip( + vm_cfg['ctrl_mac'], + init_cfg['ctrl_ip_setting']) + assert ret LOG.info('initConfigVM config ip ok') if 'ctrl_gw' in init_cfg: ret = vm9pctrl.config_gw(init_cfg['ctrl_gw']) - assert ret == True + assert ret LOG.info('initConfigVM ctrl_gw ok') if "ctrl_ip_setting" in init_cfg and "amqp_server" in init_cfg: identity = init_cfg['ctrl_ip_setting'].split('/')[0] @@ -209,7 +224,7 @@ class VMControlOperation(object): user = init_cfg['amqp_user'] passwd = init_cfg['amqp_passwd'] ret = vm9pctrl.config_amqp(identity, server, port, user, passwd) - assert ret == True + assert ret LOG.info('initConfigVM config_amqp ok') if 'tap_pktloop_config' in init_cfg: taps = vm_cfg['taps'] @@ -217,6 +232,6 @@ class VMControlOperation(object): for tap in taps: macs.append(tap['tap_mac']) ret = vm9pctrl.set_pktloop_dpdk(macs) - assert ret == True + assert ret LOG.info('initConfigVM set_pktloop_dpdk ok') return True diff --git a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm_xml_help.py b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm_xml_help.py index 6f9131e7..89c10963 100644 --- a/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm_xml_help.py +++ b/testsuites/vstf/vstf_scripts/vstf/agent/env/basic/vm_xml_help.py @@ -38,7 +38,7 @@ xml_disk = ''' <source file='IMAGE_PATH'/> <target dev='vda' bus='virtio'/> </disk>''' - + xml_ctrl_br = ''' <interface type='bridge'> <mac address='CTRL_MAC'/> @@ -63,7 +63,7 @@ xml_br = ''' <model type='virtio'/> <target dev='TAP_NAME'/> </interface>''' - + xml_pci = ''' <hostdev mode='subsystem' type='pci' managed='yes'> <driver name='kvm'/> @@ -82,4 +82,3 @@ xml_tail = ''' </graphics> </devices> </domain>''' - |