SHA256
1
0
forked from pool/salt
salt/fix-the-removed-six.itermitems-and-six.-_type-262.patch

181 lines
6.5 KiB
Diff

From 01e2e60a5aba609d219b73f1018f12517a294a64 Mon Sep 17 00:00:00 2001
From: Cedric Bosdonnat <cbosdonnat@suse.com>
Date: Tue, 15 Sep 2020 13:46:06 +0200
Subject: [PATCH] Fix the removed six.itermitems and six.*_type* (#262)
* Fix the removed six.itermitems and six.*_type*
Upstream py2 to py3 cleanup tool removes a bunch of six calls that we
still need when backporting since our Salt minion might still be running
on python 2.7.
* fixup! Fix the removed six.itermitems and six.*_type*
---
salt/_compat.py | 25 ++++++++++++++++---------
salt/modules/virt.py | 11 ++++-------
salt/states/virt.py | 1 +
salt/utils/xmlutil.py | 3 ++-
tests/unit/modules/test_virt.py | 2 +-
5 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/salt/_compat.py b/salt/_compat.py
index d9425523cf..de100de3fa 100644
--- a/salt/_compat.py
+++ b/salt/_compat.py
@@ -7,6 +7,7 @@ Salt compatibility code
import binascii
import logging
import sys
+import xml.sax.saxutils as saxutils
from salt.exceptions import SaltException
from salt.ext.six import binary_type, integer_types, string_types, text_type
@@ -261,21 +262,25 @@ def ip_address(address):
try:
return ipaddress.IPv4Address(address)
except (ipaddress.AddressValueError, ipaddress.NetmaskValueError) as err:
- log.debug('Error while parsing IPv4 address: %s', address)
+ log.debug("Error while parsing IPv4 address: %s", address)
log.debug(err)
try:
return IPv6AddressScoped(address)
except (ipaddress.AddressValueError, ipaddress.NetmaskValueError) as err:
- log.debug('Error while parsing IPv6 address: %s', address)
+ log.debug("Error while parsing IPv6 address: %s", address)
log.debug(err)
if isinstance(address, bytes):
- raise ipaddress.AddressValueError('{} does not appear to be an IPv4 or IPv6 address. '
- 'Did you pass in a bytes (str in Python 2) instead '
- 'of a unicode object?'.format(repr(address)))
+ raise ipaddress.AddressValueError(
+ "{} does not appear to be an IPv4 or IPv6 address. "
+ "Did you pass in a bytes (str in Python 2) instead "
+ "of a unicode object?".format(repr(address))
+ )
- raise ValueError('{} does not appear to be an IPv4 or IPv6 address'.format(repr(address)))
+ raise ValueError(
+ "{} does not appear to be an IPv4 or IPv6 address".format(repr(address))
+ )
def ip_interface(address):
@@ -302,16 +307,18 @@ def ip_interface(address):
try:
return ipaddress.IPv4Interface(address)
except (ipaddress.AddressValueError, ipaddress.NetmaskValueError) as err:
- log.debug('Error while getting IPv4 interface for address %s', address)
+ log.debug("Error while getting IPv4 interface for address %s", address)
log.debug(err)
try:
return ipaddress.IPv6Interface(address)
except (ipaddress.AddressValueError, ipaddress.NetmaskValueError) as err:
- log.debug('Error while getting IPv6 interface for address %s', address)
+ log.debug("Error while getting IPv6 interface for address %s", address)
log.debug(err)
- raise ValueError('{} does not appear to be an IPv4 or IPv6 interface'.format(address))
+ raise ValueError(
+ "{} does not appear to be an IPv4 or IPv6 interface".format(address)
+ )
if ipaddress:
diff --git a/salt/modules/virt.py b/salt/modules/virt.py
index ec40f08359..c042738370 100644
--- a/salt/modules/virt.py
+++ b/salt/modules/virt.py
@@ -88,8 +88,6 @@ import string # pylint: disable=deprecated-module
import subprocess
import sys
import time
-from xml.etree import ElementTree
-from xml.sax import saxutils
import jinja2.exceptions
import salt.utils.files
@@ -99,8 +97,9 @@ import salt.utils.stringutils
import salt.utils.templates
import salt.utils.xmlutil as xmlutil
import salt.utils.yaml
-from salt._compat import ipaddress
+from salt._compat import ElementTree, ipaddress, saxutils
from salt.exceptions import CommandExecutionError, SaltInvocationError
+from salt.ext import six
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
from salt.ext.six.moves.urllib.parse import urlparse, urlunparse
from salt.utils.virt import check_remote, download_remote
@@ -1516,7 +1515,7 @@ def _handle_remote_boot_params(orig_boot):
"""
saltinst_dir = None
new_boot = orig_boot.copy()
- keys = orig_boot.keys()
+ keys = set(orig_boot.keys())
cases = [
{"efi"},
{"kernel", "initrd", "efi"},
@@ -2559,9 +2558,7 @@ def update(
# Attaching device
if source_file:
- ElementTree.SubElement(
- updated_disk, "source", attrib={"file": source_file}
- )
+ ElementTree.SubElement(updated_disk, "source", file=source_file)
changes["disk"]["new"] = new_disks
diff --git a/salt/states/virt.py b/salt/states/virt.py
index b45cf72ed3..df7ebb63e6 100644
--- a/salt/states/virt.py
+++ b/salt/states/virt.py
@@ -22,6 +22,7 @@ import salt.utils.files
import salt.utils.stringutils
import salt.utils.versions
from salt.exceptions import CommandExecutionError, SaltInvocationError
+from salt.ext import six
try:
import libvirt # pylint: disable=import-error
diff --git a/salt/utils/xmlutil.py b/salt/utils/xmlutil.py
index b9f047820b..111ca155d4 100644
--- a/salt/utils/xmlutil.py
+++ b/salt/utils/xmlutil.py
@@ -7,6 +7,7 @@ import string # pylint: disable=deprecated-module
from xml.etree import ElementTree
import salt.utils.data
+from salt.ext import six
def _conv_name(x):
@@ -160,7 +161,7 @@ def clean_node(parent_map, node, ignored=None):
has_text = node.text is not None and node.text.strip()
parent = parent_map.get(node)
if (
- len(node.attrib.keys() - (ignored or [])) == 0
+ len(set(node.attrib.keys()) - set(ignored or [])) == 0
and not list(node)
and not has_text
):
diff --git a/tests/unit/modules/test_virt.py b/tests/unit/modules/test_virt.py
index 4775fec31f..4a4c0395a7 100644
--- a/tests/unit/modules/test_virt.py
+++ b/tests/unit/modules/test_virt.py
@@ -45,7 +45,7 @@ class LibvirtMock(MagicMock): # pylint: disable=too-many-ancestors
"""
def __init__(self, msg):
- super().__init__(msg)
+ super(Exception, self).__init__(msg)
self.msg = msg
def get_error_message(self):
--
2.29.2