mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix up issues found in review
This commit is contained in:
parent
02bb9f5e8a
commit
cd8387128a
35 changed files with 98 additions and 120 deletions
|
@ -106,8 +106,8 @@ def _connect(profile):
|
|||
for sql in stmts:
|
||||
cur.execute(sql)
|
||||
elif profile.get("create_table", True):
|
||||
cur.execute(("CREATE TABLE {} (key text, " "value blob)").format(table))
|
||||
cur.execute(("CREATE UNIQUE INDEX {} ON {} " "(key)").format(idx, table))
|
||||
cur.execute(("CREATE TABLE {} (key text, value blob)").format(table))
|
||||
cur.execute(("CREATE UNIQUE INDEX {} ON {} (key)").format(idx, table))
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
|
||||
|
@ -123,8 +123,7 @@ def set_(key, value, profile=None):
|
|||
conn, cur, table = _connect(profile)
|
||||
value = memoryview(salt.utils.msgpack.packb(value))
|
||||
q = profile.get(
|
||||
"set_query",
|
||||
("INSERT OR REPLACE INTO {} VALUES " "(:key, :value)").format(table),
|
||||
"set_query", ("INSERT OR REPLACE INTO {} VALUES (:key, :value)").format(table),
|
||||
)
|
||||
conn.execute(q, {"key": key, "value": value})
|
||||
conn.commit()
|
||||
|
@ -138,9 +137,7 @@ def get(key, profile=None):
|
|||
if not profile:
|
||||
return None
|
||||
_, cur, table = _connect(profile)
|
||||
q = profile.get(
|
||||
"get_query", ("SELECT value FROM {} WHERE " "key=:key".format(table))
|
||||
)
|
||||
q = profile.get("get_query", ("SELECT value FROM {} WHERE key=:key".format(table)))
|
||||
res = cur.execute(q, {"key": key})
|
||||
res = res.fetchone()
|
||||
if not res:
|
||||
|
|
|
@ -28,7 +28,7 @@ def deserialize(stream_or_string, **options):
|
|||
cp = configparser.ConfigParser(**options)
|
||||
|
||||
try:
|
||||
if not isinstance(stream_or_string, (bytes, (str,))):
|
||||
if not isinstance(stream_or_string, (bytes, str)):
|
||||
cp.read_file(stream_or_string)
|
||||
else:
|
||||
cp.read_file(io.StringIO(stream_or_string))
|
||||
|
|
|
@ -231,7 +231,7 @@ class Loader(BaseLoader): # pylint: disable=W0232
|
|||
hash(key)
|
||||
except TypeError:
|
||||
err = (
|
||||
"While constructing a mapping {} found unacceptable " "key {}"
|
||||
"While constructing a mapping {} found unacceptable key {}"
|
||||
).format(node.start_mark, key_node.start_mark)
|
||||
raise ConstructorError(err)
|
||||
value = self.construct_object(value_node, deep=False)
|
||||
|
|
|
@ -100,7 +100,7 @@ def install(name, link, path, priority):
|
|||
}
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = ("Alternative for {} not installed: {}").format(name, out)
|
||||
ret["comment"] = "Alternative for {} not installed: {}".format(name, out)
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -143,7 +143,7 @@ def remove(name, path):
|
|||
current = __salt__["alternatives.show_current"](name)
|
||||
if current:
|
||||
ret["result"] = True
|
||||
ret["comment"] = ("Alternative for {} is set to it's default path {}").format(
|
||||
ret["comment"] = "Alternative for {} is set to it's default path {}".format(
|
||||
name, current
|
||||
)
|
||||
return ret
|
||||
|
|
|
@ -80,7 +80,7 @@ def tuned(name, **kwargs):
|
|||
|
||||
if not __salt__["file.is_blkdev"]:
|
||||
ret["comment"] = (
|
||||
"Changes to {} cannot be applied. " "Not a block device. "
|
||||
"Changes to {} cannot be applied. Not a block device. "
|
||||
).format(name)
|
||||
elif __opts__["test"]:
|
||||
ret["comment"] = "Changes to {} will be applied ".format(name)
|
||||
|
@ -174,7 +174,7 @@ def formatted(name, fs_type="ext4", force=False, **kwargs):
|
|||
current_fs = _checkblk(name)
|
||||
|
||||
if current_fs == fs_type:
|
||||
ret["comment"] = ("{} has been formatted " "with {}").format(name, fs_type)
|
||||
ret["comment"] = "{} has been formatted with {}".format(name, fs_type)
|
||||
ret["changes"] = {"new": fs_type, "old": current_fs}
|
||||
ret["result"] = True
|
||||
return ret
|
||||
|
|
|
@ -98,7 +98,7 @@ def _role_present(
|
|||
)
|
||||
if r.get("error"):
|
||||
ret["result"] = False
|
||||
failure_comment = "Failed to get existing identity pool roles: " "{}".format(
|
||||
failure_comment = "Failed to get existing identity pool roles: {}".format(
|
||||
r["error"].get("message", r["error"])
|
||||
)
|
||||
ret["comment"] = "{}\n{}".format(ret["comment"], failure_comment)
|
||||
|
@ -230,7 +230,7 @@ def pool_present(
|
|||
|
||||
if __opts__["test"]:
|
||||
if identity_pools is None:
|
||||
ret["comment"] = "A new identity pool named {} will be " "created.".format(
|
||||
ret["comment"] = "A new identity pool named {} will be created.".format(
|
||||
IdentityPoolName
|
||||
)
|
||||
else:
|
||||
|
@ -266,7 +266,7 @@ def pool_present(
|
|||
)
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to add a new identity pool: " "{}".format(
|
||||
ret["comment"] = "Failed to add a new identity pool: {}".format(
|
||||
r["error"].get("message", r["error"])
|
||||
)
|
||||
return ret
|
||||
|
@ -400,7 +400,7 @@ def pool_absent(
|
|||
)
|
||||
if r.get("error"):
|
||||
ret["result"] = False
|
||||
failure_comment = "Failed to delete identity pool {}: " "{}".format(
|
||||
failure_comment = "Failed to delete identity pool {}: {}".format(
|
||||
IdentityPoolId, r["error"].get("message", r["error"])
|
||||
)
|
||||
ret["comment"] = "{}\n{}".format(ret["comment"], failure_comment)
|
||||
|
|
|
@ -397,7 +397,7 @@ def present(
|
|||
|
||||
ret = {"name": name, "result": True, "comment": "", "changes": {}}
|
||||
|
||||
if not isinstance(security_groups, ((str,), list, type(None))):
|
||||
if not isinstance(security_groups, (str, list, type(None))):
|
||||
msg = (
|
||||
"The 'security_group' parameter must be either a list or a "
|
||||
"comma-separated string."
|
||||
|
|
|
@ -483,7 +483,7 @@ def _function_config_present(
|
|||
)
|
||||
if not _r.get("updated"):
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to update function: " "{}.".format(
|
||||
ret["comment"] = "Failed to update function: {}.".format(
|
||||
_r["error"]["message"]
|
||||
)
|
||||
ret["changes"] = {}
|
||||
|
@ -543,7 +543,7 @@ def _function_code_present(
|
|||
)
|
||||
if not func.get("updated"):
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to update function: " "{}.".format(
|
||||
ret["comment"] = "Failed to update function: {}.".format(
|
||||
func["error"]["message"]
|
||||
)
|
||||
ret["changes"] = {}
|
||||
|
@ -622,7 +622,7 @@ def _function_permissions_present(
|
|||
oldperms[sid] = {}
|
||||
if not _r.get("updated"):
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to update function: " "{}.".format(
|
||||
ret["comment"] = "Failed to update function: {}.".format(
|
||||
_r["error"]["message"]
|
||||
)
|
||||
ret["changes"] = {}
|
||||
|
@ -678,7 +678,7 @@ def function_absent(
|
|||
)
|
||||
if not r["deleted"]:
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to delete function: " "{}.".format(
|
||||
ret["comment"] = "Failed to delete function: {}.".format(
|
||||
r["error"]["message"]
|
||||
)
|
||||
return ret
|
||||
|
@ -744,7 +744,7 @@ def alias_present(
|
|||
|
||||
if "error" in r:
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to create alias: " "{}.".format(r["error"]["message"])
|
||||
ret["comment"] = "Failed to create alias: {}.".format(r["error"]["message"])
|
||||
return ret
|
||||
|
||||
if not r.get("exists"):
|
||||
|
@ -764,7 +764,7 @@ def alias_present(
|
|||
)
|
||||
if not r.get("created"):
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to create alias: " "{}.".format(
|
||||
ret["comment"] = "Failed to create alias: {}.".format(
|
||||
r["error"]["message"]
|
||||
)
|
||||
return ret
|
||||
|
@ -855,7 +855,7 @@ def alias_absent(
|
|||
)
|
||||
if "error" in r:
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to delete alias: " "{}.".format(r["error"]["message"])
|
||||
ret["comment"] = "Failed to delete alias: {}.".format(r["error"]["message"])
|
||||
return ret
|
||||
|
||||
if r and not r["exists"]:
|
||||
|
@ -871,7 +871,7 @@ def alias_absent(
|
|||
)
|
||||
if not r["deleted"]:
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to delete alias: " "{}.".format(r["error"]["message"])
|
||||
ret["comment"] = "Failed to delete alias: {}.".format(r["error"]["message"])
|
||||
return ret
|
||||
ret["changes"]["old"] = {"alias": Name}
|
||||
ret["changes"]["new"] = {"alias": None}
|
||||
|
|
|
@ -115,11 +115,11 @@ def present(name, cloud_provider, onlyif=None, unless=None, opts=None, **kwargs)
|
|||
ret["changes"] = info
|
||||
ret["result"] = True
|
||||
ret["comment"] = (
|
||||
"Created instance {} using provider {} " "and the following options: {}"
|
||||
"Created instance {} using provider {} and the following options: {}"
|
||||
).format(name, cloud_provider, pprint.pformat(kwargs))
|
||||
elif info and "Error" in info:
|
||||
ret["result"] = False
|
||||
ret["comment"] = ("Failed to create instance {}" "using profile {}: {}").format(
|
||||
ret["comment"] = "Failed to create instance {} using profile {}: {}".format(
|
||||
name, profile, info["Error"],
|
||||
)
|
||||
else:
|
||||
|
@ -272,11 +272,11 @@ def profile(name, profile, onlyif=None, unless=None, opts=None, **kwargs):
|
|||
elif error:
|
||||
ret["result"] = False
|
||||
ret["comment"] = (
|
||||
"Failed to create instance {}" " using profile {}: {}"
|
||||
"Failed to create instance {} using profile {}: {}"
|
||||
).format(name, profile, "{}\n{}\n".format(main_error, name_error).strip(),)
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = ("Failed to create instance {}" "using profile {}").format(
|
||||
ret["comment"] = "Failed to create instance {} using profile {}".format(
|
||||
name, profile,
|
||||
)
|
||||
return ret
|
||||
|
|
|
@ -577,7 +577,7 @@ def file(
|
|||
source = name
|
||||
|
||||
if not replace and os.stat(cron_path).st_size > 0:
|
||||
ret["comment"] = "User {} already has a crontab. No changes " "made".format(
|
||||
ret["comment"] = "User {} already has a crontab. No changes made".format(
|
||||
user
|
||||
)
|
||||
os.unlink(cron_path)
|
||||
|
@ -665,13 +665,13 @@ def file(
|
|||
ret["result"] = True
|
||||
ret["changes"] = ret["changes"]
|
||||
else:
|
||||
ret["comment"] = "Unable to update user {} crontab {}." " Error: {}".format(
|
||||
ret["comment"] = "Unable to update user {} crontab {}. Error: {}".format(
|
||||
user, cron_path, cron_ret["stderr"]
|
||||
)
|
||||
ret["result"] = False
|
||||
ret["changes"] = {}
|
||||
elif ret["result"]:
|
||||
ret["comment"] = "Crontab for user {} is in the correct " "state".format(user)
|
||||
ret["comment"] = "Crontab for user {} is in the correct state".format(user)
|
||||
ret["changes"] = {}
|
||||
|
||||
os.unlink(cron_path)
|
||||
|
|
|
@ -208,7 +208,7 @@ def set(name, data, **kwargs):
|
|||
if args["type"] == "password":
|
||||
ret["changes"][key] = "(password hidden)"
|
||||
else:
|
||||
ret["changes"][key] = ("{}").format(args["value"])
|
||||
ret["changes"][key] = "{}".format(args["value"])
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Some settings failed to be applied."
|
||||
|
|
|
@ -2531,5 +2531,5 @@ def mod_watch(name, sfun=None, **kwargs):
|
|||
"name": name,
|
||||
"changes": {},
|
||||
"result": False,
|
||||
"comment": ("watch requisite is not" " implemented for {}".format(sfun)),
|
||||
"comment": "watch requisite is not implemented for {}".format(sfun),
|
||||
}
|
||||
|
|
|
@ -543,7 +543,7 @@ def portgroups_configured(name, dvs, portgroups):
|
|||
"""
|
||||
datacenter = _get_datacenter_name()
|
||||
log.info(
|
||||
"Running state {} on DVS '{}', datacenter " "'{}'".format(name, dvs, datacenter)
|
||||
"Running state %s on DVS '%s', datacenter '%s'", name, dvs, datacenter
|
||||
)
|
||||
changes_required = False
|
||||
ret = {"name": name, "changes": {}, "result": None, "comment": None}
|
||||
|
@ -707,7 +707,7 @@ def uplink_portgroup_configured(name, dvs, uplink_portgroup):
|
|||
|
||||
"""
|
||||
datacenter = _get_datacenter_name()
|
||||
log.info("Running {} on DVS '{}', datacenter '{}'" "".format(name, dvs, datacenter))
|
||||
log.info("Running %s on DVS '%s', datacenter '%s'", name, dvs, datacenter)
|
||||
changes_required = False
|
||||
ret = {"name": name, "changes": {}, "result": None, "comment": None}
|
||||
comments = []
|
||||
|
@ -720,7 +720,7 @@ def uplink_portgroup_configured(name, dvs, uplink_portgroup):
|
|||
current_uplink_portgroup = __salt__["vsphere.list_uplink_dvportgroup"](
|
||||
dvs=dvs, service_instance=si
|
||||
)
|
||||
log.trace("current_uplink_portgroup = " "{}".format(current_uplink_portgroup))
|
||||
log.trace("current_uplink_portgroup = %s", current_uplink_portgroup)
|
||||
diff_dict = _get_diff_dict(current_uplink_portgroup, uplink_portgroup)
|
||||
if diff_dict:
|
||||
changes_required = True
|
||||
|
@ -761,7 +761,7 @@ def uplink_portgroup_configured(name, dvs, uplink_portgroup):
|
|||
)
|
||||
__salt__["vsphere.disconnect"](si)
|
||||
except salt.exceptions.CommandExecutionError as exc:
|
||||
log.error("Error: {}\n{}".format(exc, traceback.format_exc()))
|
||||
log.error("Error: %s", exc, exc_info=True)
|
||||
if si:
|
||||
__salt__["vsphere.disconnect"](si)
|
||||
if not __opts__["test"]:
|
||||
|
|
|
@ -84,7 +84,7 @@ def datacenter_configured(name):
|
|||
dc_name = __salt__["esxdatacenter.get_details"]()["datacenter"]
|
||||
else:
|
||||
dc_name = name
|
||||
log.info("Running datacenter_configured for datacenter '{}'" "".format(dc_name))
|
||||
log.info("Running datacenter_configured for datacenter '{}'".format(dc_name))
|
||||
ret = {"name": name, "changes": {}, "result": None, "comment": "Default"}
|
||||
comments = []
|
||||
si = None
|
||||
|
@ -95,7 +95,7 @@ def datacenter_configured(name):
|
|||
)
|
||||
if not dcs:
|
||||
if __opts__["test"]:
|
||||
comments.append("State will create " "datacenter '{}'.".format(dc_name))
|
||||
comments.append("State will create datacenter '{}'.".format(dc_name))
|
||||
else:
|
||||
log.debug("Creating datacenter '{}'. ".format(dc_name))
|
||||
__salt__["vsphere.create_datacenter"](dc_name, si)
|
||||
|
@ -104,7 +104,7 @@ def datacenter_configured(name):
|
|||
ret["changes"].update({"new": {"name": dc_name}})
|
||||
else:
|
||||
comments.append(
|
||||
"Datacenter '{}' already exists. Nothing to be " "done.".format(dc_name)
|
||||
"Datacenter '{}' already exists. Nothing to be done.".format(dc_name)
|
||||
)
|
||||
log.info(comments[-1])
|
||||
__salt__["vsphere.disconnect"](si)
|
||||
|
|
|
@ -497,7 +497,7 @@ def vm_updated(
|
|||
"name": name,
|
||||
"result": True,
|
||||
"changes": changes,
|
||||
"comment": "Virtual machine " "{} was updated successfully".format(vm_name),
|
||||
"comment": "Virtual machine {} was updated successfully".format(vm_name),
|
||||
}
|
||||
|
||||
return result
|
||||
|
@ -579,7 +579,7 @@ def vm_created(
|
|||
"name": name,
|
||||
"result": True,
|
||||
"changes": changes,
|
||||
"comment": "Virtual machine " "{} created successfully".format(vm_name),
|
||||
"comment": "Virtual machine {} created successfully".format(vm_name),
|
||||
}
|
||||
|
||||
return result
|
||||
|
@ -628,7 +628,7 @@ def vm_registered(vm_name, datacenter, placement, vm_file, power_on=False):
|
|||
{
|
||||
"result": True,
|
||||
"changes": {"name": vm_name, "power_on": power_on},
|
||||
"comment": "Virtual machine " "{} registered successfully".format(vm_name),
|
||||
"comment": "Virtual machine {} registered successfully".format(vm_name),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ def present(
|
|||
ret["changes"]["new"] = "Dashboard {} created.".format(name)
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = ("Failed to create dashboard {}, " "response={}").format(
|
||||
ret["comment"] = "Failed to create dashboard {}, response={}".format(
|
||||
name, response
|
||||
)
|
||||
return ret
|
||||
|
@ -200,7 +200,7 @@ def present(
|
|||
)
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = ("Failed to update dashboard {}, " "response={}").format(
|
||||
ret["comment"] = "Failed to update dashboard {}, response={}".format(
|
||||
name, response
|
||||
)
|
||||
return ret
|
||||
|
|
|
@ -183,7 +183,7 @@ def present(
|
|||
if username in db_users:
|
||||
if role is False:
|
||||
if __opts__["test"]:
|
||||
ret["comment"] = "Org {} user {} will be " "deleted".format(
|
||||
ret["comment"] = "Org {} user {} will be deleted".format(
|
||||
name, username
|
||||
)
|
||||
return ret
|
||||
|
|
|
@ -135,7 +135,7 @@ def present(
|
|||
ret["changes"]["new"] = "Dashboard {} created.".format(name)
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = ("Failed to create dashboard {}, " "response={}").format(
|
||||
ret["comment"] = ("Failed to create dashboard {}, "response={}").format(
|
||||
name, response
|
||||
)
|
||||
return ret
|
||||
|
@ -159,8 +159,8 @@ def present(
|
|||
if __opts__["test"]:
|
||||
ret["result"] = None
|
||||
ret["comment"] = str(
|
||||
"Dashboard {0} is set to be updated, changes={1}"
|
||||
).format( # future lint: blacklisted-function
|
||||
"Dashboard {} is set to be updated, changes={}"
|
||||
).format(
|
||||
name,
|
||||
salt.utils.json.dumps(
|
||||
_dashboard_diff(_cleaned(new_dashboard), _cleaned(old_dashboard)),
|
||||
|
@ -181,7 +181,7 @@ def present(
|
|||
)
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = ("Failed to update dashboard {}, " "response={}").format(
|
||||
ret["comment"] = ("Failed to update dashboard {}, response={}").format(
|
||||
name, response
|
||||
)
|
||||
return ret
|
||||
|
|
|
@ -87,7 +87,7 @@ def present(name, passwd, admin=False, grants=None, **client_args):
|
|||
):
|
||||
ret[
|
||||
"comment"
|
||||
] = "Failed to set admin privilege to " "user {}".format(name)
|
||||
] = "Failed to set admin privilege to user {}".format(name)
|
||||
ret["result"] = False
|
||||
return ret
|
||||
ret["changes"]["Admin privileges"] = admin
|
||||
|
|
|
@ -282,15 +282,15 @@ def absent(name, entry=None, entries=None, family="ipv4", **kwargs):
|
|||
ret["result"] = True
|
||||
ret[
|
||||
"comment"
|
||||
] += "ipset entry {1} removed from set {0} for {2}\n".format(
|
||||
kwargs["set_name"], _entry, family
|
||||
] += "ipset entry {} removed from set {} for {}\n".format(
|
||||
_entry_, kwargs["set_name"], family
|
||||
)
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = (
|
||||
"Failed to delete ipset entry from set {0} for {2}. "
|
||||
"Attempted entry was {1}.\n"
|
||||
"{3}\n".format(kwargs["set_name"], _entry, family, command)
|
||||
"Failed to delete ipset entry from set {} for {}. "
|
||||
"Attempted entry was {}.\n"
|
||||
"{}\n".format(kwargs["set_name"], family, _entry, command)
|
||||
)
|
||||
return ret
|
||||
|
||||
|
@ -325,7 +325,7 @@ def flush(name, family="ipv4", **kwargs):
|
|||
return ret
|
||||
else:
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to flush ipset entries from set {} for {}" "".format(
|
||||
ret["comment"] = "Failed to flush ipset entries from set {} for {}".format(
|
||||
name, family
|
||||
)
|
||||
return ret
|
||||
|
|
|
@ -218,7 +218,7 @@ def present(name, acl_type, acl_name="", perms="", recurse=False, force=False):
|
|||
)
|
||||
ret.update(
|
||||
{
|
||||
"comment": "Updated permissions for " "{}".format(acl_name),
|
||||
"comment": "Updated permissions for {}".format(acl_name),
|
||||
"result": True,
|
||||
"changes": changes,
|
||||
}
|
||||
|
|
|
@ -155,11 +155,9 @@ class TextFormat:
|
|||
self.codes.extend((codes["extended"], "2"))
|
||||
self.codes.extend(*qualify_triple_int(kwargs["bg_rgb"]))
|
||||
|
||||
# pylint: disable=string-substitution-usage-error
|
||||
self.sequence = "{}{}{}".format(
|
||||
graph_prefix, ";".join(self.codes), graph_suffix
|
||||
)
|
||||
# pylint: enable=string-substitution-usage-error
|
||||
|
||||
def __call__(self, text, reset=True):
|
||||
"""
|
||||
|
@ -174,7 +172,7 @@ class TextFormat:
|
|||
'The answer is: {0}'.format(green_blink_text(42))
|
||||
"""
|
||||
end = TextFormat("reset") if reset else ""
|
||||
return "{}{}{}".format(self.sequence, text, end) # pylint: disable=E1321
|
||||
return "{}{}{}".format(self.sequence, text, end)
|
||||
|
||||
def __str__(self):
|
||||
return self.sequence
|
||||
|
|
|
@ -15,7 +15,6 @@ import tarfile
|
|||
import tempfile
|
||||
import zipfile
|
||||
|
||||
# pylint: enable=import-error,no-name-in-module
|
||||
import distro
|
||||
import jinja2
|
||||
import msgpack
|
||||
|
|
|
@ -38,7 +38,7 @@ def get_timestamp_at(time_in=None, time_at=None):
|
|||
return time.mktime(time_at.timetuple())
|
||||
elif time_at:
|
||||
log.debug("Predicted at specified as %s", time_at)
|
||||
if isinstance(time_at, ((int,), float)):
|
||||
if isinstance(time_at, (int, float)):
|
||||
# then it's a timestamp
|
||||
return time_at
|
||||
else:
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
"""
|
||||
|
||||
|
||||
import contextlib
|
||||
import datetime
|
||||
import inspect
|
||||
import logging
|
||||
|
@ -81,12 +80,6 @@ def _format_warning(message, category, filename, lineno, line=None):
|
|||
return "{}:{}: {}: {}\n".format(filename, lineno, category.__name__, message)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def _patched_format_warning():
|
||||
# Under Py3 we no longer have to patch warnings.formatwarning
|
||||
yield
|
||||
|
||||
|
||||
def warn_until(
|
||||
version,
|
||||
message,
|
||||
|
@ -151,12 +144,11 @@ def warn_until(
|
|||
)
|
||||
|
||||
if _dont_call_warnings is False:
|
||||
with _patched_format_warning():
|
||||
warnings.warn(
|
||||
message.format(version=version.formatted_version),
|
||||
category,
|
||||
stacklevel=stacklevel,
|
||||
)
|
||||
warnings.warn(
|
||||
message.format(version=version.formatted_version),
|
||||
category,
|
||||
stacklevel=stacklevel,
|
||||
)
|
||||
|
||||
|
||||
def warn_until_date(
|
||||
|
@ -221,12 +213,11 @@ def warn_until_date(
|
|||
)
|
||||
|
||||
if _dont_call_warnings is False:
|
||||
with _patched_format_warning():
|
||||
warnings.warn(
|
||||
message.format(date=date.isoformat(), today=today.isoformat()),
|
||||
category,
|
||||
stacklevel=stacklevel,
|
||||
)
|
||||
warnings.warn(
|
||||
message.format(date=date.isoformat(), today=today.isoformat()),
|
||||
category,
|
||||
stacklevel=stacklevel,
|
||||
)
|
||||
|
||||
|
||||
def kwargs_warn_until(
|
||||
|
|
|
@ -99,7 +99,7 @@ def vsan_supported(service_instance):
|
|||
except vim.fault.NoPermission as exc:
|
||||
log.exception(exc)
|
||||
raise VMwareApiError(
|
||||
"Not enough permissions. Required privilege: " "{}".format(exc.privilegeId)
|
||||
"Not enough permissions. Required privilege: {}".format(exc.privilegeId)
|
||||
)
|
||||
except vim.fault.VimFault as exc:
|
||||
log.exception(exc)
|
||||
|
@ -187,7 +187,7 @@ def get_host_vsan_system(service_instance, host_ref, hostname=None):
|
|||
)
|
||||
if not objs:
|
||||
raise VMwareObjectRetrievalError(
|
||||
"Host's '{}' VSAN system was " "not retrieved".format(hostname)
|
||||
"Host's '{}' VSAN system was not retrieved".format(hostname)
|
||||
)
|
||||
log.trace("[%s] Retrieved VSAN system", hostname)
|
||||
return objs[0]["object"]
|
||||
|
@ -238,7 +238,7 @@ def create_diskgroup(
|
|||
except vim.fault.NoPermission as exc:
|
||||
log.exception(exc)
|
||||
raise VMwareApiError(
|
||||
"Not enough permissions. Required privilege: " "{}".format(exc.privilegeId)
|
||||
"Not enough permissions. Required privilege: {}".format(exc.privilegeId)
|
||||
)
|
||||
except vim.fault.VimFault as exc:
|
||||
log.exception(exc)
|
||||
|
@ -305,7 +305,7 @@ def add_capacity_to_diskgroup(
|
|||
except vim.fault.NoPermission as exc:
|
||||
log.exception(exc)
|
||||
raise VMwareApiError(
|
||||
"Not enough permissions. Required privilege: " "{}".format(exc.privilegeId)
|
||||
"Not enough permissions. Required privilege: {}".format(exc.privilegeId)
|
||||
)
|
||||
except vim.fault.VimFault as exc:
|
||||
log.exception(exc)
|
||||
|
@ -389,7 +389,7 @@ def remove_capacity_from_diskgroup(
|
|||
except vim.fault.NoPermission as exc:
|
||||
log.exception(exc)
|
||||
raise VMwareApiError(
|
||||
"Not enough permissions. Required privilege: " "{}".format(exc.privilegeId)
|
||||
"Not enough permissions. Required privilege: {}".format(exc.privilegeId)
|
||||
)
|
||||
except vim.fault.VimFault as exc:
|
||||
log.exception(exc)
|
||||
|
|
|
@ -919,7 +919,7 @@ def delete_key_recursive(hive, key, use_32bit_registry=False):
|
|||
try:
|
||||
win32api.RegDeleteKey(key_handle, "")
|
||||
ret["Deleted"].append(r"{}\{}".format(hive, sub_key_path))
|
||||
except OSError as exc: # pylint: disable=undefined-variable
|
||||
except OSError as exc:
|
||||
log.error(exc, exc_info=True)
|
||||
ret["Failed"].append(r"{}\{} {}".format(hive, sub_key_path, exc))
|
||||
except win32api.error as exc:
|
||||
|
|
|
@ -100,9 +100,9 @@ def write(data, path, saltenv="base", index=0):
|
|||
index, saltenv
|
||||
)
|
||||
if os.path.isabs(path):
|
||||
return (
|
||||
"The path passed in {} is not relative to the environment " "{}"
|
||||
).format(path, saltenv)
|
||||
return ("The path passed in {} is not relative to the environment {}").format(
|
||||
path, saltenv
|
||||
)
|
||||
root = __opts__["file_roots"][saltenv][index]
|
||||
dest = os.path.join(root, path)
|
||||
if not salt.utils.verify.clean_path(root, dest, subdir=True):
|
||||
|
|
|
@ -45,8 +45,7 @@ except ImportError:
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
required_moto = "0.3.7"
|
||||
required_moto_py3 = "1.0.1"
|
||||
required_moto = "1.0.1"
|
||||
|
||||
|
||||
def _has_required_moto():
|
||||
|
@ -62,17 +61,13 @@ def _has_required_moto():
|
|||
)
|
||||
if moto_version < salt.utils.versions.LooseVersion(required_moto):
|
||||
return False
|
||||
elif moto_version < salt.utils.versions.LooseVersion(required_moto_py3):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@skipIf(HAS_MOTO is False, "The moto module must be installed.")
|
||||
@skipIf(
|
||||
_has_required_moto() is False,
|
||||
"The moto module must be >= to {} for "
|
||||
"PY2 or {} for PY3.".format(required_moto, required_moto_py3),
|
||||
"The moto module must be >= to {}".format(required_moto),
|
||||
)
|
||||
class BotoRoute53TestCase(TestCase, LoaderModuleMockMixin):
|
||||
"""
|
||||
|
|
|
@ -340,7 +340,7 @@ class SolrTestCase(TestCase, LoaderModuleMockMixin):
|
|||
"""
|
||||
self.assertEqual(
|
||||
solr.signal("signal"),
|
||||
("signal is an invalid signal. Try: one of: start, stop or restart"),
|
||||
"signal is an invalid signal. Try: one of: start, stop or restart",
|
||||
)
|
||||
|
||||
def test_reload_core(self):
|
||||
|
|
|
@ -372,7 +372,7 @@ class TLSAddTestCase(TestCase, LoaderModuleMockMixin):
|
|||
certk = "{}/{}/certs/{}.key".format(
|
||||
ca_path, ca_name, _TLS_TEST_DATA["create_ca"]["CN"]
|
||||
)
|
||||
ret = ('Created Private Key: "{}." ' 'Created CSR for "{}": "{}."').format(
|
||||
ret = 'Created Private Key: "{}." Created CSR for "{}": "{}."'.format(
|
||||
certk, _TLS_TEST_DATA["create_ca"]["CN"], certp
|
||||
)
|
||||
mock_opt = MagicMock(return_value=ca_path)
|
||||
|
@ -407,7 +407,7 @@ class TLSAddTestCase(TestCase, LoaderModuleMockMixin):
|
|||
certk = "{}/{}/certs/{}.key".format(
|
||||
ca_path, ca_name, _TLS_TEST_DATA["create_ca"]["CN"]
|
||||
)
|
||||
ret = ('Created Private Key: "{}." ' 'Created CSR for "{}": "{}."').format(
|
||||
ret = 'Created Private Key: "{}." Created CSR for "{}": "{}."').format(
|
||||
certk, _TLS_TEST_DATA["create_ca"]["CN"], certp
|
||||
)
|
||||
mock_opt = MagicMock(return_value=ca_path)
|
||||
|
@ -445,7 +445,7 @@ class TLSAddTestCase(TestCase, LoaderModuleMockMixin):
|
|||
certk = "{}/{}/certs/{}.key".format(
|
||||
ca_path, tls_dir, _TLS_TEST_DATA["create_ca"]["CN"]
|
||||
)
|
||||
ret = ('Created Private Key: "{}." ' 'Created Certificate: "{}."').format(
|
||||
ret = 'Created Private Key: "{}." Created Certificate: "{}."'.format(
|
||||
certk, certp
|
||||
)
|
||||
mock_opt = MagicMock(return_value=ca_path)
|
||||
|
@ -473,7 +473,7 @@ class TLSAddTestCase(TestCase, LoaderModuleMockMixin):
|
|||
certk = "{}/{}/certs/{}.key".format(
|
||||
ca_path, tls_dir, _TLS_TEST_DATA["create_ca"]["CN"]
|
||||
)
|
||||
ret = ('Created Private Key: "{}." ' 'Created Certificate: "{}."').format(
|
||||
ret = 'Created Private Key: "{}." Created Certificate: "{}."'.format(
|
||||
certk, certp
|
||||
)
|
||||
mock_opt = MagicMock(return_value=ca_path)
|
||||
|
@ -750,7 +750,7 @@ class TLSAddTestCase(TestCase, LoaderModuleMockMixin):
|
|||
certk = "{}/{}/certs/{}.key".format(
|
||||
ca_path, ca_name, _TLS_TEST_DATA["create_ca"]["CN"]
|
||||
)
|
||||
ret = ('Created Private Key: "{}." ' 'Created CSR for "{}": "{}."').format(
|
||||
ret = 'Created Private Key: "{}." Created CSR for "{}": "{}."'.format(
|
||||
certk, _TLS_TEST_DATA["create_ca"]["CN"], certp
|
||||
)
|
||||
with patch.dict(
|
||||
|
|
|
@ -22,7 +22,7 @@ class WinPathTestCase(TestCase, LoaderModuleMockMixin):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.pathsep = ";" # future lint: disable=blacklisted-function
|
||||
self.pathsep = ";"
|
||||
|
||||
def assert_call_matches(self, mock_obj, new_path):
|
||||
mock_obj.assert_called_once_with(
|
||||
|
|
|
@ -141,9 +141,7 @@ class WinSystemTestCase(TestCase, LoaderModuleMockMixin):
|
|||
modules_globals["wmi"] = wmi
|
||||
|
||||
if win_system.HAS_WIN32NET_MODS is False:
|
||||
win32api = types.ModuleType(
|
||||
"win32api" # future lint: disable=blacklisted-function
|
||||
)
|
||||
win32api = types.ModuleType("win32api")
|
||||
now = datetime.now()
|
||||
win32api.GetLocalTime = MagicMock(
|
||||
return_value=[
|
||||
|
|
|
@ -127,7 +127,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
|||
},
|
||||
):
|
||||
with patch.dict(linux_acl.__opts__, {"test": False}):
|
||||
comt = "Error updating permissions for {}: Custom err" "".format(
|
||||
comt = "Error updating permissions for {}: Custom err".format(
|
||||
acl_name
|
||||
)
|
||||
ret = {
|
||||
|
@ -142,7 +142,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
|||
# New - test=True
|
||||
with patch.dict(linux_acl.__salt__, {"acl.modfacl": mock_modfacl}):
|
||||
with patch.dict(linux_acl.__opts__, {"test": True}):
|
||||
comt = "New permissions will be applied " "for {}: {}".format(
|
||||
comt = "New permissions will be applied for {}: {}".format(
|
||||
acl_name, perms
|
||||
)
|
||||
ret = {
|
||||
|
@ -189,7 +189,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
|||
},
|
||||
):
|
||||
with patch.dict(linux_acl.__opts__, {"test": False}):
|
||||
comt = "Error updating permissions for {}: Custom err" "".format(
|
||||
comt = "Error updating permissions for {}: Custom err".format(
|
||||
acl_name
|
||||
)
|
||||
ret = {
|
||||
|
@ -382,7 +382,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(linux_acl.__salt__, {"acl.getfacl": mock}):
|
||||
# Update - test=True
|
||||
with patch.dict(linux_acl.__opts__, {"test": True}):
|
||||
comt = "Updated permissions will be applied for {}: A -> {}" "".format(
|
||||
comt = "Updated permissions will be applied for {}: A -> {}".format(
|
||||
acl_names, perms
|
||||
)
|
||||
expected = {
|
||||
|
@ -436,7 +436,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
|||
},
|
||||
):
|
||||
with patch.dict(linux_acl.__opts__, {"test": False}):
|
||||
comt = "Error updating permissions for {}: Custom err" "".format(
|
||||
comt = "Error updating permissions for {}: Custom err".format(
|
||||
acl_names
|
||||
)
|
||||
expected = {
|
||||
|
@ -452,7 +452,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
|||
# New - test=True
|
||||
with patch.dict(linux_acl.__salt__, {"acl.modfacl": mock_modfacl}):
|
||||
with patch.dict(linux_acl.__opts__, {"test": True}):
|
||||
comt = "New permissions will be applied " "for {}: {}".format(
|
||||
comt = "New permissions will be applied for {}: {}".format(
|
||||
acl_names, perms
|
||||
)
|
||||
expected = {
|
||||
|
@ -500,7 +500,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
|||
},
|
||||
):
|
||||
with patch.dict(linux_acl.__opts__, {"test": False}):
|
||||
comt = "Error updating permissions for {}: Custom err" "".format(
|
||||
comt = "Error updating permissions for {}: Custom err".format(
|
||||
acl_names
|
||||
)
|
||||
expected = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import imp
|
||||
import importlib
|
||||
|
||||
import salt.utils.locales as locales
|
||||
from tests.support.mock import patch
|
||||
|
@ -9,12 +9,12 @@ class TestLocales(TestCase):
|
|||
def test_get_encodings(self):
|
||||
# reload locales modules before and after to defeat memoization of
|
||||
# get_encodings()
|
||||
imp.reload(locales)
|
||||
importlib.reload(locales)
|
||||
with patch("sys.getdefaultencoding", return_value="xyzzy"):
|
||||
encodings = locales.get_encodings()
|
||||
for enc in (__salt_system_encoding__, "xyzzy", "utf-8", "latin-1"):
|
||||
self.assertIn(enc, encodings)
|
||||
imp.reload(locales)
|
||||
importlib.reload(locales)
|
||||
|
||||
def test_split_locale(self):
|
||||
self.assertDictEqual(
|
||||
|
|
Loading…
Add table
Reference in a new issue