mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
use zmq.IPC_PATH_MAX_LEN constant
less code duplication better language
This commit is contained in:
parent
119c1bc2ac
commit
7b84c70477
@ -30,7 +30,7 @@ except ImportError:
|
||||
# Import salt libs
|
||||
from salt.exceptions import (
|
||||
AuthenticationError, CommandExecutionError, CommandNotFoundError,
|
||||
SaltInvocationError, SaltReqTimeoutError, SaltSystemExit
|
||||
SaltInvocationError, SaltReqTimeoutError
|
||||
)
|
||||
import salt.client
|
||||
import salt.crypt
|
||||
@ -631,25 +631,9 @@ class Minion(object):
|
||||
)
|
||||
else:
|
||||
epub_uri = 'ipc://{0}'.format(epub_sock_path)
|
||||
salt.utils.check_ipc_path_max_len(epub_uri)
|
||||
epull_uri = 'ipc://{0}'.format(epull_sock_path)
|
||||
for uri in (epub_uri, epull_uri):
|
||||
if uri.startswith('tcp://'):
|
||||
# This check only applies to IPC sockets
|
||||
continue
|
||||
# The socket path is limited to 107 characters on Solaris and
|
||||
# Linux, and 103 characters on BSD-based systems.
|
||||
# Let's fail at the lower level so no system checks are
|
||||
# required.
|
||||
if len(uri) > 103:
|
||||
raise SaltSystemExit(
|
||||
'The socket path length is more that what ZMQ allows. '
|
||||
'The length of {0!r} is more than 103 characters. '
|
||||
'Either try to reduce the length of this setting\'s '
|
||||
'path or switch to TCP; In the configuration file set '
|
||||
'"ipc_mode: tcp"'.format(
|
||||
uri
|
||||
)
|
||||
)
|
||||
salt.utils.check_ipc_path_max_len(epull_uri)
|
||||
log.debug(
|
||||
'{0} PUB socket URI: {1}'.format(
|
||||
self.__class__.__name__, epub_uri
|
||||
|
@ -20,6 +20,7 @@ import datetime
|
||||
import platform
|
||||
import tempfile
|
||||
import subprocess
|
||||
import zmq
|
||||
from calendar import month_abbr as months
|
||||
|
||||
try:
|
||||
@ -32,7 +33,9 @@ except ImportError:
|
||||
# Import salt libs
|
||||
import salt.minion
|
||||
import salt.payload
|
||||
from salt.exceptions import SaltClientError, CommandNotFoundError
|
||||
from salt.exceptions import (
|
||||
SaltClientError, CommandNotFoundError, SaltSystemExit
|
||||
)
|
||||
|
||||
|
||||
# Do not use these color declarations, use get_colors()
|
||||
@ -795,3 +798,18 @@ def is_linux():
|
||||
Simple function to return if a host is Linux or not
|
||||
'''
|
||||
return sys.platform.startswith('linux')
|
||||
|
||||
|
||||
def check_ipc_path_max_len(uri):
|
||||
# The socket path is limited to 107 characters on Solaris and
|
||||
# Linux, and 103 characters on BSD-based systems.
|
||||
if zmq.IPC_PATH_MAX_LEN and len(uri) > zmq.IPC_PATH_MAX_LEN:
|
||||
raise SaltSystemExit(
|
||||
'The socket path is longer than allowed by OS. '
|
||||
'{0!r} is longer than {1} characters. '
|
||||
'Either try to reduce the length of this setting\'s '
|
||||
'path or switch to TCP; in the configuration file, '
|
||||
'set "ipc_mode: tcp".'.format(
|
||||
uri, zmq.IPC_PATH_MAX_LEN
|
||||
)
|
||||
)
|
||||
|
@ -29,8 +29,8 @@ import zmq
|
||||
import salt.payload
|
||||
import salt.loader
|
||||
import salt.state
|
||||
import salt.utils
|
||||
from salt._compat import string_types
|
||||
from salt.exceptions import SaltSystemExit
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -57,10 +57,12 @@ class SaltEvent(object):
|
||||
sock_dir,
|
||||
'master_event_pub.ipc'
|
||||
))
|
||||
salt.utils.check_ipc_path_max_len(puburi)
|
||||
pulluri = 'ipc://{0}'.format(os.path.join(
|
||||
sock_dir,
|
||||
'master_event_pull.ipc'
|
||||
))
|
||||
salt.utils.check_ipc_path_max_len(pulluri)
|
||||
else:
|
||||
if kwargs.get('ipc_mode', '') == 'tcp':
|
||||
puburi = 'tcp://127.0.0.1:{0}'.format(
|
||||
@ -74,29 +76,12 @@ class SaltEvent(object):
|
||||
sock_dir,
|
||||
'minion_event_{0}_pub.ipc'.format(id_hash)
|
||||
))
|
||||
salt.utils.check_ipc_path_max_len(puburi)
|
||||
pulluri = 'ipc://{0}'.format(os.path.join(
|
||||
sock_dir,
|
||||
'minion_event_{0}_pull.ipc'.format(id_hash)
|
||||
))
|
||||
for uri in (puburi, pulluri):
|
||||
if uri.startswith('tcp://'):
|
||||
# This check only applies to IPC sockets
|
||||
continue
|
||||
# The socket path is limited to 107 characters on Solaris and
|
||||
# Linux, and 103 characters on BSD-based systems.
|
||||
# Let's fail at the lower level so no system checks are
|
||||
# required.
|
||||
if len(uri) > 103:
|
||||
raise SaltSystemExit(
|
||||
'The socket path length is more that what ZMQ allows. '
|
||||
'The length of {0!r} is more than 103 characters. '
|
||||
'Either try to reduce the length of this setting\'s '
|
||||
'path or switch to TCP; In the configuration file set '
|
||||
'"ipc_mode: tcp"'.format(
|
||||
uri
|
||||
)
|
||||
)
|
||||
|
||||
salt.utils.check_ipc_path_max_len(pulluri)
|
||||
log.debug(
|
||||
'{0} PUB socket URI: {1}'.format(self.__class__.__name__, puburi)
|
||||
)
|
||||
@ -105,7 +90,6 @@ class SaltEvent(object):
|
||||
)
|
||||
return puburi, pulluri
|
||||
|
||||
|
||||
def subscribe(self, tag):
|
||||
'''
|
||||
Subscribe to events matching the passed tag.
|
||||
|
Loading…
Reference in New Issue
Block a user