def test_validate_auth_with_integer_password(self): auth_type = bgp_consts.SUPPORTED_AUTH_TYPES[1] with self.assertRaisesRegex( bgp_driver_exc.InvalidParamType, EXC_INV_PARAMTYPE % {'param': '12345', 'param_type': 'string'}): bgp_driver_utils.validate_auth(auth_type, 12345)
def add_bgp_peer(self, speaker_as, peer_ip, peer_as, auth_type='none', password=None): curr_speaker = self.cache.get_bgp_speaker(speaker_as) if not curr_speaker: raise bgp_driver_exc.BgpSpeakerNotAdded(local_as=speaker_as, rtid=self.routerid) # Validate peer_ip and peer_as. utils.validate_as_num('remote_as', peer_as) utils.validate_string(peer_ip) utils.validate_auth(auth_type, password) # Notify Ryu about BGP Peer addition curr_speaker.neighbor_add(address=peer_ip, remote_as=peer_as, password=password, connect_mode=CONNECT_MODE_ACTIVE) LOG.info( _LI('Added BGP Peer %(peer)s for remote_as=%(as)d to ' 'BGP Speaker running for local_as=%(local_as)d.'), { 'peer': peer_ip, 'as': peer_as, 'local_as': speaker_as })
def test_validate_auth_with_integer_password(self): auth_type = bgp_consts.SUPPORTED_AUTH_TYPES[1] with self.assertRaisesRegex( bgp_driver_exc.InvalidParamType, EXC_INV_PARAMTYPE % {'param': '12345', 'param_type': 'string'}): bgp_driver_utils.validate_auth(auth_type, 12345)
def add_bgp_peer(self, speaker_as, peer_ip, peer_as, auth_type='none', password=None, enable_evpn=None, hold_time=None, connect_mode=CONNECT_MODE_ACTIVE): curr_speaker = self.cache.get_bgp_speaker(speaker_as) if not curr_speaker: raise bgp_driver_exc.BgpSpeakerNotAdded(local_as=speaker_as, rtid=self.routerid) # Validate peer_ip and peer_as. utils.validate_as_num('remote_as', peer_as) ip_version = utils.validate_ip_addr(peer_ip) utils.validate_auth(auth_type, password) if password is not None: password = encodeutils.to_utf8(password) kwargs = {} if enable_evpn is not None: kwargs['enable_evpn'] = enable_evpn if hold_time is not None: kwargs['hold_time'] = hold_time # Notify Ryu about BGP Peer addition if ip_version == lib_consts.IP_VERSION_4: enable_ipv4 = True enable_ipv6 = False else: enable_ipv4 = False enable_ipv6 = True curr_speaker.neighbor_add(address=peer_ip, remote_as=peer_as, enable_ipv4=enable_ipv4, enable_ipv6=enable_ipv6, password=password, connect_mode=connect_mode, **kwargs) LOG.info( _LI('Added BGP Peer %(peer)s for remote_as=%(as)d to ' 'BGP Speaker running for local_as=%(local_as)d.'), { 'peer': peer_ip, 'as': peer_as, 'local_as': speaker_as })
def add_bgp_peer(self, speaker_as, peer_ip, peer_as, auth_type='none', password=None): curr_speaker = self.cache.get_bgp_speaker(speaker_as) if not curr_speaker: raise bgp_driver_exc.BgpSpeakerNotAdded(local_as=speaker_as, rtid=self.routerid) # Validate peer_ip and peer_as. utils.validate_as_num('remote_as', peer_as) utils.validate_string(peer_ip) utils.validate_auth(auth_type, password) # Notify Ryu about BGP Peer addition curr_speaker.neighbor_add(address=peer_ip, remote_as=peer_as, password=password, connect_mode=CONNECT_MODE_ACTIVE) LOG.info(_LI('Added BGP Peer %(peer)s for remote_as=%(as)d to ' 'BGP Speaker running for local_as=%(local_as)d.'), {'peer': peer_ip, 'as': peer_as, 'local_as': speaker_as})
def test_validate_auth_with_not_none_auth_type_and_none_password(self): auth_type = bgp_consts.SUPPORTED_AUTH_TYPES[1] with self.assertRaisesRegex( bgp_driver_exc.PasswordNotSpecified, EXC_PASSWORD_NOTSPEC % {'auth_type': auth_type}): bgp_driver_utils.validate_auth(auth_type, None)
def test_validate_auth_with_invalid_auth_type(self): auth_type = 'abcde' with self.assertRaisesRegex( bgp_driver_exc.InvaildAuthType, EXC_INV_AUTHTYPE % {'auth_type': auth_type}): bgp_driver_utils.validate_auth(auth_type, 'password')
def test_validate_auth_with_valid_auth_type(self): passwords = [None, 'password'] for (auth_type, passwd) in zip(bgp_consts.SUPPORTED_AUTH_TYPES, passwords): self.assertIsNone(bgp_driver_utils.validate_auth( auth_type, passwd))
def test_validate_auth_with_none_auth_type_and_not_none_password(self): auth_type = None with self.assertRaisesRegex( bgp_driver_exc.InvaildAuthType, EXC_INV_AUTHTYPE % {'auth_type': auth_type}): bgp_driver_utils.validate_auth(auth_type, 'password')
def test_validate_auth_with_not_none_auth_type_and_none_password(self): auth_type = bgp_consts.SUPPORTED_AUTH_TYPES[1] with self.assertRaisesRegex( bgp_driver_exc.PasswordNotSpecified, EXC_PASSWORD_NOTSPEC % {'auth_type': auth_type}): bgp_driver_utils.validate_auth(auth_type, None)
def test_validate_auth_with_invalid_auth_type(self): auth_type = 'abcde' with self.assertRaisesRegex( bgp_driver_exc.InvaildAuthType, EXC_INV_AUTHTYPE % {'auth_type': auth_type}): bgp_driver_utils.validate_auth(auth_type, 'password')
def test_validate_auth_with_valid_auth_type(self): passwords = [None, 'password'] for (auth_type, passwd) in zip(bgp_consts.SUPPORTED_AUTH_TYPES, passwords): self.assertIsNone(bgp_driver_utils.validate_auth(auth_type, passwd))
def test_validate_auth_with_none_auth_type_and_not_none_password(self): auth_type = None with self.assertRaisesRegex( bgp_driver_exc.InvaildAuthType, EXC_INV_AUTHTYPE % {'auth_type': auth_type}): bgp_driver_utils.validate_auth(auth_type, 'password')