diff --git a/akanda/router/drivers/bird.py b/akanda/router/drivers/bird.py index 3e98f9b..858c255 100644 --- a/akanda/router/drivers/bird.py +++ b/akanda/router/drivers/bird.py @@ -42,11 +42,11 @@ class BirdManager(base.Manager): def restart(self): try: - utils.execute(['/etc/rc.d/bird6', 'check'], self.root_helper) + utils.execute(['/etc/init.d/bird6', 'status'], self.root_helper) except: # pragma no cover - utils.execute(['/etc/rc.d/bird6', 'start'], self.root_helper) + utils.execute(['/etc/init.d/bird6', 'start'], self.root_helper) else: # pragma no cover - utils.execute(['/etc/rc.d/bird6', 'reload'], self.root_helper) + utils.execute(['/etc/init.d/bird6', 'reload'], self.root_helper) def build_config(config, interface_map): diff --git a/akanda/router/drivers/dnsmasq.py b/akanda/router/drivers/dnsmasq.py index 14518bb..057548e 100644 --- a/akanda/router/drivers/dnsmasq.py +++ b/akanda/router/drivers/dnsmasq.py @@ -25,7 +25,7 @@ from akanda.router import utils LOG = logging.getLogger(__name__) CONF_DIR = '/etc/dnsmasq.d' -RC_PATH = '/etc/rc.d/dnsmasq' +RC_PATH = '/etc/init.d/dnsmasq' DEFAULT_LEASE = 86400 @@ -90,7 +90,7 @@ class DHCPManager(base.Manager): def restart(self): try: - utils.execute(['/etc/rc.d/dnsmasq', 'stop'], self.root_helper) + utils.execute(['/etc/init.d/dnsmasq', 'stop'], self.root_helper) except: pass @@ -99,7 +99,7 @@ class DHCPManager(base.Manager): while remaining: remaining -= 1 try: - utils.execute(['/etc/rc.d/dnsmasq', 'start'], self.root_helper) + utils.execute(['/etc/init.d/dnsmasq', 'start'], self.root_helper) return except Exception: if remaining <= 0: diff --git a/akanda/router/drivers/ifconfig.py b/akanda/router/drivers/ifconfig.py index eca194c..5a0ea31 100644 --- a/akanda/router/drivers/ifconfig.py +++ b/akanda/router/drivers/ifconfig.py @@ -15,6 +15,7 @@ # under the License. +import functools import re import netaddr @@ -111,14 +112,17 @@ class InterfaceManager(base.Manager): self.sudo(real_ifname, 'description', interface.description) def _update_addresses(self, real_ifname, interface, old_interface): - family = {4: 'inet', 6: 'inet6'} - add = lambda a: ( - real_ifname, family[a[0].version], 'add', '%s/%s' % (a[0], a[1]) - ) - delete = lambda a: ( - real_ifname, family[a[0].version], 'del', '%s/%s' % (a[0], a[1]) - ) + def _gen_cmd(cmd, address): + family = {4: 'inet', 6: 'inet6'}[address[0].version] + args = [real_ifname, family] + if family == 'inet6': + args.append(cmd) + args.append('%s/%s' % (address[0], address[1])) + return args + + add = functools.partial(_gen_cmd, 'add') + delete = functools.partial(_gen_cmd, 'del') mutator = lambda a: (a.ip, a.prefixlen) self._update_set(real_ifname, interface, old_interface, diff --git a/akanda/router/drivers/metadata.py b/akanda/router/drivers/metadata.py index acfe1db..1822a28 100644 --- a/akanda/router/drivers/metadata.py +++ b/akanda/router/drivers/metadata.py @@ -55,7 +55,7 @@ class MetadataManager(base.Manager): def ensure_started(self): try: - execute(['/etc/rc.d/metadata', 'check'], self.root_helper) + execute(['/etc/rc.d/metadata', 'status'], self.root_helper) except: execute(['/etc/rc.d/metadata', 'start'], self.root_helper) diff --git a/test/unit/drivers/test_bird.py b/test/unit/drivers/test_bird.py index e411c30..c858ea2 100644 --- a/test/unit/drivers/test_bird.py +++ b/test/unit/drivers/test_bird.py @@ -96,17 +96,17 @@ class BirdTestCase(TestCase): def test_restart(self): self.mgr.restart() self.mock_execute.assert_has_calls([ - mock.call(['/etc/rc.d/bird6', 'check'], 'sudo'), - mock.call(['/etc/rc.d/bird6', 'reload'], 'sudo'), + mock.call(['/etc/init.d/bird6', 'status'], 'sudo'), + mock.call(['/etc/init.d/bird6', 'reload'], 'sudo'), ]) def test_restart_failure(self): with mock.patch('akanda.router.utils.execute') as execute: - execute.side_effect = [Exception('check failed!'), None] + execute.side_effect = [Exception('status failed!'), None] self.mgr.restart() execute.assert_has_calls([ - mock.call(['/etc/rc.d/bird6', 'check'], 'sudo'), - mock.call(['/etc/rc.d/bird6', 'start'], 'sudo'), + mock.call(['/etc/init.d/bird6', 'status'], 'sudo'), + mock.call(['/etc/init.d/bird6', 'start'], 'sudo'), ]) def test_build_config(self): diff --git a/test/unit/drivers/test_dnsmasq.py b/test/unit/drivers/test_dnsmasq.py index 23c280d..c6eb568 100644 --- a/test/unit/drivers/test_dnsmasq.py +++ b/test/unit/drivers/test_dnsmasq.py @@ -136,6 +136,6 @@ class DnsmasqTestCase(TestCase): def test_restart(self): self.mgr.restart() self.mock_execute.assert_has_calls([ - mock.call(['/etc/rc.d/dnsmasq', 'stop'], 'sudo'), - mock.call(['/etc/rc.d/dnsmasq', 'start'], 'sudo') + mock.call(['/etc/init.d/dnsmasq', 'stop'], 'sudo'), + mock.call(['/etc/init.d/dnsmasq', 'start'], 'sudo') ]) diff --git a/test/unit/drivers/test_ifconfig.py b/test/unit/drivers/test_ifconfig.py index b4699e0..58b1ec3 100644 --- a/test/unit/drivers/test_ifconfig.py +++ b/test/unit/drivers/test_ifconfig.py @@ -269,6 +269,34 @@ class IfconfigTestCase(TestCase): mock.ANY ) + def test_address_add(self): + cmd = '/sbin/ifconfig' + v4 = netaddr.IPNetwork('172.16.27.13/24') + v6 = netaddr.IPNetwork('fdca:3ba5:a17a:acda:20c:29ff:fe94:723d/64') + iface = mock.Mock(all_addresses=[v4, v6]) + old_iface = mock.Mock(all_addresses=[]) + + mgr = ifconfig.InterfaceManager() + mgr._update_addresses('em0', iface, old_iface) + assert self.mock_execute.call_args_list == [ + mock.call([cmd, 'em0', 'inet', str(v4)], 'sudo'), + mock.call([cmd, 'em0', 'inet6', 'add', str(v6)], 'sudo'), + ] + + def test_address_remove(self): + cmd = '/sbin/ifconfig' + v4 = netaddr.IPNetwork('172.16.27.13/24') + v6 = netaddr.IPNetwork('fdca:3ba5:a17a:acda:20c:29ff:fe94:723d/64') + iface = mock.Mock(all_addresses=[]) + old_iface = mock.Mock(all_addresses=[v4, v6]) + + mgr = ifconfig.InterfaceManager() + mgr._update_addresses('em0', iface, old_iface) + assert self.mock_execute.call_args_list == [ + mock.call([cmd, 'em0', 'inet', str(v4)], 'sudo'), + mock.call([cmd, 'em0', 'inet6', 'del', str(v6)], 'sudo'), + ] + def test_update_set(self): iface = mock.Mock() iface.all_addresses = ['a', 'b']