mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Added a bunch of unit tests for modules.debian_ip.build_interface().
This commit is contained in:
parent
b905cf6c12
commit
cf61c8d9cf
@ -174,6 +174,284 @@ class DebianIpTestCase(TestCase, LoaderModuleMockMixin):
|
||||
with patch.object(jinja2.Environment, 'get_template', mock):
|
||||
self.assertEqual(debian_ip.get_interface('lo'), '')
|
||||
|
||||
# 'build_interface' function tests: 12
|
||||
|
||||
def test_build_interface(self):
|
||||
'''
|
||||
Test if salt correctly builds interfaces.
|
||||
'''
|
||||
interfaces = [
|
||||
# IPv4-only interface; single address
|
||||
{'iface_name': 'eth1', 'iface_type': 'eth', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'ipaddr': '192.168.4.9',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '192.168.4.1',
|
||||
'enable_ipv6': False,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto eth1\n',
|
||||
'iface eth1 inet static\n',
|
||||
' address 192.168.4.9\n',
|
||||
' netmask 255.255.255.0\n',
|
||||
' gateway 192.168.4.1\n',
|
||||
'\n']},
|
||||
# IPv6-only; single address
|
||||
{'iface_name': 'eth2', 'iface_type': 'eth', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'ipv6proto': 'static',
|
||||
'ipv6ipaddr': '2001:db8:dead:beef::3',
|
||||
'ipv6netmask': '64',
|
||||
'ipv6gateway': '2001:db8:dead:beef::1',
|
||||
'enable_ipv6': True,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto eth2\n',
|
||||
'iface eth2 inet6 static\n',
|
||||
' address 2001:db8:dead:beef::3\n',
|
||||
' netmask 64\n',
|
||||
' gateway 2001:db8:dead:beef::1\n',
|
||||
'\n']},
|
||||
# IPv4 and IPv6; shared/overridden settings
|
||||
{'iface_name': 'eth3', 'iface_type': 'eth', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'ipaddr': '192.168.4.9',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '192.168.4.1',
|
||||
'ipv6proto': 'static',
|
||||
'ipv6ipaddr': '2001:db8:dead:beef::3',
|
||||
'ipv6netmask': '64',
|
||||
'ipv6gateway': '2001:db8:dead:beef::1',
|
||||
'ttl': '18', # shared
|
||||
'ipv6ttl': '15', # overriden for v6
|
||||
'mtu': '1480', # shared
|
||||
'enable_ipv6': True,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto eth3\n',
|
||||
'iface eth3 inet static\n',
|
||||
' address 192.168.4.9\n',
|
||||
' netmask 255.255.255.0\n',
|
||||
' gateway 192.168.4.1\n',
|
||||
' ttl 18\n',
|
||||
' mtu 1480\n',
|
||||
'iface eth3 inet6 static\n',
|
||||
' address 2001:db8:dead:beef::3\n',
|
||||
' netmask 64\n',
|
||||
' gateway 2001:db8:dead:beef::1\n',
|
||||
' ttl 15\n',
|
||||
' mtu 1480\n',
|
||||
'\n']},
|
||||
# Slave iface
|
||||
{'iface_name': 'eth4', 'iface_type': 'slave', 'enabled': True,
|
||||
'settings': {
|
||||
'master': 'bond0',
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto eth4\n',
|
||||
'iface eth4 inet manual\n',
|
||||
' bond-master bond0\n',
|
||||
'\n']},
|
||||
# Bond; with address IPv4 and IPv6 address; slaves as string
|
||||
{'iface_name': 'bond5', 'iface_type': 'bond', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'ipaddr': '10.1.0.14',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '10.1.0.1',
|
||||
'ipv6proto': 'static',
|
||||
'ipv6ipaddr': '2001:db8:dead:c0::3',
|
||||
'ipv6netmask': '64',
|
||||
'ipv6gateway': '2001:db8:dead:c0::1',
|
||||
'mode': '802.3ad',
|
||||
'slaves': 'eth4 eth5',
|
||||
'enable_ipv6': True,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto bond5\n',
|
||||
'iface bond5 inet static\n',
|
||||
' address 10.1.0.14\n',
|
||||
' netmask 255.255.255.0\n',
|
||||
' gateway 10.1.0.1\n',
|
||||
' bond-ad_select 0\n',
|
||||
' bond-downdelay 200\n',
|
||||
' bond-lacp_rate 0\n',
|
||||
' bond-miimon 100\n',
|
||||
' bond-mode 4\n',
|
||||
' bond-slaves eth4 eth5\n',
|
||||
' bond-updelay 0\n',
|
||||
' bond-use_carrier on\n',
|
||||
'iface bond5 inet6 static\n',
|
||||
' address 2001:db8:dead:c0::3\n',
|
||||
' netmask 64\n',
|
||||
' gateway 2001:db8:dead:c0::1\n',
|
||||
# TODO: I suspect there should be more here.
|
||||
'\n']},
|
||||
# Bond; with address IPv4 and IPv6 address; slaves as list
|
||||
{'iface_name': 'bond6', 'iface_type': 'bond', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'ipaddr': '10.1.0.14',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '10.1.0.1',
|
||||
'ipv6proto': 'static',
|
||||
'ipv6ipaddr': '2001:db8:dead:c0::3',
|
||||
'ipv6netmask': '64',
|
||||
'ipv6gateway': '2001:db8:dead:c0::1',
|
||||
'mode': '802.3ad',
|
||||
# TODO: Need to add this support
|
||||
#'slaves': ['eth4', 'eth5'],
|
||||
'slaves': 'eth4 eth5',
|
||||
'enable_ipv6': True,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto bond6\n',
|
||||
'iface bond6 inet static\n',
|
||||
' address 10.1.0.14\n',
|
||||
' netmask 255.255.255.0\n',
|
||||
' gateway 10.1.0.1\n',
|
||||
' bond-ad_select 0\n',
|
||||
' bond-downdelay 200\n',
|
||||
' bond-lacp_rate 0\n',
|
||||
' bond-miimon 100\n',
|
||||
' bond-mode 4\n',
|
||||
' bond-slaves eth4 eth5\n',
|
||||
' bond-updelay 0\n',
|
||||
' bond-use_carrier on\n',
|
||||
'iface bond6 inet6 static\n',
|
||||
' address 2001:db8:dead:c0::3\n',
|
||||
' netmask 64\n',
|
||||
' gateway 2001:db8:dead:c0::1\n',
|
||||
# TODO: I suspect there should be more here.
|
||||
'\n']},
|
||||
# Bond VLAN; with IPv4 address
|
||||
{'iface_name': 'bond1.7', 'iface_type': 'vlan', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'ipaddr': '10.7.0.8',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '10.7.0.1',
|
||||
'slaves': 'eth6 eth7',
|
||||
'mode': '802.3ad',
|
||||
'enable_ipv6': False,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto bond1.7\n',
|
||||
'iface bond1.7 inet static\n',
|
||||
' vlan-raw-device bond1\n',
|
||||
' address 10.7.0.8\n',
|
||||
' netmask 255.255.255.0\n',
|
||||
' gateway 10.7.0.1\n',
|
||||
' mode 802.3ad\n',
|
||||
'\n']},
|
||||
# Bond; without address
|
||||
{'iface_name': 'bond1.8', 'iface_type': 'vlan', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'slaves': 'eth6 eth7',
|
||||
'mode': '802.3ad',
|
||||
'enable_ipv6': False,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto bond1.8\n',
|
||||
'iface bond1.8 inet static\n',
|
||||
' vlan-raw-device bond1\n',
|
||||
' mode 802.3ad\n',
|
||||
'\n']},
|
||||
# DNS NS as list
|
||||
{'iface_name': 'eth9', 'iface_type': 'eth', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'ipaddr': '192.168.4.9',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '192.168.4.1',
|
||||
'enable_ipv6': False,
|
||||
'noifupdown': True,
|
||||
'dns': ['8.8.8.8', '8.8.4.4'],
|
||||
},
|
||||
'return': [
|
||||
'auto eth9\n',
|
||||
'iface eth9 inet static\n',
|
||||
' address 192.168.4.9\n',
|
||||
' netmask 255.255.255.0\n',
|
||||
' gateway 192.168.4.1\n',
|
||||
' dns-nameservers 8.8.8.8 8.8.4.4\n',
|
||||
'\n']},
|
||||
# DNS NS as string
|
||||
{'iface_name': 'eth10', 'iface_type': 'eth', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'static',
|
||||
'ipaddr': '192.168.4.9',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '192.168.4.1',
|
||||
'enable_ipv6': False,
|
||||
'noifupdown': True,
|
||||
'dns': '8.8.8.8 8.8.4.4',
|
||||
},
|
||||
'return': [
|
||||
'auto eth10\n',
|
||||
'iface eth10 inet static\n',
|
||||
' address 192.168.4.9\n',
|
||||
' netmask 255.255.255.0\n',
|
||||
' gateway 192.168.4.1\n',
|
||||
' dns-nameservers 8.8.8.8 8.8.4.4\n',
|
||||
'\n']},
|
||||
# Loopback; with IPv4 and IPv6 address
|
||||
{'iface_name': 'lo11', 'iface_type': 'loopback', 'enabled': True,
|
||||
'settings': {
|
||||
'proto': 'loopback',
|
||||
'ipaddr': '192.168.4.9',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '192.168.4.1',
|
||||
'ipv6ipaddr': 'fc00::1',
|
||||
'ipv6netmask': '128',
|
||||
'ipv6_autoconf': False,
|
||||
'enable_ipv6': True,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto lo11\n',
|
||||
'iface lo11 inet loopback\n',
|
||||
' address 192.168.4.9\n',
|
||||
' netmask 255.255.255.0\n',
|
||||
' gateway 192.168.4.1\n',
|
||||
'iface lo11 inet6 loopback\n',
|
||||
' address fc00::1\n',
|
||||
' netmask 128\n',
|
||||
'\n']},
|
||||
# Loopback; without address
|
||||
{'iface_name': 'lo12', 'iface_type': 'loopback', 'enabled': True,
|
||||
'settings': {
|
||||
'enable_ipv6': False,
|
||||
'noifupdown': True,
|
||||
},
|
||||
'return': [
|
||||
'auto lo12\n',
|
||||
'iface lo12 inet loopback\n',
|
||||
'\n']},
|
||||
]
|
||||
|
||||
for iface in interfaces:
|
||||
# Skip tests that require __salt__['pkg.install']()
|
||||
if iface['iface_type'] not in ['bridge', 'pppoe', 'vlan']:
|
||||
self.assertListEqual(debian_ip.build_interface(
|
||||
iface = iface['iface_name'],
|
||||
iface_type = iface['iface_type'],
|
||||
enabled = iface['enabled'],
|
||||
**iface['settings']),
|
||||
iface['return'])
|
||||
|
||||
# 'up' function tests: 1
|
||||
|
||||
def test_up(self):
|
||||
|
Loading…
Reference in New Issue
Block a user