Ejemplo n.º 1
0
    def on_delete_request(self, rsrc_id):
        app_unique_name = rsrc_id

        with lc.LogContext(_LOGGER, rsrc_id):
            veth, _ = _device_from_rsrc_id(app_unique_name)

            try:
                netdev.dev_state(veth)
                netdev.link_del_veth(veth)

            except (OSError, IOError) as err:
                if err.errno != errno.ENOENT:
                    raise

            # Remove it from our state (if present)
            dev_info = self._devices.pop(app_unique_name, None)
            if dev_info is not None and 'ip' in dev_info:
                # Remove the environment mark on the IP
                if 'environment' in dev_info:
                    _delete_mark_rule(
                        dev_info['ip'],
                        dev_info['environment']
                    )
                # VIPs deallocation (the owner is the resource link)
                self._vips.free(app_unique_name, dev_info['ip'])

        return True
Ejemplo n.º 2
0
    def test_dev_state_lldown(self):
        """Test device state read.
        """
        mock_handle = io.open.return_value
        mock_handle.read.return_value = 'lowerlayerdown\n'

        res = netdev.dev_state('foo')

        io.open.assert_called_with('/sys/class/net/foo/operstate')
        self.assertEqual(res, netdev.DevState.LOWER_LAYER_DOWN)
Ejemplo n.º 3
0
    def test_dev_state_up(self):
        """Test device state read.
        """
        mock_handle = io.open.return_value
        mock_handle.read.return_value = 'up\n'

        res = netdev.dev_state('foo')

        io.open.assert_called_with('/sys/class/net/foo/operstate')
        self.assertEqual(res, netdev.DevState.UP)
Ejemplo n.º 4
0
    def test_dev_state(self, mock_open):
        """Test device state read.
        """
        mock_file = mock_open.return_value
        mock_filectx = mock_file.__enter__.return_value
        mock_filectx.read.return_value = 'up\n'

        res = netdev.dev_state('foo')

        mock_open.assert_called_with('/sys/class/net/foo/operstate')
        self.assertEqual(res, netdev.DevState.UP)