diff --git a/neutron/services/metering/drivers/iptables/iptables_driver.py b/neutron/services/metering/drivers/iptables/iptables_driver.py index dd0ff16a34..fd61ace2ac 100644 --- a/neutron/services/metering/drivers/iptables/iptables_driver.py +++ b/neutron/services/metering/drivers/iptables/iptables_driver.py @@ -77,7 +77,7 @@ class RouterWithMetering(object): self.router = router self.root_helper = config.get_root_helper(self.conf) self.iptables_manager = iptables_manager.IptablesManager( - root_helper=self.conf.root_helper, + root_helper=self.root_helper, namespace=self.ns_name(), binary_name=WRAP_NAME) self.metering_labels = {} diff --git a/neutron/tests/unit/services/metering/drivers/test_iptables_driver.py b/neutron/tests/unit/services/metering/drivers/test_iptables_driver.py index 63654361f0..6064407e65 100644 --- a/neutron/tests/unit/services/metering/drivers/test_iptables_driver.py +++ b/neutron/tests/unit/services/metering/drivers/test_iptables_driver.py @@ -36,7 +36,7 @@ class IptablesDriverTestCase(base.BaseTestCase): self.addCleanup(self.utils_exec_p.stop) self.iptables_cls_p = mock.patch( 'neutron.agent.linux.iptables_manager.IptablesManager') - iptables_cls = self.iptables_cls_p.start() + self.iptables_cls = self.iptables_cls_p.start() self.addCleanup(self.iptables_cls_p.stop) self.iptables_inst = mock.Mock() self.v4filter_inst = mock.Mock() @@ -45,15 +45,31 @@ class IptablesDriverTestCase(base.BaseTestCase): self.v6filter_inst.chains = [] self.iptables_inst.ipv4 = {'filter': self.v4filter_inst} self.iptables_inst.ipv6 = {'filter': self.v6filter_inst} - iptables_cls.return_value = self.iptables_inst + self.iptables_cls.return_value = self.iptables_inst cfg.CONF.set_override('interface_driver', 'neutron.agent.linux.interface.NullDriver') - self.router_info_inst = mock.Mock() - self.router_info_inst.iptables_manager = self.iptables_inst - + cfg.CONF.set_override('root_helper', + 'fake_sudo', + 'AGENT') self.metering = iptables_driver.IptablesMeteringDriver('metering', cfg.CONF) + def test_root_helper(self): + routers = [{'_metering_labels': [ + {'id': 'c5df2fe5-c600-4a2a-b2f4-c0fb6df73c83', + 'rules': []}], + 'admin_state_up': True, + 'gw_port_id': '7d411f48-ecc7-45e0-9ece-3b5bdb54fcee', + 'id': '473ec392-1711-44e3-b008-3251ccfc5099', + 'name': 'router1', + 'status': 'ACTIVE', + 'tenant_id': '6c5f5d2a1fa2441e88e35422926f48e8'}] + self.metering.add_metering_label(None, routers) + + self.iptables_cls.assert_called_with(root_helper='fake_sudo', + namespace=mock.ANY, + binary_name=mock.ANY) + def test_add_metering_label(self): routers = [{'_metering_labels': [ {'id': 'c5df2fe5-c600-4a2a-b2f4-c0fb6df73c83',