Resolve formatting issues

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
Radostin Stoyanov 2020-08-19 09:56:20 +01:00 committed by Daniel Wozniak
parent b38eb51f4b
commit c9e80ea2a8
10 changed files with 179 additions and 235 deletions

View file

@ -670,7 +670,9 @@ def _migrate(dom, dst_uri, **kwargs):
try:
bandwidth_value = int(max_bandwidth)
except ValueError:
raise SaltInvocationError("Invalid max_bandwidth value: {}".format(max_bandwidth))
raise SaltInvocationError(
"Invalid max_bandwidth value: {}".format(max_bandwidth)
)
dom.migrateSetMaxSpeed(bandwidth_value)
max_downtime = kwargs.get("max_downtime")
@ -678,7 +680,9 @@ def _migrate(dom, dst_uri, **kwargs):
try:
downtime_value = int(max_downtime)
except ValueError:
raise SaltInvocationError("Invalid max_downtime value: {}".format(max_downtime))
raise SaltInvocationError(
"Invalid max_downtime value: {}".format(max_downtime)
)
dom.migrateSetMaxDowntime(downtime_value)
if kwargs.get("offline") is True:
@ -710,7 +714,9 @@ def _migrate(dom, dst_uri, **kwargs):
parallel_connections = kwargs.get("parallel_connections")
if parallel_connections:
try:
params[libvirt.VIR_MIGRATE_PARAM_PARALLEL_CONNECTIONS] = int(parallel_connections)
params[libvirt.VIR_MIGRATE_PARAM_PARALLEL_CONNECTIONS] = int(
parallel_connections
)
except ValueError:
raise SaltInvocationError("Invalid parallel_connections value")
flags |= libvirt.VIR_MIGRATE_PARALLEL

View file

@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
"""
Set up the Salt integration test suite
"""
from __future__ import absolute_import, print_function
import atexit
import copy
import errno
@ -125,18 +121,18 @@ class ThreadingMixIn(socketserver.ThreadingMixIn):
daemon_threads = False
class ThreadedSocketServer(ThreadingMixIn, socketserver.TCPServer, object):
class ThreadedSocketServer(ThreadingMixIn, socketserver.TCPServer):
allow_reuse_address = True
def server_activate(self):
self.shutting_down = threading.Event()
super(ThreadedSocketServer, self).server_activate()
super().server_activate()
def server_close(self):
if hasattr(self, "shutting_down"):
self.shutting_down.set()
super(ThreadedSocketServer, self).server_close()
super().server_close()
class SocketServerRequestHandler(socketserver.StreamRequestHandler):
@ -155,7 +151,7 @@ class SocketServerRequestHandler(socketserver.StreamRequestHandler):
del record_dict
except (EOFError, KeyboardInterrupt, SystemExit):
break
except socket.error as exc:
except OSError as exc:
try:
if exc.errno == errno.WSAECONNRESET:
# Connection reset on windows
@ -174,7 +170,7 @@ class TestDaemonStartFailed(Exception):
"""
class TestDaemon(object):
class TestDaemon:
"""
Set up the master and minion daemons, and run related cases
"""
@ -186,7 +182,7 @@ class TestDaemon(object):
self.colors = salt.utils.color.get_colors(
self.parser.options.no_colors is False
)
self.clear_line = "\r{0}\r".format(
self.clear_line = "\r{}\r".format(
" " * getattr(self.parser.options, "output_columns", PNUM)
)
self.virt_minion_enabled = False
@ -210,7 +206,7 @@ class TestDaemon(object):
# Set up PATH to mockbin
self._enter_mockbin()
self.minion_targets = set(["minion", "sub_minion"])
self.minion_targets = {"minion", "sub_minion"}
if self.virt_minion_enabled:
self.minion_targets.add("virt_minion_0")
self.minion_targets.add("virt_minion_1")
@ -270,14 +266,16 @@ class TestDaemon(object):
finally:
self.post_setup_minions()
def start_virt_minion(self,
name,
config_dir,
libvirt_tcp_port,
libvirt_tls_port,
ssh_port,
sshd_port,
host_uuid):
def start_virt_minion(
self,
name,
config_dir,
libvirt_tcp_port,
libvirt_tls_port,
ssh_port,
sshd_port,
host_uuid,
):
"""
Start virt minion daemon
"""
@ -477,9 +475,7 @@ class TestDaemon(object):
Generate keys and start an ssh daemon on an alternate port
"""
sys.stdout.write(
" * {LIGHT_GREEN}Starting {0} ... {ENDC}".format(
"SSH server", **self.colors
)
" * {LIGHT_GREEN}Starting {} ... {ENDC}".format("SSH server", **self.colors)
)
keygen = salt.utils.path.which("ssh-keygen")
sshd = salt.utils.path.which("sshd")
@ -521,7 +517,7 @@ class TestDaemon(object):
_, keygen_err = keygen_process.communicate()
if keygen_err:
print(
"ssh-keygen had errors: {0}".format(
"ssh-keygen had errors: {}".format(
salt.utils.stringutils.to_str(keygen_err)
)
)
@ -579,7 +575,7 @@ class TestDaemon(object):
_, keygen_dsa_err = keygen_process_dsa.communicate()
if keygen_dsa_err:
print(
"ssh-keygen had errors: {0}".format(
"ssh-keygen had errors: {}".format(
salt.utils.stringutils.to_str(keygen_dsa_err)
)
)
@ -606,7 +602,7 @@ class TestDaemon(object):
_, keygen_escda_err = keygen_process_ecdsa.communicate()
if keygen_escda_err:
print(
"ssh-keygen had errors: {0}".format(
"ssh-keygen had errors: {}".format(
salt.utils.stringutils.to_str(keygen_escda_err)
)
)
@ -633,7 +629,7 @@ class TestDaemon(object):
_, keygen_ed25519_err = keygen_process_ed25519.communicate()
if keygen_ed25519_err:
print(
"ssh-keygen had errors: {0}".format(
"ssh-keygen had errors: {}".format(
salt.utils.stringutils.to_str(keygen_ed25519_err)
)
)
@ -641,17 +637,17 @@ class TestDaemon(object):
with salt.utils.files.fopen(
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "sshd_config"), "a"
) as ssh_config:
ssh_config.write("AuthorizedKeysFile {0}\n".format(auth_key_file))
ssh_config.write("AuthorizedKeysFile {}\n".format(auth_key_file))
if not keygen_dsa_err:
ssh_config.write("HostKey {0}\n".format(server_dsa_priv_key_file))
ssh_config.write("HostKey {}\n".format(server_dsa_priv_key_file))
if not keygen_escda_err:
ssh_config.write("HostKey {0}\n".format(server_ecdsa_priv_key_file))
ssh_config.write("HostKey {}\n".format(server_ecdsa_priv_key_file))
if not keygen_ed25519_err:
ssh_config.write("HostKey {0}\n".format(server_ed25519_priv_key_file))
ssh_config.write("HostKey {}\n".format(server_ed25519_priv_key_file))
self.sshd_pidfile = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "sshd.pid")
self.sshd_process = subprocess.Popen(
[sshd, "-f", "sshd_config", "-o", "PidFile={0}".format(self.sshd_pidfile)],
[sshd, "-f", "sshd_config", "-o", "PidFile={}".format(self.sshd_pidfile)],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
@ -660,7 +656,7 @@ class TestDaemon(object):
_, sshd_err = self.sshd_process.communicate()
if sshd_err:
print(
"sshd had errors on startup: {0}".format(
"sshd had errors on startup: {}".format(
salt.utils.stringutils.to_str(sshd_err)
)
)
@ -670,9 +666,9 @@ class TestDaemon(object):
with salt.utils.files.fopen(
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "roster"), "a"
) as roster:
roster.write(" user: {0}\n".format(RUNTIME_VARS.RUNNING_TESTS_USER))
roster.write(" user: {}\n".format(RUNTIME_VARS.RUNNING_TESTS_USER))
roster.write(
" priv: {0}/{1}\n".format(RUNTIME_VARS.TMP_CONF_DIR, "key_test")
" priv: {}/{}\n".format(RUNTIME_VARS.TMP_CONF_DIR, "key_test")
)
if salt.utils.platform.is_darwin():
roster.write(" set_path: $PATH:/usr/local/bin/\n")
@ -727,7 +723,7 @@ class TestDaemon(object):
os.makedirs(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR)
print(
" * Transplanting configuration files to '{0}'".format(
" * Transplanting configuration files to '{}'".format(
RUNTIME_VARS.TMP_CONF_DIR
)
)
@ -964,11 +960,11 @@ class TestDaemon(object):
opts_dict["ext_pillar"] = []
if salt.utils.platform.is_windows():
opts_dict["ext_pillar"].append(
{"cmd_yaml": "type {0}".format(os.path.join(FILES, "ext.yaml"))}
{"cmd_yaml": "type {}".format(os.path.join(FILES, "ext.yaml"))}
)
else:
opts_dict["ext_pillar"].append(
{"cmd_yaml": "cat {0}".format(os.path.join(FILES, "ext.yaml"))}
{"cmd_yaml": "cat {}".format(os.path.join(FILES, "ext.yaml"))}
)
# all read, only owner write
@ -1002,7 +998,7 @@ class TestDaemon(object):
# Point the config values to the correct temporary paths
for name in ("hosts", "aliases"):
optname = "{0}.file".format(name)
optname = "{}.file".format(name)
optname_path = os.path.join(TMP, name)
master_opts[optname] = optname_path
minion_opts[optname] = optname_path
@ -1076,7 +1072,7 @@ class TestDaemon(object):
"syndic_master",
"proxy",
):
computed_config = copy.deepcopy(locals()["{0}_opts".format(entry)])
computed_config = copy.deepcopy(locals()["{}_opts".format(entry)])
with salt.utils.files.fopen(
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry), "w"
) as fp_:
@ -1372,7 +1368,7 @@ class TestDaemon(object):
):
if os.path.isdir(dirname):
try:
shutil.rmtree(six.text_type(dirname), onerror=remove_readonly)
shutil.rmtree(str(dirname), onerror=remove_readonly)
except Exception: # pylint: disable=broad-except
log.exception("Failed to remove directory: %s", dirname)
@ -1394,8 +1390,8 @@ class TestDaemon(object):
if job_finished is False:
sys.stdout.write(
" * {LIGHT_YELLOW}[Quit in {0}]{ENDC} Waiting for {1}".format(
"{0}".format(expire - now).rsplit(".", 1)[0],
" * {LIGHT_YELLOW}[Quit in {}]{ENDC} Waiting for {}".format(
"{}".format(expire - now).rsplit(".", 1)[0],
", ".join(running),
**self.colors,
)
@ -1413,57 +1409,53 @@ class TestDaemon(object):
def __client_job_running(self, targets, jid):
running = self.client.cmd(list(targets), "saltutil.running", tgt_type="list")
return [k for (k, v) in six.iteritems(running) if v and v[0]["jid"] == jid]
return [k for (k, v) in running.items() if v and v[0]["jid"] == jid]
def sync_minion_modules_(self, modules_kind, targets, timeout=None):
if not timeout:
timeout = 120
# Let's sync all connected minions
print(
" {LIGHT_BLUE}*{ENDC} Syncing minion's {1} "
"(saltutil.sync_{1})".format(
", ".join(targets), modules_kind, **self.colors
)
" {LIGHT_BLUE}*{ENDC} Syncing minion's {} "
"(saltutil.sync_{})".format(", ".join(targets), modules_kind, **self.colors)
)
syncing = set(targets)
jid_info = self.client.run_job(
list(targets),
"saltutil.sync_{0}".format(modules_kind),
"saltutil.sync_{}".format(modules_kind),
tgt_type="list",
timeout=999999999999999,
)
if self.wait_for_jid(targets, jid_info["jid"], timeout) is False:
print(
" {LIGHT_RED}*{ENDC} WARNING: Minions failed to sync {0}. "
"Tests requiring these {0} WILL fail".format(
modules_kind, **self.colors
)
" {LIGHT_RED}*{ENDC} WARNING: Minions failed to sync {}. "
"Tests requiring these {} WILL fail".format(modules_kind, **self.colors)
)
raise SystemExit()
while syncing:
rdata = self.client.get_full_returns(jid_info["jid"], syncing, 1)
if rdata:
for name, output in six.iteritems(rdata):
for name, output in rdata.items():
if not output["ret"]:
# Already synced!?
syncing.remove(name)
continue
if isinstance(output["ret"], six.string_types):
if isinstance(output["ret"], str):
# An errors has occurred
print(
" {LIGHT_RED}*{ENDC} {0} Failed to sync {2}: "
"{1}".format(
" {LIGHT_RED}*{ENDC} {} Failed to sync {2}: "
"{}".format(
name, output["ret"], modules_kind, **self.colors
)
)
return False
print(
" {LIGHT_GREEN}*{ENDC} Synced {0} {2}: "
"{1}".format(
" {LIGHT_GREEN}*{ENDC} Synced {} {2}: "
"{}".format(
name, ", ".join(output["ret"]), modules_kind, **self.colors
)
)
@ -1472,8 +1464,8 @@ class TestDaemon(object):
syncing.remove(name)
except KeyError:
print(
" {LIGHT_RED}*{ENDC} {0} already synced??? "
"{1}".format(name, output, **self.colors)
" {LIGHT_RED}*{ENDC} {} already synced??? "
"{}".format(name, output, **self.colors)
)
return True

View file

@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
"""
Validate the virt module
"""
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
from numbers import Number
from xml.etree import ElementTree
@ -212,7 +209,7 @@ class VirtTest(ModuleCase):
self.assertIn(info["cpumodel"], self.cpu_models)
class VirtMinion(object):
class VirtMinion:
def __init__(self, module_case, target_name, sshd_port, tcp_port, tls_port):
self.target_name = target_name
self.uri = "localhost:{}".format(sshd_port)
@ -222,26 +219,21 @@ class VirtMinion(object):
self.module_case = module_case
def run(self, func, args=None):
return self.module_case.run_function(func, args or [], minion_tgt=self.target_name)
return self.module_case.run_function(
func, args or [], minion_tgt=self.target_name
)
@skip_if_binaries_missing("docker")
@slowTest
class VirtMigrateTest(ModuleCase):
def setUp(self):
super(VirtMigrateTest, self).setUp()
super().setUp()
self.minion_0 = VirtMinion(
self,
"virt_minion_0",
sshd_port=2201,
tcp_port=2203,
tls_port=2204
self, "virt_minion_0", sshd_port=2201, tcp_port=2203, tls_port=2204
)
self.minion_1 = VirtMinion(
self,
"virt_minion_1",
sshd_port=2202,
tcp_port=2205,
tls_port=2206
self, "virt_minion_1", sshd_port=2202, tcp_port=2205, tls_port=2206
)
self.domain = "core-vm"
self.skipSetUpTearDown = ["test_define_xml_path"]
@ -250,10 +242,7 @@ class VirtMigrateTest(ModuleCase):
self.minion_0.run("virt.define_xml_path", ["/core-vm.xml"])
self.minion_0.run("virt.start", [self.domain])
self.wait_for_all_jobs(
minions=(
self.minion_0.target_name,
self.minion_1.target_name,
)
minions=(self.minion_0.target_name, self.minion_1.target_name)
)
def tearDown(self):
@ -263,12 +252,9 @@ class VirtMigrateTest(ModuleCase):
self.minion_0.run("virt.undefine", [self.domain])
self.minion_1.run("virt.undefine", [self.domain])
self.wait_for_all_jobs(
minions=(
self.minion_0.target_name,
self.minion_1.target_name,
)
minions=(self.minion_0.target_name, self.minion_1.target_name)
)
super(VirtMigrateTest, self).tearDown()
super().tearDown()
def test_define_xml_path(self):
"""

View file

@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-
"""
Set up the Salt multimaster test suite
"""
# Import Python libs
from __future__ import absolute_import, print_function
import copy
import logging
import os
@ -74,7 +70,7 @@ class MultimasterTestDaemon(TestDaemon):
self._enter_mockbin()
self.master_targets = [self.mm_master_opts, self.mm_sub_master_opts]
self.minion_targets = set(["mm-minion", "mm-sub-minion"])
self.minion_targets = {"mm-minion", "mm-sub-minion"}
if self.parser.options.transport == "zeromq":
self.start_zeromq_daemons()
@ -307,7 +303,7 @@ class MultimasterTestDaemon(TestDaemon):
os.makedirs(RUNTIME_VARS.TMP_MM_CONF_DIR)
os.makedirs(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR)
print(
" * Transplanting multimaster configuration files to '{0}'".format(
" * Transplanting multimaster configuration files to '{}'".format(
RUNTIME_VARS.TMP_CONF_DIR
)
)
@ -489,11 +485,11 @@ class MultimasterTestDaemon(TestDaemon):
opts_dict["ext_pillar"] = []
if salt.utils.platform.is_windows():
opts_dict["ext_pillar"].append(
{"cmd_yaml": "type {0}".format(os.path.join(FILES, "ext.yaml"))}
{"cmd_yaml": "type {}".format(os.path.join(FILES, "ext.yaml"))}
)
else:
opts_dict["ext_pillar"].append(
{"cmd_yaml": "cat {0}".format(os.path.join(FILES, "ext.yaml"))}
{"cmd_yaml": "cat {}".format(os.path.join(FILES, "ext.yaml"))}
)
# all read, only owner write
@ -527,7 +523,7 @@ class MultimasterTestDaemon(TestDaemon):
# Point the config values to the correct temporary paths
for name in ("hosts", "aliases"):
optname = "{0}.file".format(name)
optname = "{}.file".format(name)
optname_path = os.path.join(TMP, name)
master_opts[optname] = optname_path
sub_master_opts[optname] = optname_path

View file

@ -1,13 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Discover all instances of unittest.TestCase in this directory.
"""
# pylint: disable=file-perms
# Import python libs
from __future__ import absolute_import, print_function
import collections
import os
import sys
@ -44,9 +41,6 @@ try:
except ImportError:
pass
# Import salt libs
from salt.ext import six # isort:skip
try:
from tests.support.paths import TMP, SYS_TMP_DIR, INTEGRATION_TEST_DIR
from tests.support.paths import CODE_DIR as SALT_ROOT
@ -62,7 +56,7 @@ except ImportError as exc:
import pprint
pprint.pprint(sys.path)
six.reraise(*sys.exc_info())
raise
from tests.integration import TestDaemon, TestDaemonStartFailed # isort:skip
from tests.multimaster import MultimasterTestDaemon # isort:skip
@ -87,7 +81,7 @@ try:
if SALT_ROOT:
os.chdir(SALT_ROOT)
except OSError as err:
print("Failed to change directory to salt's source: {0}".format(err))
print("Failed to change directory to salt's source: {}".format(err))
# Soft and hard limits on max open filehandles
MAX_OPEN_FILES = {
@ -157,15 +151,15 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
"""
suites = set(TEST_SUITES.keys())
if not include_unit:
suites -= set(["unit"])
suites -= {"unit"}
if not include_cloud_provider:
suites -= set(["cloud_provider"])
suites -= {"cloud_provider"}
if not include_proxy:
suites -= set(["proxy"])
suites -= {"proxy"}
if not include_kitchen:
suites -= set(["kitchen"])
suites -= {"kitchen"}
if not include_multimaster:
suites -= set(["multimaster"])
suites -= {"multimaster"}
return suites
@ -574,7 +568,7 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
)
# Print out which version of python this test suite is running on
print(" * Python Version: {0}".format(" ".join(sys.version.split())))
print(" * Python Version: {}".format(" ".join(sys.version.split())))
# Transplant configuration
TestDaemon.transplant_configs(transport=self.options.transport)
@ -617,59 +611,59 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
syndic_master_conf = TestDaemon.config("syndic_master")
print_header(" * Syndic master configuration values (MoM)", top=False)
print("interface: {0}".format(syndic_master_conf["interface"]))
print("publish port: {0}".format(syndic_master_conf["publish_port"]))
print("return port: {0}".format(syndic_master_conf["ret_port"]))
print("interface: {}".format(syndic_master_conf["interface"]))
print("publish port: {}".format(syndic_master_conf["publish_port"]))
print("return port: {}".format(syndic_master_conf["ret_port"]))
print("\n")
print_header(" * Syndic configuration values", top=True)
print("interface: {0}".format(syndic_conf["interface"]))
print("syndic master: {0}".format(syndic_conf["syndic_master"]))
print("interface: {}".format(syndic_conf["interface"]))
print("syndic master: {}".format(syndic_conf["syndic_master"]))
print(
"syndic master port: {0}".format(syndic_conf["syndic_master_port"])
"syndic master port: {}".format(syndic_conf["syndic_master_port"])
)
print("\n")
print_header(" * Master configuration values", top=True)
print("interface: {0}".format(master_conf["interface"]))
print("publish port: {0}".format(master_conf["publish_port"]))
print("return port: {0}".format(master_conf["ret_port"]))
print("interface: {}".format(master_conf["interface"]))
print("publish port: {}".format(master_conf["publish_port"]))
print("return port: {}".format(master_conf["ret_port"]))
print("\n")
print_header(" * Minion configuration values", top=True)
print("interface: {0}".format(minion_conf["interface"]))
print("master: {0}".format(minion_conf["master"]))
print("master port: {0}".format(minion_conf["master_port"]))
print("interface: {}".format(minion_conf["interface"]))
print("master: {}".format(minion_conf["master"]))
print("master port: {}".format(minion_conf["master_port"]))
if minion_conf["ipc_mode"] == "tcp":
print("tcp pub port: {0}".format(minion_conf["tcp_pub_port"]))
print("tcp pull port: {0}".format(minion_conf["tcp_pull_port"]))
print("tcp pub port: {}".format(minion_conf["tcp_pub_port"]))
print("tcp pull port: {}".format(minion_conf["tcp_pull_port"]))
print("\n")
print_header(" * Sub Minion configuration values", top=True)
print("interface: {0}".format(sub_minion_conf["interface"]))
print("master: {0}".format(sub_minion_conf["master"]))
print("master port: {0}".format(sub_minion_conf["master_port"]))
print("interface: {}".format(sub_minion_conf["interface"]))
print("master: {}".format(sub_minion_conf["master"]))
print("master port: {}".format(sub_minion_conf["master_port"]))
if sub_minion_conf["ipc_mode"] == "tcp":
print("tcp pub port: {0}".format(sub_minion_conf["tcp_pub_port"]))
print("tcp pull port: {0}".format(sub_minion_conf["tcp_pull_port"]))
print("tcp pub port: {}".format(sub_minion_conf["tcp_pub_port"]))
print("tcp pull port: {}".format(sub_minion_conf["tcp_pull_port"]))
print("\n")
print_header(" * Proxy Minion configuration values", top=True)
print("interface: {0}".format(proxy_conf["interface"]))
print("master: {0}".format(proxy_conf["master"]))
print("master port: {0}".format(proxy_conf["master_port"]))
print("interface: {}".format(proxy_conf["interface"]))
print("master: {}".format(proxy_conf["master"]))
print("master port: {}".format(proxy_conf["master_port"]))
if minion_conf["ipc_mode"] == "tcp":
print("tcp pub port: {0}".format(proxy_conf["tcp_pub_port"]))
print("tcp pull port: {0}".format(proxy_conf["tcp_pull_port"]))
print("tcp pub port: {}".format(proxy_conf["tcp_pub_port"]))
print("tcp pull port: {}".format(proxy_conf["tcp_pull_port"]))
print("\n")
print_header(
" Your client configuration is at {0}".format(
" Your client configuration is at {}".format(
TestDaemon.config_location()
)
)
print(
"To access the minion: salt -c {0} minion test.ping".format(
"To access the minion: salt -c {} minion test.ping".format(
TestDaemon.config_location()
)
)
@ -700,41 +694,41 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
sub_minion_conf = MultimasterTestDaemon.config("mm_sub_minion")
print_header(" * Master configuration values", top=True)
print("interface: {0}".format(master_conf["interface"]))
print("publish port: {0}".format(master_conf["publish_port"]))
print("return port: {0}".format(master_conf["ret_port"]))
print("interface: {}".format(master_conf["interface"]))
print("publish port: {}".format(master_conf["publish_port"]))
print("return port: {}".format(master_conf["ret_port"]))
print("\n")
print_header(" * Second master configuration values", top=True)
print("interface: {0}".format(sub_master_conf["interface"]))
print("publish port: {0}".format(sub_master_conf["publish_port"]))
print("return port: {0}".format(sub_master_conf["ret_port"]))
print("interface: {}".format(sub_master_conf["interface"]))
print("publish port: {}".format(sub_master_conf["publish_port"]))
print("return port: {}".format(sub_master_conf["ret_port"]))
print("\n")
print_header(" * Minion configuration values", top=True)
print("interface: {0}".format(minion_conf["interface"]))
print("masters: {0}".format(", ".join(minion_conf["master"])))
print("interface: {}".format(minion_conf["interface"]))
print("masters: {}".format(", ".join(minion_conf["master"])))
if minion_conf["ipc_mode"] == "tcp":
print("tcp pub port: {0}".format(minion_conf["tcp_pub_port"]))
print("tcp pull port: {0}".format(minion_conf["tcp_pull_port"]))
print("tcp pub port: {}".format(minion_conf["tcp_pub_port"]))
print("tcp pull port: {}".format(minion_conf["tcp_pull_port"]))
print("\n")
print_header(" * Sub Minion configuration values", top=True)
print("interface: {0}".format(sub_minion_conf["interface"]))
print("masters: {0}".format(", ".join(sub_minion_conf["master"])))
print("interface: {}".format(sub_minion_conf["interface"]))
print("masters: {}".format(", ".join(sub_minion_conf["master"])))
if sub_minion_conf["ipc_mode"] == "tcp":
print("tcp pub port: {0}".format(sub_minion_conf["tcp_pub_port"]))
print("tcp pull port: {0}".format(sub_minion_conf["tcp_pull_port"]))
print("tcp pub port: {}".format(sub_minion_conf["tcp_pub_port"]))
print("tcp pull port: {}".format(sub_minion_conf["tcp_pull_port"]))
print("\n")
print_header(
" Your client configurations are at {0}".format(
" Your client configurations are at {}".format(
", ".join(MultimasterTestDaemon.config_location())
)
)
print("To access minions from different masters use:")
for location in MultimasterTestDaemon.config_location():
print(" salt -c {0} minion test.ping".format(location))
print(" salt -c {} minion test.ping".format(location))
while True:
time.sleep(1)
@ -776,12 +770,12 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
# Increase limits
if set_limits:
print(
" * Max open files settings is too low (soft: {0}, hard: {1}) "
" * Max open files settings is too low (soft: {}, hard: {}) "
"for running the tests".format(prev_soft, prev_hard)
)
print(
" * Trying to raise the limits to soft: "
"{0}, hard: {1}".format(soft, hard)
"{}, hard: {}".format(soft, hard)
)
try:
if salt.utils.platform.is_windows():
@ -792,10 +786,10 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
except Exception as err: # pylint: disable=broad-except
print(
"ERROR: Failed to raise the max open files settings -> "
"{0}".format(err)
"{}".format(err)
)
print("Please issue the following command on your console:")
print(" ulimit -n {0}".format(soft))
print(" ulimit -n {}".format(soft))
self.exit()
finally:
print("~" * getattr(self.options, "output_columns", PNUM))

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
:codeauthor: Pedro Algarvio (pedro@algarvio.me)
@ -8,8 +7,6 @@
Some reusable class Mixins
"""
from __future__ import absolute_import, print_function
import atexit
import copy
import functools
@ -49,7 +46,7 @@ except ImportError:
log = logging.getLogger(__name__)
class CheckShellBinaryNameAndVersionMixin(object):
class CheckShellBinaryNameAndVersionMixin:
"""
Simple class mix-in to subclass in companion to :class:`ShellCase<tests.support.case.ShellCase>` which
adds a test case to verify proper version report from Salt's CLI tools.
@ -82,7 +79,7 @@ class CheckShellBinaryNameAndVersionMixin(object):
self.assertIn(self._call_binary_expected_version_, out)
class AdaptedConfigurationTestCaseMixin(object):
class AdaptedConfigurationTestCaseMixin:
__slots__ = ()
@ -390,7 +387,7 @@ class ShellCaseCommonTestsMixin(CheckShellBinaryNameAndVersionMixin):
if not out:
self.skipTest(
"Failed to get the output of 'git describe'. "
"Error: '{0}'".format(salt.utils.stringutils.to_str(err))
"Error: '{}'".format(salt.utils.stringutils.to_str(err))
)
parsed_version = SaltStackVersion.parse(out)
@ -398,7 +395,7 @@ class ShellCaseCommonTestsMixin(CheckShellBinaryNameAndVersionMixin):
if parsed_version.info < __version_info__:
self.skipTest(
"We're likely about to release a new version. This test "
"would fail. Parsed('{0}') < Expected('{1}')".format(
"would fail. Parsed('{}') < Expected('{}')".format(
parsed_version.info, __version_info__
)
)
@ -423,9 +420,7 @@ class _FixLoaderModuleMockMixinMroOrder(type):
def __new__(mcs, cls_name, cls_bases, cls_dict):
if cls_name == "LoaderModuleMockMixin":
return super(_FixLoaderModuleMockMixinMroOrder, mcs).__new__(
mcs, cls_name, cls_bases, cls_dict
)
return super().__new__(mcs, cls_name, cls_bases, cls_dict)
bases = list(cls_bases)
for idx, base in enumerate(bases):
if base.__name__ == "LoaderModuleMockMixin":
@ -433,9 +428,7 @@ class _FixLoaderModuleMockMixinMroOrder(type):
break
# Create the class instance
instance = super(_FixLoaderModuleMockMixinMroOrder, mcs).__new__(
mcs, cls_name, tuple(bases), cls_dict
)
instance = super().__new__(mcs, cls_name, tuple(bases), cls_dict)
# Apply our setUp function decorator
instance.setUp = LoaderModuleMockMixin.__setup_loader_modules_mocks__(
@ -444,9 +437,7 @@ class _FixLoaderModuleMockMixinMroOrder(type):
return instance
class LoaderModuleMockMixin(
six.with_metaclass(_FixLoaderModuleMockMixinMroOrder, object)
):
class LoaderModuleMockMixin(metaclass=_FixLoaderModuleMockMixinMroOrder):
"""
This class will setup salt loader dunders.
@ -482,15 +473,15 @@ class LoaderModuleMockMixin(
)
class XMLEqualityMixin(object):
class XMLEqualityMixin:
def assertEqualXML(self, e1, e2):
if six.PY3 and isinstance(e1, bytes):
e1 = e1.decode("utf-8")
if six.PY3 and isinstance(e2, bytes):
e2 = e2.decode("utf-8")
if isinstance(e1, six.string_types):
if isinstance(e1, str):
e1 = etree.XML(e1)
if isinstance(e2, six.string_types):
if isinstance(e2, str):
e2 = etree.XML(e2)
if e1.tag != e2.tag:
return False
@ -505,13 +496,13 @@ class XMLEqualityMixin(object):
return all(self.assertEqualXML(c1, c2) for c1, c2 in zip(e1, e2))
class SaltReturnAssertsMixin(object):
class SaltReturnAssertsMixin:
def assertReturnSaltType(self, ret):
try:
self.assertTrue(isinstance(ret, dict))
except AssertionError:
raise AssertionError(
"{0} is not dict. Salt returned: {1}".format(type(ret).__name__, ret)
"{} is not dict. Salt returned: {}".format(type(ret).__name__, ret)
)
def assertReturnNonEmptySaltType(self, ret):
@ -527,7 +518,7 @@ class SaltReturnAssertsMixin(object):
if isinstance(keys, tuple):
# If it's a tuple, turn it into a list
keys = list(keys)
elif isinstance(keys, six.string_types):
elif isinstance(keys, str):
# If it's a string, make it a one item list
keys = [keys]
elif not isinstance(keys, list):
@ -538,15 +529,15 @@ class SaltReturnAssertsMixin(object):
def __getWithinSaltReturn(self, ret, keys):
self.assertReturnNonEmptySaltType(ret)
ret_data = []
for part in six.itervalues(ret):
for part in ret.values():
keys = self.__return_valid_keys(keys)
okeys = keys[:]
try:
ret_item = part[okeys.pop(0)]
except (KeyError, TypeError):
raise AssertionError(
"Could not get ret{0} from salt's return: {1}".format(
"".join(["['{0}']".format(k) for k in keys]), part
"Could not get ret{} from salt's return: {}".format(
"".join(["['{}']".format(k) for k in keys]), part
)
)
while okeys:
@ -554,8 +545,8 @@ class SaltReturnAssertsMixin(object):
ret_item = ret_item[okeys.pop(0)]
except (KeyError, TypeError):
raise AssertionError(
"Could not get ret{0} from salt's return: {1}".format(
"".join(["['{0}']".format(k) for k in keys]), part
"Could not get ret{} from salt's return: {}".format(
"".join(["['{}']".format(k) for k in keys]), part
)
)
ret_data.append(ret_item)
@ -566,16 +557,16 @@ class SaltReturnAssertsMixin(object):
for saltret in self.__getWithinSaltReturn(ret, "result"):
self.assertTrue(saltret)
except AssertionError:
log.info("Salt Full Return:\n{0}".format(pprint.pformat(ret)))
log.info("Salt Full Return:\n{}".format(pprint.pformat(ret)))
try:
raise AssertionError(
"{result} is not True. Salt Comment:\n{comment}".format(
**(next(six.itervalues(ret)))
**(next(iter(ret.values())))
)
)
except (AttributeError, IndexError):
raise AssertionError(
"Failed to get result. Salt Returned:\n{0}".format(
"Failed to get result. Salt Returned:\n{}".format(
pprint.pformat(ret)
)
)
@ -585,16 +576,16 @@ class SaltReturnAssertsMixin(object):
for saltret in self.__getWithinSaltReturn(ret, "result"):
self.assertFalse(saltret)
except AssertionError:
log.info("Salt Full Return:\n{0}".format(pprint.pformat(ret)))
log.info("Salt Full Return:\n{}".format(pprint.pformat(ret)))
try:
raise AssertionError(
"{result} is not False. Salt Comment:\n{comment}".format(
**(next(six.itervalues(ret)))
**(next(iter(ret.values())))
)
)
except (AttributeError, IndexError):
raise AssertionError(
"Failed to get result. Salt Returned: {0}".format(ret)
"Failed to get result. Salt Returned: {}".format(ret)
)
def assertSaltNoneReturn(self, ret):
@ -602,16 +593,16 @@ class SaltReturnAssertsMixin(object):
for saltret in self.__getWithinSaltReturn(ret, "result"):
self.assertIsNone(saltret)
except AssertionError:
log.info("Salt Full Return:\n{0}".format(pprint.pformat(ret)))
log.info("Salt Full Return:\n{}".format(pprint.pformat(ret)))
try:
raise AssertionError(
"{result} is not None. Salt Comment:\n{comment}".format(
**(next(six.itervalues(ret)))
**(next(iter(ret.values())))
)
)
except (AttributeError, IndexError):
raise AssertionError(
"Failed to get result. Salt Returned: {0}".format(ret)
"Failed to get result. Salt Returned: {}".format(ret)
)
def assertInSaltComment(self, in_comment, ret):
@ -687,7 +678,7 @@ def _fetch_events(q, opts):
q.put(events)
class SaltMinionEventAssertsMixin(object):
class SaltMinionEventAssertsMixin:
"""
Asserts to verify that a given event was seen
"""
@ -737,5 +728,5 @@ class SaltMinionEventAssertsMixin(object):
break
self.fetch_proc.terminate()
raise AssertionError(
"Event {0} was not received by minion".format(desired_event)
"Event {} was not received by minion".format(desired_event)
)

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
:codeauthor: Pedro Algarvio (pedro@algarvio.me)
:copyright: Copyright 2017 by the SaltStack Team, see AUTHORS for more details.
@ -10,9 +9,6 @@
Tests related paths
"""
from __future__ import absolute_import
import logging
import os
import re
@ -63,7 +59,7 @@ TMP_ROOT_DIR = os.path.join(TMP, "rootdir")
FILES = os.path.join(INTEGRATION_TEST_DIR, "files")
BASE_FILES = os.path.join(INTEGRATION_TEST_DIR, "files", "file", "base")
PROD_FILES = os.path.join(INTEGRATION_TEST_DIR, "files", "file", "prod")
PYEXEC = "python{0}.{1}".format(*sys.version_info)
PYEXEC = "python{}.{}".format(*sys.version_info)
MOCKBIN = os.path.join(INTEGRATION_TEST_DIR, "mockbin")
SCRIPT_DIR = os.path.join(CODE_DIR, "scripts")
TMP_STATE_TREE = os.path.join(SYS_TMP_DIR, "salt-temp-state-tree")

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
:copyright: Copyright 2017 by the SaltStack Team, see AUTHORS for more details.
:license: Apache 2.0, see LICENSE for more details.
@ -10,8 +9,6 @@
Process handling utilities
"""
from __future__ import absolute_import
import logging
import os
import subprocess
@ -64,7 +61,7 @@ class Salt(ScriptPathMixin, PytestSalt):
"""
def __init__(self, *args, **kwargs):
super(Salt, self).__init__(None, *args, **kwargs)
super().__init__(None, *args, **kwargs)
class SaltCall(ScriptPathMixin, PytestSaltCall):
@ -73,7 +70,7 @@ class SaltCall(ScriptPathMixin, PytestSaltCall):
"""
def __init__(self, *args, **kwargs):
super(SaltCall, self).__init__(None, *args, **kwargs)
super().__init__(None, *args, **kwargs)
class SaltKey(ScriptPathMixin, PytestSaltKey):
@ -82,7 +79,7 @@ class SaltKey(ScriptPathMixin, PytestSaltKey):
"""
def __init__(self, *args, **kwargs):
super(SaltKey, self).__init__(None, *args, **kwargs)
super().__init__(None, *args, **kwargs)
class SaltRun(ScriptPathMixin, PytestSaltRun):
@ -91,7 +88,7 @@ class SaltRun(ScriptPathMixin, PytestSaltRun):
"""
def __init__(self, *args, **kwargs):
super(SaltRun, self).__init__(None, *args, **kwargs)
super().__init__(None, *args, **kwargs)
class SaltProxy(GetSaltRunFixtureMixin, PytestSaltProxy):
@ -118,7 +115,7 @@ class SaltSyndic(GetSaltRunFixtureMixin, PytestSaltSyndic):
"""
class SaltVirtContainer(object):
class SaltVirtContainer:
"""
Class which represents virt-minion container
"""
@ -247,7 +244,7 @@ def start_virt_daemon(
libvirt_tcp_port,
libvirt_tls_port,
host_uuid,
daemon_config_dir
daemon_config_dir,
):
"""
Start a salt minion daemon inside a container.
@ -336,8 +333,8 @@ def start_daemon(
process.terminate()
if attempts >= 3:
fail_method(
"The pytest {0}({1}) has failed to confirm running status "
"after {2} attempts".format(
"The pytest {}({}) has failed to confirm running status "
"after {} attempts".format(
daemon_name, daemon_id, attempts
)
)
@ -365,7 +362,7 @@ def start_daemon(
if process is not None:
terminate_process(process.pid, kill_children=True, slow_stop=slow_stop)
raise fail_method(
"The pytest {0}({1}) has failed to start after {2} attempts".format(
"The pytest {}({}) has failed to start after {} attempts".format(
daemon_name, daemon_id, attempts - 1
)
)

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
tests.support.pytest.fixtures
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -166,15 +165,11 @@ def salt_syndic_master_config(request, salt_factories):
ext_pillar = []
if salt.utils.platform.is_windows():
ext_pillar.append(
{
"cmd_yaml": "type {0}".format(
os.path.join(RUNTIME_VARS.FILES, "ext.yaml")
)
}
{"cmd_yaml": "type {}".format(os.path.join(RUNTIME_VARS.FILES, "ext.yaml"))}
)
else:
ext_pillar.append(
{"cmd_yaml": "cat {0}".format(os.path.join(RUNTIME_VARS.FILES, "ext.yaml"))}
{"cmd_yaml": "cat {}".format(os.path.join(RUNTIME_VARS.FILES, "ext.yaml"))}
)
# We need to copy the extension modules into the new master root_dir or
@ -261,15 +256,11 @@ def salt_master_config(request, salt_factories, salt_syndic_master_config):
ext_pillar = []
if salt.utils.platform.is_windows():
ext_pillar.append(
{
"cmd_yaml": "type {0}".format(
os.path.join(RUNTIME_VARS.FILES, "ext.yaml")
)
}
{"cmd_yaml": "type {}".format(os.path.join(RUNTIME_VARS.FILES, "ext.yaml"))}
)
else:
ext_pillar.append(
{"cmd_yaml": "cat {0}".format(os.path.join(RUNTIME_VARS.FILES, "ext.yaml"))}
{"cmd_yaml": "cat {}".format(os.path.join(RUNTIME_VARS.FILES, "ext.yaml"))}
)
ext_pillar.append(
{

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
:codeauthor: Pedro Algarvio (pedro@algarvio.me)
@ -44,9 +43,7 @@
.. _`pytest`: http://pytest.org
.. _`nose`: https://nose.readthedocs.org
"""
from __future__ import absolute_import, print_function
"""
import logging
import os
import shutil
@ -54,7 +51,6 @@ import shutil
import salt.utils.path
import salt.utils.platform
import tests.support.paths as paths
from salt.ext import six
try:
import pwd
@ -75,7 +71,7 @@ def this_user():
class RootsDict(dict):
def merge(self, data):
for key, values in six.iteritems(data):
for key, values in data.items():
if key not in self:
self[key] = values
continue
@ -115,7 +111,7 @@ def recursive_copytree(source, destination, overwrite=False):
shutil.copy2(src_path, dst_path)
class RuntimeVars(object):
class RuntimeVars:
__self_attributes__ = ("_vars", "_locked", "lock")
@ -132,8 +128,7 @@ class RuntimeVars(object):
self._locked = True
def __iter__(self):
for name, value in six.iteritems(self._vars):
yield name, value
yield from self._vars.items()
def __getattribute__(self, name):
if name in object.__getattribute__(self, "_vars"):
@ -143,7 +138,7 @@ class RuntimeVars(object):
def __setattr__(self, name, value):
if getattr(self, "_locked", False) is True:
raise RuntimeError(
"After {0} is locked, no additional data can be added to it".format(
"After {} is locked, no additional data can be added to it".format(
self.__class__.__name__
)
)