def test__configure_veth(self): """Tests configuring container networking. """ # Access protected _configure_veth # pylint: disable=W0212 newnet._configure_veth( 'test1234', '192.168.0.100', '192.168.254.254' ) treadmill.netdev.link_set_up.assert_has_calls( [ mock.call('lo'), mock.call('eth0'), ] ) treadmill.netdev.dev_conf_arp_ignore_set.assert_called_with('eth0', 3) treadmill.netdev.addr_add.assert_called_with( '192.168.0.100/32', 'eth0', addr_scope='link' ) treadmill.netdev.route_add.assert_has_calls( [ mock.call( '192.168.254.254', devname='eth0', route_scope='link' ), mock.call( 'default', via='192.168.254.254', src='192.168.0.100', ) ] ) self.assertTrue(treadmill.iptables.initialize_container.called)
def test__configure_veth_service_ip(self): """Tests configuring container networking with service ip. """ # Access protected _configure_veth # pylint: disable=W0212 newnet._configure_veth( 'test1234', '192.168.0.100', '192.168.254.254', '10.0.0.1', ) treadmill.netdev.link_set_up.assert_has_calls( [ mock.call('lo'), mock.call('eth0'), ] ) treadmill.netdev.dev_conf_arp_ignore_set.assert_called_with('eth0', 3) treadmill.netdev.addr_add.assert_has_calls( [ mock.call('10.0.0.1/32', 'eth0', addr_scope='host'), mock.call('192.168.0.100/32', 'eth0', addr_scope='link'), ] ) treadmill.netdev.route_add.assert_has_calls( [ mock.call( '192.168.254.254', devname='eth0', route_scope='link' ), mock.call( 'default', via='192.168.254.254', src='10.0.0.1', ) ] ) self.assertTrue(treadmill.iptables.initialize_container.called) treadmill.iptables.add_raw_rule.assert_has_calls( [ mock.call('nat', 'PREROUTING', '-i eth0 -j DNAT --to-destination 10.0.0.1'), mock.call('nat', 'POSTROUTING', '-o eth0 -j SNAT --to-source 192.168.0.100'), ] )