mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
This branch no longer targets py 2.6
This commit is contained in:
parent
7b503e562b
commit
4b59c351e4
@ -8,7 +8,6 @@ Salt compatibility code
|
||||
from __future__ import absolute_import
|
||||
import sys
|
||||
import types
|
||||
import subprocess
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext.six import binary_type, string_types, text_type
|
||||
@ -134,46 +133,6 @@ def string_io(data=None): # cStringIO can't handle unicode
|
||||
except (UnicodeEncodeError, TypeError):
|
||||
return StringIO(data)
|
||||
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
|
||||
# Backport of Python's 2.7 subprocess methods not found in 2.6
|
||||
# This code comes directly from the 2.7 subprocess module
|
||||
|
||||
def check_output(*popenargs, **kwargs):
|
||||
r"""Run command with arguments and return its output as a byte string.
|
||||
|
||||
If the exit code was non-zero it raises a CalledProcessError. The
|
||||
CalledProcessError object will have the return code in the returncode
|
||||
attribute and output in the output attribute.
|
||||
|
||||
The arguments are the same as for the Popen constructor. Example:
|
||||
|
||||
>>> check_output(["ls", "-l", "/dev/null"])
|
||||
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
|
||||
|
||||
The stdout argument is not allowed as it is used internally.
|
||||
To capture standard error in the result, use stderr=STDOUT.
|
||||
|
||||
>>> check_output(["/bin/sh", "-c",
|
||||
... "ls -l non_existent_file ; exit 0"],
|
||||
... stderr=STDOUT)
|
||||
'ls: non_existent_file: No such file or directory\n'
|
||||
"""
|
||||
if 'stdout' in kwargs:
|
||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise subprocess.CalledProcessError(retcode, cmd, output=output)
|
||||
return output
|
||||
subprocess.check_output = check_output
|
||||
|
||||
|
||||
if PY3:
|
||||
import ipaddress
|
||||
else:
|
||||
|
@ -7,10 +7,10 @@ The jail module for FreeBSD
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
from salt._compat import subprocess
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'jail'
|
||||
|
@ -18,14 +18,13 @@ import sys
|
||||
import time
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import subprocess
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils
|
||||
import salt.ext.six as six
|
||||
import salt.utils.event
|
||||
from salt._compat import subprocess
|
||||
from salt.utils.network import host_to_ips as _host_to_ips
|
||||
# pylint: disable=W0611
|
||||
from salt.modules.status import ping_master, time_
|
||||
|
@ -12,6 +12,7 @@ import types
|
||||
import socket
|
||||
import logging
|
||||
import platform
|
||||
import subprocess
|
||||
from string import ascii_letters, digits
|
||||
|
||||
# Import 3rd-party libs
|
||||
@ -26,7 +27,7 @@ except ImportError:
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
from salt._compat import subprocess, ipaddress
|
||||
from salt._compat import ipaddress
|
||||
|
||||
# inet_pton does not exist in Windows, this is a workaround
|
||||
if salt.utils.is_windows():
|
||||
|
@ -7,9 +7,7 @@ Common functions for working with RPM packages
|
||||
from __future__ import absolute_import
|
||||
import collections
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
from salt._compat import subprocess
|
||||
import subprocess
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -33,8 +33,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
}
|
||||
return {virt: loader_globals, config: loader_globals}
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_boot_default_dev(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -49,8 +47,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
root = ET.fromstring(xml_data)
|
||||
self.assertEqual(root.find('os/boot').attrib['dev'], 'hd')
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_boot_custom_dev(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -66,8 +62,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
root = ET.fromstring(xml_data)
|
||||
self.assertEqual(root.find('os/boot').attrib['dev'], 'cdrom')
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_boot_multiple_devs(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -84,8 +78,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
devs = root.findall('.//boot')
|
||||
self.assertTrue(len(devs) == 2)
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_serial_console(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -103,8 +95,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual(root.find('devices/serial').attrib['type'], 'pty')
|
||||
self.assertEqual(root.find('devices/console').attrib['type'], 'pty')
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_telnet_console(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -124,8 +114,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual(root.find('devices/console').attrib['type'], 'tcp')
|
||||
self.assertEqual(root.find('devices/console/source').attrib['service'], '22223')
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_telnet_console_unspecified_port(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -144,8 +132,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual(root.find('devices/console').attrib['type'], 'tcp')
|
||||
self.assertIsInstance(int(root.find('devices/console/source').attrib['service']), int)
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_serial_no_console(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -163,8 +149,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual(root.find('devices/serial').attrib['type'], 'pty')
|
||||
self.assertEqual(root.find('devices/console'), None)
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_telnet_no_console(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -226,8 +210,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual(eth0['source'], 'br0')
|
||||
self.assertEqual(eth0['model'], 'virtio')
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_vol_xml_for_kvm(self):
|
||||
xml_data = virt._gen_vol_xml('vmname', 'system', 8192, 'kvm')
|
||||
root = ET.fromstring(xml_data)
|
||||
@ -236,8 +218,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual(root.find('capacity').attrib['unit'], 'KiB')
|
||||
self.assertEqual(root.find('capacity').text, str(8192 * 1024))
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_vol_xml_for_esxi(self):
|
||||
xml_data = virt._gen_vol_xml('vmname', 'system', 8192, 'esxi')
|
||||
root = ET.fromstring(xml_data)
|
||||
@ -246,8 +226,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual(root.find('capacity').attrib['unit'], 'KiB')
|
||||
self.assertEqual(root.find('capacity').text, str(8192 * 1024))
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_kvm_default_profile(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -286,8 +264,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertTrue(
|
||||
re.match('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$', mac, re.I))
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_gen_xml_for_esxi_default_profile(self):
|
||||
diskp = virt._disk_profile('default', 'esxi')
|
||||
nicp = virt._nic_profile('default', 'esxi')
|
||||
@ -325,8 +301,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertTrue(
|
||||
re.match('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$', mac, re.I))
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
@patch('salt.modules.virt._nic_profile')
|
||||
@patch('salt.modules.virt._disk_profile')
|
||||
def test_gen_xml_for_esxi_custom_profile(self, disk_profile, nic_profile):
|
||||
@ -374,8 +348,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertTrue(len(root.findall('.//disk')) == 2)
|
||||
self.assertTrue(len(root.findall('.//interface')) == 2)
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
@patch('salt.modules.virt._nic_profile')
|
||||
@patch('salt.modules.virt._disk_profile')
|
||||
def test_gen_xml_for_kvm_custom_profile(self, disk_profile, nic_profile):
|
||||
@ -423,8 +395,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertTrue(len(root.findall('.//disk')) == 2)
|
||||
self.assertTrue(len(root.findall('.//interface')) == 2)
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_controller_for_esxi(self):
|
||||
diskp = virt._disk_profile('default', 'esxi')
|
||||
nicp = virt._nic_profile('default', 'esxi')
|
||||
@ -442,8 +412,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
controller = controllers[0]
|
||||
self.assertEqual(controller.attrib['model'], 'lsilogic')
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_controller_for_kvm(self):
|
||||
diskp = virt._disk_profile('default', 'kvm')
|
||||
nicp = virt._nic_profile('default', 'kvm')
|
||||
@ -502,8 +470,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
re.match('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$',
|
||||
interface_attrs['mac'], re.I))
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_get_graphics(self):
|
||||
get_xml_mock = MagicMock(return_value='''<domain type='kvm' id='7'>
|
||||
<name>test-vm</name>
|
||||
@ -520,8 +486,6 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual('5900', graphics['port'])
|
||||
self.assertEqual('0.0.0.0', graphics['listen'])
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'ElementTree version 1.3 required'
|
||||
' which comes with Python 2.7')
|
||||
def test_get_nics(self):
|
||||
get_xml_mock = MagicMock(return_value='''<domain type='kvm' id='7'>
|
||||
<name>test-vm</name>
|
||||
|
Loading…
Reference in New Issue
Block a user