96 lines
3.3 KiB
Diff
96 lines
3.3 KiB
Diff
|
From 1ca1bb7c01b1e589147c32b16eda719537ab5b62 Mon Sep 17 00:00:00 2001
|
||
|
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
|
||
|
<psuarezhernandez@suse.com>
|
||
|
Date: Tue, 22 Sep 2020 15:15:51 +0100
|
||
|
Subject: [PATCH] Invalidate file list cache when cache file modified
|
||
|
time is in the future (bsc#1176397)
|
||
|
|
||
|
Add test_future_file_list_cache_file_ignored unit test
|
||
|
---
|
||
|
salt/fileserver/__init__.py | 2 +-
|
||
|
tests/unit/test_fileserver.py | 47 +++++++++++++++++++++++++++++++++--
|
||
|
2 files changed, 46 insertions(+), 3 deletions(-)
|
||
|
|
||
|
diff --git a/salt/fileserver/__init__.py b/salt/fileserver/__init__.py
|
||
|
index 919987e2fc..1b8de51bdc 100644
|
||
|
--- a/salt/fileserver/__init__.py
|
||
|
+++ b/salt/fileserver/__init__.py
|
||
|
@@ -142,7 +142,7 @@ def check_file_list_cache(opts, form, list_cache, w_lock):
|
||
|
'file=%s mtime=%s current_time=%s',
|
||
|
list_cache, current_time, file_mtime
|
||
|
)
|
||
|
- age = 0
|
||
|
+ age = -1
|
||
|
else:
|
||
|
age = current_time - file_mtime
|
||
|
else:
|
||
|
diff --git a/tests/unit/test_fileserver.py b/tests/unit/test_fileserver.py
|
||
|
index d38e22c8e1..b92b32947b 100644
|
||
|
--- a/tests/unit/test_fileserver.py
|
||
|
+++ b/tests/unit/test_fileserver.py
|
||
|
@@ -6,11 +6,17 @@
|
||
|
# Import Python libs
|
||
|
from __future__ import absolute_import, print_function, unicode_literals
|
||
|
|
||
|
-# Import Salt Testing libs
|
||
|
-from tests.support.unit import TestCase
|
||
|
+import datetime
|
||
|
+import os
|
||
|
+import time
|
||
|
|
||
|
+import salt.utils.files
|
||
|
from salt import fileserver
|
||
|
|
||
|
+# Import Salt Testing libs
|
||
|
+from tests.support.helpers import with_tempdir
|
||
|
+from tests.support.unit import TestCase
|
||
|
+
|
||
|
|
||
|
class MapDiffTestCase(TestCase):
|
||
|
def test_diff_with_diffent_keys(self):
|
||
|
@@ -28,3 +34,40 @@ class MapDiffTestCase(TestCase):
|
||
|
map1 = {'file1': 12345}
|
||
|
map2 = {'file1': 1234}
|
||
|
assert fileserver.diff_mtime_map(map1, map2) is True
|
||
|
+
|
||
|
+
|
||
|
+class VCSBackendWhitelistCase(TestCase):
|
||
|
+ def setup_loader_modules(self):
|
||
|
+ return {fileserver: {}}
|
||
|
+
|
||
|
+ @with_tempdir()
|
||
|
+ def test_future_file_list_cache_file_ignored(self, cachedir):
|
||
|
+ opts = {
|
||
|
+ "fileserver_backend": ["roots"],
|
||
|
+ "cachedir": cachedir,
|
||
|
+ "extension_modules": "",
|
||
|
+ }
|
||
|
+
|
||
|
+ back_cachedir = os.path.join(cachedir, "file_lists/roots")
|
||
|
+ os.makedirs(os.path.join(back_cachedir))
|
||
|
+
|
||
|
+ # Touch a couple files
|
||
|
+ for filename in ("base.p", "foo.txt"):
|
||
|
+ with salt.utils.files.fopen(
|
||
|
+ os.path.join(back_cachedir, filename), "wb"
|
||
|
+ ) as _f:
|
||
|
+ if filename == "base.p":
|
||
|
+ _f.write(b"\x80")
|
||
|
+
|
||
|
+ # Set modification time to file list cache file to 1 year in the future
|
||
|
+ now = datetime.datetime.utcnow()
|
||
|
+ future = now + datetime.timedelta(days=365)
|
||
|
+ mod_time = time.mktime(future.timetuple())
|
||
|
+ os.utime(os.path.join(back_cachedir, "base.p"), (mod_time, mod_time))
|
||
|
+
|
||
|
+ list_cache = os.path.join(back_cachedir, "base.p")
|
||
|
+ w_lock = os.path.join(back_cachedir, ".base.w")
|
||
|
+ ret = fileserver.check_file_list_cache(opts, "files", list_cache, w_lock)
|
||
|
+ assert (
|
||
|
+ ret[1] is True
|
||
|
+ ), "Cache file list cache file is not refreshed when future modification time"
|
||
|
--
|
||
|
2.28.0
|
||
|
|
||
|
|