mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
[2016.11] Merge forward from 2016.3 to 2016.11 (#39234)
* Fix for #38697 * Lint fixes * Added missing source_hash_name argument in get_managed function Additional fix to #33187 Customer was still seeing errors, this should now work. Tested with 2015.8.13 and 2016.11.2 * [2016.3] Pylint fix (#39202) * Ignore empty dicts in highstate outputter Closes #37174 * Sort the return list from the fileserver.envs runner * Fix the win_ip_test failures (#39230) The changes made in #38793 changes the "get_all_ointerfaces" call to be a list of DNS servers. This change adjusts the tests structure from a string to a list and fixes the test failure.
This commit is contained in:
parent
fd3284f0c7
commit
84ff63875c
@ -6,7 +6,6 @@ from __future__ import absolute_import
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
import socket
|
||||
import time
|
||||
|
||||
# Import salt libs
|
||||
@ -41,62 +40,53 @@ def _interface_configs():
|
||||
'''
|
||||
cmd = ['netsh', 'interface', 'ip', 'show', 'config']
|
||||
lines = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
|
||||
iface = ''
|
||||
ip = 0
|
||||
dns_flag = None
|
||||
wins_flag = None
|
||||
ret = {}
|
||||
current_iface = None
|
||||
current_ip_list = None
|
||||
|
||||
for line in lines:
|
||||
if dns_flag:
|
||||
try:
|
||||
socket.inet_aton(line.strip())
|
||||
ret[iface][dns_flag].append(line.strip())
|
||||
dns_flag = None
|
||||
continue
|
||||
except socket.error as exc:
|
||||
dns_flag = None
|
||||
if wins_flag:
|
||||
try:
|
||||
socket.inet_aton(line.strip())
|
||||
ret[iface][wins_flag].append(line.strip())
|
||||
wins_flag = None
|
||||
continue
|
||||
except socket.error as exc:
|
||||
wins_flag = None
|
||||
|
||||
line = line.strip()
|
||||
if not line:
|
||||
iface = ''
|
||||
current_iface = None
|
||||
current_ip_list = None
|
||||
continue
|
||||
|
||||
if 'Configuration for interface' in line:
|
||||
_, iface = line.rstrip('"').split('"', 1) # get iface name
|
||||
ret[iface] = {}
|
||||
ip = 0
|
||||
current_iface = {}
|
||||
ret[iface] = current_iface
|
||||
continue
|
||||
try:
|
||||
key, val = line.split(':', 1)
|
||||
except ValueError as exc:
|
||||
log.debug('Could not split line. Error was {0}.'.format(exc))
|
||||
continue
|
||||
if 'DNS Servers' in line:
|
||||
dns_flag = key.strip()
|
||||
ret[iface][key.strip()] = [val.strip()]
|
||||
continue
|
||||
if 'WINS Servers' in line:
|
||||
wins_flag = key.strip()
|
||||
ret[iface][key.strip()] = [val.strip()]
|
||||
continue
|
||||
if 'IP Address' in key:
|
||||
if 'ip_addrs' not in ret[iface]:
|
||||
ret[iface]['ip_addrs'] = []
|
||||
ret[iface]['ip_addrs'].append(dict([(key.strip(), val.strip())]))
|
||||
continue
|
||||
if 'Subnet Prefix' in key:
|
||||
subnet, _, netmask = val.strip().split(' ', 2)
|
||||
ret[iface]['ip_addrs'][ip]['Subnet'] = subnet.strip()
|
||||
ret[iface]['ip_addrs'][ip]['Netmask'] = netmask.lstrip().rstrip(')')
|
||||
ip = ip + 1
|
||||
|
||||
if ':' not in line:
|
||||
if current_ip_list:
|
||||
current_ip_list.append(line)
|
||||
else:
|
||||
log.warning('Cannot parse "{0}"'.format(line))
|
||||
continue
|
||||
|
||||
key, val = line.split(':', 1)
|
||||
key = key.strip()
|
||||
val = val.strip()
|
||||
|
||||
lkey = key.lower()
|
||||
if ('dns servers' in lkey) or ('wins servers' in lkey):
|
||||
current_ip_list = []
|
||||
current_iface[key] = current_ip_list
|
||||
current_ip_list.append(val)
|
||||
|
||||
elif 'ip address' in lkey:
|
||||
current_iface.setdefault('ip_addrs', []).append({key: val})
|
||||
|
||||
elif 'subnet prefix' in lkey:
|
||||
subnet, _, netmask = val.split(' ', 2)
|
||||
last_ip = current_iface['ip_addrs'][-1]
|
||||
last_ip['Subnet'] = subnet.strip()
|
||||
last_ip['Netmask'] = netmask.lstrip().rstrip(')')
|
||||
|
||||
else:
|
||||
ret[iface][key.strip()] = val.strip()
|
||||
current_iface[key] = val
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -190,7 +190,7 @@ def _format_host(host, data):
|
||||
# Verify that the needed data is present
|
||||
data_tmp = {}
|
||||
for tname, info in six.iteritems(data):
|
||||
if isinstance(info, dict) and tname is not 'changes' and '__run_num__' not in info:
|
||||
if isinstance(info, dict) and tname is not 'changes' and info and '__run_num__' not in info:
|
||||
err = (u'The State execution failed to record the order '
|
||||
'in which all states were executed. The state '
|
||||
'return missing data is:')
|
||||
|
@ -36,7 +36,7 @@ def envs(backend=None, sources=False):
|
||||
salt-run fileserver.envs git
|
||||
'''
|
||||
fileserver = salt.fileserver.Fileserver(__opts__)
|
||||
return fileserver.envs(back=backend, sources=sources)
|
||||
return sorted(fileserver.envs(back=backend, sources=sources))
|
||||
|
||||
|
||||
def clear_file_list_cache(saltenv=None, backend=None):
|
||||
|
@ -412,6 +412,7 @@ def __get_artifact(salt_source):
|
||||
template=None,
|
||||
source=salt_source['source'],
|
||||
source_hash=None,
|
||||
source_hash_name=None,
|
||||
user=None,
|
||||
group=None,
|
||||
mode=None,
|
||||
|
@ -65,12 +65,12 @@ class WinShadowTestCase(TestCase):
|
||||
Test if it return configs for all interfaces.
|
||||
'''
|
||||
ret = {'Ethernet': {'DHCP enabled': 'Yes',
|
||||
'DNS servers configured through DHCP': '1.2.3.4',
|
||||
'DNS servers configured through DHCP': ['1.2.3.4'],
|
||||
'Default Gateway': '1.2.3.1',
|
||||
'Gateway Metric': '0',
|
||||
'InterfaceMetric': '20',
|
||||
'Register with which suffix': 'Primary only',
|
||||
'WINS servers configured through DHCP': 'None',
|
||||
'WINS servers configured through DHCP': ['None'],
|
||||
'ip_addrs': [{'IP Address': '1.2.3.74',
|
||||
'Netmask': '255.255.255.0',
|
||||
'Subnet': '1.2.3.0/24'}]}}
|
||||
@ -86,11 +86,11 @@ class WinShadowTestCase(TestCase):
|
||||
Test if it return the configuration of a network interface.
|
||||
'''
|
||||
ret = {'DHCP enabled': 'Yes',
|
||||
'DNS servers configured through DHCP': '1.2.3.4',
|
||||
'DNS servers configured through DHCP': ['1.2.3.4'],
|
||||
'Default Gateway': '1.2.3.1', 'Gateway Metric': '0',
|
||||
'InterfaceMetric': '20',
|
||||
'Register with which suffix': 'Primary only',
|
||||
'WINS servers configured through DHCP': 'None',
|
||||
'WINS servers configured through DHCP': ['None'],
|
||||
'ip_addrs': [{'IP Address': '1.2.3.74',
|
||||
'Netmask': '255.255.255.0',
|
||||
'Subnet': '1.2.3.0/24'}]}
|
||||
|
Loading…
Reference in New Issue
Block a user