def test_generic_post_callback(self): require_user('root') require_bridge() ifP1 = self.get_ifname() ifP2 = self.get_ifname() ifM = self.get_ifname() def cb(ipdb, msg, action): if action == 'RTM_NEWLINK' and \ msg.get_attr('IFLA_IFNAME', '') in (ifP1, ifP2): obj = ipdb.interfaces[msg['index']] ipdb.interfaces[ifM].add_port(obj) ipdb.interfaces[ifM].commit() wd0 = self.ip.watchdog(ifname=ifM) wd1 = self.ip.watchdog(ifname=ifP1) wd2 = self.ip.watchdog(ifname=ifP2) # create bridge self.ip.create(kind='bridge', ifname=ifM).commit() wd0.wait() # register callback self.ip.register_callback(cb) # create ports self.ip.create(kind='dummy', ifname=ifP1).commit() self.ip.create(kind='dummy', ifname=ifP2).commit() wd1.wait() wd2.wait() # check that ports are attached assert self.ip.interfaces[ifP1].index in \ self.ip.interfaces[ifM].ports assert self.ip.interfaces[ifP2].index in \ self.ip.interfaces[ifM].ports # unregister callback self.ip.unregister_callback(cb)
def test_generic_post_callback(self): require_user('root') require_bridge() def cb(ipdb, msg, action): if action == 'RTM_NEWLINK' and \ msg.get_attr('IFLA_IFNAME', '').startswith('bala_port'): with ipdb.exclusive: obj = ipdb.interfaces[msg['index']] ipdb.interfaces.bala.add_port(obj) ipdb.interfaces.bala.commit() wd0 = self.ip.watchdog(ifname='bala') wd1 = self.ip.watchdog(ifname='bala_port0') wd2 = self.ip.watchdog(ifname='bala_port1') # create bridge self.ip.create(kind='bridge', ifname='bala').commit() wd0.wait() # register callback self.ip.register_callback(cb) # create ports self.ip.create(kind='dummy', ifname='bala_port0').commit() self.ip.create(kind='dummy', ifname='bala_port1').commit() wd1.wait() wd2.wait() time.sleep(1) # check that ports are attached assert self.ip.interfaces.bala_port0.index in \ self.ip.interfaces.bala.ports assert self.ip.interfaces.bala_port1.index in \ self.ip.interfaces.bala.ports # unregister callback self.ip.unregister_callback(cb)
def test_cfail_rollback(self): require_user('root') require_bridge() # create ports with self.ip.create(kind='dummy', ifname='bala_port0'): pass with self.ip.create(kind='dummy', ifname='bala_port1'): pass assert 'bala_port0' in self.ip.interfaces assert 'bala_port1' in self.ip.interfaces # commits should fail clear_fail_bit(_FAIL_COMMIT) clear_fail_bit(_FAIL_ROLLBACK) try: # create bridge with self.ip.create(kind='bridge', ifname='bala') as i: i.add_ip('172.16.0.1/24') i.add_ip('172.16.0.2/24') i.add_port(self.ip.interfaces.bala_port0) i.add_port(self.ip.interfaces.bala_port1) except RuntimeError: pass finally: # set bit again set_fail_bit(_FAIL_COMMIT) set_fail_bit(_FAIL_ROLLBACK) # expected results: # 1. interface created # 2. no addresses # 3. no ports assert 'bala' in self.ip.interfaces assert 'bala_port0' in self.ip.interfaces assert 'bala_port1' in self.ip.interfaces assert ('172.16.0.1', 24) not in self.ip.interfaces.bala.ipaddr assert ('172.16.0.2', 24) not in self.ip.interfaces.bala.ipaddr assert self.ip.interfaces.bala_port0.index not in \ self.ip.interfaces.bala.ports assert self.ip.interfaces.bala_port1.index not in \ self.ip.interfaces.bala.ports
def test_generic_post_callback(self): require_user('root') require_bridge() ifP1 = self.get_ifname() ifP2 = self.get_ifname() ifM = self.get_ifname() def cb(ipdb, msg, action): if action == 'RTM_NEWLINK' and \ msg.get_attr('IFLA_IFNAME', '') in (ifP1, ifP2): obj = ipdb.interfaces[msg['index']] ipdb.interfaces[ifM].add_port(obj) try: ipdb.interfaces[ifM].commit() except Exception: pass wd0 = self.ip.watchdog(ifname=ifM) wd1 = self.ip.watchdog(ifname=ifP1) wd2 = self.ip.watchdog(ifname=ifP2) # create bridge self.ip.create(kind='bridge', ifname=ifM).commit() wd0.wait() # register callback self.ip.register_callback(cb) # create ports self.ip.create(kind='dummy', ifname=ifP1).commit() self.ip.create(kind='dummy', ifname=ifP2).commit() wd1.wait() wd2.wait() # check that ports are attached assert self.ip.interfaces[ifP1].index in \ self.ip.interfaces[ifM].ports assert self.ip.interfaces[ifP2].index in \ self.ip.interfaces[ifM].ports # unregister callback self.ip.unregister_callback(cb)
def test_ipdb_autobr(self): require_user('root') require_bridge() self.launcher('ipdb_autobr')
def test_create_bridge(self): require_user('root') require_bridge() self._create_master('bridge')
def test_shadow_bridge(self): require_user('root') require_bridge() self._test_shadow('bridge')