def testIterNetworkHierarchy(self): _netinfo = { 'networks': {}, 'vlans': {}, 'nics': ['testnic1', 'testnic2'], 'bondings': {}, 'bridges': {} } fakeInfo = netinfo.NetInfo(_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 testIsVlanIdValid(self): vlanIds = ('badValue', Vlan.MAX_ID + 1) for vlanId in vlanIds: with self.assertRaises(errors.ConfigNetworkError) as cneContext: Vlan.validateTag(vlanId) self.assertEqual(cneContext.exception.errCode, errors.ERR_BAD_VLAN) self.assertEqual(Vlan.validateTag(0), None) self.assertEqual(Vlan.validateTag(Vlan.MAX_ID), None)
def create_vlan(vlan, br, vlan_type, enable=True): v = Vlan() v.vlan = vlan v.br = br v.type = vlan_type v.enable = enable v.save() return v
def testTextualRepr(self): _netinfo = {'networks': {}, 'vlans': {}, 'nics': ['testnic1', 'testnic2'], 'bondings': {}, 'bridges': {}} fakeInfo = netinfo.NetInfo(_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)))))')