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
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)
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()))
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
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)
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)
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)
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)
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)
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)
def setup_method(self, m): self.iface = nmnettestlib.iface_name()
def setUp(self): self.nm_settings = NMDbusSettings() self.iface = iface_name()
def setup(self, adapter, m): self.iface = nmnettestlib.iface_name() yield # The bond was acquired, therefore VDSM needs to clean it. BONDREMOVE = {self.iface: {'remove': True}} adapter.setupNetworks({}, BONDREMOVE, NOCHK)
def setup_method(self, m): super(TestNetworkManagerLegacy, self).setup_method(m) self.iface = nmnettestlib.iface_name()
from network.nettestlib import dummy_device from network.nmnettestlib import iface_name from network.nmnettestlib import NMService from network.nmnettestlib import nm_connections from network.nmnettestlib import TEST_LINK_TYPE from vdsm.network.nm import errors from vdsm.network.nm.nmdbus import NMDbus from vdsm.network.nm.nmdbus import nmtypes from vdsm.network.nm.nmdbus.active import NMDbusActiveConnections from vdsm.network.nm.nmdbus.device import NMDbusDevice from vdsm.network.nm.nmdbus.settings import NMDbusSettings from .netintegtestlib import requires_systemctl IFACE = iface_name() IPV4ADDR = '10.1.1.1/29' @pytest.fixture(scope='module', autouse=True) def setup(): requires_systemctl() nm_service = NMService() nm_service.setup() try: NMDbus.init() except DBusException as ex: if 'Failed to connect to socket' in ex.args[0]: pytest.skip('dbus socket or the NM service may not be available') yield nm_service.teardown()