def test_acquire_non_ifcfg_nic(self, mock_kill, mock_flush, mock_iface): mock_iface.return_value.exists.return_value = True with ifacquire.Transaction(netinfo_nets={}) as a: a.acquire(ifaces=[NIC_NAME]) mock_kill.assert_any_call(NIC_NAME, family=4) mock_kill.assert_any_call(NIC_NAME, family=6) mock_flush.assert_called_with(NIC_NAME)
def test_acquire_non_ifcfg_nic(self, mock_kill, mock_flush): with ifacquire.Transaction(netinfo_nets={}) as a: a.acquire(ifaces=[NIC_NAME]) mock_kill.assert_any_call(NIC_NAME, family=4) mock_kill.assert_any_call(NIC_NAME, family=6) mock_flush.assert_called_with(NIC_NAME)
def test_do_not_acquire_owned_nic(self, mock_open, mock_ifdown, mock_kill, mock_flush): with ifacquire.Transaction(netinfo_nets=NETINFO_NETS) as a: a.acquire(ifaces=[NIC_NAME]) mock_open.assert_not_called() mock_ifdown.assert_not_called() mock_kill.assert_not_called() mock_flush.assert_not_called()
def test_rollback_acquired_ifcfg_nic(self, mock_atomic_write, mock_open, mock_ifup): open_file = mock_open() atomic_write_file = mock_atomic_write() open_file.readlines.return_value = NIC_IFCFG atomic_write_file.readlines.return_value = NIC_IFCFG with self.assertRaises(TestException): with ifacquire.Transaction(netinfo_nets={}) as a: a.acquire(ifaces=[NIC_NAME]) raise TestException() atomic_write_file.writelines.assert_called_with(NIC_IFCFG) mock_ifup.assert_called_with(NIC_NAME)
def _setup_ovs(networks, bondings, options, net_info, in_rollback): _ovs_info = ovs_info.OvsInfo() ovs_nets = ovs_info.create_netinfo(_ovs_info)['networks'] nets2add, nets2edit, nets2remove = _split_setup_actions(networks, ovs_nets) bonds2add, bonds2edit, bonds2remove = _split_setup_actions( bondings, net_info['bondings']) # TODO: If a nework is to be edited, we remove it and recreate again. # We should implement editation. nets2add.update(nets2edit) nets2remove.update(nets2edit) # FIXME: we are not able to move a nic from bond to network in one setup with Transaction(in_rollback=in_rollback) as config: setup_bonds = SetupBonds(bonds2add, bonds2edit, bonds2remove, config) with ifacquire.Transaction(ovs_nets) as acq: _remove_networks(nets2remove, _ovs_info, config) setup_bonds.remove_bonds() # Post removal of nets, update ovs_nets. ovs_nets = ovs_info.create_netinfo(_ovs_info)['networks'] kernel_bonds = bond.Bond.bonds() validator.validate_nic_usage( nets2add, bonds2add, _get_kernel_nets_nics(ovs_nets, kernel_bonds), _get_kernel_bonds_slaves(kernel_bonds), ) acq.acquire(setup_bonds.ifaces_for_acquirement) setup_bonds.edit_bonds() setup_bonds.add_bonds() _add_networks(nets2add, _ovs_info, config, acq) ovs_switch.update_network_to_bridge_mappings(ovs_info.OvsInfo()) setup_ipv6autoconf(networks) set_ovs_links_up(nets2add, bonds2add, bonds2edit) setup_ovs_ip_config(nets2add, nets2remove) _setup_ovs_dns(nets2add) connectivity.check(options)
def _test_acquire_ifcfg_nic(self, mock_atomic_write, mock_open, mock_ifdown, original_ifcfg, ifcfg_after_turn_down, ifcfg_after_disable_onboot): open_file = mock_open() atomic_write_file = mock_atomic_write() open_file.readlines.return_value = original_ifcfg atomic_write_file.readlines.return_value = original_ifcfg with ifacquire.Transaction(netinfo_nets={}) as a: a.acquire(ifaces=[NIC_NAME]) atomic_write_file.writelines.assert_called_with( ifcfg_after_turn_down) atomic_write_file.readlines.return_value = ifcfg_after_turn_down mock_ifdown.assert_called_with(NIC_NAME) atomic_write_file.writelines.assert_called_with( ifcfg_after_disable_onboot)