def test_bond_edit_failure_on_slave_add(self): with dummy_devices(2) as (nic1, nic2): with bond_device() as base_bond, bond_device() as edit_bond: base_bond.add_slaves((nic1, )) edit_bond.add_slaves((nic2, )) with self.assertRaises(IOError): with Bond(edit_bond.master) as broken_bond: self.assertTrue(broken_bond.exists()) broken_bond.add_slaves((nic1, )) self.assertTrue(edit_bond.exists()) self.assertEqual(set((nic2, )), edit_bond.slaves)
def test_ovs_info_with_sb_bond(self): with dummy_device() as nic: with bond_device([nic]) as bond: with _setup_ovs_network(self.ovsdb, bond): expected_bridges = { TEST_BRIDGE: { 'stp': False, 'dpdk_enabled': False, 'ports': { TEST_VLANED_NETWORK: { 'level': info.NORTHBOUND, 'tag': TEST_VLAN, }, TEST_BRIDGE: { 'level': None, 'tag': None }, bond: { 'level': info.SOUTHBOUND, 'tag': None }, }, } } ovs_info = info.OvsInfo() obtained_bridges = ovs_info.bridges self.assertEqual(obtained_bridges, expected_bridges) obtained_bridges_by_sb = ovs_info.bridges_by_sb self.assertEqual(obtained_bridges_by_sb, {bond: TEST_BRIDGE})
def test_ovs_info_with_sb_bond(self): with dummy_device() as nic: with bond_device([nic]) as bond: with _setup_ovs_network(self.ovsdb, bond): expected_bridges = { TEST_BRIDGE: { 'stp': False, 'dpdk_enabled': False, 'ports': { TEST_VLANED_NETWORK: { 'level': info.NORTHBOUND, 'tag': TEST_VLAN }, TEST_BRIDGE: { 'level': None, 'tag': None }, bond: { 'level': info.SOUTHBOUND, 'tag': None } } } } ovs_info = info.OvsInfo() obtained_bridges = ovs_info.bridges self.assertEqual(obtained_bridges, expected_bridges) obtained_bridges_by_sb = ovs_info.bridges_by_sb self.assertEqual(obtained_bridges_by_sb, {bond: TEST_BRIDGE})
def test_bond_devices_are_up(self): with dummy_devices(2) as (nic1, nic2): with bond_device() as bond: bond.add_slaves((nic1, nic2)) bond.up() self.assertTrue(iface(nic1).is_up()) self.assertTrue(iface(nic2).is_up()) self.assertTrue(iface(bond.master).is_up())
def test_bond_set_one_arp_ip_target(self): OPTIONS = { 'mode': '1', 'arp_interval': '1000', 'arp_ip_target': '192.168.122.1', } with bond_device() as bond: bond.set_options(OPTIONS) bond.refresh() self.assertEqual(bond.options, OPTIONS)
def test_bond_create_failure_on_slave_add(self): with dummy_devices(2) as (nic1, nic2): with bond_device() as base_bond: base_bond.add_slaves((nic1, nic2)) bond_name = random_iface_name('bond_', max_length=11) with self.assertRaises(IOError): with Bond(bond_name) as broken_bond: broken_bond.create() broken_bond.add_slaves((nic1, nic2)) self.assertFalse(Bond(bond_name).exists())
def test_do_not_detach_slaves_while_changing_options(self): OPTIONS = {'miimon': '110'} with dummy_devices(2) as (nic1, nic2): with bond_device() as bond: bond.add_slaves((nic1, nic2)) mock_slaves = bond.del_slaves = bond.add_slaves = mock.Mock() bond.set_options(OPTIONS) mock_slaves.assert_not_called()
def test_bond_exists(self): OPTIONS = {'mode': '1', 'miimon': '300'} with dummy_devices(2) as (nic1, nic2): with bond_device() as _bond: _bond.set_options(OPTIONS) _bond.add_slaves((nic1, nic2)) _bond.up() bond = Bond(_bond.master) self.assertEqual(bond.slaves, set((nic1, nic2))) self.assertEqual(bond.options, OPTIONS)
def test_bond_monitor(self, nics): notifier = FakeNotifier() with bond_device(slaves=nics) as bond: bond.set_options({'mode': '1'}) bond.up() bond.set_options({'active_slave': nics[0]}) bond_monitor.initialize_monitor(notifier) try: bond.set_options({'active_slave': nics[1]}) _wait_until(lambda: notifier.calls) finally: bond_monitor.stop() assert notifier.calls == [('|net|host_conn|no_id', None)]
def test_bond_set_two_arp_ip_targets(self): OPTIONS = { 'mode': '1', 'arp_interval': '1000', 'arp_ip_target': '10.1.3.1,10.1.2.1', } with bond_device() as bond: bond.set_options(OPTIONS) bond.refresh() self.assertEqual( _sorted_arp_ip_target(bond.options), _sorted_arp_ip_target(OPTIONS), )
def test_bond_monitor(self): notifier = FakeNotifier() with dummy_devices(2) as (nic1, nic2): with bond_device(slaves=(nic1, nic2)) as bond: bond.set_options({'mode': '1'}) bond.up() bond.set_options({'active_slave': nic1}) bond_monitor.initialize_monitor(notifier) try: bond.set_options({'active_slave': nic2}) _wait_until(lambda: notifier.calls) finally: bond_monitor.stop() self.assertEqual(notifier.calls, [('|net|host_conn|no_id', None)])
def test_bond_edit_options(self): OPTIONS_A = {'mode': '1', 'miimon': '300'} OPTIONS_B = {'mode': '2'} OPTIONS_C = {'mode': 'balance-rr', 'miimon': '150'} with dummy_devices(2) as (nic1, nic2): with bond_device() as bond: bond.set_options(OPTIONS_A) bond.add_slaves((nic1, nic2)) _bond = Bond(bond.master) self.assertEqual(_bond.options, OPTIONS_A) bond.set_options(OPTIONS_B) _bond.refresh() self.assertEqual(_bond.options, OPTIONS_B) bond.set_options(OPTIONS_C) _bond.refresh() OPTIONS_C['mode'] = '0' self.assertEqual(_bond.options, OPTIONS_C)
def test_bond_update_existing_arp_ip_targets(self): preserved_addr = '10.1.4.1' removed_addr = '10.1.3.1,10.1.2.1' added_addr = '10.1.1.1' OPTIONS_A = { 'mode': '1', 'arp_interval': '1000', 'arp_ip_target': ','.join([preserved_addr, removed_addr]), } OPTIONS_B = { 'mode': '1', 'arp_interval': '1000', 'arp_ip_target': ','.join([preserved_addr, added_addr]), } with dummy_devices(2) as (nic1, nic2): with bond_device() as bond: bond.set_options(OPTIONS_A) bond.set_options(OPTIONS_B) bond.refresh() self.assertEqual(bond.options, OPTIONS_B)
def _bond_device_master(slaves): with nettestlib.bond_device(slaves) as bond: yield bond.master
def bond0(nics): with bond_device(nics) as bond: bond.up() yield bond
def test_bond_properties_with_filter(self): with bond_device() as bond: properties = sysfs_options.properties(bond.master, filter_properties=('mode', )) self.assertTrue('mode' in properties) self.assertEqual(1, len(properties))
def bond0(nics): with bond_device(nics) as bond: yield bond
def bond0_with_slaves(nic0, nic1): slaves = [nic0, nic1] with bond_device(slaves) as bond: yield bond, slaves
def _bond_device_master(slaves): with bond_device(slaves) as bond: yield bond
def test_bond_properties_with_filter_out(self): with bond_device() as bond: properties = sysfs_options.properties( bond.master, filter_out_properties=('mode', )) self.assertTrue('mode' not in properties) self.assertGreater(len(properties), 1)
def test_bond_without_slaves(self): with bond_device() as bond: self.assertFalse(iface(bond.master).is_up())
def test_bond_properties_includes_non_options_keys(self): with bond_device() as bond: self.assertTrue('active_slave' in bond.properties)
def test_bond_with_slaves(self): with dummy_devices(2) as (nic1, nic2): with bond_device() as bond: bond.add_slaves((nic1, nic2)) self.assertFalse(iface(bond.master).is_up())
def bond2(): with bond_device() as bond: yield bond
def test_bond_list(self): with bond_device() as b1, bond_device() as b2, bond_device() as b3: actual_bond_set = set(Bond.bonds()) expected_bond_set = set([b1.master, b2.master, b3.master]) self.assertLessEqual(expected_bond_set, actual_bond_set)