def test_parse_deb_config_data_commands(self): contents = dedent("""\ iface eth0 inet manual pre-up preup1 pre-up preup2 up up1 post-up postup1 pre-down predown1 down down1 down down2 post-down postdown1 """) ifaces = {} net.parse_deb_config_data(ifaces, contents, '', '/etc/network/interfaces') self.assertEqual( { 'eth0': { 'auto': False, 'family': 'inet', 'method': 'manual', 'pre-up': ['preup1', 'preup2'], 'up': ['up1'], 'post-up': ['postup1'], 'pre-down': ['predown1'], 'down': ['down1', 'down2'], 'post-down': ['postdown1'], '_source_path': '/etc/network/interfaces', }, }, ifaces)
def test_parse_deb_config_data_bond(self): contents = dedent("""\ iface eth0 inet manual bond-master bond0 bond-primary eth0 bond-mode active-backup iface eth1 inet manual bond-master bond0 bond-primary eth0 bond-mode active-backup iface bond0 inet static address 192.168.1.1 netmask 255.255.255.0 bond-slaves none bond-primary eth0 bond-mode active-backup bond-miimon 100 """) ifaces = {} net.parse_deb_config_data(ifaces, contents, '', '/etc/network/interfaces') self.assertEqual( { 'eth0': { 'auto': False, 'family': 'inet', 'method': 'manual', 'bond': { 'master': 'bond0', 'primary': 'eth0', 'mode': 'active-backup', }, '_source_path': '/etc/network/interfaces', }, 'eth1': { 'auto': False, 'family': 'inet', 'method': 'manual', 'bond': { 'master': 'bond0', 'primary': 'eth0', 'mode': 'active-backup', }, '_source_path': '/etc/network/interfaces', }, 'bond0': { 'auto': False, 'family': 'inet', 'method': 'static', 'address': '192.168.1.1', 'netmask': '255.255.255.0', 'bond': { 'slaves': 'none', 'primary': 'eth0', 'mode': 'active-backup', 'miimon': '100', }, '_source_path': '/etc/network/interfaces', }, }, ifaces)
def test_parse_deb_config_data_auto(self): contents = dedent("""\ auto eth0 eth1 iface eth0 inet manual iface eth1 inet manual """) ifaces = {} net.parse_deb_config_data(ifaces, contents, '', '/etc/network/interfaces') self.assertEqual( { 'eth0': { 'auto': True, 'control': 'auto', 'family': 'inet', 'method': 'manual', '_source_path': '/etc/network/interfaces', }, 'eth1': { 'auto': True, 'family': 'inet', 'control': 'auto', 'method': 'manual', '_source_path': '/etc/network/interfaces', }, }, ifaces)
def test_parse_deb_config_data_ignores_comments(self): contents = dedent("""\ # ignore # iface eth0 inet static # address 192.168.1.1 """) ifaces = {} net.parse_deb_config_data(ifaces, contents, '', '') self.assertEqual({}, ifaces)
def test_parse_deb_config_data_bridge(self): contents = dedent("""\ iface eth0 inet manual iface eth1 inet manual iface br0 inet static address 192.168.1.1 netmask 255.255.255.0 bridge_maxwait 30 bridge_ports eth0 eth1 bridge_pathcost eth0 1 bridge_pathcost eth1 2 bridge_portprio eth0 0 bridge_portprio eth1 1 """) ifaces = {} net.parse_deb_config_data(ifaces, contents, '', '/etc/network/interfaces') self.assertEqual( { 'eth0': { 'auto': False, 'family': 'inet', 'method': 'manual', '_source_path': '/etc/network/interfaces', }, 'eth1': { 'auto': False, 'family': 'inet', 'method': 'manual', '_source_path': '/etc/network/interfaces', }, 'br0': { 'auto': False, 'family': 'inet', 'method': 'static', 'address': '192.168.1.1', 'netmask': '255.255.255.0', 'bridge': { 'maxwait': '30', 'ports': ['eth0', 'eth1'], 'pathcost': { 'eth0': '1', 'eth1': '2', }, 'portprio': { 'eth0': '0', 'eth1': '1' }, }, '_source_path': '/etc/network/interfaces', }, }, ifaces)
def make_config(self, path=None, name=None, contents=None, parse=True): if path is None: path = self.target if name is None: name = 'interfaces' path = os.path.join(path, name) if contents is None: contents = dedent("""\ auto eth0 iface eth0 inet static address 192.168.1.2 netmask 255.255.255.0 hwaddress aa:bb:cc:dd:ee:ff """) with open(path, 'w') as stream: stream.write(contents) ifaces = None if parse: ifaces = {} net.parse_deb_config_data(ifaces, contents, '', path) return path, ifaces
def test_parse_deb_config_data_basic(self): contents = dedent("""\ iface eth0 inet static address 192.168.1.2 netmask 255.255.255.0 hwaddress aa:bb:cc:dd:ee:ff """) ifaces = {} net.parse_deb_config_data(ifaces, contents, '', '/etc/network/interfaces') self.assertEqual( { 'eth0': { 'auto': False, 'family': 'inet', 'method': 'static', 'address': '192.168.1.2', 'netmask': '255.255.255.0', 'hwaddress': 'aa:bb:cc:dd:ee:ff', '_source_path': '/etc/network/interfaces', }, }, ifaces)
def test_parse_deb_config_data_dns(self): contents = dedent("""\ iface eth0 inet static dns-nameservers 192.168.1.1 192.168.1.2 dns-search curtin local """) ifaces = {} net.parse_deb_config_data(ifaces, contents, '', '/etc/network/interfaces') self.assertEqual( { 'eth0': { 'auto': False, 'family': 'inet', 'method': 'static', 'dns': { 'nameservers': ['192.168.1.1', '192.168.1.2'], 'search': ['curtin', 'local'], }, '_source_path': '/etc/network/interfaces', }, }, ifaces)