Add base CollectionArchivator class
This class required for archivation and restore groups of archivators.
You can set up extra_pre_restore_check, extra_backup and extra_restore
action. This actions will runn after base_actions of classes setting up
in archivator_classes.
Usage:
class SimpleCollectionArchivator(CollectionArchivator):
archivator_classes = [Archivator1, Archivator2, Archivator3]
Change-Id: Ie534ffd5c06abd48837f84dfb495410dbf5afa61
(cherry picked from commit 3636aa3793
)
This commit is contained in:
parent
35b4a1adf1
commit
ee5223ae12
@ -135,3 +135,25 @@ class PathArchivator(Base):
|
||||
member.name = member.name.split("/", 1)[-1]
|
||||
path = self.path
|
||||
self.archive.extract(member, path)
|
||||
|
||||
|
||||
class CollectionArchivator(Base):
|
||||
|
||||
archivators_classes = []
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CollectionArchivator, self).__init__(*args, **kwargs)
|
||||
self.archivators = [c(*args, **kwargs)
|
||||
for c in self.archivators_classes]
|
||||
|
||||
def backup(self):
|
||||
for archvator in self.archivators:
|
||||
archvator.backup()
|
||||
|
||||
def restore(self):
|
||||
for archvator in self.archivators:
|
||||
archvator.restore()
|
||||
|
||||
def pre_restore_check(self):
|
||||
for archvator in self.archivators:
|
||||
archvator.pre_restore_check()
|
||||
|
33
octane/tests/test_base_collection_archivator.py
Normal file
33
octane/tests/test_base_collection_archivator.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from octane.handlers.backup_restore import base
|
||||
|
||||
|
||||
@pytest.mark.parametrize("action", ["backup", "restore", "pre_restore_check"])
|
||||
@pytest.mark.parametrize("archivators", [[mock.Mock(), mock.Mock()], []])
|
||||
def test_collection_archivator(action, archivators):
|
||||
|
||||
class TestCollectionArchivator(base.CollectionArchivator):
|
||||
|
||||
archivators_classes = archivators
|
||||
|
||||
archive = mock.Mock()
|
||||
context = mock.Mock()
|
||||
|
||||
getattr(TestCollectionArchivator(archive, context), action)()
|
||||
|
||||
for archivator in archivators:
|
||||
getattr(archivator.return_value, action).assert_called_once_with()
|
Loading…
Reference in New Issue
Block a user