mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge branch '2016.11' into '2017.7'
Conflicts: - tests/unit/modules/test_rh_ip.py
This commit is contained in:
commit
9fcc2a70b5
@ -689,9 +689,24 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
|
||||
if opt in opts:
|
||||
result[opt] = opts[opt]
|
||||
|
||||
for opt in ['ipaddrs', 'ipv6addrs']:
|
||||
if opt in opts:
|
||||
result[opt] = opts[opt]
|
||||
if 'ipaddrs' in opts:
|
||||
result['ipaddrs'] = []
|
||||
for opt in opts['ipaddrs']:
|
||||
if salt.utils.validate.net.ipv4_addr(opt):
|
||||
ip, prefix = [i.strip() for i in opt.split('/')]
|
||||
result['ipaddrs'].append({'ipaddr': ip, 'prefix': prefix})
|
||||
else:
|
||||
msg = 'ipv4 CIDR is invalid'
|
||||
log.error(msg)
|
||||
raise AttributeError(msg)
|
||||
|
||||
if 'ipv6addrs' in opts:
|
||||
for opt in opts['ipv6addrs']:
|
||||
if not salt.utils.validate.net.ipv6_addr(opt):
|
||||
msg = 'ipv6 CIDR is invalid'
|
||||
log.error(msg)
|
||||
raise AttributeError(msg)
|
||||
result['ipv6addrs'] = opts['ipv6addrs']
|
||||
|
||||
if 'enable_ipv6' in opts:
|
||||
result['enable_ipv6'] = opts['enable_ipv6']
|
||||
|
@ -19,12 +19,17 @@ DEVICE="{{name}}"
|
||||
{%endif%}{% if ipaddr_end %}IPADDR_END="{{ipaddr_end}}"
|
||||
{%endif%}{% if netmask %}NETMASK="{{netmask}}"
|
||||
{%endif%}{% if prefix %}PREFIX="{{prefix}}"
|
||||
{%endif%}{% if ipaddrs %}{% for i in ipaddrs -%}
|
||||
IPADDR{{loop.index}}="{{i['ipaddr']}}"
|
||||
PREFIX{{loop.index}}="{{i['prefix']}}"
|
||||
{% endfor -%}
|
||||
{%endif%}{% if gateway %}GATEWAY="{{gateway}}"
|
||||
{%endif%}{% if enable_ipv6 %}IPV6INIT="yes"
|
||||
{% if ipv6_autoconf %}IPV6_AUTOCONF="{{ipv6_autoconf}}"
|
||||
{%endif%}{% if dhcpv6c %}DHCPV6C="{{dhcpv6c}}"
|
||||
{%endif%}{% if ipv6addr %}IPV6ADDR="{{ipv6addr}}"
|
||||
{%endif%}{% if ipv6gateway %}IPV6_DEFAULTGW="{{ipv6gateway}}"
|
||||
{%endif%}{% if ipv6addrs %}IPV6ADDR_SECONDARIES="{{ ipv6addrs|join(' ') }}"
|
||||
{%endif%}{% if ipv6_peerdns %}IPV6_PEERDNS="{{ipv6_peerdns}}"
|
||||
{%endif%}{% if ipv6_defroute %}IPV6_DEFROUTE="{{ipv6_defroute}}"
|
||||
{%endif%}{% if ipv6_peerroutes %}IPV6_PEERROUTES="{{ipv6_peerroutes}}"
|
||||
|
@ -16,6 +16,7 @@ from tests.support.mock import (
|
||||
patch)
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.ext.six.moves import range
|
||||
import salt.modules.rh_ip as rh_ip
|
||||
|
||||
# Import 3rd-party libs
|
||||
@ -60,7 +61,6 @@ class RhipTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
with patch.dict(rh_ip.__grains__, {'os': 'Fedora'}):
|
||||
with patch.object(rh_ip, '_raise_error_iface', return_value=None):
|
||||
|
||||
self.assertRaises(AttributeError,
|
||||
rh_ip.build_interface,
|
||||
'iface', 'slave', True)
|
||||
@ -70,34 +70,53 @@ class RhipTestCase(TestCase, LoaderModuleMockMixin):
|
||||
rh_ip.build_interface,
|
||||
'iface', 'eth', True, netmask='255.255.255.255', prefix=32,
|
||||
test=True)
|
||||
self.assertRaises(AttributeError,
|
||||
rh_ip.build_interface,
|
||||
'iface', 'eth', True, ipaddrs=['A'],
|
||||
test=True)
|
||||
self.assertRaises(AttributeError,
|
||||
rh_ip.build_interface,
|
||||
'iface', 'eth', True, ipv6addrs=['A'],
|
||||
test=True)
|
||||
|
||||
with patch.object(rh_ip, '_parse_settings_bond', MagicMock()):
|
||||
mock = jinja2.exceptions.TemplateNotFound('foo')
|
||||
with patch.object(jinja2.Environment,
|
||||
'get_template',
|
||||
MagicMock(side_effect=mock)):
|
||||
self.assertEqual(rh_ip.build_interface('iface',
|
||||
'vlan',
|
||||
True), '')
|
||||
|
||||
with patch.object(rh_ip, '_read_temp', return_value='A'):
|
||||
for osrelease in range(5, 8):
|
||||
with patch.dict(rh_ip.__grains__, {'os': 'RedHat', 'osrelease': str(osrelease)}):
|
||||
with patch.object(rh_ip, '_raise_error_iface', return_value=None):
|
||||
with patch.object(rh_ip, '_parse_settings_bond', MagicMock()):
|
||||
mock = jinja2.exceptions.TemplateNotFound('foo')
|
||||
with patch.object(jinja2.Environment,
|
||||
'get_template', MagicMock()):
|
||||
'get_template',
|
||||
MagicMock(side_effect=mock)):
|
||||
self.assertEqual(rh_ip.build_interface('iface',
|
||||
'vlan',
|
||||
True,
|
||||
test='A'),
|
||||
'A')
|
||||
True), '')
|
||||
|
||||
with patch.object(rh_ip, '_write_file_iface',
|
||||
return_value=None):
|
||||
with patch.object(os.path, 'join',
|
||||
return_value='A'):
|
||||
with patch.object(rh_ip, '_read_file',
|
||||
with patch.object(rh_ip, '_read_temp', return_value='A'):
|
||||
with patch.object(jinja2.Environment,
|
||||
'get_template', MagicMock()):
|
||||
self.assertEqual(rh_ip.build_interface('iface',
|
||||
'vlan',
|
||||
True,
|
||||
test='A'),
|
||||
'A')
|
||||
|
||||
with patch.object(rh_ip, '_write_file_iface',
|
||||
return_value=None):
|
||||
with patch.object(os.path, 'join',
|
||||
return_value='A'):
|
||||
self.assertEqual(rh_ip.build_interface
|
||||
('iface', 'vlan',
|
||||
True), 'A')
|
||||
with patch.object(rh_ip, '_read_file',
|
||||
return_value='A'):
|
||||
self.assertEqual(rh_ip.build_interface
|
||||
('iface', 'vlan',
|
||||
True), 'A')
|
||||
if osrelease > 6:
|
||||
with patch.dict(rh_ip.__salt__, {'network.interfaces': lambda: {'eth': True}}):
|
||||
self.assertEqual(rh_ip.build_interface
|
||||
('iface', 'eth', True,
|
||||
ipaddrs=['127.0.0.1/8']), 'A')
|
||||
self.assertEqual(rh_ip.build_interface
|
||||
('iface', 'eth', True,
|
||||
ipv6addrs=['fc00::1/128']), 'A')
|
||||
|
||||
def test_build_routes(self):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user