Add cobbler profiles and distros backup

During the upgrade from the 6.0 release configuration files of profiles and
distributions for Cobbler should be preserved because this release provides
Ubuntu 12.04 that is not presented in 8.0.

Closes-bug: 1571586
Change-Id: Id9323cbd5f5b73451e5d97ffd4191155c5f5dd5f
(cherry picked from commit 0165988b8f)
This commit is contained in:
Sergey Abramov 2016-04-20 13:57:11 +03:00 committed by Oleg Gelbukh
parent ee5223ae12
commit bfc286cc11
3 changed files with 92 additions and 30 deletions

View File

@ -14,12 +14,35 @@ from octane.handlers.backup_restore import base
from octane.util import docker
class CobblerArchivator(base.ContainerArchivator):
class CobblerSystemArchivator(base.ContainerArchivator):
backup_directory = "/var/lib/cobbler/config/systems.d/"
banned_files = ["default.json"]
container = "cobbler"
backup_name = "cobbler"
class CobblerProfileArchivator(base.ContainerArchivator):
backup_directory = "/var/lib/cobbler/config/profiles.d/"
banned_files = ["bootstrap.json", "ubuntu_bootstrap.json"]
container = "cobbler"
backup_name = "cobbler_profiles"
class CobblerDistroArchivator(base.ContainerArchivator):
backup_directory = "/var/lib/cobbler/config/distros.d/"
banned_files = ["bootstrap.json", "ubuntu_bootstrap.json"]
container = "cobbler"
backup_name = "cobbler_distros"
class CobblerArchivator(base.CollectionArchivator):
archivators_classes = [
CobblerSystemArchivator,
CobblerProfileArchivator,
CobblerDistroArchivator,
]
def restore(self):
super(CobblerArchivator, self).restore()
docker.stop_container("cobbler")

View File

@ -46,19 +46,35 @@ def test_path_backup(mocker, cls, path, name):
@pytest.mark.parametrize(
"cls,banned_files,backup_directory,allowed_files,container,backup_name", [
(
cobbler.CobblerArchivator,
cobbler.CobblerSystemArchivator,
["default.json"],
"/var/lib/cobbler/config/systems.d/",
None,
"cobbler",
"cobbler",
),
(
cobbler.CobblerProfileArchivator,
["bootstrap.json", "ubuntu_bootstrap.json"],
"/var/lib/cobbler/config/profiles.d/",
None,
"cobbler",
"cobbler_profiles",
),
(
cobbler.CobblerDistroArchivator,
["bootstrap.json", "ubuntu_bootstrap.json"],
"/var/lib/cobbler/config/distros.d/",
None,
"cobbler",
"cobbler_distros",
),
])
def test_container_backup(
mocker, cls, banned_files, backup_directory, allowed_files, container,
backup_name):
test_archive = mocker.Mock()
data_lst = (banned_files or []) + (allowed_files or []) + ["tmp1", "tmp2"]
data_lst = banned_files + (allowed_files or []) + ["tmp1", "tmp2"]
stdout_data_lst = [os.path.join(backup_directory, f) for f in data_lst]
data = " ".join(stdout_data_lst)
docker_mock = mocker.patch(
@ -80,11 +96,9 @@ def test_container_backup(
side_effect=foo)
files_to_archive = data_lst
files_to_archive = [d for d in files_to_archive
if d in (allowed_files or [])]
files_to_archive = [d for d in files_to_archive
if d not in (banned_files or [])]
if allowed_files:
files_to_archive = [d for d in files_to_archive if d in allowed_files]
files_to_archive = [d for d in files_to_archive if d not in banned_files]
backuped_files = set()
cls(test_archive).backup()
docker_mock.assert_called_once_with(
@ -94,6 +108,8 @@ def test_container_backup(
)
for filename in files_to_archive:
assert filename in backuped_files
for filename in set(data_lst) - set(files_to_archive):
assert filename not in backuped_files
@pytest.mark.parametrize("cls,db", [

View File

@ -153,28 +153,41 @@ def test_path_restore(mocker, cls, path, members):
member.assert_extract(path)
@pytest.mark.parametrize(
"cls,path,container,backup_name,members,mock_actions",
[
(
cobbler.CobblerArchivator,
"/var/lib/cobbler/config/systems.d/",
"cobbler",
"cobbler",
[
("cobbler/file", True, True),
("cobbler/dir/file", True, True),
],
[
("octane.util.docker.stop_container", "cobbler"),
("octane.util.docker.start_container", "cobbler")
]
),
])
@pytest.mark.parametrize("cls,path,container,backup_name,members", [
(
cobbler.CobblerSystemArchivator,
"/var/lib/cobbler/config/systems.d/",
"cobbler",
"cobbler",
[
("cobbler/file", True, True),
("cobbler/dir/file", True, True),
],
),
(
cobbler.CobblerDistroArchivator,
"/var/lib/cobbler/config/distros.d/",
"cobbler",
"cobbler_distros",
[
("cobbler_distros/file", True, True),
("cobbler_distros/dir/file", True, True),
],
),
(
cobbler.CobblerProfileArchivator,
"/var/lib/cobbler/config/profiles.d/",
"cobbler",
"cobbler_profiles",
[
("cobbler_profiles/file", True, True),
("cobbler_profiles/dir/file", True, True),
],
),
])
def test_container_archivator(
mocker, cls, path, container, members, mock_actions, backup_name):
mocker, cls, path, container, members, backup_name):
docker = mocker.patch("octane.util.docker.write_data_in_docker_file")
extra_mocks = [(mocker.patch(n), p) for n, p in mock_actions]
members = [TestMember(n, f, e) for n, f, e in members]
archive = TestArchive(members, cls)
cls(archive).restore()
@ -184,8 +197,18 @@ def test_container_archivator(
docker.assert_has_calls([
mock.call(container, os.path.join(path, path_restor), member.dump)
])
for extra_mock, param in extra_mocks:
extra_mock.assert_called_once_with(param)
def test_cobbler_archivator(mocker):
mocker.patch.object(cobbler.CobblerSystemArchivator, "restore")
mocker.patch.object(cobbler.CobblerDistroArchivator, "restore")
mocker.patch.object(cobbler.CobblerProfileArchivator, "restore")
stop_container = mocker.patch("octane.util.docker.stop_container")
start_container = mocker.patch("octane.util.docker.start_container")
cobbler.CobblerArchivator(mock.Mock(), mock.Mock()).restore()
stop_container.assert_called_once_with("cobbler")
start_container.assert_called_once_with("cobbler")
@pytest.mark.parametrize("cls,db,sync_db_cmd,mocked_action_name", [