Esempio n. 1
0
    def test_adding_a_net_with_mtu_lower_than_base_nic_mtu(self, switch,
                                                           bridged, bonded):
        with dummy_devices(1) as (nic,):
            NETWORK1_ATTRS = {'bridged': bridged,
                              'vlan': VLAN1,
                              'mtu': 1000,
                              'switch': switch}
            NETNEW = {NETWORK1_NAME: NETWORK1_ATTRS}

            if bonded:
                NETWORK1_ATTRS['bonding'] = BOND_NAME
                BONDBASE = {BOND_NAME: {'nics': [nic], 'switch': switch}}
                link2monitor = BOND_NAME
            else:
                NETWORK1_ATTRS['nic'] = nic
                BONDBASE = {}
                link2monitor = nic

            with adapter.setupNetworks(NETNEW, BONDBASE, nftestlib.NOCHK):
                with nftestlib.monitor_stable_link_state(link2monitor):
                    adapter.assertLinkMtu(nic, NETWORK1_ATTRS)

                    if bonded:
                        vlan1 = BOND_NAME + '.' + str(
                            NETWORK1_ATTRS['vlan'])
                        adapter.assertLinkMtu(BOND_NAME, NETWORK1_ATTRS)
                    else:
                        vlan1 = nic + '.' + str(NETWORK1_ATTRS['vlan'])

                    adapter.assertLinkMtu(vlan1, NETWORK1_ATTRS)
Esempio n. 2
0
    def _test_add_net_with_ip(self, families, switch,
                              bonded=False, vlaned=False, bridged=False):
        with dummy_devices(2) as (nic1, nic2):
            network_attrs = {'bridged': bridged, 'switch': switch}

            if IpFamily.IPv4 in families:
                network_attrs['ipaddr'] = IPv4_ADDRESS
                network_attrs['netmask'] = IPv4_NETMASK
            if IpFamily.IPv6 in families:
                network_attrs['ipv6addr'] = IPv6_ADDRESS

            if bonded:
                bondcreate = {
                    BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}
                network_attrs['bonding'] = BOND_NAME
            else:
                bondcreate = {}
                network_attrs['nic'] = nic1

            if vlaned:
                network_attrs['vlan'] = VLAN

            netcreate = {NETWORK_NAME: network_attrs}

            with adapter.setupNetworks(netcreate, bondcreate, NOCHK):
                adapter.assertNetworkIp(NETWORK_NAME,
                                        netcreate[NETWORK_NAME])
Esempio n. 3
0
    def test_add_static_ip_to_the_existing_net_with_bond(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            network_attrs1 = {'bonding': BOND_NAME,
                              'bridged': False,
                              'ipaddr': IPv4_ADDRESS,
                              'netmask': IPv4_NETMASK,
                              'switch': switch}

            network_attrs2 = {'bonding': BOND_NAME,
                              'bridged': True,
                              'vlan': VLAN,
                              'switch': switch}

            bond = {BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}
            netconf = {NETWORK_NAME: network_attrs1,
                       NETWORK2_NAME: network_attrs2}

            net2 = {NETWORK2_NAME: netconf[NETWORK2_NAME]}

            with adapter.setupNetworks(netconf, bond, NOCHK):
                adapter.assertNetworkIp(NETWORK_NAME, network_attrs1)
                adapter.assertNetworkIp(NETWORK2_NAME, network_attrs2)
                network_attrs2['ipaddr'] = IPv4_ADDRESS2
                network_attrs2['netmask'] = IPv4_NETMASK
                adapter.setupNetworks(net2, bond, NOCHK)
                adapter.assertNetworkIp(NETWORK_NAME, network_attrs1)
                adapter.assertNetworkIp(NETWORK2_NAME, network_attrs2)
Esempio n. 4
0
    def test_mtu_default_value_of_base_nic_after_all_nets_are_removed(self,
                                                                      switch,
                                                                      bridged,
                                                                      bonded):
        if switch == 'legacy' and bonded:
            pytest.xfail('BZ#1633528')
        with dummy_devices(1) as (nic,):
            NETWORK1_ATTRS = {'bridged': bridged,
                              'vlan': VLAN1,
                              'mtu': 1600,
                              'switch': switch}
            NETBASE = {NETWORK1_NAME: NETWORK1_ATTRS}
            DEFAULT_MTU = {'mtu': 1500}
            if bonded:
                NETWORK1_ATTRS['bonding'] = BOND_NAME
                BONDBASE = {BOND_NAME: {'nics': [nic], 'switch': switch}}
            else:
                NETWORK1_ATTRS['nic'] = nic
                BONDBASE = {}

            with adapter.setupNetworks(NETBASE, BONDBASE, nftestlib.NOCHK):
                adapter.setupNetworks(
                    {NETWORK1_NAME: {'remove': True}}, {}, nftestlib.NOCHK)

                adapter.assertLinkMtu(nic, DEFAULT_MTU)
                if bonded:
                    adapter.assertLinkMtu(BOND_NAME, DEFAULT_MTU)
Esempio n. 5
0
    def test_add_bond_with_two_nics(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            BONDCREATE = {
                BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}

            with adapter.setupNetworks({}, BONDCREATE, NOCHK):
                adapter.assertBond(BOND_NAME, BONDCREATE[BOND_NAME])
Esempio n. 6
0
 def test_bond_devices_are_up(self):
     with dummy_devices(2) as (nic1, nic2):
         with bond_device() as bond:
             bond.add_slaves((nic1, nic2))
             bond.up()
             self.assertTrue(iface(nic1).is_up())
             self.assertTrue(iface(nic2).is_up())
             self.assertTrue(iface(bond.master).is_up())
Esempio n. 7
0
    def test_configured_connections_attributes_existence(self):
        with dummy_devices(1) as nics:
            with nm_connections(self.iface, IPV4ADDR, slaves=nics) as connames:
                nm_con = self._get_connection(connames[0])

                self.assertEqual(connames[0], nm_con.connection.id)
                self.assertIsNotNone(nm_con.connection.uuid)
                self.assertIsNotNone(nm_con.connection.type)
Esempio n. 8
0
File: nm_test.py Progetto: nirs/vdsm
    def test_remove_all_non_active_connection_from_a_device(self):
        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface, IPV4ADDR, slaves=nics, con_count=3):

                device = networkmanager.Device(iface)
                device.cleanup_inactive_connections()

                self.assertEqual(1, sum(1 for _ in device.connections()))
Esempio n. 9
0
 def test_add_net_with_mtu(self, switch, bridged):
     with dummy_devices(1) as (nic,):
         NETCREATE = {NETWORK_NAME: {'nic': nic,
                                     'bridged': bridged,
                                     'mtu': 2000,
                                     'switch': switch}}
         with adapter.setupNetworks(NETCREATE, {}, nftestlib.NOCHK):
             adapter.assertNetwork(NETWORK_NAME, NETCREATE[NETWORK_NAME])
             adapter.assertLinkMtu(nic, NETCREATE[NETWORK_NAME])
Esempio n. 10
0
    def test_remove_bond(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            BONDCREATE = {
                BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}
            BONDREMOVE = {BOND_NAME: {'remove': True}}

            with adapter.setupNetworks({}, BONDCREATE, NOCHK):
                adapter.setupNetworks({}, BONDREMOVE, NOCHK)
                adapter.assertNoBond(BOND_NAME)
Esempio n. 11
0
    def test_bond_options_with_the_mode_specified_last(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            BONDCREATE = {BOND_NAME: {
                'nics': [nic1, nic2],
                'options': 'lacp_rate=fast mode=802.3ad',
                'switch': switch}}

            with adapter.setupNetworks({}, BONDCREATE, NOCHK):
                adapter.assertBond(BOND_NAME, BONDCREATE[BOND_NAME])
Esempio n. 12
0
    def test_bond_mode_1(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            BONDCREATE = {BOND_NAME: {
                'nics': [nic1, nic2],
                'options': 'mode=1 primary=' + nic1,
                'switch': switch}}

            with adapter.setupNetworks({}, BONDCREATE, NOCHK):
                adapter.assertBond(BOND_NAME, BONDCREATE[BOND_NAME])
Esempio n. 13
0
 def test_add_bridge_with_custom_opts(self, switch):
     with dummy_devices(1) as (nic,):
         NETCREATE = {NETWORK_NAME: {
             'nic': nic,
             'switch': switch,
             'custom': {
                 'bridge_opts': 'multicast_snooping=0 multicast_router=0'}}}
         with adapter.setupNetworks(NETCREATE, {}, nftestlib.NOCHK):
             adapter.assertBridgeOpts(NETWORK_NAME,
                                      NETCREATE[NETWORK_NAME])
Esempio n. 14
0
    def test_bond_slaves_order_does_not_affect_the_mac_address(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            bond1 = {BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}
            bond2 = {BOND_NAME: {'nics': [nic2, nic1], 'switch': switch}}

            with adapter.setupNetworks({}, bond1, NOCHK):
                bond1_hwaddr = adapter.netinfo.bondings[BOND_NAME]['hwaddr']
            with adapter.setupNetworks({}, bond2, NOCHK):
                bond2_hwaddr = adapter.netinfo.bondings[BOND_NAME]['hwaddr']

            assert bond1_hwaddr == bond2_hwaddr
Esempio n. 15
0
    def test_remove_bridged_net_and_keep_bond(self, switch):
        with dummy_devices(2) as nics:
            NETCREATE = {
                NETWORK1_NAME: {'bonding': BOND_NAME, 'switch': switch}}
            BONDCREATE = {BOND_NAME: {'nics': nics, 'switch': switch}}

            with adapter.setupNetworks(NETCREATE, BONDCREATE, NOCHK):
                NETCREATE[NETWORK1_NAME] = {'remove': True}
                adapter.setupNetworks(NETCREATE, {}, NOCHK)

                adapter.assertNoNetwork(NETWORK1_NAME)
Esempio n. 16
0
 def test_bond_mode_change(self, switch):
     with dummy_devices(2) as nics:
         BONDCREATE = {BOND_NAME: {'nics': nics,
                                   'switch': switch,
                                   'options': 'mode=1 miimon=150'}}
         BONDEDIT = {BOND_NAME: {'nics': nics,
                                 'switch': switch,
                                 'options': 'mode=3'}}
         with adapter.setupNetworks({}, BONDCREATE, NOCHK):
             adapter.setupNetworks({}, BONDEDIT, NOCHK)
             adapter.assertBond(BOND_NAME, BONDEDIT[BOND_NAME])
Esempio n. 17
0
    def test_do_not_detach_slaves_while_changing_options(self):
        OPTIONS = {'miimon': '110'}

        with dummy_devices(2) as (nic1, nic2):
            with bond_device() as bond:
                bond.add_slaves((nic1, nic2))
                mock_slaves = bond.del_slaves = bond.add_slaves = mock.Mock()

                bond.set_options(OPTIONS)

                mock_slaves.assert_not_called()
Esempio n. 18
0
    def test_delete_one_of_two_connections(self):
        with dummy_devices(1) as nics:
            with nm_connections(self.iface, IPV4ADDR,
                                slaves=nics, con_count=2) as connames:

                con0 = self._get_connection(connames[0])
                con0.delete()
                self.assertIsNone(self._get_connection(connames[0]))

                con1 = self._get_connection(connames[1])
                self.assertEqual(connames[1], con1.connection.id)
Esempio n. 19
0
    def test_attach_nic_with_ip_as_a_slave_to_ipless_network(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            addrAdd(nic1, IPv4_ADDRESS, IPv4_PREFIX_LEN)

            NETCREATE = {
                NETWORK_NAME: {'bonding': BOND_NAME, 'switch': switch}}
            BONDCREATE = {
                BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}
            with adapter.setupNetworks(NETCREATE, BONDCREATE, NOCHK):
                nic_netinfo = adapter.netinfo.nics[nic1]
                adapter.assertDisabledIPv4(nic_netinfo)
Esempio n. 20
0
    def test_create_net_without_default_route(self, switch, preserve_conf):
        with dummy_devices(1) as (nic1,):
            net1_attrs = {'nic': nic1,
                          'ipaddr': IPv4_ADDRESS,
                          'netmask': IPv4_NETMASK,
                          'gateway': IPv4_GATEWAY,
                          'switch': switch}
            net1create = {NETWORK_NAME: net1_attrs}

            with adapter.setupNetworks(net1create, {}, NOCHK):
                adapter.assertNetworkIp(NETWORK_NAME, net1_attrs)
Esempio n. 21
0
 def test_create_network_and_reuse_existing_owned_bridge(self, switch):
     with dummy_devices(2) as (nic1, nic2):
         NETSETUP1 = {NETWORK_NAME: {'nic': nic1, 'switch': switch}}
         NETSETUP2 = {NETWORK_NAME: {'nic': nic2, 'switch': switch}}
         with adapter.setupNetworks(NETSETUP1, {}, nftestlib.NOCHK):
             with _create_tap() as tapdev:
                 _attach_dev_to_bridge(tapdev, NETWORK_NAME)
                 with nftestlib.monitor_stable_link_state(NETWORK_NAME):
                     adapter.setupNetworks(NETSETUP2, {}, nftestlib.NOCHK)
                     adapter.assertNetwork(NETWORK_NAME,
                                           NETSETUP2[NETWORK_NAME])
Esempio n. 22
0
    def test_bond_create_failure_on_slave_add(self):
        with dummy_devices(2) as (nic1, nic2):
            with bond_device() as base_bond:
                base_bond.add_slaves((nic1, nic2))

                bond_name = random_iface_name('bond_', max_length=11)
                with self.assertRaises(IOError):
                    with Bond(bond_name) as broken_bond:
                        broken_bond.create()
                        broken_bond.add_slaves((nic1, nic2))
                self.assertFalse(Bond(bond_name).exists())
Esempio n. 23
0
    def test_change_bond_slaves(self, switch):
        with dummy_devices(3) as (nic1, nic2, nic3):
            BONDCREATE = {
                BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}
            BONDEDIT = {
                BOND_NAME: {'nics': [nic1, nic3], 'switch': switch}}

            with adapter.setupNetworks({}, BONDCREATE, NOCHK):
                with nftestlib.monitor_stable_link_state(BOND_NAME):
                    adapter.setupNetworks({}, BONDEDIT, NOCHK)
                    adapter.assertBond(BOND_NAME, BONDEDIT[BOND_NAME])
Esempio n. 24
0
    def test_bond_exists(self):
        OPTIONS = {'mode': '1', 'miimon': '300'}
        with dummy_devices(2) as (nic1, nic2):
            with bond_device() as _bond:
                _bond.set_options(OPTIONS)
                _bond.add_slaves((nic1, nic2))
                _bond.up()

                bond = Bond(_bond.master)
                self.assertEqual(bond.slaves, set((nic1, nic2)))
                self.assertEqual(bond.options, OPTIONS)
Esempio n. 25
0
 def test_bond_active_slave_report(self, switch):
     with dummy_devices(2) as nics:
         BONDCREATE = {BOND_NAME: {'nics': nics,
                                   'switch': switch,
                                   'options': 'mode=1'}}
         BONDEDIT = {BOND_NAME: {'nics': nics,
                                 'switch': switch,
                                 'options': 'mode=4'}}
         with adapter.setupNetworks({}, BONDCREATE, NOCHK):
             adapter.assertBondActiveSlaveExists(BOND_NAME, nics)
             adapter.setupNetworks({}, BONDEDIT, NOCHK)
             adapter.assertBondNoActiveSlaveExists(BOND_NAME)
Esempio n. 26
0
    def test_resize_bond(self, switch):
        with dummy_devices(4) as (nic1, nic2, nic3, nic4):
            bond = {BOND_NAME: {'nics': [nic1, nic2],
                                'switch': switch}}
            with adapter.setupNetworks({}, bond, NOCHK):
                bond[BOND_NAME]['nics'] += [nic3, nic4]
                adapter.setupNetworks({}, bond, NOCHK)
                adapter.assertBond(BOND_NAME, bond[BOND_NAME])

                bond[BOND_NAME]['nics'].remove(nic4)
                adapter.setupNetworks({}, bond, NOCHK)
                adapter.assertBond(BOND_NAME, bond[BOND_NAME])
Esempio n. 27
0
    def test_bond_edit_failure_on_slave_add(self):
        with dummy_devices(2) as (nic1, nic2):
            with bond_device() as base_bond, bond_device() as edit_bond:
                base_bond.add_slaves((nic1,))
                edit_bond.add_slaves((nic2,))

                with self.assertRaises(IOError):
                    with Bond(edit_bond.master) as broken_bond:
                        self.assertTrue(broken_bond.exists())
                        broken_bond.add_slaves((nic1,))
                self.assertTrue(edit_bond.exists())
                self.assertEqual(set((nic2,)), edit_bond.slaves)
Esempio n. 28
0
    def test_add_slave_to_a_bonded_network_with_non_default_mtu(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            NETBASE = {NETWORK_NAME: {'bonding': BOND_NAME,
                                      'bridged': False,
                                      'mtu': 2000,
                                      'switch': switch}}
            BONDBASE = {BOND_NAME: {'nics': [nic1], 'switch': switch}}

            with adapter.setupNetworks(NETBASE, BONDBASE, nftestlib.NOCHK):
                BONDBASE[BOND_NAME]['nics'].append(nic2)
                adapter.setupNetworks({}, BONDBASE, nftestlib.NOCHK)
                adapter.assertLinkMtu(nic2, NETBASE[NETWORK_NAME])
Esempio n. 29
0
    def test_add_bond_with_enforced_mac_address(self, switch):
        if switch == 'ovs':
            pytest.xfail(
                'Bond mac enforcement is currently not implemented for ovs')
        HWADDRESS = 'ce:0c:46:59:c9:d1'
        with dummy_devices(2) as (nic1, nic2):
            BONDCREATE = {
                BOND_NAME: {'nics': [nic1, nic2],
                            'hwaddr': HWADDRESS,
                            'switch': switch}}

            with adapter.setupNetworks({}, BONDCREATE, NOCHK):
                adapter.assertBond(BOND_NAME, BONDCREATE[BOND_NAME])
Esempio n. 30
0
    def test_add_bridge_with_stp(self, switch):
        if switch == 'ovs':
            pytest.xfail('stp is currently not implemented for ovs')

        with dummy_devices(1) as (nic,):
            NETCREATE = {NETWORK_NAME: {'nic': nic,
                                        'switch': switch,
                                        'stp': True}}
            with adapter.setupNetworks(NETCREATE, {}, nftestlib.NOCHK):
                adapter.assertNetworkExists(NETWORK_NAME)
                adapter.assertNetworkBridged(NETWORK_NAME)
                adapter.assertBridgeOpts(NETWORK_NAME,
                                         NETCREATE[NETWORK_NAME])
Esempio n. 31
0
    def test_add_net_on_existing_external_vlanned_bond(self):
        ADDRESS1 = '192.168.99.1'
        ADDRESS2 = '192.168.99.254'
        PREFIX = '29'
        with dummy_devices(2) as (nic1, nic2):
            with Bond(BOND_NAME, slaves=(nic1, nic2)) as bond:
                bond.create()
                bond.up()
                with vlan_device(bond.master) as vlan:
                    # Make slaves dirty intentionally and check if they recover
                    self._set_ip_address('1.1.1.1/29', nic1)
                    self._set_ip_address('1.1.1.2/29', nic2)

                    self._set_ip_address(ADDRESS1 + '/' + PREFIX, bond.master)
                    self._set_ip_address(ADDRESS2 + '/' + PREFIX, vlan.devName)

                    NETBASE = {
                        NETWORK1_NAME: {
                            'bonding': BOND_NAME,
                            'bridged': True,
                            'ipaddr': ADDRESS1,
                            'prefix': PREFIX,
                            'switch': 'legacy'
                        }
                    }
                    with adapter.setupNetworks(NETBASE, {}, NOCHK):
                        adapter.assertNetwork(NETWORK1_NAME,
                                              NETBASE[NETWORK1_NAME])
                        adapter.assertBond(BOND_NAME, {
                            'nics': [nic1, nic2],
                            'switch': 'legacy'
                        })

                        nic1_info = adapter.netinfo.nics[nic1]
                        nic2_info = adapter.netinfo.nics[nic2]
                        vlan_info = adapter.netinfo.vlans[vlan.devName]
                        assert nic1_info['ipv4addrs'] == []
                        assert nic2_info['ipv4addrs'] == []
                        assert vlan_info['ipv4addrs'] == [
                            ADDRESS2 + '/' + PREFIX
                        ]

            adapter.setupNetworks({}, {BOND_NAME: {'remove': True}}, NOCHK)
Esempio n. 32
0
    def test_remove_bond_under_network(self, switch, bridged):
        with dummy_devices(1) as nics:
            NETCREATE = {
                NETWORK1_NAME: {
                    'bonding': BOND_NAME,
                    'bridged': bridged,
                    'switch': switch
                }
            }
            BONDCREATE = {BOND_NAME: {'nics': nics, 'switch': switch}}
            with adapter.setupNetworks(NETCREATE, BONDCREATE, NOCHK):

                BONDEDIT = {BOND_NAME: {'remove': True}}
                with pytest.raises(SetupNetworksError) as err:
                    adapter.setupNetworks({}, BONDEDIT, NOCHK)
                assert err.value.status == ne.ERR_USED_BOND

                adapter.assertNetwork(NETWORK1_NAME, NETCREATE[NETWORK1_NAME])
                adapter.assertBond(BOND_NAME, BONDCREATE[BOND_NAME])
Esempio n. 33
0
 def test_bond_mode_change(self, switch):
     with dummy_devices(2) as nics:
         BONDCREATE = {
             BOND_NAME: {
                 'nics': nics,
                 'switch': switch,
                 'options': 'mode=1 miimon=150',
             }
         }
         BONDEDIT = {
             BOND_NAME: {
                 'nics': nics,
                 'switch': switch,
                 'options': 'mode=3',
             }
         }
         with adapter.setupNetworks({}, BONDCREATE, NOCHK):
             adapter.setupNetworks({}, BONDEDIT, NOCHK)
             adapter.assertBond(BOND_NAME, BONDEDIT[BOND_NAME])
Esempio n. 34
0
    def test_nm_connection_lifetime(self):
        nm_act_cons = NMDbusActiveConnections()
        nm_device = NMDbusDevice()

        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface, IPV4ADDR, slaves=nics):
                device = nm_device.device(iface)
                device.syncoper.waitfor_activated_state()
                active_con_path = device.active_connection_path()
                active_con = nm_act_cons.connection(active_con_path)

                self.assertEqual(TEST_LINK_TYPE, str(active_con.type()))
                self.assertEqual(
                    nmtypes.NMActiveConnectionState.ACTIVATED,
                    active_con.state(),
                )

        self._assert_no_device(iface)
Esempio n. 35
0
    def test_switch_change_bonded_network_with_static_ip(self, sw_src, sw_dst):
        with dummy_devices(2) as (nic1, nic2):
            NETSETUP_SOURCE = {NET1_NAME: {
                'bonding': BOND_NAME,
                'ipaddr': IPv4_ADDRESS,
                'netmask': IPv4_NETMASK,
                'ipv6addr': IPv6_ADDRESS + '/' + IPv6_PREFIX_LEN,
                'switch': sw_src}}
            NETSETUP_TARGET = _change_switch_type(NETSETUP_SOURCE, sw_dst)
            BONDSETUP_SOURCE = {BOND_NAME: {
                'nics': [nic1, nic2], 'switch': sw_src}}
            BONDSETUP_TARGET = _change_switch_type(BONDSETUP_SOURCE, sw_dst)

            with adapter.setupNetworks(
                    NETSETUP_SOURCE, BONDSETUP_SOURCE, NOCHK):
                adapter.setupNetworks(
                    NETSETUP_TARGET, BONDSETUP_TARGET, NOCHK)
                adapter.assertNetwork(NET1_NAME, NETSETUP_TARGET[NET1_NAME])
                adapter.assertBond(BOND_NAME, BONDSETUP_TARGET[BOND_NAME])
Esempio n. 36
0
    def test_adding_a_net_updates_the_mtu(self, switch, bridged, bonded):
        with dummy_devices(1) as (nic,):
            NETWORK1_ATTRS = {'bridged': bridged,
                              'vlan': VLAN1,
                              'mtu': 1600,
                              'switch': switch}
            NETWORK2_ATTRS = {'bridged': bridged,
                              'vlan': VLAN2,
                              'mtu': 2000,
                              'switch': switch}
            NETBASE = {NETWORK1_NAME: NETWORK1_ATTRS}
            NETNEW = {NETWORK2_NAME: NETWORK2_ATTRS}

            if bonded:
                NETWORK1_ATTRS['bonding'] = BOND_NAME
                NETWORK2_ATTRS['bonding'] = BOND_NAME
                BONDBASE = {BOND_NAME: {'nics': [nic], 'switch': switch}}
                link2monitor = BOND_NAME
            else:
                NETWORK1_ATTRS['nic'] = nic
                NETWORK2_ATTRS['nic'] = nic
                BONDBASE = {}
                link2monitor = nic

            with adapter.setupNetworks(NETBASE, BONDBASE, nftestlib.NOCHK):
                with nftestlib.monitor_stable_link_state(link2monitor):
                    with adapter.setupNetworks(NETNEW, {}, nftestlib.NOCHK):
                        adapter.assertNetwork(NETWORK2_NAME, NETWORK2_ATTRS)
                        adapter.assertLinkMtu(nic, NETWORK2_ATTRS)

                        if bonded:
                            vlan1 = BOND_NAME + '.' + str(
                                NETWORK1_ATTRS['vlan'])
                            vlan2 = BOND_NAME + '.' + str(
                                NETWORK2_ATTRS['vlan'])
                            adapter.assertLinkMtu(BOND_NAME, NETWORK2_ATTRS)
                        else:
                            vlan1 = nic + '.' + str(NETWORK1_ATTRS['vlan'])
                            vlan2 = nic + '.' + str(NETWORK2_ATTRS['vlan'])

                        adapter.assertLinkMtu(vlan1, NETWORK1_ATTRS)
                        adapter.assertLinkMtu(vlan2, NETWORK2_ATTRS)
Esempio n. 37
0
def test_setup_invalid_bridge_opts_fails():
    with dummy_devices(1) as (nic,):
        net_attrs = {
            'nic': nic,
            'switch': 'legacy',
            'custom': {'bridge_opts': 'foo=0'},
        }

        # Currently, as the network scripts are still used, adding a
        # non existent option will not raise any error, thus eventually
        # failing with an assertionError due to no error raised.
        expect_setup_err_cm = pytest.raises(SetupNetworksError)
        expected_assert_err_cm = pytest.raises(AssertionError)
        nm_backend = nftestlib.is_nmstate_backend()

        with expect_setup_err_cm if nm_backend else expected_assert_err_cm:
            adapter.setupNetworks({NETWORK_NAME: net_attrs}, {}, NOCHK)

        adapter.update_netinfo()
        adapter.assertNoNetwork(NETWORK_NAME)
Esempio n. 38
0
    def test_bond_update_existing_arp_ip_targets(self):
        preserved_addr = '10.1.4.1'
        removed_addr = '10.1.3.1,10.1.2.1'
        added_addr = '10.1.1.1'

        OPTIONS_A = {
            'mode': '1',
            'arp_interval': '1000',
            'arp_ip_target': ','.join([preserved_addr, removed_addr])}
        OPTIONS_B = {
            'mode': '1',
            'arp_interval': '1000',
            'arp_ip_target': ','.join([preserved_addr, added_addr])}

        with dummy_devices(2) as (nic1, nic2):
            with bond_device() as bond:
                bond.set_options(OPTIONS_A)
                bond.set_options(OPTIONS_B)
                bond.refresh()
                self.assertEqual(bond.options, OPTIONS_B)
Esempio n. 39
0
    def test_bond_edit_options(self):
        OPTIONS_A = {'mode': '1', 'miimon': '300'}
        OPTIONS_B = {'mode': '2'}
        OPTIONS_C = {'mode': 'balance-rr', 'miimon': '150'}

        with dummy_devices(2) as (nic1, nic2):
            with bond_device() as bond:
                bond.set_options(OPTIONS_A)
                bond.add_slaves((nic1, nic2))
                _bond = Bond(bond.master)
                self.assertEqual(_bond.options, OPTIONS_A)

                bond.set_options(OPTIONS_B)
                _bond.refresh()
                self.assertEqual(_bond.options, OPTIONS_B)

                bond.set_options(OPTIONS_C)
                _bond.refresh()
                OPTIONS_C['mode'] = '0'
                self.assertEqual(_bond.options, OPTIONS_C)
Esempio n. 40
0
    def test_add_net_on_existing_external_bond_preserving_mac(self, switch):
        if switch == 'ovs':
            pytest.xfail('Preserving bond mac is not supported on OVS switch.')
        HWADDRESS = 'ce:0c:46:59:c9:d1'
        with dummy_devices(2) as (nic1, nic2):
            with Bond(BOND_NAME, slaves=(nic1, nic2)) as bond:
                bond.create()
                iface(BOND_NAME).set_address(HWADDRESS)

                NETBASE = {NETWORK1_NAME: {'bonding': BOND_NAME,
                                           'bridged': False,
                                           'switch': switch}}
                with adapter.setupNetworks(NETBASE, {}, NOCHK):
                    adapter.assertNetwork(NETWORK1_NAME,
                                          NETBASE[NETWORK1_NAME])
                    adapter.assertBond(
                        BOND_NAME, {'nics': [nic1, nic2],
                                    'hwaddr': HWADDRESS,
                                    'switch': switch})
            adapter.setupNetworks({}, {BOND_NAME: {'remove': True}}, NOCHK)
Esempio n. 41
0
 def test_bond_active_slave_report(self, switch):
     with dummy_devices(2) as nics:
         BONDCREATE = {
             BOND_NAME: {
                 'nics': nics,
                 'switch': switch,
                 'options': 'mode=1'
             }
         }
         BONDEDIT = {
             BOND_NAME: {
                 'nics': nics,
                 'switch': switch,
                 'options': 'mode=4'
             }
         }
         with adapter.setupNetworks({}, BONDCREATE, NOCHK):
             adapter.assertBondActiveSlaveExists(BOND_NAME, nics)
             adapter.setupNetworks({}, BONDEDIT, NOCHK)
             adapter.assertBondNoActiveSlaveExists(BOND_NAME)
Esempio n. 42
0
    def test_remove_broken_network(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            BROKEN_NETCREATE = {
                NETWORK_NAME: {
                    'bonding': BOND_NAME,
                    'bridged': True,
                    'vlan': VLAN,
                    'netmask': '300.300.300.300',
                    'ipaddr': '300.300.300.300',
                    'switch': switch
                }
            }
            BONDCREATE = {BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}

            with pytest.raises(SetupNetworksError):
                adapter.setupNetworks(BROKEN_NETCREATE, BONDCREATE, NOCHK)

                adapter.update_netinfo()
                adapter.assertNoNetwork(NETWORK_NAME)
                adapter.assertNoBond(BOND_NAME)
Esempio n. 43
0
    def _test_add_net_with_ip(self,
                              families,
                              switch,
                              bonded=False,
                              vlaned=False,
                              bridged=False):
        IPv6_ADDRESS_AND_PREFIX_LEN = IPv6_ADDRESS + '/' + IPv6_PREFIX_LEN

        with dummy_devices(2) as (nic1, nic2):
            network_attrs = {'bridged': bridged, 'switch': switch}

            if IpFamily.IPv4 in families:
                network_attrs['ipaddr'] = IPv4_ADDRESS
                network_attrs['netmask'] = IPv4_NETMASK
            if IpFamily.IPv6 in families:
                network_attrs['ipv6addr'] = IPv6_ADDRESS_AND_PREFIX_LEN

            if bonded:
                bondcreate = {
                    BOND_NAME: {
                        'nics': [nic1, nic2],
                        'switch': switch
                    }
                }
                network_attrs['bonding'] = BOND_NAME
            else:
                bondcreate = {}
                network_attrs['nic'] = nic1

            if vlaned:
                network_attrs['vlan'] = VLAN

            netcreate = {NETWORK_NAME: network_attrs}

            with adapter.setupNetworks(netcreate, bondcreate, NOCHK):
                adapter.assertNetworkIp(NETWORK_NAME, netcreate[NETWORK_NAME])
                if vlaned:
                    base = (adapter.netinfo.bondings.get(BOND_NAME)
                            or adapter.netinfo.nics[nic1])
                    adapter.assertDisabledIPv4(base)
                    adapter.assertDisabledIPv6(base)
Esempio n. 44
0
    def test_base_iface_mtu_is_preserved_when_not_all_nets_on_top_are_deleted(
            self, switch, bridged, bonded):
        if switch == 'legacy' and bonded and not nmstate.is_nmstate_backend():
            pytest.xfail('BZ#1633528')

        common_net_mtu = MTU_1600
        with dummy_devices(1) as (nic, ):
            vlaned_network = {
                'bridged': bridged,
                'vlan': VLAN1,
                'mtu': common_net_mtu,
                'switch': switch,
            }
            non_vlaned_network = {
                'bridged': bridged,
                'mtu': common_net_mtu,
                'switch': switch,
            }
            all_networks = {
                NETWORK1_NAME: vlaned_network,
                NETWORK2_NAME: non_vlaned_network,
            }

            mtu_to_keep = {'mtu': common_net_mtu}
            if bonded:
                vlaned_network['bonding'] = BOND_NAME
                non_vlaned_network['bonding'] = BOND_NAME
                bonds = {BOND_NAME: {'nics': [nic], 'switch': switch}}
            else:
                vlaned_network['nic'] = nic
                non_vlaned_network['nic'] = nic
                bonds = {}

            with adapter.setupNetworks(all_networks, bonds, nftestlib.NOCHK):
                adapter.setupNetworks({NETWORK1_NAME: {
                    'remove': True
                }}, {}, nftestlib.NOCHK)

                adapter.assertLinkMtu(nic, mtu_to_keep)
                if bonded:
                    adapter.assertLinkMtu(BOND_NAME, mtu_to_keep)
Esempio n. 45
0
    def test_switch_change_bonded_network(self, sw_src, sw_dst):
        with dummy_devices(2) as (nic1, nic2):
            NETSETUP_SOURCE = {
                NET1_NAME: {
                    'bonding': BOND_NAME,
                    'switch': sw_src
                }
            }
            NETSETUP_TARGET = _change_switch_type(NETSETUP_SOURCE, sw_dst)
            BONDSETUP_SOURCE = {
                BOND_NAME: {
                    'nics': [nic1, nic2],
                    'switch': sw_src
                }
            }
            BONDSETUP_TARGET = _change_switch_type(BONDSETUP_SOURCE, sw_dst)

            with self.setupNetworks(NETSETUP_SOURCE, BONDSETUP_SOURCE, NOCHK):
                self.setupNetworks(NETSETUP_TARGET, BONDSETUP_TARGET, NOCHK)
                self.assertNetwork(NET1_NAME, NETSETUP_TARGET[NET1_NAME])
                self.assertBond(BOND_NAME, BONDSETUP_TARGET[BOND_NAME])
Esempio n. 46
0
    def test_restore_missing_network_from_config(self, switch, bridged):
        with dummy_devices(1) as (nic, ):
            SETUP_NET = {
                NETWORK_NAME: {
                    'nic': nic,
                    'bridged': bridged,
                    'switch': switch,
                }
            }
            REMOVE_NET = {NETWORK_NAME: {'remove': True}}

            with adapter.reset_persistent_config():
                with adapter.setupNetworks(SETUP_NET, {}, NOCHK):
                    adapter.setSafeNetworkConfig()
                    adapter.setupNetworks(REMOVE_NET, {}, NOCHK)

                    adapter.assertNoNetworkExists(NETWORK_NAME)

                    adapter.restore_nets()

                    adapter.assertNetworkExists(NETWORK_NAME)
Esempio n. 47
0
    def test_removing_a_net_updates_the_mtu(self, switch, bridged, bonded):
        if switch == 'ovs':
            pytest.xfail('MTU editation is not supported on OVS switches.')
        with dummy_devices(1) as (nic, ):
            NETWORK1_ATTRS = {
                'bridged': bridged,
                'vlan': VLAN1,
                'mtu': 1600,
                'switch': switch
            }
            NETWORK2_ATTRS = {
                'bridged': bridged,
                'vlan': VLAN2,
                'mtu': 2000,
                'switch': switch
            }
            NETBASE = {
                NETWORK1_NAME: NETWORK1_ATTRS,
                NETWORK2_NAME: NETWORK2_ATTRS
            }
            if bonded:
                NETWORK1_ATTRS['bonding'] = BOND_NAME
                NETWORK2_ATTRS['bonding'] = BOND_NAME
                BONDBASE = {BOND_NAME: {'nics': [nic], 'switch': switch}}
                link2monitor = BOND_NAME
            else:
                NETWORK1_ATTRS['nic'] = nic
                NETWORK2_ATTRS['nic'] = nic
                BONDBASE = {}
                link2monitor = nic

            with self.setupNetworks(NETBASE, BONDBASE, nftestlib.NOCHK):
                with nftestlib.monitor_stable_link_state(link2monitor):
                    self.setupNetworks({NETWORK2_NAME: {
                        'remove': True
                    }}, {}, nftestlib.NOCHK)
                    self.assertNetwork(NETWORK1_NAME, NETWORK1_ATTRS)
                    self.assertLinkMtu(nic, NETWORK1_ATTRS)
                    if bonded:
                        self.assertLinkMtu(BOND_NAME, NETWORK1_ATTRS)
Esempio n. 48
0
    def test_move_net_from_one_iface_to_another_with_non_default_mtu(
            self, switch, bridged, bonded, vlan):
        if switch == 'legacy' and bonded and not nmstate.is_nmstate_backend():
            pytest.skip('Not supported with ifcfg BZ#1790761')
        with dummy_devices(2) as (nic1, nic2):
            net_attrs = {'bridged': bridged, 'mtu': MTU_2000, 'switch': switch}
            default_mtu = {'mtu': DEFAULT_MTU}
            if bonded:
                net_attrs['bonding'] = BOND_NAME
                BONDBASE = {
                    BOND_NAME: {
                        'nics': [nic1],
                        'switch': switch
                    },
                    BOND_NAME2: {
                        'nics': [nic2],
                        'switch': switch
                    },
                }
            else:
                net_attrs['nic'] = nic1
                BONDBASE = {}

            if vlan:
                net_attrs['vlan'] = VLAN1

            with adapter.setupNetworks({NETWORK_NAME: net_attrs}, BONDBASE,
                                       nftestlib.NOCHK):
                if bonded:
                    net_attrs['bonding'] = BOND_NAME2
                else:
                    net_attrs['nic'] = nic2
                adapter.setupNetworks({NETWORK_NAME: net_attrs}, {},
                                      nftestlib.NOCHK)
                adapter.assertNetwork(NETWORK_NAME, net_attrs)
                if bonded:
                    adapter.assertLinkMtu(BOND_NAME, default_mtu)
                    adapter.assertLinkMtu(BOND_NAME2, net_attrs)
                adapter.assertLinkMtu(nic1, default_mtu)
                adapter.assertLinkMtu(nic2, net_attrs)
Esempio n. 49
0
 def test_move_vlan_and_create_new_network_on_old_iface(self, switch):
     with dummy_devices(2) as (nic1, nic2):
         initital_net_attrs = {
             'bridged': False,
             'nic': nic1,
             'vlan': VLANID,
             'switch': switch,
         }
         with adapter.setupNetworks({NET_1: initital_net_attrs}, {}, NOCHK):
             updated_net_attributes = {
                 'bridged': False,
                 'nic': nic2,
                 'vlan': VLANID,
                 'switch': switch,
             }
             with adapter.setupNetworks(
                 {NET_1: updated_net_attributes, NET_2: initital_net_attrs},
                 {},
                 NOCHK,
             ):
                 adapter.assertNetwork(NET_1, updated_net_attributes)
                 adapter.assertNetwork(NET_2, initital_net_attrs)
Esempio n. 50
0
    def test_add_vlan_network_on_existing_external_bond_with_used_slave(self):
        with dummy_devices(2) as (nic1, nic2):
            with Bond(BOND_NAME, slaves=(nic1, nic2)) as bond:
                bond.create()
                bond.up()
                with vlan_device(nic1):
                    NETBASE = {
                        NETWORK1_NAME: {
                            'bonding': BOND_NAME,
                            'bridged': True,
                            'switch': 'legacy',
                            'vlan': 17,
                        }
                    }

                    with pytest.raises(SetupNetworksError) as err:
                        with adapter.setupNetworks(NETBASE, {}, NOCHK):
                            pass

                    assert err.value.status == ne.ERR_USED_NIC
                    assert 'already used by' in err.value.msg
                bond.destroy()
Esempio n. 51
0
    def test_given_bonded_net_replace_bond_with_a_slave(self, switch, bridged):
        with dummy_devices(2) as (nic1, nic2):
            NETBASE = {
                NETWORK1_NAME: {
                    'bonding': BOND_NAME,
                    'bridged': bridged,
                    'switch': switch,
                }
            }
            BONDBASE = {BOND_NAME: {'nics': [nic1, nic2], 'switch': switch}}

            with adapter.setupNetworks(NETBASE, BONDBASE, NOCHK):
                NETBASE[NETWORK1_NAME] = {
                    'nic': nic1,
                    'bridged': bridged,
                    'switch': switch,
                }
                BONDBASE[BOND_NAME] = {'remove': True}
                adapter.setupNetworks(NETBASE, BONDBASE, NOCHK)

                adapter.assertNetwork(NETWORK1_NAME, NETBASE[NETWORK1_NAME])
                adapter.assertNoBond(BOND_NAME)
Esempio n. 52
0
    def test_given_bonded_net_transfer_one_slave_to_new_net(
            self, switch, bridged):
        with dummy_devices(3) as (nic1, nic2, nic3):
            NETBASE = {
                NETWORK1_NAME: {
                    'bonding': BOND_NAME,
                    'bridged': bridged,
                    'switch': switch
                }
            }
            BONDBASE = {
                BOND_NAME: {
                    'nics': [nic1, nic2, nic3],
                    'switch': switch
                }
            }

            with adapter.setupNetworks(NETBASE, BONDBASE, NOCHK):
                NETNEW = {
                    NETWORK2_NAME: {
                        'nic': nic3,
                        'bridged': bridged,
                        'switch': switch
                    }
                }
                BONDEDIT = {
                    BOND_NAME: {
                        'nics': [nic1, nic2],
                        'switch': switch
                    }
                }
                with nftestlib.monitor_stable_link_state(BOND_NAME):
                    adapter.setupNetworks({}, BONDEDIT, NOCHK)
                with adapter.setupNetworks(NETNEW, {}, NOCHK):
                    adapter.assertNetwork(NETWORK1_NAME,
                                          NETBASE[NETWORK1_NAME])
                    adapter.assertNetwork(NETWORK2_NAME, NETNEW[NETWORK2_NAME])
                    adapter.assertBond(BOND_NAME, BONDEDIT[BOND_NAME])
Esempio n. 53
0
    def test_add_net_and_move_ipv4_default_gateway(self, switch):
        with dummy_devices(2) as (nic1, nic2):
            net1_attrs = {'nic': nic1,
                          'ipaddr': IPv4_ADDRESS,
                          'netmask': IPv4_NETMASK,
                          'gateway': IPv4_GATEWAY,
                          'defaultRoute': True,
                          'switch': switch}
            net2_attrs = {'nic': nic2,
                          'ipaddr': IPv4_ADDRESS2,
                          'netmask': IPv4_NETMASK,
                          'gateway': IPv4_GATEWAY2,
                          'defaultRoute': True,
                          'switch': switch}
            net1create = {NETWORK_NAME: net1_attrs}
            net2create = {NETWORK2_NAME: net2_attrs}

            with restore_resolv_conf(), preserve_default_route():
                with adapter.setupNetworks(net1create, {}, NOCHK):
                    with adapter.setupNetworks(net2create, {}, NOCHK):
                        net1_attrs['defaultRoute'] = False
                        adapter.assertNetworkIp(NETWORK_NAME, net1_attrs)
                        adapter.assertNetworkIp(NETWORK2_NAME, net2_attrs)
    def test_rollback_target_bond_configuration_with_invalid_ip(self,
                                                                sw_src,
                                                                sw_dst):
        with dummy_devices(3) as (nic1, nic2, nic3):
            NETSETUP_SOURCE = {NET1_NAME: {
                'nic': nic1, 'switch': sw_src}}
            BONDSETUP_SOURCE = {BOND_NAME: {
                'nics': [nic2, nic3], 'switch': sw_src}}
            NETSETUP_TARGET = {NET1_NAME: {
                'nic': nic1,
                'ipaddr': '300.300.300.300',  # invalid
                'netmask': IPv4_NETMASK,
                'switch': sw_dst}}
            BONDSETUP_TARGET = {BOND_NAME: {
                'nics': [nic2, nic3], 'switch': sw_dst}}

            with self.setupNetworks(NETSETUP_SOURCE, BONDSETUP_SOURCE, NOCHK):
                with pytest.raises(SetupNetworksError) as e:
                    self.setupNetworks(
                        NETSETUP_TARGET, BONDSETUP_TARGET, NOCHK)
                assert e.value.status == ne.ERR_BAD_ADDR
                self.assertNetwork(NET1_NAME, NETSETUP_SOURCE[NET1_NAME])
                self.assertBond(BOND_NAME, BONDSETUP_SOURCE[BOND_NAME])
Esempio n. 55
0
 def test_bond_arp_ip_target_change(self, switch):
     with dummy_devices(2) as nics:
         create_options = ('mode=1 arp_interval=1000 '
                           'arp_ip_target=192.168.122.1')
         BONDCREATE = {
             BOND_NAME: {
                 'nics': nics,
                 'switch': switch,
                 'options': create_options
             }
         }
         edit_options = ('mode=1 arp_interval=1000 '
                         'arp_ip_target=10.1.3.1,10.1.2.1')
         BONDEDIT = {
             BOND_NAME: {
                 'nics': nics,
                 'switch': switch,
                 'options': edit_options
             }
         }
         with adapter.setupNetworks({}, BONDCREATE, NOCHK):
             adapter.setupNetworks({}, BONDEDIT, NOCHK)
             adapter.assertBond(BOND_NAME, BONDEDIT[BOND_NAME])
Esempio n. 56
0
    def test_static_ip_configuration_v4_to_v6_and_back(self, switch):
        with dummy_devices(1) as (nic1, ):
            net_ipv4_atts = {
                'nic': nic1,
                'ipaddr': IPv4_ADDRESS,
                'netmask': IPv4_NETMASK,
                'switch': switch
            }
            net_ipv6_atts = {
                'nic': nic1,
                'ipv6addr': IPv6_ADDRESS + '/' + IPv6_PREFIX_LEN,
                'switch': switch
            }

            net_ipv4 = {NETWORK_NAME: net_ipv4_atts}
            net_ipv6 = {NETWORK_NAME: net_ipv6_atts}

            with adapter.setupNetworks(net_ipv4, {}, NOCHK):
                adapter.assertNetworkIp(NETWORK_NAME, net_ipv4_atts)
                adapter.setupNetworks(net_ipv6, {}, NOCHK)
                adapter.assertNetworkIp(NETWORK_NAME, net_ipv6_atts)
                adapter.setupNetworks(net_ipv4, {}, NOCHK)
                adapter.assertNetworkIp(NETWORK_NAME, net_ipv4_atts)
Esempio n. 57
0
    def _test_device_with_n_connections(self, con_count):
        nm_device = NMDbusDevice()
        nm_settings = NMDbusSettings()
        nm_act_cons = NMDbusActiveConnections()

        configured_connections = set()
        active_connections = set()

        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(
                iface, IPV4ADDR, slaves=nics, con_count=con_count
            ):
                device = nm_device.device(iface)
                for connection_path in device.connections_path():
                    settings_con = nm_settings.connection(connection_path)
                    configured_connections.add(settings_con.connection.id)

                ac = nm_act_cons.connection(device.active_connection_path())
                active_connections.add(ac.id())

        self.assertEqual(con_count, len(configured_connections))
        self.assertEqual(set([iface + '0']), active_connections)
Esempio n. 58
0
 def test_edit_mtu_on_network(self, switch, bridged, bonded, vlan, mtu):
     with dummy_devices(1) as (nic, ):
         net_attrs = {'bridged': bridged, 'mtu': MTU_2000, 'switch': switch}
         if bonded:
             base_iface = BOND_NAME
             net_attrs['bonding'] = BOND_NAME
             BONDBASE = {BOND_NAME: {'nics': [nic], 'switch': switch}}
         else:
             base_iface = nic
             net_attrs['nic'] = nic
             BONDBASE = {}
         if vlan:
             net_attrs['vlan'] = VLAN1
         with adapter.setupNetworks({NETWORK_NAME: net_attrs}, BONDBASE,
                                    nftestlib.NOCHK):
             net_attrs['mtu'] = mtu
             adapter.setupNetworks({NETWORK_NAME: net_attrs}, {},
                                   nftestlib.NOCHK)
             adapter.assertNetwork(NETWORK_NAME, net_attrs)
             if bonded:
                 adapter.assertLinkMtu(BOND_NAME, net_attrs)
             if vlan:
                 adapter.assertLinkMtu(f'{base_iface}.{VLAN1}', net_attrs)
             adapter.assertLinkMtu(nic, net_attrs)
Esempio n. 59
0
    def test_add_net_based_on_existing_vlan_bond_nm_setup(self):
        vlan_id = '101'
        NET = {
            NETWORK_NAME: {
                'bonding': self.iface,
                'vlan': int(vlan_id),
                'switch': self.switch,
            }
        }
        with dummy_devices(1) as nics:
            with nmnettestlib.nm_connections(
                self.iface, ipv4addr=None, vlan=vlan_id, slaves=nics
            ):
                bond_hwaddress = link_iface.iface(self.iface).address()
                vlan_iface = '.'.join([self.iface, vlan_id])
                vlan_hwaddress = link_iface.iface(vlan_iface).address()
                assert vlan_hwaddress == bond_hwaddress

                with adapter.setupNetworks(NET, {}, NOCHK):
                    adapter.assertNetwork(NETWORK_NAME, NET[NETWORK_NAME])

                    # Check if the mac has been preserved.
                    bridge_hwaddress = link_iface.iface(NETWORK_NAME).address()
                    assert vlan_hwaddress == bridge_hwaddress
Esempio n. 60
0
    def test_device_attributes_existence(self):
        nm_device = NMDbusDevice()
        nm_settings = NMDbusSettings()

        device_count = 0
        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface, IPV4ADDR, slaves=nics):
                for device in nm_device.devices():
                    try:
                        assert device.interface() is not None
                        assert device.state() is not None
                        assert device.active_connection_path() is not None
                        assert device.connections_path() is not None
                    except errors.NMPropertiesNotFoundError:
                        continue

                    for connection_path in device.connections_path():
                        settings_con = nm_settings.connection(connection_path)
                        assert settings_con.connection.uuid is not None

                    device_count += 1

        self.assertGreaterEqual(device_count, 1)