Ejemplo n.º 1
0
    def testValidateBondingOptions(self):
        opts = 'mode=802.3ad miimon=150'
        badOpts = 'foo=bar badopt=one'

        with self.assertRaises(errors.ConfigNetworkError) as cne:
            Bond.validateOptions(badOpts)
        self.assertEqual(cne.exception.errCode, errors.ERR_BAD_BONDING)
        self.assertEqual(Bond.validateOptions(opts), None)
Ejemplo n.º 2
0
    def testValidateBondingOptions(self):
        opts = 'mode=802.3ad miimon=150'
        badOpts = 'foo=bar badopt=one'

        with self.assertRaises(errors.ConfigNetworkError) as cne:
            Bond.validateOptions(badOpts)
        self.assertEqual(cne.exception.errCode, errors.ERR_BAD_BONDING)
        self.assertEqual(Bond.validateOptions(opts), None)
Ejemplo n.º 3
0
    def testIsBondingNameValid(self):
        bondNames = ('badValue', ' bond14', 'bond14 ', 'bond14a', 'bond0 0')

        for bondName in bondNames:
            with self.assertRaises(errors.ConfigNetworkError) as cneContext:
                Bond.validateName(bondName)
            self.assertEqual(cneContext.exception.errCode,
                             errors.ERR_BAD_BONDING)

        self.assertEqual(Bond.validateName('bond11'), None)
        self.assertEqual(Bond.validateName('bond11128421982'), None)
Ejemplo n.º 4
0
    def testValidateBondingOptions(self):
        if not os.path.exists(netinfo.BONDING_MASTERS):
            raise SkipTest("bonding kernel module could not be found.")

        opts = 'mode=802.3ad miimon=150'
        badOpts = 'foo=bar badopt=one'

        with self.assertRaises(errors.ConfigNetworkError) as cne:
            Bond.validateOptions('bond0', badOpts)
        self.assertEqual(cne.exception.errCode, errors.ERR_BAD_BONDING)
        self.assertEqual(Bond.validateOptions('bond0', opts), None)
Ejemplo n.º 5
0
    def testIsBondingNameValid(self):
        bondNames = ('badValue', ' bond14', 'bond14 ', 'bond14a', 'bond0 0')

        for bondName in bondNames:
            with self.assertRaises(errors.ConfigNetworkError) as cneContext:
                Bond.validateName(bondName)
            self.assertEqual(cneContext.exception.errCode,
                             errors.ERR_BAD_BONDING)

        self.assertEqual(Bond.validateName('bond11'), None)
        self.assertEqual(Bond.validateName('bond11128421982'), None)
Ejemplo n.º 6
0
    def testBondReorderOptions(self):
        empty = Bond._reorderOptions('')
        self.assertEqual(empty, '')

        modeless = Bond._reorderOptions('miimon=250')
        self.assertEqual(modeless, 'miimon=250')

        ordered = Bond._reorderOptions('mode=4 miimon=250')
        self.assertEqual(ordered, 'mode=4 miimon=250')

        inverted = Bond._reorderOptions('miimon=250 mode=4')
        self.assertEqual(inverted, 'mode=4 miimon=250')
Ejemplo n.º 7
0
    def testBondReorderOptions(self):
        empty = Bond._reorderOptions('')
        self.assertEqual(empty, '')

        modeless = Bond._reorderOptions('miimon=250')
        self.assertEqual(modeless, 'miimon=250')

        ordered = Bond._reorderOptions('mode=4 miimon=250')
        self.assertEqual(ordered, 'mode=4 miimon=250')

        inverted = Bond._reorderOptions('miimon=250 mode=4')
        self.assertEqual(inverted, 'mode=4 miimon=250')
Ejemplo n.º 8
0
    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))
Ejemplo n.º 9
0
 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)))))')