Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing an issue on mac_system where the virtual function wouldnt load #50421

Merged
merged 1 commit into from Nov 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
146 changes: 47 additions & 99 deletions salt/modules/mac_system.py
Expand Up @@ -8,7 +8,6 @@
Using this module will enable ``atrun`` on the system if it is disabled.
'''
from __future__ import absolute_import, unicode_literals, print_function
import os

# Import python libs
try: # python 3
Expand All @@ -19,8 +18,6 @@
import getpass

# Import salt libs
from salt.ext import six
import salt.utils.mac_utils
import salt.utils.platform
from salt.exceptions import SaltInvocationError, CommandExecutionError

Expand All @@ -47,35 +44,10 @@ def __virtual__():

def _atrun_enabled():
'''
Check to see if atrun is enabled on the system
Check to see if atrun is running and enabled on the system
'''
name = 'com.apple.atrun'
services = __utils__['mac_utils.available_services']()
label = None

if name in services:
label = services[name]['plist']['Label']
else:
for service in six.itervalues(services):
if service['file_path'].lower() == name:
# Match on full path
label = service['plist']['Label']
break
basename, ext = os.path.splitext(service['file_name'])
if basename.lower() == name:
# Match on basename
label = service['plist']['Label']
break

if not label:
return False

try:
# Collect information on service: will raise an error if it fails
salt.utils.mac_utils.launchctl('list',
label,
return_stdout=True)
return True
return __salt__['service.list']('com.apple.atrun')
except CommandExecutionError:
return False

Expand All @@ -85,33 +57,11 @@ def _enable_atrun():
Enable and start the atrun daemon
'''
name = 'com.apple.atrun'
services = __utils__['mac_utils.available_services']()
label = None
path = None

if name in services:
label = services[name]['plist']['Label']
path = services[name]['file_path']
else:
for service in six.itervalues(services):
if service['file_path'].lower() == name:
# Match on full path
label = service['plist']['Label']
path = service['file_path']
break
basename, ext = os.path.splitext(service['file_name'])
if basename.lower() == name:
# Match on basename
label = service['plist']['Label']
path = service['file_path']
break

if not label:
try:
__salt__['service.enable'](name)
__salt__['service.start'](name)
except CommandExecutionError:
return False

salt.utils.mac_utils.launchctl('enable',
'system/{0}'.format(label))
salt.utils.mac_utils.launchctl('load', path)
return _atrun_enabled()


Expand Down Expand Up @@ -259,11 +209,11 @@ def get_remote_login():

salt '*' system.get_remote_login
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -getremotelogin')

enabled = salt.utils.mac_utils.validate_enabled(
salt.utils.mac_utils.parse_return(ret))
enabled = __utils__['mac_utils.validate_enabled'](
__utils__['mac_utils.parse_return'](ret))

return enabled == 'on'

Expand All @@ -285,16 +235,14 @@ def set_remote_login(enable):

salt '*' system.set_remote_login True
'''
state = salt.utils.mac_utils.validate_enabled(enable)
state = __utils__['mac_utils.validate_enabled'](enable)

cmd = 'systemsetup -f -setremotelogin {0}'.format(state)
salt.utils.mac_utils.execute_return_success(cmd)
__utils__['mac_utils.execute_return_success'](cmd)

return salt.utils.mac_utils.confirm_updated(
state,
get_remote_login,
normalize_ret=True,
)
return __utils__['mac_utils.confirm_updated'](state,
get_remote_login,
normalize_ret=True)


def get_remote_events():
Expand All @@ -310,11 +258,11 @@ def get_remote_events():

salt '*' system.get_remote_events
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -getremoteappleevents')

enabled = salt.utils.mac_utils.validate_enabled(
salt.utils.mac_utils.parse_return(ret))
enabled = __utils__['mac_utils.validate_enabled'](
__utils__['mac_utils.parse_return'](ret))

return enabled == 'on'

Expand All @@ -337,12 +285,12 @@ def set_remote_events(enable):

salt '*' system.set_remote_events On
'''
state = salt.utils.mac_utils.validate_enabled(enable)
state = __utils__['mac_utils.validate_enabled'](enable)

cmd = 'systemsetup -setremoteappleevents {0}'.format(state)
salt.utils.mac_utils.execute_return_success(cmd)
__utils__['mac_utils.execute_return_success'](cmd)

return salt.utils.mac_utils.confirm_updated(
return __utils__['mac_utils.confirm_updated'](
state,
get_remote_events,
normalize_ret=True,
Expand All @@ -362,10 +310,10 @@ def get_computer_name():

salt '*' system.get_computer_name
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -getcomputername')

return salt.utils.mac_utils.parse_return(ret)
return __utils__['mac_utils.parse_return'](ret)


def set_computer_name(name):
Expand All @@ -384,9 +332,9 @@ def set_computer_name(name):
salt '*' system.set_computer_name "Mike's Mac"
'''
cmd = 'systemsetup -setcomputername "{0}"'.format(name)
salt.utils.mac_utils.execute_return_success(cmd)
__utils__['mac_utils.execute_return_success'](cmd)

return salt.utils.mac_utils.confirm_updated(
return __utils__['mac_utils.confirm_updated'](
name,
get_computer_name,
)
Expand All @@ -405,10 +353,10 @@ def get_subnet_name():

salt '*' system.get_subnet_name
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -getlocalsubnetname')

return salt.utils.mac_utils.parse_return(ret)
return __utils__['mac_utils.parse_return'](ret)


def set_subnet_name(name):
Expand All @@ -431,9 +379,9 @@ def set_subnet_name(name):
salt '*' system.set_subnet_name "Mike's Mac"
'''
cmd = 'systemsetup -setlocalsubnetname "{0}"'.format(name)
salt.utils.mac_utils.execute_return_success(cmd)
__utils__['mac_utils.execute_return_success'](cmd)

return salt.utils.mac_utils.confirm_updated(
return __utils__['mac_utils.confirm_updated'](
name,
get_subnet_name,
)
Expand All @@ -452,10 +400,10 @@ def get_startup_disk():

salt '*' system.get_startup_disk
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -getstartupdisk')

return salt.utils.mac_utils.parse_return(ret)
return __utils__['mac_utils.parse_return'](ret)


def list_startup_disks():
Expand All @@ -471,7 +419,7 @@ def list_startup_disks():

salt '*' system.list_startup_disks
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -liststartupdisks')

return ret.splitlines()
Expand Down Expand Up @@ -501,9 +449,9 @@ def set_startup_disk(path):
raise SaltInvocationError(msg)

cmd = 'systemsetup -setstartupdisk {0}'.format(path)
salt.utils.mac_utils.execute_return_result(cmd)
__utils__['mac_utils.execute_return_result'](cmd)

return salt.utils.mac_utils.confirm_updated(
return __utils__['mac_utils.confirm_updated'](
path,
get_startup_disk,
)
Expand All @@ -524,10 +472,10 @@ def get_restart_delay():

salt '*' system.get_restart_delay
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -getwaitforstartupafterpowerfailure')

return salt.utils.mac_utils.parse_return(ret)
return __utils__['mac_utils.parse_return'](ret)


def set_restart_delay(seconds):
Expand Down Expand Up @@ -565,9 +513,9 @@ def set_restart_delay(seconds):
raise SaltInvocationError(msg)

cmd = 'systemsetup -setwaitforstartupafterpowerfailure {0}'.format(seconds)
salt.utils.mac_utils.execute_return_success(cmd)
__utils__['mac_utils.execute_return_success'](cmd)

return salt.utils.mac_utils.confirm_updated(
return __utils__['mac_utils.confirm_updated'](
seconds,
get_restart_delay,
)
Expand All @@ -587,11 +535,11 @@ def get_disable_keyboard_on_lock():

salt '*' system.get_disable_keyboard_on_lock
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -getdisablekeyboardwhenenclosurelockisengaged')

enabled = salt.utils.mac_utils.validate_enabled(
salt.utils.mac_utils.parse_return(ret))
enabled = __utils__['mac_utils.validate_enabled'](
__utils__['mac_utils.parse_return'](ret))

return enabled == 'on'

Expand All @@ -614,13 +562,13 @@ def set_disable_keyboard_on_lock(enable):

salt '*' system.set_disable_keyboard_on_lock False
'''
state = salt.utils.mac_utils.validate_enabled(enable)
state = __utils__['mac_utils.validate_enabled'](enable)

cmd = 'systemsetup -setdisablekeyboardwhenenclosurelockisengaged ' \
'{0}'.format(state)
salt.utils.mac_utils.execute_return_success(cmd)
__utils__['mac_utils.execute_return_success'](cmd)

return salt.utils.mac_utils.confirm_updated(
return __utils__['mac_utils.confirm_updated'](
state,
get_disable_keyboard_on_lock,
normalize_ret=True,
Expand All @@ -640,10 +588,10 @@ def get_boot_arch():

salt '*' system.get_boot_arch
'''
ret = salt.utils.mac_utils.execute_return_result(
ret = __utils__['mac_utils.execute_return_result'](
'systemsetup -getkernelbootarchitecturesetting')

arch = salt.utils.mac_utils.parse_return(ret)
arch = __utils__['mac_utils.parse_return'](ret)

if 'default' in arch:
return 'default'
Expand Down Expand Up @@ -688,9 +636,9 @@ def set_boot_arch(arch='default'):
raise SaltInvocationError(msg)

cmd = 'systemsetup -setkernelbootarchitecture {0}'.format(arch)
salt.utils.mac_utils.execute_return_success(cmd)
__utils__['mac_utils.execute_return_success'](cmd)

return salt.utils.mac_utils.confirm_updated(
return __utils__['mac_utils.confirm_updated'](
arch,
get_boot_arch,
)