mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
#39901: Add unit tests
This commit is contained in:
parent
613d500876
commit
43c81dfdee
@ -692,27 +692,21 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
|
||||
if 'ipaddrs' in opts:
|
||||
result['ipaddrs'] = []
|
||||
for opt in opts['ipaddrs']:
|
||||
try:
|
||||
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 address is invalid'
|
||||
log.error(msg)
|
||||
raise AttributeError(msg)
|
||||
except Exception:
|
||||
_raise_error_iface(iface, 'ipaddrs', ['127.0.0.1/8'])
|
||||
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']:
|
||||
try:
|
||||
if not salt.utils.validate.net.ipv6_addr(opt):
|
||||
msg = 'ipv6 address is invalid'
|
||||
log.error(msg)
|
||||
raise AttributeError(msg)
|
||||
result['ipv6addrs'] = opts['ipv6addrs']
|
||||
except Exception:
|
||||
_raise_error_iface(iface, 'ipv6addrs', ['fc00::1/128'])
|
||||
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']
|
||||
|
@ -62,7 +62,6 @@ class RhipTestCase(TestCase):
|
||||
'''
|
||||
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)
|
||||
@ -72,34 +71,54 @@ class RhipTestCase(TestCase):
|
||||
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