def test_match_success(self): interface = random_string() remote_device = random_string() remote_interface = random_string() neighbor = Neighbor(remote_device, remote_interface) for intf in ['any', interface]: for remote_d in ['any', remote_device]: for remote_i in ['any', remote_interface]: pattern = InterfacePattern(intf, remote_d, remote_i, random_string()) result = pattern.match(interface, [neighbor]) self.assertTrue(result)
def test_create_interface_pattern(self): intf = 'Ethernet1' remote_device = random_string() remote_interface = random_string() obj = InterfacePattern(intf, remote_device, remote_interface, random_string()) reprobj = 'InterfacePattern(interface=%s, remote_device=%s, ' \ 'remote_interface=%s)' % \ (intf, remote_device, remote_interface) self.assertEqual(repr(obj), reprobj)
def compile_known_function(self, interface, cls): pattern = InterfacePattern(random_string(), interface, random_string(), random_string()) self.assertIsInstance(pattern.remote_device_re, cls)
def test_match_failure(self): interface = random_string() remote_device = random_string() remote_interface = random_string() for intf in ['none', interface + 'dummy']: pattern = InterfacePattern(intf, remote_device, remote_interface, random_string()) neighbor = Neighbor(remote_device, remote_interface) result = pattern.match(interface, [neighbor]) self.assertFalse(result) for remote_d in ['none', remote_device + 'dummy']: pattern = InterfacePattern(interface, remote_d, remote_interface, random_string()) neighbor = Neighbor(remote_device, remote_interface) result = pattern.match(interface, [neighbor]) self.assertFalse(result) for remote_i in ['none', remote_interface + 'dummy']: pattern = InterfacePattern(interface, remote_device, remote_i, random_string()) neighbor = Neighbor(remote_device, remote_interface) result = pattern.match(interface, [neighbor]) self.assertFalse(result) for remote_d in ['none', remote_device + 'dummy']: for remote_i in ['none', remote_interface + 'dummy']: pattern = InterfacePattern(interface, remote_d, remote_i, random_string()) neighbor = Neighbor(remote_device, remote_interface) result = pattern.match(interface, [neighbor]) self.assertFalse(result) for intf in ['none', interface + 'dummy']: for remote_i in ['none', remote_interface + 'dummy']: pattern = InterfacePattern(intf, remote_device, remote_i, random_string()) neighbor = Neighbor(remote_device, remote_interface) result = pattern.match(interface, [neighbor]) self.assertFalse(result) for intf in ['none', interface + 'dummy']: for remote_d in ['none', remote_device + 'dummy']: pattern = InterfacePattern(intf, remote_d, remote_interface, random_string()) neighbor = Neighbor(remote_device, remote_interface) result = pattern.match(interface, [neighbor]) self.assertFalse(result) for intf in ['none', interface + 'dummy']: for remote_d in ['none', remote_device + 'dummy']: for remote_i in ['none', remote_interface + 'dummy']: pattern = InterfacePattern(intf, remote_d, remote_i, random_string()) neighbor = Neighbor(remote_device, remote_interface) result = pattern.match(interface, [neighbor]) self.assertFalse(result)