Encode injected file data (server-side)

In before, we sent raw file data from client to server over
HTTP. This commit encode injected file data by using
RFC 3548 that are suitable for binary data sent as
part of an HTTP request.

The file will be encoded at client side before sending it
to server. The encoded data will be decoded at server side
before injecting into the container. This commit did the
server-side decoding. Client-side encoding will be done
by another patch.

Needed-By: I41838ccc5c0b5e01d84195cd27f1f5e4dbe84a78
Change-Id: I1ae959778f904dc52f102721558c2ede0ca2e09e
This commit is contained in:
Hongbin Lu 2018-09-05 02:14:04 +00:00
parent 8af77465c3
commit d610918a3c
2 changed files with 6 additions and 3 deletions

View File

@ -16,6 +16,7 @@ from oslo_serialization import jsonutils
from oslo_utils import uuidutils
from zun.common import exception
from zun.common import utils
import zun.conf
from zun.tests import base
from zun.volume import driver
@ -228,7 +229,8 @@ class LocalVolumeDriverTestCase(base.TestCase):
expected_file_path = self.fake_mountpoint + '/' + self.fake_uuid
mock_open.assert_called_once_with(expected_file_path, 'wb')
mock_open().write.assert_called_once_with(self.fake_contents)
mock_open().write.assert_called_once_with(
utils.decode_file_data(self.fake_contents))
mock_get_mountpoint.assert_called_once_with(self.fake_uuid)
@mock.patch('shutil.rmtree')

View File

@ -15,7 +15,6 @@ import functools
import shutil
import six
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import fileutils
@ -24,6 +23,7 @@ from stevedore import driver as stevedore_driver
from zun.common import exception
from zun.common.i18n import _
from zun.common import mount
from zun.common import utils
import zun.conf
from zun.volume import cinder_api
from zun.volume import cinder_workflow
@ -96,7 +96,8 @@ class Local(VolumeDriver):
fileutils.ensure_tree(mountpoint)
filename = '/'.join([mountpoint, volume.uuid])
with open(filename, 'wb') as fd:
fd.write(volume.contents)
content = utils.decode_file_data(volume.contents)
fd.write(content)
def _remove_local_file(self, volume):
mountpoint = mount.get_mountpoint(volume.uuid)