mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Get rid of old hashes of file that 'are expected to be removed' and are indeed 'already removed'
This commit is contained in:
parent
17eec25ed2
commit
84239ac052
2 changed files with 59 additions and 13 deletions
|
@ -485,6 +485,12 @@ def _update_conf_hashes(category, hashes):
|
|||
if category_conf is None:
|
||||
category_conf = {}
|
||||
|
||||
# If a file shall be removed and is indeed removed, forget entirely about
|
||||
# that path.
|
||||
# It avoid keeping weird old entries like
|
||||
# /etc/nginx/conf.d/some.domain.that.got.removed.conf
|
||||
hashes = {path: hash_ for path, hash_ in hashes.items() if hash_ is not None or os.path.exists(path)}
|
||||
|
||||
category_conf['conffiles'] = hashes
|
||||
categories[category] = category_conf
|
||||
_save_regenconf_infos(categories)
|
||||
|
|
|
@ -1,31 +1,25 @@
|
|||
import glob
|
||||
import os
|
||||
import pytest
|
||||
import shutil
|
||||
import requests
|
||||
|
||||
from conftest import message, raiseYunohostError
|
||||
|
||||
from moulinette import m18n
|
||||
from moulinette.utils.filesystem import mkdir
|
||||
|
||||
from yunohost.domain import _get_maindomain, domain_add, domain_remove, domain_list
|
||||
from yunohost.utils.error import YunohostError
|
||||
from yunohost.regenconf import manually_modified_files, _get_conf_hashes, _force_clear_hashes
|
||||
from yunohost.domain import domain_add, domain_remove, domain_list
|
||||
from yunohost.regenconf import regen_conf, manually_modified_files, _get_conf_hashes, _force_clear_hashes
|
||||
|
||||
TEST_DOMAIN = "secondarydomain.test"
|
||||
TEST_DOMAIN_NGINX_CONFIG = "/etc/nginx/conf.d/secondarydomain.test.conf"
|
||||
TEST_DOMAIN_NGINX_CONFIG = "/etc/nginx/conf.d/%s.conf" % TEST_DOMAIN
|
||||
TEST_DOMAIN_DNSMASQ_CONFIG = "/etc/dnsmasq.d/%s" % TEST_DOMAIN
|
||||
|
||||
|
||||
def setup_function(function):
|
||||
|
||||
_force_clear_hashes([TEST_DOMAIN_NGINX_CONFIG])
|
||||
clean()
|
||||
|
||||
|
||||
def teardown_function(function):
|
||||
|
||||
clean()
|
||||
_force_clear_hashes([TEST_DOMAIN_NGINX_CONFIG])
|
||||
|
||||
|
||||
def clean():
|
||||
|
||||
assert os.system("pgrep slapd >/dev/null") == 0
|
||||
|
@ -78,3 +72,49 @@ def test_add_domain_conf_already_exists():
|
|||
assert os.path.exists(TEST_DOMAIN_NGINX_CONFIG)
|
||||
assert TEST_DOMAIN_NGINX_CONFIG in _get_conf_hashes("nginx")
|
||||
assert TEST_DOMAIN_NGINX_CONFIG not in manually_modified_files()
|
||||
|
||||
|
||||
def test_stale_hashes_get_removed_if_empty():
|
||||
"""
|
||||
This is intended to test that if a file gets removed and is indeed removed,
|
||||
we don't keep a useless empty hash corresponding to an old file.
|
||||
In this case, we test this using the dnsmasq conf file (we don't do this
|
||||
using the nginx conf file because it's already force-removed during
|
||||
domain_remove())
|
||||
"""
|
||||
|
||||
domain_add(TEST_DOMAIN)
|
||||
|
||||
assert os.path.exists(TEST_DOMAIN_DNSMASQ_CONFIG)
|
||||
assert TEST_DOMAIN_DNSMASQ_CONFIG in _get_conf_hashes("dnsmasq")
|
||||
|
||||
domain_remove(TEST_DOMAIN)
|
||||
|
||||
assert not os.path.exists(TEST_DOMAIN_DNSMASQ_CONFIG)
|
||||
assert TEST_DOMAIN_DNSMASQ_CONFIG not in _get_conf_hashes("dnsmasq")
|
||||
|
||||
|
||||
def test_stale_hashes_if_file_manually_deleted():
|
||||
"""
|
||||
Same as other test, but manually delete the file in between and check
|
||||
behavior
|
||||
"""
|
||||
|
||||
domain_add(TEST_DOMAIN)
|
||||
|
||||
assert os.path.exists(TEST_DOMAIN_DNSMASQ_CONFIG)
|
||||
assert TEST_DOMAIN_DNSMASQ_CONFIG in _get_conf_hashes("dnsmasq")
|
||||
|
||||
os.remove(TEST_DOMAIN_DNSMASQ_CONFIG)
|
||||
|
||||
assert not os.path.exists(TEST_DOMAIN_DNSMASQ_CONFIG)
|
||||
|
||||
regen_conf(names=["dnsmasq"])
|
||||
|
||||
assert not os.path.exists(TEST_DOMAIN_DNSMASQ_CONFIG)
|
||||
assert TEST_DOMAIN_DNSMASQ_CONFIG in _get_conf_hashes("dnsmasq")
|
||||
|
||||
domain_remove(TEST_DOMAIN)
|
||||
|
||||
assert not os.path.exists(TEST_DOMAIN_DNSMASQ_CONFIG)
|
||||
assert TEST_DOMAIN_DNSMASQ_CONFIG not in _get_conf_hashes("dnsmasq")
|
||||
|
|
Loading…
Add table
Reference in a new issue