Skip to content

Commit

Permalink
Merge pull request avocado-framework#2838 from qiankehan/inspekt
Browse files Browse the repository at this point in the history
virttest: Fix inspekt checking failures
  • Loading branch information
chloerh authored Jan 15, 2021
2 parents 52fd538 + b27bd2b commit 480f90c
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 50 deletions.
2 changes: 2 additions & 0 deletions virttest/kernel_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class FS(object):
"""
Base class for proc/sys FS set and get
"""

def __init__(self, fs, session=None):
"""
Initializes path, session and func to trigger cmd
Expand Down Expand Up @@ -116,6 +117,7 @@ class to get or set sysfs values in host, remote host or in VM
>>> obj.sys_fs_value # To get the value
>>> obj.sys_fs_value = "never" # To set the value
"""

def __init__(self, sys_fs, session=None, regex=r"\[%s\]"):
"""
Initializes path, session and func to trigger cmd
Expand Down
3 changes: 2 additions & 1 deletion virttest/libvirt_xml/vm_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ def set_graphics_attr(vm_name, attr, index=0, virsh_instance=base.virsh):
:param virsh_instance: virsh instance
"""
vmxml = VMXML.new_from_inactive_dumpxml(
vm_name, virsh_instance=virsh_instance)
vm_name, virsh_instance=virsh_instance)
graphic = vmxml.xmltreefile.find('devices').findall('graphics')
for key in attr:
logging.debug("Set %s='%s'" % (key, attr[key]))
Expand Down Expand Up @@ -3524,6 +3524,7 @@ class VMKeywrapXML(base.LibvirtXMLBase):
kw.set_cipher("aes", "off")
vmxml.set_keywrap(kw)
"""

def __init__(self, virsh_instance=base.virsh):
super(VMKeywrapXML, self).__init__(virsh_instance=virsh_instance)
self.xml = '<keywrap/>'
Expand Down
6 changes: 3 additions & 3 deletions virttest/qemu_devices/qcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,9 +1874,9 @@ def define_hbas(qtype, atype, bus, unit, port, qbus, pci_bus, iothread,
peers.append({'host': peer['host'],
'type': peer.get('type', 'inet'),
'port': '%s' % peer.get('port', '0')})
gluster_peers.update({'server.{i}.{k}'.format(i=i+1, k=k): v
for i, server in enumerate(peers)
for k, v in six.iteritems(server)})
gluster_peers.update({'server.{i}.{k}'.format(i=i + 1, k=k): v
for i, server in enumerate(peers)
for k, v in six.iteritems(server)})
elif access.storage_type == 'nbd':
reconnect_delay = access.reconnect_delay
elif access.storage_type == 'curl':
Expand Down
6 changes: 5 additions & 1 deletion virttest/qemu_devices/qdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ def get_qid(self):

class QBlockdevFormatNode(QBlockdevNode):
""" New a format type blockdev node. """

def __init__(self, aobject):
child_bus = QDriveBus('drive_%s' % aobject, aobject)
super(QBlockdevFormatNode, self).__init__(aobject, child_bus)
Expand Down Expand Up @@ -867,6 +868,7 @@ class QBlockdevFormatLuks(QBlockdevFormatNode):

class QBlockdevProtocol(QBlockdevNode):
""" New a protocol blockdev node. """

def __init__(self, aobject):
super(QBlockdevProtocol, self).__init__(aobject, None, False)

Expand Down Expand Up @@ -1778,7 +1780,7 @@ def start_daemon(self):
self._daemon_process = aexpect.run_bg(cmd, **run_bg_kwargs)
if status_active:
self._daemon_process.read_until_any_line_matches(
status_active, timeout=read_until_timeout)
status_active, timeout=read_until_timeout)
else:
time.sleep(start_until_timeout)
logging.info("Created %s daemon process with parent PID %d.",
Expand Down Expand Up @@ -1841,6 +1843,7 @@ class QVirtioFSDev(QDaemonDev):
"""
Virtiofs pseudo device.
"""

def __init__(self, aobject, binary, sock_path, source, extra_options=None):
"""
:param aobject: The aobject of virtiofs daemon.
Expand Down Expand Up @@ -1895,6 +1898,7 @@ class QSwtpmDev(QDaemonDev):
"""
Virtual swtpm pseudo device.
"""

def __init__(self, aobject, binary, sock_path, storage_path,
version=None, extra_options=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion virttest/qemu_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ def netdev_add(self, backend, name, **kwargs):
"""
kwargs = self._build_args(**kwargs)
extra_args = "".join([",%s=%s" % (k, v if not isinstance(v, bool) else
"on" if v else "off") for k, v in kwargs.items()])
"on" if v else "off") for k, v in kwargs.items()])
netdev_cmd = "netdev_add type=%s,id=%s%s" % (backend, name, extra_args)
return self.cmd(netdev_cmd)

Expand Down
22 changes: 11 additions & 11 deletions virttest/qemu_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def filename_to_file_opts(filename):
'volume': matches.group('volume'),
'path': matches.group('path')}
file_opts.update({'server.{i}.{k}'.format(i=i, k=k): v
for i, server in enumerate(servers)
for k, v in six.iteritems(server)})
for i, server in enumerate(servers)
for k, v in six.iteritems(server)})
elif re.match(r'nbd(\+\w+)?://', filename):
filename_pattern = re.compile(
r'nbd(\+(?:.+))?://((?P<host>[^/:?]+)(:(?P<port>\d+))?)?'
Expand All @@ -113,7 +113,7 @@ def filename_to_file_opts(filename):
if host:
# 10890 is the default port for tcp connection
port = matches.group('port') if matches.group(
'port') else '10809'
'port') else '10809'
server = {'server.type': 'inet',
'server.host': host,
'server.port': port}
Expand Down Expand Up @@ -245,9 +245,9 @@ def _get_image_meta(image, params, root_dir):
peers.append({'host': peer['host'],
'type': peer.get('type', 'inet'),
'port': '%s' % peer.get('port', '0')})
meta['file'].update({'server.{i}.{k}'.format(i=i+1, k=k): v
for i, server in enumerate(peers)
for k, v in six.iteritems(server)})
meta['file'].update({'server.{i}.{k}'.format(i=i + 1, k=k): v
for i, server in enumerate(peers)
for k, v in six.iteritems(server)})
elif auth_info.storage_type == 'nbd':
# qemu-img, as a client, accesses nbd storage
if auth_info.tls_creds:
Expand Down Expand Up @@ -312,7 +312,7 @@ def get_image_repr(image, params, root_dir, representation=None):
func = mapping.get(representation, None)
if func is None:
image_secret = storage.ImageSecret.image_secret_define_by_params(
image, params)
image, params)

access_needed = False
auth_info = storage.StorageAuth.auth_info_define_by_params(image,
Expand Down Expand Up @@ -418,7 +418,7 @@ class QemuImg(storage.QemuImg):
"commit_drop": "-d",
"compare_strict_mode": "-s",
"compare_second_image_format": "-F"
}
}
create_cmd = ("create {secret_object} {tls_creds_object} {image_format} "
"{backing_file} {backing_format} {unsafe!b} {options} "
"{image_filename} {image_size}")
Expand Down Expand Up @@ -1526,7 +1526,7 @@ def resize(self, size, shrink=False, preallocation=None):
"resize_preallocation": preallocation,
"image_filename": self.image_filename,
"image_size": size,
}
}
if self.encryption_config.key_secret:
cmd_dict["image_filename"] = "'%s'" % get_image_json(
self.tag, self.params, self.root_dir)
Expand Down Expand Up @@ -1574,7 +1574,7 @@ def measure(self, target_fmt, size=None, output="human"):
target_image_params["image_format"] = "luks"
target_image_params["image_secret"] = target_image_secret
target_image_object = QemuImg(
target_image_params, self.root_dir, target_image)
target_image_params, self.root_dir, target_image)
cmd_list.append(target_image_object._secret_objects[-1])
cmd_list.append('-o key-secret=%s' %
target_image_object.encryption_config.key_secret.aid)
Expand All @@ -1590,7 +1590,7 @@ def measure(self, target_fmt, size=None, output="human"):
cmd_list.append("'%s'" % image_json_str)
else:
cmd_list.extend([("-f %s" % self.image_format),
self.image_filename])
self.image_filename])

cmd_result = process.run(" ".join(cmd_list), ignore_status=True)
return cmd_result
Expand Down
2 changes: 1 addition & 1 deletion virttest/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def __init__(self, params):
self.vm_user = params.get("vm_user", 'root')
self.port = params.get("port", 22)
if not all([self.remote_host, self.remote_user, self.remote_pwd,
self.vm_ip, self.vm_pwd]):
self.vm_ip, self.vm_pwd]):
raise exceptions.TestError("At least one of [remote_host|"
"remote_user|remote_pwd|vm_ip|"
"vm_pwd] is invalid!")
Expand Down
2 changes: 2 additions & 0 deletions virttest/remote_commander/remote_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def __setstate__(self, state):
class CmdQuery(object):
"""Command-msg-request from VM to avocado-vt test.
"""

def __init__(self, *args, **kargs):
"""
Command for asking from VM to avocado-vt.
Expand All @@ -146,6 +147,7 @@ def __init__(self, *args, **kargs):
class CmdRespond(object):
"""Command-msg-answer from avocado-test to VM.
"""

def __init__(self, respond):
"""
Command for answering avocado-vt to VM.
Expand Down
1 change: 1 addition & 0 deletions virttest/staging/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ class Service(object):
"""
class to handle service operations in Remote machine/Guest
"""

def __init__(self, service_name, session=None, timeout=120):
"""
Initialize the service return Factory object if session is None
Expand Down
7 changes: 4 additions & 3 deletions virttest/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def get_iso_filename(cdrom_params, root_dir, basename=False):
iso = cdrom_params.get("cdrom")
if iso:
iso = os.path.basename(iso) if basename else utils_misc.get_path(
root_dir, iso)
root_dir, iso)
return iso


Expand Down Expand Up @@ -568,6 +568,7 @@ class ImageAccessInfo(object):
Access info to the logical image, which can include the network
storage image only, or the image and its backing images.
"""

def __init__(self, image, image_auth, image_backing_auth):
"""
:param image: image tag name
Expand Down Expand Up @@ -613,7 +614,7 @@ def retrieve_access_info(image, params):

for img in images:
auth = StorageAuth.auth_info_define_by_params(
img, params.object_params(img))
img, params.object_params(img))
if auth is not None:
access_info[img] = auth

Expand Down Expand Up @@ -801,7 +802,7 @@ def __init__(self, params, root_dir, tag):
self.snapshot_format = ss_params.get("image_format")

self.image_access = ImageAccessInfo.access_info_define_by_params(
self.tag, self.params)
self.tag, self.params)

self.data_file = self.external_data_file_defined_by_params(
params, root_dir, tag)
Expand Down
4 changes: 2 additions & 2 deletions virttest/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def __init__(self, params=None):
if self.physical_nic.split(':', 1)[0] == "shell":
self.physical_nic = process.run(
self.physical_nic.split(':', 1)[1], shell=True
).stdout_text.strip()
).stdout_text.strip()
if self.physical_nic not in utils_net.get_host_iface():
raise exceptions.TestSetupFail("Physical network '%s'"
"does not exist" %
Expand Down Expand Up @@ -1538,7 +1538,7 @@ def set_linkvf_ib(self):
logging.info("The key %s corresponds to %s", key, pids[key])
for subkey in pids[key].keys():
status = process.system("echo %s > %s" % (pids[key][subkey],
os.path.join(key, subkey)), shell=True)
os.path.join(key, subkey)), shell=True)
if status != 0:
return False
return True
Expand Down
1 change: 1 addition & 0 deletions virttest/utils_iptables.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Firewall_cmd(object):
"""
class handles firewall-cmd methods
"""

def __init__(self, session=None):
"""
initialises the firewall cmd objects
Expand Down
1 change: 1 addition & 0 deletions virttest/utils_libvirt/libvirt_keywrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ProtectedKeyHelper(object):
"""
Helper class to test for protected key support on s390x
"""

def __init__(self, session=None):
self.session = session
self.sysfs = "/sys/devices/virtual/misc/pkey/protkey"
Expand Down
2 changes: 1 addition & 1 deletion virttest/utils_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,7 @@ def get_winutils_vol(session, label="WIN_UTILS"):
:return: volume ID.
"""
return wait_for(lambda: get_win_disk_vol(session,
condition="VolumeName='%s'" % label), 240)
condition="VolumeName='%s'" % label), 240)


def set_winutils_letter(session, cmd, label="WIN_UTILS"):
Expand Down
2 changes: 1 addition & 1 deletion virttest/utils_selinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def diff_defcon(pathname, dirdesc=False, selinux_force=False):
:return: List of tuple(pathname, from context, to context)
"""
return _format_changes(_run_restorecon(pathname, dirdesc,
selinux_force=selinux_force))
selinux_force=selinux_force))


def apply_defcon(pathname, dirdesc=False, selinux_force=False):
Expand Down
2 changes: 1 addition & 1 deletion virttest/utils_split_daemons.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def is_modular_daemon(session=None):
"virtstoraged.socket", "virtproxyd.socket"]

if any([service.Factory.create_service(d, run=runner).status()
for d in daemons]):
for d in daemons]):
IS_MODULAR_DAEMON[host_key] = True
else:
IS_MODULAR_DAEMON[host_key] = False
Expand Down
2 changes: 1 addition & 1 deletion virttest/utils_test/libvirt_domjobinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _search_jobinfo(jobinfo, ignore_status=False):
groups = re.findall(r'[0-9.]+', item.strip())
logging.debug("In '%s' search '%s'\n", item, groups[0])
if (math.fabs(float(groups[0]) - float(compare_to_value)) //
float(compare_to_value) > diff_rate):
float(compare_to_value) > diff_rate):
err_msg = ("{} {} has too much difference from "
"{}".format(jobinfo_item,
groups[0],
Expand Down
Loading

0 comments on commit 480f90c

Please sign in to comment.