Skip to content

Commit

Permalink
Merge pull request #50973 from garethgreenaway/merge-develop
Browse files Browse the repository at this point in the history
[develop] Merge forward from fluorine to develop
  • Loading branch information
dwoz authored Dec 30, 2018
2 parents c473ef2 + fed22c5 commit 4d2a7f7
Show file tree
Hide file tree
Showing 32 changed files with 1,007 additions and 184 deletions.
5 changes: 2 additions & 3 deletions salt/engines/libvirt_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _get_libvirt_enum_string(prefix, value):
# Filter out the values starting with a common base as they match another enum
prefixes = [_compute_subprefix(p) for p in attributes]
counts = {p: prefixes.count(p) for p in prefixes}
sub_prefixes = [p for p, count in counts.items() if count > 1]
sub_prefixes = [p for p, count in counts.items() if count > 1 or (p.endswith('_') and p[:-1] in prefixes)]
filtered = [attr for attr in attributes if _compute_subprefix(attr) not in sub_prefixes]

for candidate in filtered:
Expand Down Expand Up @@ -313,10 +313,9 @@ def get_address(addr):
'''
transform address structure into event data piece
'''
data = {'family': _get_libvirt_enum_string('{0}_ADDRESS_'.format(prefix), addr['family']),
return {'family': _get_libvirt_enum_string('{0}_ADDRESS_'.format(prefix), addr['family']),
'node': addr['node'],
'service': addr['service']}
return addr

_salt_send_domain_event(opaque, conn, domain, opaque['event'], {
'phase': _get_libvirt_enum_string(prefix, phase),
Expand Down
2 changes: 1 addition & 1 deletion salt/fileserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def backends(self, back=None):

# Avoid error logging when performing lookups in the LazyDict by
# instead doing the membership check on the result of a call to its
# .keys() attribute rather than on the LaztDict itself.
# .keys() attribute rather than on the LazyDict itself.
server_funcs = self.servers.keys()
try:
subtract_only = all((x.startswith('-') for x in back))
Expand Down
8 changes: 6 additions & 2 deletions salt/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,12 @@ def handle_key_cache(self):
keys.append(fn_)
log.debug('Writing master key cache')
# Write a temporary file securely
with salt.utils.atomicfile.atomic_open(os.path.join(self.opts['pki_dir'], acc, '.key_cache')) as cache_file:
self.serial.dump(keys, cache_file)
if six.PY2:
with salt.utils.atomicfile.atomic_open(os.path.join(self.opts['pki_dir'], acc, '.key_cache')) as cache_file:
self.serial.dump(keys, cache_file)
else:
with salt.utils.atomicfile.atomic_open(os.path.join(self.opts['pki_dir'], acc, '.key_cache'), mode='wb') as cache_file:
self.serial.dump(keys, cache_file)

def handle_key_rotate(self, now):
'''
Expand Down
3 changes: 1 addition & 2 deletions salt/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,9 +991,8 @@ def _check_minions(self):
'''
if not self.minions:
err = ('Minion unable to successfully connect to '
'a Salt Master. Exiting.')
'a Salt Master.')
log.error(err)
raise SaltSystemExit(code=42, msg=err)

def _spawn_minions(self, timeout=60):
'''
Expand Down
30 changes: 9 additions & 21 deletions salt/modules/icinga2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
import logging
import subprocess

# Import Salt libs
import salt.utils.path
import salt.utils.platform
from salt.utils.icinga2 import get_certs_path

log = logging.getLogger(__name__)

Expand All @@ -32,18 +32,6 @@ def __virtual__():
return (False, 'Icinga2 not installed.')


def _execute(cmd, ret_code=False):
process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
if ret_code:
return process.wait()
output, error = process.communicate()
if output:
log.debug(output)
return output
log.debug(error)
return error


def generate_ticket(domain):
'''
Generate and save an icinga2 ticket.
Expand All @@ -58,7 +46,7 @@ def generate_ticket(domain):
salt '*' icinga2.generate_ticket domain.tld
'''
result = _execute(["icinga2", "pki", "ticket", "--cn", domain])
result = __salt__['cmd.run_all'](["icinga2", "pki", "ticket", "--cn", domain], python_shell=False)
return result


Expand All @@ -76,7 +64,7 @@ def generate_cert(domain):
salt '*' icinga2.generate_cert domain.tld
'''
result = _execute(["icinga2", "pki", "new-cert", "--cn", domain, "--key", "/etc/icinga2/pki/{0}.key".format(domain), "--cert", "/etc/icinga2/pki/{0}.crt".format(domain)], ret_code=True)
result = __salt__['cmd.run_all'](["icinga2", "pki", "new-cert", "--cn", domain, "--key", "{0}{1}.key".format(get_certs_path(), domain), "--cert", "{0}{1}.crt".format(get_certs_path(), domain)], python_shell=False)
return result


Expand All @@ -94,8 +82,8 @@ def save_cert(domain, master):
salt '*' icinga2.save_cert domain.tld master.domain.tld
'''
result = _execute(["icinga2", "pki", "save-cert", "--key", "/etc/icinga2/pki/{0}.key".format(domain), "--cert", "/etc/icinga2/pki/{0}.cert".format(domain), "--trustedcert",
"/etc/icinga2/pki/trusted-master.crt", "--host", master], ret_code=True)
result = __salt__['cmd.run_all'](["icinga2", "pki", "save-cert", "--key", "{0}{1}.key".format(get_certs_path(), domain), "--cert", "{0}{1}.cert".format(get_certs_path(), domain), "--trustedcert",
"{0}trusted-master.crt".format(get_certs_path()), "--host", master], python_shell=False)
return result


Expand All @@ -114,8 +102,8 @@ def request_cert(domain, master, ticket, port):
salt '*' icinga2.request_cert domain.tld master.domain.tld TICKET_ID
'''
result = _execute(["icinga2", "pki", "request", "--host", master, "--port", port, "--ticket", ticket, "--key", "/etc/icinga2/pki/{0}.key".format(domain), "--cert",
"/etc/icinga2/pki/{0}.crt".format(domain), "--trustedcert", "/etc/icinga2/pki/trusted-master.crt", "--ca", "/etc/icinga2/pki/ca.crt"], ret_code=True)
result = __salt__['cmd.run_all'](["icinga2", "pki", "request", "--host", master, "--port", port, "--ticket", ticket, "--key", "{0}{1}.key".format(get_certs_path(), domain), "--cert",
"{0}{1}.crt".format(get_certs_path(), domain), "--trustedcert", "{0}trusted-master.crt".format(get_certs_path()), "--ca", "{0}ca.crt".format(get_certs_path())], python_shell=False)
return result


Expand All @@ -134,6 +122,6 @@ def node_setup(domain, master, ticket):
salt '*' icinga2.node_setup domain.tld master.domain.tld TICKET_ID
'''
result = _execute(["icinga2", "node", "setup", "--ticket", ticket, "--endpoint", master, "--zone", domain, "--master_host", master, "--trustedcert", "/etc/icinga2/pki/trusted-master.crt"],
ret_code=True)
result = __salt__['cmd.run_all'](["icinga2", "node", "setup", "--ticket", ticket, "--endpoint", master, "--zone", domain, "--master_host", master, "--trustedcert", "{0}trusted-master.crt".format(get_certs_path())],
python_shell=False)
return result
2 changes: 1 addition & 1 deletion salt/modules/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ def user_grants(user,
return False

ret = []
results = cur.fetchall()
results = salt.utils.data.decode(cur.fetchall())
for grant in results:
tmp = grant[0].split(' IDENTIFIED BY')[0]
if 'WITH GRANT OPTION' in grant[0] and 'WITH GRANT OPTION' not in tmp:
Expand Down
13 changes: 7 additions & 6 deletions salt/modules/ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import re

# Import salt libs
import salt.utils.data
from salt.exceptions import SaltInvocationError, CommandExecutionError

# Import third party libs
Expand Down Expand Up @@ -53,9 +54,9 @@ def _get_proc_cmdline(proc):
It's backward compatible with < 2.0 versions of psutil.
'''
try:
return proc.cmdline() if PSUTIL2 else proc.cmdline
return salt.utils.data.decode(proc.cmdline() if PSUTIL2 else proc.cmdline)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return ''
return []


def _get_proc_create_time(proc):
Expand All @@ -65,7 +66,7 @@ def _get_proc_create_time(proc):
It's backward compatible with < 2.0 versions of psutil.
'''
try:
return proc.create_time() if PSUTIL2 else proc.create_time
return salt.utils.data.decode(proc.create_time() if PSUTIL2 else proc.create_time)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return None

Expand All @@ -77,7 +78,7 @@ def _get_proc_name(proc):
It's backward compatible with < 2.0 versions of psutil.
'''
try:
return proc.name() if PSUTIL2 else proc.name
return salt.utils.data.decode(proc.name() if PSUTIL2 else proc.name)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return []

Expand All @@ -89,7 +90,7 @@ def _get_proc_status(proc):
It's backward compatible with < 2.0 versions of psutil.
'''
try:
return proc.status() if PSUTIL2 else proc.status
return salt.utils.data.decode(proc.status() if PSUTIL2 else proc.status)
except (psutil.NoSuchProcess, psutil.AccessDenied):
return None

Expand All @@ -101,7 +102,7 @@ def _get_proc_username(proc):
It's backward compatible with < 2.0 versions of psutil.
'''
try:
return proc.username() if PSUTIL2 else proc.username
return salt.utils.data.decode(proc.username() if PSUTIL2 else proc.username)
except (psutil.NoSuchProcess, psutil.AccessDenied, KeyError):
return None

Expand Down
11 changes: 6 additions & 5 deletions salt/modules/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,11 +1976,12 @@ def update(name,
need_update = True

# Update the memory, note that libvirt outputs all memory sizes in KiB
mem_node = desc.find('memory')
if mem and int(mem_node.text) != mem * 1024:
mem_node.text = six.text_type(mem)
mem_node.set('unit', 'MiB')
need_update = True
for mem_node_name in ['memory', 'currentMemory']:
mem_node = desc.find(mem_node_name)
if mem and int(mem_node.text) != mem * 1024:
mem_node.text = six.text_type(mem)
mem_node.set('unit', 'MiB')
need_update = True

# Update the XML definition with the new disks and diff changes
devices_node = desc.find('devices')
Expand Down
Loading

0 comments on commit 4d2a7f7

Please sign in to comment.