def test_interface_update(): """ Test update method on ConfigInterface """ bridge1 = ConfigInterface() bridge1.name = "lan" bridge1.proto = "static" bridge1.ifname = ["eth1", "eth2"] bridge1.type = "bridge" bridge1.ipaddr = "192.168.1.2" bridge1.netmask = "255.255.255.0" bridge1.gateway = "192.168.1.1" bridge1.setup() # Test removing one interface and adding another. bridge2 = bridge1.copy() bridge2.ifname = ["eth2", "eth3"] commands = bridge1.updateRevert(bridge2, {}) commands.extend(bridge1.updateApply(bridge2, {})) for cmd in commands: print(cmd) assert len(commands) == 6 # Should be removing eth1, adding eth3, and doing nothing to eth2. assert in_commands("ip link set dev eth1 nomaster", commands) assert in_commands("ip link set dev eth3 master br-lan", commands) assert not in_commands("eth2", commands) # Test changing the IP address and gateway. bridge3 = bridge2.copy() bridge3.ipaddr = "192.168.2.2" bridge3.gateway = "192.168.2.1" commands = bridge2.updateRevert(bridge3, {}) commands.extend(bridge2.updateApply(bridge3, {})) print("---") for cmd in commands: print(cmd) assert len(commands) == 3 # Test making a change that requires doing a complete reload of the config # section. bridge4 = bridge3.copy() bridge4.proto = "dhcp" commands = bridge4.updateRevert(bridge3, {}) commands.extend(bridge4.updateApply(bridge3, {})) print("---") for cmd in commands: print(cmd) assert len(commands) == 14