Example #1
0
    def _assert_kernel_vs_running_config(self):
        """
        This is a special test, that checks setup integrity through
        non vdsm api data.
        The networking configuration relies on a semi-persistent running
        configuration files, describing the requested configuration.
        This configuration is checked against the actual caps report.
        """

        running_config = kernelconfig.normalize(self.running_config)
        running_config = running_config.as_unicode()

        netinfo = _normalize_caps(self.netinfo)
        kernel_config = kernelconfig.KernelConfig(netinfo)

        _extend_with_bridge_opts(kernel_config, running_config)
        kernel_config = kernel_config.as_unicode()
        _normalize_bonds((kernel_config, running_config))

        self._assert_inclusive_nameservers(kernel_config, running_config)
        # Do not use KernelConfig.__eq__ to get a better exception if something
        # breaks.
        assert running_config['networks'] == kernel_config['networks']
        if is_nmstate_enabled():
            self._assert_inclusive_bond_options(kernel_config, running_config)
        assert running_config['bonds'] == kernel_config['bonds']
Example #2
0
def _classify_nets_bonds_config(persistent_config):
    """
    Return the configuration of networks and bonds, separating the ones changed
    and the ones unchanged:
    changed_nets, changed_bonds, unchanged_nets, unchanged_bonds
    """
    net_info = NetInfo(netswitch.configurator.netinfo())
    current_config = kernelconfig.KernelConfig(net_info)
    desired_config = kernelconfig.normalize(persistent_config)

    changed_nets_names, extra_nets_names = _classify_entities_difference(
        desired_config.networks, current_config.networks
    )

    changed_bonds_names, extra_bonds_names = _classify_entities_difference(
        desired_config.bonds, current_config.bonds
    )

    changed_nets = {
        net: persistent_config.networks[net] for net in changed_nets_names
    }
    changed_bonds = {
        bond: persistent_config.bonds[bond] for bond in changed_bonds_names
    }
    extra_nets = {net: {'remove': True} for net in extra_nets_names}
    extra_bonds = {
        bond: {'remove': True}
        for bond in extra_bonds_names
        if _owned_ifcfg(bond)
    }

    return changed_nets, changed_bonds, extra_nets, extra_bonds
Example #3
0
def remove_networks(networks, bondings, configurator, _netinfo,
                    libvirt_nets):
    kernel_config = kernelconfig.KernelConfig(_netinfo)
    normalized_config = kernelconfig.normalize(
        netconfpersistence.BaseConfig(networks, bondings))

    for network, attrs in networks.items():
        if network in _netinfo.networks:
            logging.debug('Removing network %r', network)
            keep_bridge = _should_keep_bridge(
                network_attrs=normalized_config.networks[network],
                currently_bridged=_netinfo.networks[network]['bridged'],
                net_kernel_config=kernel_config.networks[network]
            )

            _del_network(network, configurator,
                         _netinfo=_netinfo,
                         keep_bridge=keep_bridge)
            _netinfo.del_network(network)
            _netinfo.updateDevices()
        elif network in libvirt_nets:
            # If the network was not in _netinfo but is in the networks
            # returned by libvirt, it means that we are dealing with
            # a broken network.
            logging.debug('Removing broken network %r', network)
            _del_broken_network(network, libvirt_nets[network],
                                configurator=configurator)
            _netinfo.updateDevices()
        elif 'remove' in attrs:
            raise ConfigNetworkError(ne.ERR_BAD_BRIDGE, "Cannot delete "
                                     "network %r: It doesn't exist in the "
                                     "system" % network)
Example #4
0
def remove_networks(networks, bondings, configurator, _netinfo):
    kernel_config = kernelconfig.KernelConfig(_netinfo)
    normalized_config = kernelconfig.normalize(
        netconfpersistence.BaseConfig(networks, bondings, {})
    )
    running_nets = configurator.runningConfig.networks

    for network, attrs in networks.items():
        if network in _netinfo.networks:
            logging.debug('Removing network %r', network)
            keep_bridge = _should_keep_bridge(
                network_attrs=normalized_config.networks[network],
                currently_bridged=_netinfo.networks[network]['bridged'],
                net_kernel_config=kernel_config.networks[network],
            )

            _del_network(
                network, configurator, _netinfo, None, keep_bridge=keep_bridge
            )
            _netinfo.updateDevices()
        elif network in running_nets:
            # If the network was not in _netinfo but is in the persisted
            # networks, it means that we are dealing with a broken network.
            logging.debug('Removing broken network %r', network)
            _del_broken_network(
                network, running_nets[network], configurator=configurator
            )
            _netinfo.updateDevices()
Example #5
0
def _classify_nets_bonds_config(persistent_config):
    """
    Return the configuration of networks and bonds, separating the ones changed
    and the ones unchanged:
    changed_nets, changed_bonds, unchanged_nets, unchanged_bonds
    """
    net_info = NetInfo(netswitch.configurator.netinfo())
    current_config = kernelconfig.KernelConfig(net_info)
    desired_config = kernelconfig.normalize(persistent_config)

    changed_nets_names, extra_nets_names = _classify_entities_difference(
        desired_config.networks, current_config.networks)

    changed_bonds_names, extra_bonds_names = _classify_entities_difference(
        desired_config.bonds, current_config.bonds)

    changed_nets = {
        net: persistent_config.networks[net]
        for net in changed_nets_names
    }
    changed_bonds = {
        bond: persistent_config.bonds[bond]
        for bond in changed_bonds_names
    }
    extra_nets = {net: {'remove': True} for net in extra_nets_names}
    # We cannot ensure which bond is being owned by us, so we should not
    # remove them
    # TODO This should be removed once the cleanup is done
    extra_bonds = {}

    return changed_nets, changed_bonds, extra_nets, extra_bonds
Example #6
0
def remove_networks(networks, bondings, configurator, _netinfo):
    kernel_config = kernelconfig.KernelConfig(_netinfo)
    normalized_config = kernelconfig.normalize(
        netconfpersistence.BaseConfig(networks, bondings))
    running_nets = configurator.runningConfig.networks

    for network, attrs in networks.items():
        if network in _netinfo.networks:
            logging.debug('Removing network %r', network)
            keep_bridge = _should_keep_bridge(
                network_attrs=normalized_config.networks[network],
                currently_bridged=_netinfo.networks[network]['bridged'],
                net_kernel_config=kernel_config.networks[network])

            _del_network(network,
                         configurator,
                         _netinfo,
                         keep_bridge=keep_bridge)
            _netinfo.updateDevices()
        elif network in running_nets:
            # If the network was not in _netinfo but is in the persisted
            # networks, it means that we are dealing with a broken network.
            logging.debug('Removing broken network %r', network)
            _del_broken_network(network,
                                running_nets[network],
                                configurator=configurator)
            _netinfo.updateDevices()
        elif 'remove' in attrs:
            raise ConfigNetworkError(
                ne.ERR_BAD_BRIDGE, "Cannot delete "
                "network %r: It doesn't exist in the "
                "system" % network)
Example #7
0
def _classify_nets_bonds_config(persistent_config):
    """
    Return the configuration of networks and bonds, separating the ones changed
    and the ones unchanged:
    changed_nets, changed_bonds, unchanged_nets, unchanged_bonds
    """
    net_info = NetInfo(netswitch.configurator.netinfo())
    current_config = kernelconfig.KernelConfig(net_info)
    desired_config = kernelconfig.normalize(persistent_config)

    changed_nets_names, extra_nets_names = _classify_entities_difference(
        desired_config.networks, current_config.networks)

    changed_bonds_names, extra_bonds_names = _classify_entities_difference(
        desired_config.bonds, current_config.bonds)

    changed_nets = {net: persistent_config.networks[net]
                    for net in changed_nets_names}
    changed_bonds = {bond: persistent_config.bonds[bond]
                     for bond in changed_bonds_names}
    extra_nets = {net: {'remove': True} for net in extra_nets_names}
    extra_bonds = {bond: {'remove': True} for bond in extra_bonds_names
                   if _owned_ifcfg(bond)}

    return changed_nets, changed_bonds, extra_nets, extra_bonds
Example #8
0
    def _assert_kernel_vs_running_config(self):
        """
        This is a special test, that checks setup integrity through
        non vdsm api data.
        The networking configuration relies on a semi-persistent running
        configuration files, describing the requested configuration.
        This configuration is checked against the actual caps report.
        """

        running_config = kernelconfig.normalize(self.running_config)
        running_config = running_config.as_unicode()

        netinfo = _normalize_caps(self.netinfo)
        kernel_config = kernelconfig.KernelConfig(netinfo)

        _extend_with_bridge_opts(kernel_config, running_config)
        kernel_config = kernel_config.as_unicode()
        _normalize_bonds((kernel_config, running_config))

        self._assert_inclusive_nameservers(kernel_config, running_config)
        # Do not use KernelConfig.__eq__ to get a better exception if something
        # breaks.
        assert running_config['networks'] == kernel_config['networks']
        if vdsm_config.getboolean('vars', 'net_nmstate_enabled'):
            self._assert_inclusive_bond_options(kernel_config, running_config)
        assert running_config['bonds'] == kernel_config['bonds']
Example #9
0
def _get_running_and_kernel_config(bare_running_config):
    """:param config: vdsm configuration, could be retrieved from getProxy()
    """
    netinfo = vdsm.network.netinfo.cache.NetInfo(
        netswitch.configurator.netinfo())
    bare_kernel_config = kernelconfig.KernelConfig(netinfo)
    normalized_running_config = kernelconfig.normalize(bare_running_config)
    # Unify strings to unicode instances so differences are easier to
    # understand. This won't be needed once we move to Python 3.
    return (normalized_running_config.as_unicode(),
            bare_kernel_config.as_unicode())
Example #10
0
    def assert_kernel_vs_running_config(self):
        """
        This is a special test, that checks setup integrity through
        non vdsm api data.
        The networking configuration relies on a semi-persistent running
        configuration files, describing the requested configuration.
        This configuration is checked against the actual caps report.
        """

        running_config = kernelconfig.normalize(self.running_config)
        running_config = running_config.as_unicode()

        netinfo = _normalize_caps(self.netinfo)
        kernel_config = kernelconfig.KernelConfig(netinfo)
        kernel_config = kernel_config.as_unicode()

        # Do not use KernelConfig.__eq__ to get a better exception if something
        # breaks.
        self.assertEqual(running_config['networks'], kernel_config['networks'])
        self.assertEqual(running_config['bonds'], kernel_config['bonds'])
Example #11
0
    def assert_kernel_vs_running_config(self):
        """
        This is a special test, that checks setup integrity through
        non vdsm api data.
        The networking configuration relies on a semi-persistent running
        configuration files, describing the requested configuration.
        This configuration is checked against the actual caps report.
        """

        running_config = kernelconfig.normalize(self.running_config)
        running_config = running_config.as_unicode()

        netinfo = _normalize_caps(self.netinfo)
        kernel_config = kernelconfig.KernelConfig(netinfo)
        kernel_config = kernel_config.as_unicode()

        # Do not use KernelConfig.__eq__ to get a better exception if something
        # breaks.
        assert running_config['networks'] == kernel_config['networks']
        assert running_config['bonds'] == kernel_config['bonds']