def testIsBridgeNameValid(self): invalidBrName = ('', '-abc', 'abcdefghijklmnop', 'a:b', 'a.b') for i in invalidBrName: with self.assertRaises(errors.ConfigNetworkError) as cneContext: Bridge.validateName(i) self.assertEqual(cneContext.exception.errCode, errors.ERR_BAD_BRIDGE)
def testIterNetworkHierarchy(self): _netinfo = { 'networks': {}, 'vlans': {}, 'nics': ['testnic1', 'testnic2'], 'bondings': {}, 'bridges': {} } fakeInfo = CachingNetInfo(_netinfo) # Vlanned and bonded VM network nic1 = Nic('testnic1', configurator=None, _netinfo=fakeInfo) nic2 = Nic('testnic2', configurator=None, _netinfo=fakeInfo) bond1 = Bond('bond42', configurator=None, slaves=(nic1, nic2)) vlan1 = Vlan(bond1, 4, configurator=None) bridge1 = Bridge('testbridge', configurator=None, port=vlan1) self.assertEqual([dev for dev in bridge1], [bridge1, vlan1, bond1, nic1, nic2]) self.assertEqual(bond1, hierarchy_backing_device(bridge1)) self.assertEqual(4, hierarchy_vlan_tag(bridge1)) # Nic-less VM net bridge2 = Bridge('testbridge', configurator=None, port=None) self.assertEqual([dev for dev in bridge2], [bridge2]) self.assertEqual(None, hierarchy_backing_device(bridge2)) self.assertEqual(None, hierarchy_vlan_tag(bridge2)) # vlan-less VM net bridge3 = Bridge('testbridge', configurator=None, port=bond1) self.assertEqual([dev for dev in bridge3], [bridge3, bond1, nic1, nic2]) self.assertEqual(bond1, hierarchy_backing_device(bridge3)) self.assertEqual(None, hierarchy_vlan_tag(bridge3)) # Bond-less VM net bridge4 = Bridge('testbridge', configurator=None, port=nic1) self.assertEqual([dev for dev in bridge4], [bridge4, nic1]) self.assertEqual(nic1, hierarchy_backing_device(bridge4)) self.assertEqual(None, hierarchy_vlan_tag(bridge4)) # vlanned and bonded non-VM net self.assertEqual([dev for dev in vlan1], [vlan1, bond1, nic1, nic2]) self.assertEqual(bond1, hierarchy_backing_device(vlan1)) self.assertEqual(4, hierarchy_vlan_tag(vlan1)) # vlanned, bond-less non-VM net vlan2 = Vlan(nic1, 5, configurator=None) self.assertEqual([dev for dev in vlan2], [vlan2, nic1]) self.assertEqual(nic1, hierarchy_backing_device(vlan2)) self.assertEqual(5, hierarchy_vlan_tag(vlan2)) # non-vlanned and bonded non-VM net self.assertEqual([dev for dev in bond1], [bond1, nic1, nic2]) self.assertEqual(bond1, hierarchy_backing_device(bond1)) self.assertEqual(None, hierarchy_vlan_tag(bond1)) # non-vlanned and bond-less non-VM net self.assertEqual([dev for dev in nic2], [nic2]) self.assertEqual(nic2, hierarchy_backing_device(nic2)) self.assertEqual(None, hierarchy_vlan_tag(nic2))
def testIterNetworkHierarchy(self): _netinfo = { 'networks': {}, 'vlans': {}, 'nics': ['testnic1', 'testnic2'], 'bondings': {}, 'bridges': {}, 'nameservers': [], } fakeInfo = CachingNetInfo(_netinfo) # Vlanned and bonded VM network nic1 = Nic('testnic1', configurator=None, _netinfo=fakeInfo) nic2 = Nic('testnic2', configurator=None, _netinfo=fakeInfo) bond1 = Bond('bond42', configurator=None, slaves=(nic1, nic2)) vlan1 = Vlan(bond1, 4, configurator=None) bridge1 = Bridge('testbridge', configurator=None, port=vlan1) assert [dev for dev in bridge1] == [bridge1, vlan1, bond1, nic1, nic2] assert bond1 == hierarchy_backing_device(bridge1) assert 4 == hierarchy_vlan_tag(bridge1) # Nic-less VM net bridge2 = Bridge('testbridge', configurator=None, port=None) assert [dev for dev in bridge2] == [bridge2] assert hierarchy_backing_device(bridge2) is None assert hierarchy_vlan_tag(bridge2) is None # vlan-less VM net bridge3 = Bridge('testbridge', configurator=None, port=bond1) assert [dev for dev in bridge3] == [bridge3, bond1, nic1, nic2] assert bond1 == hierarchy_backing_device(bridge3) assert hierarchy_vlan_tag(bridge3) is None # Bond-less VM net bridge4 = Bridge('testbridge', configurator=None, port=nic1) assert [dev for dev in bridge4] == [bridge4, nic1] assert nic1 == hierarchy_backing_device(bridge4) assert hierarchy_vlan_tag(bridge4) is None # vlanned and bonded non-VM net assert [dev for dev in vlan1] == [vlan1, bond1, nic1, nic2] assert bond1 == hierarchy_backing_device(vlan1) assert 4 == hierarchy_vlan_tag(vlan1) # vlanned, bond-less non-VM net vlan2 = Vlan(nic1, 5, configurator=None) assert [dev for dev in vlan2] == [vlan2, nic1] assert nic1 == hierarchy_backing_device(vlan2) assert 5 == hierarchy_vlan_tag(vlan2) # non-vlanned and bonded non-VM net assert [dev for dev in bond1] == [bond1, nic1, nic2] assert bond1 == hierarchy_backing_device(bond1) assert hierarchy_vlan_tag(bond1) is None # non-vlanned and bond-less non-VM net assert [dev for dev in nic2] == [nic2] assert nic2 == hierarchy_backing_device(nic2) assert hierarchy_vlan_tag(nic2) is None
def testTextualRepr(self): _netinfo = {'networks': {}, 'vlans': {}, 'nics': ['testnic1', 'testnic2'], 'bondings': {}, 'bridges': {}, 'nameservers': []} fakeInfo = CachingNetInfo(_netinfo) nic1 = Nic('testnic1', None, _netinfo=fakeInfo) nic2 = Nic('testnic2', None, _netinfo=fakeInfo) bond1 = Bond('bond42', None, slaves=(nic1, nic2)) vlan1 = Vlan(bond1, '4', None) bridge1 = Bridge('testbridge', None, port=vlan1) self.assertEqual('%r' % bridge1, 'Bridge(testbridge: Vlan(bond42.4: ' 'Bond(bond42: (Nic(testnic1), Nic(testnic2)))))')