From e3b45ecc53e6df327088bf85f1d260800595252e Mon Sep 17 00:00:00 2001 From: Julien Cigar Date: Wed, 20 Apr 2016 15:26:00 +0200 Subject: [PATCH 1/7] Remove check_or_die for venv_bin While it sounds a good idea to check wether the venv_bin exists or not, due to the implementation of salt.utils.which it fails if the command contains arguments, for example "/usr/local/bin/python3.4 -m venv": 2016-04-20 12:56:46,564 [salt.state ][ERROR ][45709] An exception occurred in this state: Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/salt/state.py", line 1594, in call **cdata['kwargs']) File "/usr/local/lib/python2.7/site-packages/salt/loader.py", line 1491, in wrapper return f(*args, **kwargs) File "/usr/local/lib/python2.7/site-packages/salt/states/virtualenv_mod.py", line 169, in managed use_vt=use_vt, File "/usr/local/lib/python2.7/site-packages/salt/modules/virtualenv_mod.py", line 117, in create salt.utils.check_or_die(venv_bin) File "/usr/local/lib/python2.7/site-packages/salt/utils/__init__.py", line 804, in check_or_die raise CommandNotFoundError(command) CommandNotFoundError: /usr/local/bin/python3.4 -m venv --- salt/modules/virtualenv_mod.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/salt/modules/virtualenv_mod.py b/salt/modules/virtualenv_mod.py index e95d2fecb3..9e6d3bc379 100644 --- a/salt/modules/virtualenv_mod.py +++ b/salt/modules/virtualenv_mod.py @@ -129,8 +129,6 @@ def create(path, ''' if venv_bin is None: venv_bin = __opts__.get('venv_bin') or __pillar__.get('venv_bin') - # raise CommandNotFoundError if venv_bin is missing - salt.utils.check_or_die(venv_bin) cmd = [venv_bin] From 657d0bf5827e0fcce73ce334d5ffcc1917fab789 Mon Sep 17 00:00:00 2001 From: Julien Cigar Date: Fri, 3 Jun 2016 00:21:49 +0200 Subject: [PATCH 2/7] split the parsing of resolv.conf from the grains/core module --- salt/grains/core.py | 42 +++--------------------------------------- salt/utils/dns.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 salt/utils/dns.py diff --git a/salt/grains/core.py b/salt/grains/core.py index e9276e9a20..9a6393f550 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -36,6 +36,7 @@ _supported_dists += ('arch', 'mageia', 'meego', 'vmware', 'bluewhite64', import salt.log import salt.utils import salt.utils.network +import salt.utils.dns # Solve the Chicken and egg problem where grains need to run before any # of the modules are loaded and are generally available for any usage. @@ -1753,46 +1754,9 @@ def dns(): if salt.utils.is_windows() or 'proxyminion' in __opts__: return {} - ns4 = [] - ns6 = [] - search = [] - domain = '' - - try: - with salt.utils.fopen('/etc/resolv.conf') as f: - for line in f: - line = line.strip().split() - - try: - (directive, arg) = (line[0].lower(), line[1:]) - if directive == 'nameserver': - ip_addr = arg[0] - if (salt.utils.network.is_ipv4(ip_addr) and - ip_addr not in ns4): - ns4.append(ip_addr) - elif (salt.utils.network.is_ipv6(ip_addr) and - ip_addr not in ns6): - ns6.append(ip_addr) - elif directive == 'domain': - domain = arg[0] - elif directive == 'search': - search = list(itertools.takewhile( - lambda x: x[0] not in ('#', ';'), arg)) - except (IndexError, RuntimeError): - continue - - ret = { - 'nameservers': ns4 + ns6, - 'ip4_nameservers': ns4, - 'ip6_nameservers': ns6, - 'domain': domain, - 'search': search - } - - return {'dns': ret} - except IOError: - return {} + resolv = salt.utils.dns.parse_resolv() + return {'dns': resolv } if resolv else {} def get_machine_id(): ''' diff --git a/salt/utils/dns.py b/salt/utils/dns.py new file mode 100644 index 0000000000..cd22845390 --- /dev/null +++ b/salt/utils/dns.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +import itertools + +import salt.utils.network + +def parse_resolv(fp='/etc/resolv.conf'): + ns4 = [] + ns6 = [] + search = [] + domain = '' + + try: + with salt.utils.fopen(fp) as f: + for line in f: + line = line.strip().split() + + try: + (directive, arg) = (line[0].lower(), line[1:]) + if directive == 'nameserver': + ip_addr = arg[0] + if (salt.utils.network.is_ipv4(ip_addr) and + ip_addr not in ns4): + ns4.append(ip_addr) + elif (salt.utils.network.is_ipv6(ip_addr) and + ip_addr not in ns6): + ns6.append(ip_addr) + elif directive == 'domain': + domain = arg[0] + elif directive == 'search': + search = list(itertools.takewhile( + lambda x: x[0] not in ('#', ';'), arg)) + except (IndexError, RuntimeError): + continue + + return { + 'nameservers': ns4 + ns6, + 'ip4_nameservers': ns4, + 'ip6_nameservers': ns6, + 'domain': domain, + 'search': search + } + except IOError: + return {} From 8fadf51766828ecf5a97a52e9939097c8d72a3a8 Mon Sep 17 00:00:00 2001 From: Julien Cigar Date: Sun, 5 Jun 2016 21:26:24 +0200 Subject: [PATCH 3/7] fix lint issues --- salt/grains/core.py | 4 ++-- salt/utils/dns.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/salt/grains/core.py b/salt/grains/core.py index 9a6393f550..093e87db3c 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -12,7 +12,6 @@ as those returned here # Import python libs from __future__ import absolute_import -import itertools import os import json import socket @@ -1756,7 +1755,8 @@ def dns(): resolv = salt.utils.dns.parse_resolv() - return {'dns': resolv } if resolv else {} + return {'dns': resolv} if resolv else {} + def get_machine_id(): ''' diff --git a/salt/utils/dns.py b/salt/utils/dns.py index cd22845390..b78fdb993c 100644 --- a/salt/utils/dns.py +++ b/salt/utils/dns.py @@ -4,6 +4,7 @@ import itertools import salt.utils.network + def parse_resolv(fp='/etc/resolv.conf'): ns4 = [] ns6 = [] From eb503fad78dc7a42547342fa18ff7308cad60d1e Mon Sep 17 00:00:00 2001 From: Julien Cigar Date: Fri, 3 Jun 2016 00:21:49 +0200 Subject: [PATCH 4/7] split the parsing of resolv.conf from the grains/core module --- salt/grains/core.py | 42 +++--------------------------------------- salt/utils/dns.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 salt/utils/dns.py diff --git a/salt/grains/core.py b/salt/grains/core.py index e9276e9a20..9a6393f550 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -36,6 +36,7 @@ _supported_dists += ('arch', 'mageia', 'meego', 'vmware', 'bluewhite64', import salt.log import salt.utils import salt.utils.network +import salt.utils.dns # Solve the Chicken and egg problem where grains need to run before any # of the modules are loaded and are generally available for any usage. @@ -1753,46 +1754,9 @@ def dns(): if salt.utils.is_windows() or 'proxyminion' in __opts__: return {} - ns4 = [] - ns6 = [] - search = [] - domain = '' - - try: - with salt.utils.fopen('/etc/resolv.conf') as f: - for line in f: - line = line.strip().split() - - try: - (directive, arg) = (line[0].lower(), line[1:]) - if directive == 'nameserver': - ip_addr = arg[0] - if (salt.utils.network.is_ipv4(ip_addr) and - ip_addr not in ns4): - ns4.append(ip_addr) - elif (salt.utils.network.is_ipv6(ip_addr) and - ip_addr not in ns6): - ns6.append(ip_addr) - elif directive == 'domain': - domain = arg[0] - elif directive == 'search': - search = list(itertools.takewhile( - lambda x: x[0] not in ('#', ';'), arg)) - except (IndexError, RuntimeError): - continue - - ret = { - 'nameservers': ns4 + ns6, - 'ip4_nameservers': ns4, - 'ip6_nameservers': ns6, - 'domain': domain, - 'search': search - } - - return {'dns': ret} - except IOError: - return {} + resolv = salt.utils.dns.parse_resolv() + return {'dns': resolv } if resolv else {} def get_machine_id(): ''' diff --git a/salt/utils/dns.py b/salt/utils/dns.py new file mode 100644 index 0000000000..cd22845390 --- /dev/null +++ b/salt/utils/dns.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +import itertools + +import salt.utils.network + +def parse_resolv(fp='/etc/resolv.conf'): + ns4 = [] + ns6 = [] + search = [] + domain = '' + + try: + with salt.utils.fopen(fp) as f: + for line in f: + line = line.strip().split() + + try: + (directive, arg) = (line[0].lower(), line[1:]) + if directive == 'nameserver': + ip_addr = arg[0] + if (salt.utils.network.is_ipv4(ip_addr) and + ip_addr not in ns4): + ns4.append(ip_addr) + elif (salt.utils.network.is_ipv6(ip_addr) and + ip_addr not in ns6): + ns6.append(ip_addr) + elif directive == 'domain': + domain = arg[0] + elif directive == 'search': + search = list(itertools.takewhile( + lambda x: x[0] not in ('#', ';'), arg)) + except (IndexError, RuntimeError): + continue + + return { + 'nameservers': ns4 + ns6, + 'ip4_nameservers': ns4, + 'ip6_nameservers': ns6, + 'domain': domain, + 'search': search + } + except IOError: + return {} From aded9899e18d18cf2a382007b63d0384c45f6042 Mon Sep 17 00:00:00 2001 From: Julien Cigar Date: Sun, 5 Jun 2016 21:26:24 +0200 Subject: [PATCH 5/7] fix lint issues --- salt/grains/core.py | 4 ++-- salt/utils/dns.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/salt/grains/core.py b/salt/grains/core.py index 9a6393f550..093e87db3c 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -12,7 +12,6 @@ as those returned here # Import python libs from __future__ import absolute_import -import itertools import os import json import socket @@ -1756,7 +1755,8 @@ def dns(): resolv = salt.utils.dns.parse_resolv() - return {'dns': resolv } if resolv else {} + return {'dns': resolv} if resolv else {} + def get_machine_id(): ''' diff --git a/salt/utils/dns.py b/salt/utils/dns.py index cd22845390..b78fdb993c 100644 --- a/salt/utils/dns.py +++ b/salt/utils/dns.py @@ -4,6 +4,7 @@ import itertools import salt.utils.network + def parse_resolv(fp='/etc/resolv.conf'): ns4 = [] ns6 = [] From 1c4ad3facc16debc3cd5ddcd5cc5db888a1a5e53 Mon Sep 17 00:00:00 2001 From: Julien Cigar Date: Mon, 6 Jun 2016 13:29:38 +0200 Subject: [PATCH 6/7] add a missing # pylint: disable=E0403 --- salt/utils/dns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/utils/dns.py b/salt/utils/dns.py index b78fdb993c..d9725300f4 100644 --- a/salt/utils/dns.py +++ b/salt/utils/dns.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -import itertools +import itertools # pylint: disable=E0403 import salt.utils.network From 833fac04fe68d4254ebefa83892b7392692a5281 Mon Sep 17 00:00:00 2001 From: Julien Cigar Date: Mon, 6 Jun 2016 14:18:55 +0200 Subject: [PATCH 7/7] s/E/W... sorry it's monday :( --- salt/utils/dns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/utils/dns.py b/salt/utils/dns.py index d9725300f4..57629ba7b7 100644 --- a/salt/utils/dns.py +++ b/salt/utils/dns.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -import itertools # pylint: disable=E0403 +import itertools # pylint: disable=W0403 import salt.utils.network