From 52ab0b54c6bfb1ddb80a72b4c3a986edfe3310e9 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 22 Aug 2018 23:13:37 -0400 Subject: [PATCH] backups: Implement process manifests for Packet Signed-off-by: James Valleroy Reviewed-by: Joseph Nuthalapati --- plinth/modules/backups/backups.py | 7 ++-- plinth/modules/backups/tests/test_backups.py | 36 +++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/plinth/modules/backups/backups.py b/plinth/modules/backups/backups.py index b14fdc4d6..e317d963e 100644 --- a/plinth/modules/backups/backups.py +++ b/plinth/modules/backups/backups.py @@ -88,8 +88,11 @@ class Packet: def _process_manifests(self): """Look at manifests and fill up the list of directories/files.""" - # XXX: - pass + for manifest in self.manifests: + backup = manifest[2] + for x in ['config', 'data', 'secrets']: + self.directories += backup[x]['directories'] + self.files += backup[x]['files'] def backup_full(backup_handler): diff --git a/plinth/modules/backups/tests/test_backups.py b/plinth/modules/backups/tests/test_backups.py index 396e6c4ca..a60a697a4 100644 --- a/plinth/modules/backups/tests/test_backups.py +++ b/plinth/modules/backups/tests/test_backups.py @@ -21,12 +21,46 @@ Tests for backups module. import unittest from plinth.module_loader import load_modules -from ..backups import _list_of_all_apps_for_backup, _get_apps_in_order +from ..backups import _list_of_all_apps_for_backup, _get_apps_in_order, \ + Packet, validate + + +def _get_test_manifest(name): + return validate({ + 'config': { + 'directories': ['/etc/' + name + '/config.d/'], + 'files': ['/etc/' + name + '/config'], + }, + 'data': { + 'directories': ['/var/lib/' + name + '/data.d/'], + 'files': ['/var/lib/' + name + '/data'], + }, + 'secrets': { + 'directories': ['/etc/' + name + '/secrets.d/'], + 'files': ['/etc/' + name + '/secrets'], + }, + 'services': [name] + }) class TestBackups(unittest.TestCase): """Test cases for backups module.""" + def test_packet_process_manifests(self): + """Test that directories/files are collected from manifests.""" + manifests = [ + ('a', None, _get_test_manifest('a')), + ('b', None, _get_test_manifest('b')), + ] + packet = Packet('backup', 'apps', '/', manifests) + for manifest in manifests: + backup = manifest[2] + for x in ['config', 'data', 'secrets']: + for d in backup[x]['directories']: + assert d in packet.directories + for f in backup[x]['files']: + assert f in packet.files + def test__list_of_all_apps_for_backups(self): """Test that apps supporting backup are included in returned list.""" load_modules()