Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Newbie08
salt
invalidate-file-list-cache-when-cache-file-modi...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File invalidate-file-list-cache-when-cache-file-modified-.patch of Package salt
From c9268ec731371cdd7b2fc129ad111d9f73800752 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 | 53 +++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/salt/fileserver/__init__.py b/salt/fileserver/__init__.py index c8c417168f..b9e345d8c3 100644 --- a/salt/fileserver/__init__.py +++ b/salt/fileserver/__init__.py @@ -132,7 +132,7 @@ def check_file_list_cache(opts, form, list_cache, w_lock): 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 0bf30ee5cc..a1087bf4b0 100644 --- a/tests/unit/test_fileserver.py +++ b/tests/unit/test_fileserver.py @@ -1,14 +1,15 @@ -# -*- coding: utf-8 -*- """ :codeauthor: Joao Mesquita <jmesquita@sangoma.com> """ -# Import Python libs -from __future__ import absolute_import, print_function, unicode_literals -from salt import fileserver +import datetime +import os +import time -# Import Salt Testing libs +import salt.utils.files +from salt import fileserver +from tests.support.helpers import with_tempdir from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase @@ -31,22 +32,38 @@ class MapDiffTestCase(TestCase): assert fileserver.diff_mtime_map(map1, map2) is True -class VCSBackendWhitelistCase(TestCase, LoaderModuleMockMixin): +class VCSBackendWhitelistCase(TestCase): def setup_loader_modules(self): return {fileserver: {}} - def test_whitelist(self): + @with_tempdir() + def test_future_file_list_cache_file_ignored(self, cachedir): opts = { - "fileserver_backend": ["roots", "git", "hgfs", "svn"], + "fileserver_backend": ["roots"], + "cachedir": cachedir, "extension_modules": "", } - fs = fileserver.Fileserver(opts) - assert fs.servers.whitelist == [ - "git", - "gitfs", - "hg", - "hgfs", - "svn", - "svnfs", - "roots", - ], fs.servers.whitelist + + 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.29.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor