Exemplo n.º 1
0
    def test_priority(self, available_mocks):
        new_order = [NetplanActivator, NetworkManagerActivator]
        resp = search_activator(priority=new_order)
        assert resp == new_order

        activator = select_activator(priority=new_order)
        assert activator == new_order[0]
Exemplo n.º 2
0
    def apply_network_config(self, netconfig, bring_up=False) -> bool:
        """Apply the network config.

        If bring_up is True, attempt to bring up the passed in devices. If
        devices is None, attempt to bring up devices returned by
        _write_network_config.

        Returns True if any devices failed to come up, otherwise False.
        """
        # This method is preferred to apply_network which only takes
        # a much less complete network config format (interfaces(5)).
        network_state = parse_net_config_data(netconfig)
        try:
            self._write_network_state(network_state)
        except NotImplementedError:
            # backwards compat until all distros have apply_network_config
            return self._apply_network_from_network_config(
                netconfig, bring_up=bring_up
            )

        # Now try to bring them up
        if bring_up:
            LOG.debug("Bringing up newly configured network interfaces")
            try:
                network_activator = activators.select_activator()
            except activators.NoActivatorException:
                LOG.warning(
                    "No network activator found, not bringing up "
                    "network interfaces"
                )
                return True
            network_activator.bring_up_all_interfaces(network_state)
        else:
            LOG.debug("Not bringing up newly configured network interfaces")
        return False
Exemplo n.º 3
0
 def apply(self):
     self.datasource.distro.apply_network_config(
         self.config,
         bring_up=False,
     )
     interface_name = os.path.basename(self.devpath)
     activator = activators.select_activator()
     if self.action == "add":
         if not activator.bring_up_interface(interface_name):
             raise RuntimeError("Failed to bring up device: {}".format(
                 self.devpath))
     elif self.action == "remove":
         if not activator.bring_down_interface(interface_name):
             raise RuntimeError("Failed to bring down device: {}".format(
                 self.devpath))
Exemplo n.º 4
0
    def apply_network_config(self, netconfig, bring_up=False):
        # apply network config netconfig
        # This method is preferred to apply_network which only takes
        # a much less complete network config format (interfaces(5)).
        network_state = parse_net_config_data(netconfig)
        try:
            self._write_network_state(network_state)
        except NotImplementedError:
            # backwards compat until all distros have apply_network_config
            return self._apply_network_from_network_config(
                netconfig, bring_up=bring_up)

        # Now try to bring them up
        if bring_up:
            network_activator = activators.select_activator()
            network_activator.bring_up_all_interfaces(network_state)
        return False
Exemplo n.º 5
0
    def test_none_available(self, unavailable_mocks):
        resp = search_activator()
        assert resp == []

        with pytest.raises(RuntimeError):
            select_activator()
Exemplo n.º 6
0
 def test_priority_not_exist(self, available_mocks):
     with pytest.raises(ValueError):
         search_activator(priority=['spam', 'eggs'])
     with pytest.raises(ValueError):
         select_activator(priority=['spam', 'eggs'])
Exemplo n.º 7
0
    def test_first_not_available(self, m_available, available_mocks):
        resp = search_activator()
        assert resp == DEFAULT_PRIORITY[1:]

        resp = select_activator()
        assert resp == DEFAULT_PRIORITY[1]
Exemplo n.º 8
0
    def test_target(self, available_mocks):
        search_activator(target='/tmp')
        assert '/tmp' == available_mocks.m_which.call_args[1]['target']

        select_activator(target='/tmp')
        assert '/tmp' == available_mocks.m_which.call_args[1]['target']
Exemplo n.º 9
0
    def test_defaults(self, available_mocks):
        resp = search_activator()
        assert resp == DEFAULT_PRIORITY

        activator = select_activator()
        assert activator == DEFAULT_PRIORITY[0]
Exemplo n.º 10
0
    def test_none_available(self, unavailable_mocks):
        resp = search_activator()
        assert resp == []

        with pytest.raises(NoActivatorException):
            select_activator()
Exemplo n.º 11
0
    def test_target(self, available_mocks):
        search_activator(target="/tmp")
        assert "/tmp" == available_mocks.m_which.call_args[1]["target"]

        select_activator(target="/tmp")
        assert "/tmp" == available_mocks.m_which.call_args[1]["target"]