From 67879ebe65bdc802330458826b4471c8e43cc98b Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Wed, 4 Jan 2017 11:14:05 -0500 Subject: [PATCH 1/5] Create queue if one doesn't exist --- salt/queues/pgjsonb_queue.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/salt/queues/pgjsonb_queue.py b/salt/queues/pgjsonb_queue.py index 2c62619468..08f42c2aec 100644 --- a/salt/queues/pgjsonb_queue.py +++ b/salt/queues/pgjsonb_queue.py @@ -112,7 +112,7 @@ def _list_tables(cur): def _create_table(cur, queue): - cmd = 'CREATE TABLE {0}(id INTEGER PRIMARY KEY, '\ + cmd = 'CREATE TABLE {0}(id SERIAL PRIMARY KEY, '\ 'data jsonb NOT NULL)'.format(queue) log.debug('SQL Query: {0}'.format(cmd)) cur.execute(cmd) @@ -157,10 +157,34 @@ def list_length(queue): return len(items) +def _queue_exists(queue): + ''' + Does this queue exist + :param queue: Name of the queue + :type str + :return: True if this queue exists and + False otherwise + :rtype bool + ''' + return queue in list_queues() + + +def handle_queue_creation(queue): + if not _queue_exists(queue): + with _conn(commit=True) as cur: + log.debug('Queue %s does not exist.' + ' Creating', queue) + _create_table(cur, queue) + else: + log.debug('Queue %s already exists.', queue) + + def insert(queue, items): ''' Add an item or items to a queue ''' + handle_queue_creation(queue) + with _conn(commit=True) as cur: if isinstance(items, dict): items = json.dumps(items) From 2a5880966f13828152bc9504de99bddde8f6f66d Mon Sep 17 00:00:00 2001 From: rallytime Date: Thu, 5 Jan 2017 11:03:50 -0500 Subject: [PATCH 2/5] Change daemontools __virtualname__ from service to daemontools Fixes #37498 When `__virtualname__` is set to `service` in the daemontools execution module, it overrides the default system-wide service provider. We need to keep the default service provider, since daemontools is a third-party service. --- salt/modules/daemontools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/daemontools.py b/salt/modules/daemontools.py index d442a68d5d..367bb6cee3 100644 --- a/salt/modules/daemontools.py +++ b/salt/modules/daemontools.py @@ -31,7 +31,7 @@ __func_alias__ = { log = logging.getLogger(__name__) -__virtualname__ = 'service' +__virtualname__ = 'daemontools' VALID_SERVICE_DIRS = [ '/service', From 9ec470b4a5e561d7d8398a2d5c1f5c0f25b46de4 Mon Sep 17 00:00:00 2001 From: Tobias Thiel Date: Thu, 5 Jan 2017 17:50:51 +0100 Subject: [PATCH 3/5] State Gem: fix incorrect warning about missing rvm/rbenv --- salt/states/gem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/states/gem.py b/salt/states/gem.py index ef340814db..fc8f7974e8 100644 --- a/salt/states/gem.py +++ b/salt/states/gem.py @@ -74,7 +74,7 @@ def installed(name, # pylint: disable=C0103 Format: http://hostname[:port] ''' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} - if ruby is not None and (__salt__['rvm.is_installed'](runas=user) or __salt__['rbenv.is_installed'](runas=user)): + if ruby is not None and not(__salt__['rvm.is_installed'](runas=user) or __salt__['rbenv.is_installed'](runas=user)): log.warning( 'Use of argument ruby found, but neither rvm or rbenv is installed' ) From 8a45b13e762600306440bcbe46de8c0b29d374cb Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Thu, 5 Jan 2017 12:50:46 -0600 Subject: [PATCH 4/5] Avoid errors when sudo_user is set When sudo_user is used, the job is forked into a new pid when sudo is executed. If a state then tries itself to execute states (such as when a state invokes state.single), the fact that the forked PID was different from the PID from which the job was started will cause Salt to refuse to run the state. This avoids this by conditionally setting concurrent to True when invoking states from within states. --- salt/modules/vbox_guest.py | 9 ++++++--- salt/states/archive.py | 7 +++++-- salt/states/dockerio.py | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/salt/modules/vbox_guest.py b/salt/modules/vbox_guest.py index 4441b077e4..3fe518956f 100644 --- a/salt/modules/vbox_guest.py +++ b/salt/modules/vbox_guest.py @@ -101,19 +101,22 @@ def _additions_install_opensuse(**kwargs): r'^(\d|\.|-)*', '', __grains__.get('kernelrelease', '')) kernel_devel = 'kernel-{0}-devel'.format(kernel_type) ret = __salt__['state.single']('pkg.installed', 'devel packages', - pkgs=['make', 'gcc', kernel_devel]) + pkgs=['make', 'gcc', kernel_devel], + concurrent=bool(__opts__.get('sudo_user'))) return ret def _additions_install_ubuntu(**kwargs): ret = __salt__['state.single']('pkg.installed', 'devel packages', - pkgs=['dkms', ]) + pkgs=['dkms', ], + concurrent=bool(__opts__.get('sudo_user'))) return ret def _additions_install_fedora(**kwargs): ret = __salt__['state.single']('pkg.installed', 'devel packages', - pkgs=['dkms', 'gcc']) + pkgs=['dkms', 'gcc'], + concurrent=bool(__opts__.get('sudo_user'))) return ret diff --git a/salt/states/archive.py b/salt/states/archive.py index a77f8270b8..220d5e05c4 100644 --- a/salt/states/archive.py +++ b/salt/states/archive.py @@ -343,6 +343,7 @@ def extracted(name, __env__, '{0}.{1}'.format(re.sub('[:/\\\\]', '_', if_missing), archive_format)) + concurrent = bool(__opts__.get('sudo_user')) if not source_is_local and not os.path.isfile(filename): if __opts__['test']: ret['result'] = None @@ -363,7 +364,8 @@ def extracted(name, makedirs=True, skip_verify=skip_verify, saltenv=__env__, - source_hash_name=source_hash_name) + source_hash_name=source_hash_name, + concurrent=concurrent) log.debug('file.managed: {0}'.format(file_result)) # get value of first key try: @@ -527,7 +529,8 @@ def extracted(name, if_missing, user=user, group=group, - recurse=recurse) + recurse=recurse, + concurrent=concurrent) log.debug('file.directory: %s', dir_result) elif os.path.isfile(if_missing): log.debug('if_missing (%s) is a file, not enforcing user/group ' diff --git a/salt/states/dockerio.py b/salt/states/dockerio.py index 7dfa05abf1..9c929ea380 100644 --- a/salt/states/dockerio.py +++ b/salt/states/dockerio.py @@ -507,7 +507,8 @@ def loaded(name, tag='latest', source=None, source_hash='', force=False): __salt__['state.single']('file.managed', name=tmp_filename, source=source, - source_hash=source_hash) + source_hash=source_hash, + concurrent=bool(__opts__.get('sudo_user'))) changes = {} if image_infos['status']: From 8613d7254d29f920976071d06c91e8dc8bfe33f7 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Thu, 5 Jan 2017 13:29:48 -0600 Subject: [PATCH 5/5] pillar.get: Raise exception when merge=True and default is not a dict --- salt/modules/pillar.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/salt/modules/pillar.py b/salt/modules/pillar.py index 81df93fd89..fa585c822b 100644 --- a/salt/modules/pillar.py +++ b/salt/modules/pillar.py @@ -16,7 +16,7 @@ import salt.ext.six as six import salt.pillar import salt.utils from salt.defaults import DEFAULT_TARGET_DELIM -from salt.exceptions import CommandExecutionError +from salt.exceptions import CommandExecutionError, SaltInvocationError __proxyenabled__ = ['*'] @@ -87,6 +87,10 @@ def get(key, pillar_dict = __pillar__ if saltenv is None else items(saltenv=saltenv) if merge: + if not isinstance(default, dict): + raise SaltInvocationError( + 'default must be a dictionary when merge=True' + ) ret = salt.utils.traverse_dict_and_list(pillar_dict, key, {}, delimiter) if isinstance(ret, collections.Mapping) and \ isinstance(default, collections.Mapping):