mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix s3fs cache byte/str mismatch
This commit is contained in:
parent
e648f231d2
commit
22b9e30ad9
3 changed files with 44 additions and 3 deletions
1
changelog/53244.fixed
Normal file
1
changelog/53244.fixed
Normal file
|
@ -0,0 +1 @@
|
|||
Fix s3fs cache byte/str mismatch
|
|
@ -568,16 +568,23 @@ def _refresh_buckets_cache_file(cache_file):
|
|||
metadata[saltenv].append({bucket_name: env_files})
|
||||
|
||||
# write the metadata to disk
|
||||
_write_buckets_cache_file(metadata, cache_file)
|
||||
|
||||
return metadata
|
||||
|
||||
|
||||
def _write_buckets_cache_file(metadata, cache_file):
|
||||
"""
|
||||
Write the contents of the buckets cache file
|
||||
"""
|
||||
if os.path.isfile(cache_file):
|
||||
os.remove(cache_file)
|
||||
|
||||
log.debug("Writing buckets cache file")
|
||||
|
||||
with salt.utils.files.fopen(cache_file, "w") as fp_:
|
||||
with salt.utils.files.fopen(cache_file, "wb") as fp_:
|
||||
pickle.dump(metadata, fp_)
|
||||
|
||||
return metadata
|
||||
|
||||
|
||||
def _read_buckets_cache_file(cache_file):
|
||||
"""
|
||||
|
|
33
tests/unit/fileserver/test_s3fs.py
Normal file
33
tests/unit/fileserver/test_s3fs.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import tempfile
|
||||
|
||||
# Import Salt libs
|
||||
import salt.fileserver.s3fs as s3fs
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
||||
class S3fsFileTest(TestCase, LoaderModuleMockMixin):
|
||||
def setup_loader_modules(self):
|
||||
opts = {
|
||||
"cachedir": self.tmp_cachedir,
|
||||
}
|
||||
return {s3fs: {"__opts__": opts}}
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
|
||||
|
||||
def test_cache_round_trip(self):
|
||||
metadata = {"foo": "bar"}
|
||||
cache_file = s3fs._get_cached_file_name("base", "fake_bucket", "some_file")
|
||||
|
||||
s3fs._write_buckets_cache_file(metadata, cache_file)
|
||||
assert s3fs._read_buckets_cache_file(cache_file) == metadata
|
Loading…
Add table
Reference in a new issue