Пример #1
0
    def test_remove_all_non_active_connection_from_a_device(self, nic0):
        iface = iface_name()
        with nm_connections(iface, IPV4ADDR, slaves=(nic0, ), con_count=3):
            device = networkmanager.Device(iface)
            device.cleanup_inactive_connections()

            assert sum(1 for _ in device.connections()) == 1
Пример #2
0
    def test_configured_connections_attributes_existence(self, nic0, nmd_bus):
        with nm_connections(IFACE, IPV4ADDR, slaves=(nic0, )) as connames:
            nm_con = self._get_connection(connames[0], nmd_bus)

            assert nm_con.connection.id == connames[0]
            assert nm_con.connection.uuid is not None
            assert nm_con.connection.type is not None
Пример #3
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
Пример #4
0
    def test_detect_connection_based_on_ifcfg_file(self):
        """
        NM may use ifcfg files as its storage format for connections via the
        ifcfg-rh settings plugin.
        This is the default option under RHEL/Centos/Fedora.
        When a connection is defined, it is saved in an ifcfg file, however,
        the filename is not recorded in NM records.
        In some scenarios, it is useful look for the ifcfg filename based on
        a given connection or the other way around, looking for the connection
        given the filename.
        """
        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface,
                                IPV4ADDR,
                                slaves=nics,
                                con_count=3,
                                save=True):
                device = networkmanager.Device(iface)
                expected_uuids = {
                    con.connection.uuid
                    for con in device.connections()
                }

                actual_uuids = {
                    networkmanager.ifcfg2connection(file)[0]
                    for file in self._ifcfg_files()
                }

                self.assertLessEqual(expected_uuids, actual_uuids)
Пример #5
0
 def test_add_net_based_on_device_with_multiple_nm_connections(self):
     IPv4_ADDRESS = '192.0.2.1'
     NET = {NETWORK_NAME: {'bonding': self.iface, 'switch': self.switch}}
     with dummy_devices(1) as nics:
         with nmnettestlib.nm_connections(
                 self.iface, IPv4_ADDRESS, con_count=3, slaves=nics):
             with self.setupNetworks(NET, {}, NOCHK):
                 self.assertNetwork(NETWORK_NAME, NET[NETWORK_NAME])
Пример #6
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)
Пример #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)
Пример #8
0
    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()))
Пример #9
0
    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()))
Пример #10
0
 def test_add_net_based_on_device_with_multiple_nm_connections(
         self, adapter, nic0):
     IPv4_ADDRESS = '192.0.2.1'
     NET = {NETWORK_NAME: {'bonding': self.iface, 'switch': self.switch}}
     with nmnettestlib.nm_connections(self.iface,
                                      IPv4_ADDRESS,
                                      con_count=3,
                                      slaves=[nic0]):
         with adapter.setupNetworks(NET, {}, NOCHK):
             adapter.assertNetwork(NETWORK_NAME, NET[NETWORK_NAME])
Пример #11
0
    def test_delete_one_of_two_connections(self, nic0, nmd_bus):
        with nm_connections(IFACE, IPV4ADDR, slaves=(nic0, ),
                            con_count=2) as connames:

            con0 = self._get_connection(connames[0], nmd_bus)
            con0.delete()
            assert self._get_connection(connames[0], nmd_bus) is None

            con1 = self._get_connection(connames[1], nmd_bus)
            assert con1.connection.id == connames[1]
Пример #12
0
    def test_active_connections_properties_vs_connection_settings(
            self, nic0, nmd_bus):
        with nm_connections(IFACE, IPV4ADDR, slaves=(nic0, )):
            for active_con in nmd_bus['active_cons'].connections():
                connection_path = active_con.con_path()
                settings_con = nmd_bus['settings'].connection(connection_path)

                assert active_con.uuid() == settings_con.connection.uuid
                assert active_con.type() == settings_con.connection.type
                assert active_con.id() == settings_con.connection.id
Пример #13
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)
Пример #14
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)
Пример #15
0
    def test_active_connections_properties_existence(self, nic0, nmd_bus):
        with nm_connections(IFACE, IPV4ADDR, slaves=(nic0, )):
            con_count = 0
            for connection in nmd_bus['active_cons'].connections():
                assert connection.id is not None
                assert connection.uuid is not None
                assert connection.type is not None
                assert connection.master_con_path is not None

                con_count += 1

            assert con_count > 0
Пример #16
0
    def test_nm_connection_lifetime(self, nmd_bus):
        with dummy_device() as nic:
            with nm_connections(IFACE, IPV4ADDR, slaves=(nic, )):
                device = nmd_bus['device'].device(IFACE)
                device.syncoper.waitfor_activated_state()
                active_con_path = device.active_connection_path()
                active_con = nmd_bus['active_cons'].connection(active_con_path)

                assert str(active_con.type()) == TEST_LINK_TYPE
                active_state = nmtypes.NMActiveConnectionState.ACTIVATED
                assert active_con.state() == active_state

        self._assert_no_device(IFACE, nmd_bus['device'])
Пример #17
0
    def test_active_connections_properties_vs_connection_settings(self):
        nm_active_cons = NMDbusActiveConnections()
        nm_settings = NMDbusSettings()

        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface, IPV4ADDR, slaves=nics):
                for active_con in nm_active_cons.connections():
                    connection_path = active_con.con_path()
                    settings_con = nm_settings.connection(connection_path)

                    assert active_con.uuid() == settings_con.connection.uuid
                    assert active_con.type() == settings_con.connection.type
                    assert active_con.id() == settings_con.connection.id
Пример #18
0
    def test_active_connections_properties_vs_connection_settings(self):
        nm_active_cons = NMDbusActiveConnections()
        nm_settings = NMDbusSettings()

        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface, IPV4ADDR, slaves=nics):
                for active_con in nm_active_cons.connections():
                    connection_path = active_con.con_path()
                    settings_con = nm_settings.connection(connection_path)

                    assert active_con.uuid() == settings_con.connection.uuid
                    assert active_con.type() == settings_con.connection.type
                    assert active_con.id() == settings_con.connection.id
Пример #19
0
    def test_active_connections_properties_existence(self):
        nm_active_cons = NMDbusActiveConnections()

        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface, IPV4ADDR, slaves=nics):
                con_count = 0
                for connection in nm_active_cons.connections():
                    assert connection.id is not None
                    assert connection.uuid is not None
                    assert connection.type is not None
                    assert connection.master_con_path is not None

                    con_count += 1

                self.assertGreaterEqual(con_count, 1)
Пример #20
0
    def test_active_connections_properties_existence(self):
        nm_active_cons = NMDbusActiveConnections()

        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface, IPV4ADDR, slaves=nics):
                con_count = 0
                for connection in nm_active_cons.connections():
                    assert connection.id is not None
                    assert connection.uuid is not None
                    assert connection.type is not None
                    assert connection.master_con_path is not None

                    con_count += 1

                self.assertGreaterEqual(con_count, 1)
Пример #21
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(types.NMActiveConnectionState.ACTIVATED,
                                 active_con.state())

        self._assert_no_device(iface)
Пример #22
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(types.NMActiveConnectionState.ACTIVATED,
                                 active_con.state())

        self._assert_no_device(iface)
Пример #23
0
    def _test_device_with_n_connections(self, con_count, nic, nmd_bus):
        configured_connections = set()
        active_connections = set()
        with nm_connections(IFACE,
                            IPV4ADDR,
                            slaves=(nic, ),
                            con_count=con_count):
            device = nmd_bus['device'].device(IFACE)
            for connection_path in device.connections_path():
                settings_con = nmd_bus['settings'].connection(connection_path)
                configured_connections.add(settings_con.connection.id)

            active_con = nmd_bus['active_cons'].connection(
                device.active_connection_path())
            active_connections.add(active_con.id())

        assert len(configured_connections) == con_count
        assert active_connections == {IFACE + '0'}
Пример #24
0
    def test_device_attributes_existence(self, nic0, nmd_bus):
        device_count = 0
        with nm_connections(IFACE, IPV4ADDR, slaves=(nic0, )):
            for device in nmd_bus['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 = nmd_bus['settings'].connection(
                        connection_path)
                    assert settings_con.connection.uuid is not None

                device_count += 1

        assert device_count > 0
Пример #25
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)
Пример #26
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)
Пример #27
0
    def test_detect_connection_based_on_ifcfg_file(self):
        """
        NM may use ifcfg files as its storage format for connections via the
        ifcfg-rh settings plugin.
        This is the default option under RHEL/Centos/Fedora.
        When a connection is defined, it is saved in an ifcfg file, however,
        the filename is not recorded in NM records.
        In some scenarios, it is useful look for the ifcfg filename based on
        a given connection or the other way around, looking for the connection
        given the filename.
        """
        iface = iface_name()
        with dummy_devices(1) as nics:
            with nm_connections(iface, IPV4ADDR, slaves=nics, con_count=3,
                                save=True):
                device = networkmanager.Device(iface)
                expected_uuids = {con.connection.uuid
                                  for con in device.connections()}

                actual_uuids = {networkmanager.ifcfg2connection(file)[0]
                                for file in self._ifcfg_files()}

                self.assertLessEqual(expected_uuids, actual_uuids)
Пример #28
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)
Пример #29
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)